internal static bool IsSearchableProperty(string propertyPath, out KClass kClass, DocumentValidator documentValidator) { kClass = null; var objectPathArray = propertyPath.ToLower().Split('.'); if (objectPathArray.Length > 1 && documentValidator != null && documentValidator.entities != null && documentValidator.entities.Count > 0) { var obClass = new KClass(); var obProperty = new KProperty(); IList <KClass> allClasses = null; if (documentValidator.entities.Keys.Any(x => x == objectPathArray[0].ToLower())) { allClasses = documentValidator.entities[objectPathArray[0].ToLower()].Classes; } else if (documentValidator.entities.First().Value.Classes.Any(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == objectPathArray[0].ToLower())) { allClasses = documentValidator.entities.First().Value.Classes; } if (allClasses != null && allClasses.Any()) { var dataTypeClasses = Kitsune.Helper.Constants.DataTypeClasses; for (var i = 0; i < objectPathArray.Length; i++) { if (i == 0) { obClass = allClasses.FirstOrDefault(x => x.ClassType == KClassType.BaseClass && x.Name == objectPathArray[i]); if (obClass == null) { return(false); } } else { obProperty = obClass.PropertyList.FirstOrDefault(x => x.Name.ToLower() == objectPathArray[i]); if (obProperty == null) { return(false); } else if ((obProperty.Type == PropertyType.array && !dataTypeClasses.Contains(obProperty.DataType?.Name?.ToLower())) || obProperty.Type == PropertyType.obj) { obClass = allClasses.FirstOrDefault(x => x.ClassType == KClassType.UserDefinedClass && x.Name?.ToLower() == obProperty.DataType?.Name?.ToLower()); } else { return(false); } } } if (obClass != null) { kClass = obClass; if (obProperty != null && obProperty.Type == PropertyType.array) { return(true); } } } } return(false); }
internal KProperty GetProperty(string expression, KEntity entity) { KProperty kProperty = null; KClass kClass = null; string[] classHierarchyList = expression.Split('.'); if (entity != null) { kClass = entity.Classes.Where(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == classHierarchyList[0].ToLower()).FirstOrDefault(); if (kClass == null) { return(null); } for (int i = 1; i < classHierarchyList.Length - 1; i++) { string propName = classHierarchyList[i].Split('[')[0]; KProperty prop = kClass.PropertyList.Where(x => x.Name.ToLower() == propName.ToLower()).FirstOrDefault(); if (prop == null) { return(null); } kClass = entity.Classes.Where(x => x.Name.ToLower() == prop.DataType.Name.ToLower()).FirstOrDefault(); if (kClass == null) { return(null); } } string finalPropName = classHierarchyList[classHierarchyList.Length - 1].Split('[')[0].ToLower(); kProperty = kClass.PropertyList.Where(x => x.Name == finalPropName).FirstOrDefault(); } return(kProperty); }
internal static KClass childClasses(dynamic jsonObject, List <KClass> subclasses) { try { if (jsonObject != null) { var propertyList = jsonObject["PropertyList"]; var tempClass = new KClass() { ClassType = (KClassType)jsonObject["ClassType"].Value, Name = jsonObject["Name"].Value, Description = jsonObject["Name"].Value, IsCustom = true, }; var tempPropertyList = new List <KProperty>(); foreach (var tempArray in propertyList) { var property = new KProperty(); var typeExists = DynamicFieldExists(tempArray, "Type"); if (typeExists) { var propType = tempArray["Type"]; property.Type = (PropertyType)tempArray["Type"].Value; property.Name = tempArray["Name"].Value; if (property.Type == PropertyType.array) { var propertyName = tempArray["DataType"]; property.DataType = new DataType(propertyName["Name"].Value.ToString()); } tempPropertyList.Add(property); } else { property.Name = tempArray["Name"].Value; property.Type = PropertyType.obj; property.DataType = new DataType(tempArray["Name"].Value.ToString()); tempPropertyList.Add(property); DeeperClasses(tempArray, subclasses); } var tempObject = tempArray; } tempClass.PropertyList = tempPropertyList; return(tempClass); } } catch (Exception ex) { } return(null); }
public static bool IsSearchableProperty(string propertyPath, KEntity entity, out KClass kClass) { kClass = null; var objectPathArray = propertyPath.ToLower().Split('.'); if (objectPathArray.Length > 1) { var obClass = new KClass(); var obProperty = new KProperty(); var dataTypeClasses = Kitsune.Helper.Constants.DataTypeClasses; for (var i = 0; i < objectPathArray.Length; i++) { if (i == 0) { obClass = entity.Classes.FirstOrDefault(x => x.ClassType == KClassType.BaseClass && x.Name == objectPathArray[i]); if (obClass == null) { return(false); } } else { obProperty = obClass.PropertyList.FirstOrDefault(x => x.Name.ToLower() == objectPathArray[i]); if (obProperty == null) { return(false); } else if ((obProperty.Type == PropertyType.array && !dataTypeClasses.Contains(obProperty.DataType?.Name?.ToLower())) || obProperty.Type == PropertyType.obj) { obClass = entity.Classes.FirstOrDefault(x => x.ClassType == KClassType.UserDefinedClass && x.Name?.ToLower() == obProperty.DataType?.Name?.ToLower()); } else { return(false); } } } if (obClass != null) { kClass = obClass; if (obProperty != null && obProperty.Type == PropertyType.array) { return(true); } } } return(false); }
internal KProperty GetProperty(List <CompilerError> compileErrors, HtmlAttribute dynamicAttribute, DocumentValidator documentValidator, string referenceObject, Dictionary <string, string> classNameAlias) { KProperty kProperty = null; KClass kClass = null; string expression = referenceObject; string baseExpression = expression.Split('.')[0].Split('[')[0].ToLower(); while (baseExpression != "kresult" && baseExpression != "search" && classNameAlias.ContainsKey(baseExpression)) { string[] expressionParts = expression.Split('.'); expressionParts[0] = classNameAlias[baseExpression]; expression = String.Join(".", expressionParts); baseExpression = expression.Split('.')[0].Split('[')[0].ToLower(); } string[] classHierarchyList = expression.Split('.'); KEntity entity = documentValidator?.GetKEntityFromEntityName(classHierarchyList[0]) ?? documentValidator?.GetKEntityFromEntityName(documentValidator.defaultEntity); if (entity != null) { kClass = entity.Classes.Where(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == classHierarchyList[0].ToLower()).FirstOrDefault(); if (kClass == null) { compileErrors.Add(CompileResultHelper.GetCompileError(String.Format(ErrorCodeConstants.UnrecognizedType, classHierarchyList[0]), dynamicAttribute.Line, dynamicAttribute.LinePosition)); return(null); } for (int i = 1; i < classHierarchyList.Length - 1; i++) { string propName = classHierarchyList[i].Split('[')[0]; KProperty prop = kClass.PropertyList.Where(x => x.Name.ToLower() == propName.ToLower()).FirstOrDefault(); if (prop == null) { compileErrors.Add(CompileResultHelper.GetCompileError(String.Format(ErrorCodeConstants.UnrecognizedProperty, propName), dynamicAttribute.Line, dynamicAttribute.LinePosition)); return(null); } kClass = entity.Classes.Where(x => x.Name.ToLower() == prop.DataType.Name.ToLower()).FirstOrDefault(); if (kClass == null) { compileErrors.Add(CompileResultHelper.GetCompileError(String.Format(ErrorCodeConstants.UnrecognizedType, prop.DataType.Name), dynamicAttribute.Line, dynamicAttribute.LinePosition)); return(null); } } string finalPropName = classHierarchyList[classHierarchyList.Length - 1].Split('[')[0].ToLower(); kProperty = kClass.PropertyList.Where(x => x.Name == finalPropName && x.Type == PropertyType.array).FirstOrDefault(); } return(kProperty); }
public IActionResult CreateDataTypeClass([FromRoute] string languageId, [FromBody] KClass dataClas) { try { var userId = string.Empty; if (Request.Headers.ContainsKey("Authorization")) { userId = Request.Headers.ContainsKey("Authorization") ? Request.Headers["Authorization"].ToString() : userId; } var tempCommand = new CreateDatatypeEntityRequestModel() { Datatype = dataClas, UserId = userId, LanguageId = languageId }; // ClassType should be UserDefined for all user defined class tempCommand.Datatype.ClassType = KClassType.UserDefinedClass; List <System.ComponentModel.DataAnnotations.ValidationResult> validationResult = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); if (dataClas == null) { validationResult.Add(new System.ComponentModel.DataAnnotations.ValidationResult("DataClass can not be null")); } else if (string.IsNullOrEmpty(dataClas.Name)) { validationResult.Add(new System.ComponentModel.DataAnnotations.ValidationResult("Class name can not be null")); } if (validationResult.Any()) { return(BadRequest(validationResult)); } return(Ok(MongoConnector.CreateDataClass(new CreateDatatypeEntityRequestModel { Datatype = dataClas, LanguageId = languageId, UserId = userId }))); } catch (Exception ex) { return(BadRequest(ex)); } }
private static string UpdateIterator(string referenceObject, DocumentValidator documentValidator) { var properties = referenceObject.Split('.'); var kobjClass = new KClass(); var result = properties[0]; var searchableProperty = properties[0]; for (var i = 0; i < properties.Length; i++) { if (IsSearchableProperty(searchableProperty, out kobjClass, documentValidator)) { result += "[k_obj_" + i + "]"; } if (i < properties.Length - 1) { searchableProperty += "." + properties[i + 1]; result += ("." + properties[i + 1]); } } return(result); }
public static List <PropertyPathSegment> ExtractPropertiesFromPath(string propertyPath, KEntity entity) { List <PropertyPathSegment> kProperties = new List <PropertyPathSegment>(); var objectPathArray = propertyPath.ToLower().Split('.'); var obClass = new KClass(); var obProperty = new KProperty(); var dataTypeClasses = new string[] { "str", "date", "number", "boolean", "kstring" }; var currentProperty = string.Empty; var arrayRegex = new System.Text.RegularExpressions.Regex(@".*\[(\d+)\]", System.Text.RegularExpressions.RegexOptions.Compiled); var functionRegex = new System.Text.RegularExpressions.Regex(@"(\w+)\((.*)\)", System.Text.RegularExpressions.RegexOptions.Compiled); int?arrayIndex = 0; int tempIndex = 0; System.Text.RegularExpressions.Match arrayMatch = null; System.Text.RegularExpressions.Match functionMatch = null; for (var i = 0; i < objectPathArray.Length; i++) { currentProperty = objectPathArray[i]; arrayMatch = arrayRegex.Match(currentProperty); arrayIndex = null; if (arrayMatch != null && arrayMatch.Success) { if (int.TryParse(arrayMatch.Groups[1].Value, out tempIndex)) { arrayIndex = tempIndex; } currentProperty = currentProperty.Substring(0, currentProperty.IndexOf('[')); } if (i == 0) { obClass = entity.Classes.FirstOrDefault(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == currentProperty); if (obClass != null) { kProperties.Add(new PropertyPathSegment { PropertyDataType = obClass.Name.ToLower(), PropertyName = currentProperty, Type = PropertyType.obj }); } } else { obProperty = obClass.PropertyList.FirstOrDefault(x => x.Name.ToLower() == currentProperty); if (obProperty != null) { if ((obProperty.Type == PropertyType.array && !dataTypeClasses.Contains(obProperty.DataType?.Name?.ToLower())) || obProperty.Type == PropertyType.obj || obProperty.Type == PropertyType.kstring || obProperty.Type == PropertyType.phonenumber) { kProperties.Add(new PropertyPathSegment { PropertyName = obProperty.Name.ToLower(), PropertyDataType = obProperty.DataType.Name.ToLower(), Index = arrayIndex, Type = obProperty.Type }); obClass = entity.Classes.FirstOrDefault(x => x.Name?.ToLower() == obProperty.DataType?.Name?.ToLower()); } else { kProperties.Add(new PropertyPathSegment { PropertyName = obProperty.Name.ToLower(), PropertyDataType = obProperty.DataType.Name.ToLower(), Index = arrayIndex, Type = obProperty.Type }); } } else { functionMatch = functionRegex.Match(currentProperty); if (functionMatch.Success) { kProperties.Add(new PropertyPathSegment { PropertyName = functionMatch.Groups[1].Value, PropertyDataType = "function", Type = PropertyType.function }); } } } } return(kProperties); }
public KEntity GetKitsuneLanguage(string userEmail, string projectId, GetProjectDetailsResponseModel projectDetails, KEntity language, string userId) { if (language == null) { language = new KEntity() { Classes = new List <KClass>(), EntityName = "_system" } } ; if (projectDetails != null && language != null) { var entityTemp = language; UpdateClassViews(userEmail, projectDetails, entityTemp); #region WebAction var webActions = new WebActionAPI().GetWebActionList(userId).Result; var webActionBaseClass = new KClass { ClassType = KClassType.BaseClass, Description = "Webaction", Name = "webactions", }; IList <KProperty> PropertyList = new List <KProperty>(); IList <KClass> webactionClassList = new List <KClass>(); KClass webactionClass; if (webActions != null && webActions.WebActions != null) { foreach (var webaction in webActions.WebActions) { //Webactions.webactionname PropertyList.Add(new KProperty { DataType = new DataType("wa" + webaction.Name.ToLower()), Description = webaction.Name, Name = webaction.Name.ToLower(), Type = PropertyType.array }); //Datatype (class) of the specific webaction webactionClass = new KClass { ClassType = KClassType.UserDefinedClass, Description = "Webaction products", Name = "wa" + webaction.Name.ToLower(), PropertyList = webaction.Properties.Select(x => new KProperty { DataType = new DataType(x.DataType), Description = x.DisplayName, Name = x.PropertyName.ToLower(), Type = ConvertProperty(x.PropertyType), IsRequired = x.IsRequired }).ToList() }; webactionClass.PropertyList.Add(new KProperty { DataType = new DataType("STR"), Description = "Id", Name = "_id", Type = PropertyType.str }); webactionClass.PropertyList.Add(new KProperty { DataType = new DataType("DATE"), Description = "Created on", Name = "createdon", Type = PropertyType.date }); webactionClass.PropertyList.Add(new KProperty { DataType = new DataType("DATE"), Description = "Updated on", Name = "updatedon", Type = PropertyType.date }); entityTemp.Classes.Add(webactionClass); } } webActionBaseClass.PropertyList = PropertyList; entityTemp.Classes.Add(webActionBaseClass); #endregion if (projectId == projectDetails.ProjectId) { language = entityTemp; } } return(language); }