/// <summary> /// Creates a CDM object from a JSON object /// </summary> public static dynamic CreateConstant(CdmCorpusContext ctx, dynamic obj) { if (obj == null) { return(null); } if (obj is JValue) { return(obj.Value); } else if (obj is JObject) { if (obj["purpose"] != null || obj["dataType"] != null || obj["entity"] != null) { if (obj["dataType"] != null) { return(TypeAttributePersistence.FromData(ctx, obj)); } else if (obj["entity"] != null) { return(EntityAttributePersistence.FromData(ctx, obj)); } else { return(null); } } else if (obj["purposeReference"] != null) { return(PurposeReferencePersistence.FromData(ctx, obj)); } else if (obj["traitReference"] != null) { return(TraitReferencePersistence.FromData(ctx, obj)); } else if (obj["dataTypeReference"] != null) { return(DataTypeReferencePersistence.FromData(ctx, obj)); } else if (obj["entityReference"] != null) { return(EntityReferencePersistence.FromData(ctx, obj)); } else if (obj["attributeGroupReference"] != null) { return(AttributeGroupReferencePersistence.FromData(ctx, obj)); } else { return(obj); } } else { return(obj); } }
public static CdmTypeAttributeDefinition FromData(CdmCorpusContext ctx, JToken obj, string entityName = null) { if (obj == null) { return(null); } var typeAttribute = ctx.Corpus.MakeObject <CdmTypeAttributeDefinition>(CdmObjectType.TypeAttributeDef, (string)obj["name"]); typeAttribute.Purpose = PurposeReferencePersistence.FromData(ctx, obj["purpose"]); typeAttribute.DataType = DataTypeReferencePersistence.FromData(ctx, obj["dataType"]); typeAttribute.Cardinality = Utils.CardinalitySettingsFromData(obj["cardinality"], typeAttribute); typeAttribute.AttributeContext = AttributeContextReferencePersistence.FromData(ctx, obj["attributeContext"]); Utils.AddListToCdmCollection(typeAttribute.AppliedTraits, Utils.CreateTraitReferenceList(ctx, obj["appliedTraits"])); typeAttribute.ResolutionGuidance = AttributeResolutionGuidancePersistence.FromData(ctx, obj["resolutionGuidance"]); if (obj["isPrimaryKey"] != null && (bool)obj["isPrimaryKey"] && entityName != null) { TraitToPropertyMap t2pMap = new TraitToPropertyMap(typeAttribute); t2pMap.UpdatePropertyValue("isPrimaryKey", entityName + "/(resolvedAttributes)/" + typeAttribute.Name); } typeAttribute.Explanation = Utils.PropertyFromDataToString(obj["explanation"]); typeAttribute.Description = Utils.PropertyFromDataToString(obj["description"]); typeAttribute.IsReadOnly = Utils.PropertyFromDataToBool(obj["isReadOnly"]); typeAttribute.IsNullable = Utils.PropertyFromDataToBool(obj["isNullable"]); typeAttribute.SourceName = Utils.PropertyFromDataToString(obj["sourceName"]); typeAttribute.SourceOrdering = Utils.PropertyFromDataToInt(obj["sourceOrdering"]); typeAttribute.DisplayName = Utils.PropertyFromDataToString(obj["displayName"]); typeAttribute.ValueConstrainedToList = Utils.PropertyFromDataToBool(obj["valueConstrainedToList"]); typeAttribute.MaximumLength = Utils.PropertyFromDataToInt(obj["maximumLength"]); typeAttribute.MaximumValue = Utils.PropertyFromDataToString(obj["maximumValue"]); typeAttribute.MinimumValue = Utils.PropertyFromDataToString(obj["minimumValue"]); typeAttribute.DefaultValue = obj["defaultValue"]; typeAttribute.Projection = ProjectionPersistence.FromData(ctx, obj["projection"]); var dataFormat = Utils.PropertyFromDataToString(obj["dataFormat"]); if (dataFormat != null) { bool success = Enum.TryParse(dataFormat, true, out CdmDataFormat cdmDataFormat); if (success) { typeAttribute.DataFormat = cdmDataFormat; } else { Logger.Warning(ctx, Tag, nameof(FromData), null, CdmLogCode.WarnPersistEnumNotFound, dataFormat); } } return(typeAttribute); }
public static CdmParameterDefinition FromData(CdmCorpusContext ctx, JToken obj) { var parameter = ctx.Corpus.MakeObject <CdmParameterDefinition>(CdmObjectType.ParameterDef, (string)obj["name"]); parameter.Explanation = (string)obj["explanation"]; parameter.Required = obj["required"] != null ? (bool)obj["required"] : false; parameter.DefaultValue = Utils.CreateConstant(ctx, obj["defaultValue"]); parameter.DataTypeRef = DataTypeReferencePersistence.FromData(ctx, obj["dataType"]); return(parameter); }
public static CdmTypeAttributeDefinition FromData(CdmCorpusContext ctx, JToken obj) { if (obj == null) { return(null); } var typeAttribute = ctx.Corpus.MakeObject <CdmTypeAttributeDefinition>(CdmObjectType.TypeAttributeDef, (string)obj["name"]); typeAttribute.Purpose = PurposeReferencePersistence.FromData(ctx, obj["purpose"]); typeAttribute.DataType = DataTypeReferencePersistence.FromData(ctx, obj["dataType"]); typeAttribute.AttributeContext = AttributeContextReferencePersistence.FromData(ctx, obj["attributeContext"]); Utils.AddListToCdmCollection(typeAttribute.AppliedTraits, Utils.CreateTraitReferenceList(ctx, obj["appliedTraits"])); typeAttribute.ResolutionGuidance = AttributeResolutionGuidancePersistence.FromData(ctx, obj["resolutionGuidance"]); typeAttribute.Explanation = (string)obj["explanation"]; typeAttribute.Description = (string)obj["description"]; typeAttribute.IsReadOnly = (bool?)obj["isReadOnly"]; typeAttribute.IsNullable = (bool?)obj["isNullable"]; typeAttribute.SourceName = (string)obj["sourceName"]; typeAttribute.SourceOrdering = (int?)obj["sourceOrdering"]; typeAttribute.DisplayName = (string)obj["displayName"]; typeAttribute.Description = (string)obj["description"]; typeAttribute.ValueConstrainedToList = (bool?)obj["valueConstrainedToList"]; typeAttribute.MaximumLength = (int?)obj["maximumLength"]; typeAttribute.MaximumValue = (string)obj["maximumValue"]; typeAttribute.MinimumValue = (string)obj["minimumValue"]; var dataFormat = (string)obj["dataFormat"]; if (dataFormat != null) { bool success = Enum.TryParse(dataFormat, out CdmDataFormat cdmDataFormat); if (success) { typeAttribute.DataFormat = cdmDataFormat; } else { Logger.Warning(nameof(TypeAttributePersistence), ctx, $"Couldn't find an enum value for {dataFormat}.", "FromData"); } } typeAttribute.DefaultValue = obj["defaultValue"]; return(typeAttribute); }
public static CdmDataTypeDefinition FromData(CdmCorpusContext ctx, JToken obj) { if (obj == null) { return(null); } CdmDataTypeDefinition dataType = ctx.Corpus.MakeObject <CdmDataTypeDefinition>(CdmObjectType.DataTypeDef, (string)obj["dataTypeName"]); dataType.ExtendsDataType = DataTypeReferencePersistence.FromData(ctx, obj["extendsDataType"]); if (obj["explanation"] != null) { dataType.Explanation = (string)obj["explanation"]; } Utils.AddListToCdmCollection(dataType.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, obj["exhibitsTraits"])); return(dataType); }
public static CdmTypeAttributeDefinition FromData(CdmCorpusContext ctx, JToken obj, string entityName = null) { if (obj == null) { return(null); } var typeAttribute = ctx.Corpus.MakeObject <CdmTypeAttributeDefinition>(CdmObjectType.TypeAttributeDef, (string)obj["name"]); typeAttribute.Purpose = PurposeReferencePersistence.FromData(ctx, obj["purpose"]); typeAttribute.DataType = DataTypeReferencePersistence.FromData(ctx, obj["dataType"]); if (obj["cardinality"] != null) { string minCardinality = null; if (obj["cardinality"]["minimum"] != null) { minCardinality = (string)obj["cardinality"]["minimum"]; } string maxCardinality = null; if (obj["cardinality"]["maximum"] != null) { maxCardinality = (string)obj["cardinality"]["maximum"]; } if (string.IsNullOrWhiteSpace(minCardinality) || string.IsNullOrWhiteSpace(maxCardinality)) { Logger.Error(nameof(TypeAttributePersistence), ctx, $"Both minimum and maximum are required for the Cardinality property.", nameof(FromData)); } if (!CardinalitySettings.IsMinimumValid(minCardinality)) { Logger.Error(nameof(TypeAttributePersistence), ctx, $"Invalid minimum cardinality {minCardinality}.", nameof(FromData)); } if (!CardinalitySettings.IsMaximumValid(maxCardinality)) { Logger.Error(nameof(TypeAttributePersistence), ctx, $"Invalid maximum cardinality {maxCardinality}.", nameof(FromData)); } if (!string.IsNullOrWhiteSpace(minCardinality) && !string.IsNullOrWhiteSpace(maxCardinality) && CardinalitySettings.IsMinimumValid(minCardinality) && CardinalitySettings.IsMinimumValid(maxCardinality)) { typeAttribute.Cardinality = new CardinalitySettings(typeAttribute) { Minimum = minCardinality, Maximum = maxCardinality }; } } typeAttribute.AttributeContext = AttributeContextReferencePersistence.FromData(ctx, obj["attributeContext"]); Utils.AddListToCdmCollection(typeAttribute.AppliedTraits, Utils.CreateTraitReferenceList(ctx, obj["appliedTraits"])); typeAttribute.ResolutionGuidance = AttributeResolutionGuidancePersistence.FromData(ctx, obj["resolutionGuidance"]); if (obj["isPrimaryKey"] != null && (bool)obj["isPrimaryKey"] && entityName != null) { TraitToPropertyMap t2pMap = new TraitToPropertyMap(typeAttribute); t2pMap.UpdatePropertyValue("isPrimaryKey", entityName + "/(resolvedAttributes)/" + typeAttribute.Name); } typeAttribute.Explanation = Utils.PropertyFromDataToString(obj["explanation"]); typeAttribute.Description = Utils.PropertyFromDataToString(obj["description"]); typeAttribute.IsReadOnly = Utils.PropertyFromDataToBool(obj["isReadOnly"]); typeAttribute.IsNullable = Utils.PropertyFromDataToBool(obj["isNullable"]); typeAttribute.SourceName = Utils.PropertyFromDataToString(obj["sourceName"]); typeAttribute.SourceOrdering = Utils.PropertyFromDataToInt(obj["sourceOrdering"]); typeAttribute.DisplayName = Utils.PropertyFromDataToString(obj["displayName"]); typeAttribute.ValueConstrainedToList = Utils.PropertyFromDataToBool(obj["valueConstrainedToList"]); typeAttribute.MaximumLength = Utils.PropertyFromDataToInt(obj["maximumLength"]); typeAttribute.MaximumValue = Utils.PropertyFromDataToString(obj["maximumValue"]); typeAttribute.MinimumValue = Utils.PropertyFromDataToString(obj["minimumValue"]); typeAttribute.DefaultValue = obj["defaultValue"]; typeAttribute.Projection = ProjectionPersistence.FromData(ctx, obj["projection"]); var dataFormat = Utils.PropertyFromDataToString(obj["dataFormat"]); if (dataFormat != null) { bool success = Enum.TryParse(dataFormat, true, out CdmDataFormat cdmDataFormat); if (success) { typeAttribute.DataFormat = cdmDataFormat; } else { Logger.Warning(nameof(TypeAttributePersistence), ctx, $"Couldn't find an enum value for {dataFormat}.", nameof(FromData)); } } return(typeAttribute); }