Пример #1
0
 /// <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);
     }
 }
Пример #2
0
        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);
        }
Пример #3
0
        public static CdmPurposeDefinition FromData(CdmCorpusContext ctx, JToken obj)
        {
            var purpose = ctx.Corpus.MakeObject <CdmPurposeDefinition>(CdmObjectType.PurposeDef, (string)obj["purposeName"]);

            purpose.ExtendsPurpose = PurposeReferencePersistence.FromData(ctx, obj["extendsPurpose"]);
            if (obj["explanation"] != null)
            {
                purpose.Explanation = (string)obj["explanation"];
            }
            Utils.AddListToCdmCollection(purpose.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, obj["exhibitsTraits"]));
            return(purpose);
        }
Пример #4
0
        public static CdmEntityAttributeDefinition FromData(CdmCorpusContext ctx, JToken obj)
        {
            var entityAttribute = ctx.Corpus.MakeObject <CdmEntityAttributeDefinition>(CdmObjectType.EntityAttributeDef, (string)obj["name"]);

            if (obj["explanation"] != null)
            {
                entityAttribute.Explanation = (string)obj["explanation"];
            }

            entityAttribute.Entity = EntityReferencePersistence.FromData(ctx, obj["entity"]);

            entityAttribute.Purpose = PurposeReferencePersistence.FromData(ctx, obj["purpose"]);
            Utils.AddListToCdmCollection(entityAttribute.AppliedTraits, Utils.CreateTraitReferenceList(ctx, obj["appliedTraits"]));
            entityAttribute.ResolutionGuidance = AttributeResolutionGuidancePersistence.FromData(ctx, obj["resolutionGuidance"]);
            return(entityAttribute);
        }
Пример #5
0
        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);
        }
Пример #6
0
        public static CdmEntityAttributeDefinition FromData(CdmCorpusContext ctx, JToken obj)
        {
            var entityAttribute = ctx.Corpus.MakeObject <CdmEntityAttributeDefinition>(CdmObjectType.EntityAttributeDef, (string)obj["name"]);

            entityAttribute.Description = Utils.PropertyFromDataToString(obj["description"]);
            entityAttribute.DisplayName = Utils.PropertyFromDataToString(obj["displayName"]);
            entityAttribute.Explanation = Utils.PropertyFromDataToString(obj["explanation"]);

            entityAttribute.Cardinality = Utils.CardinalitySettingsFromData(obj["cardinality"], entityAttribute);

            entityAttribute.IsPolymorphicSource = (bool?)obj["isPolymorphicSource"];

            bool isProjection = obj["entity"] != null &&
                                !(obj["entity"] is JValue) &&
                                obj["entity"]["source"] != null;

            if (isProjection)
            {
                CdmEntityReference inlineEntityRef = ctx.Corpus.MakeObject <CdmEntityReference>(CdmObjectType.EntityRef, null);
                inlineEntityRef.ExplicitReference = ProjectionPersistence.FromData(ctx, obj["entity"]);
                entityAttribute.Entity            = inlineEntityRef;
            }
            else
            {
                entityAttribute.Entity = EntityReferencePersistence.FromData(ctx, obj["entity"]);
            }

            entityAttribute.Purpose = PurposeReferencePersistence.FromData(ctx, obj["purpose"]);
            Utils.AddListToCdmCollection(entityAttribute.AppliedTraits, Utils.CreateTraitReferenceList(ctx, obj["appliedTraits"]));
            // ignore resolution guidance if the entity is a projection
            if (obj["resolutionGuidance"] != null && isProjection)
            {
                Logger.Error((ResolveContext)ctx, Tag, nameof(FromData), null, CdmLogCode.ErrPersistEntityAttrUnsupported, entityAttribute.Name);
            }
            else
            {
                entityAttribute.ResolutionGuidance = AttributeResolutionGuidancePersistence.FromData(ctx, obj["resolutionGuidance"]);
            }
            return(entityAttribute);
        }
        public static CdmEntityAttributeDefinition FromData(CdmCorpusContext ctx, JToken obj)
        {
            var entityAttribute = ctx.Corpus.MakeObject <CdmEntityAttributeDefinition>(CdmObjectType.EntityAttributeDef, (string)obj["name"]);

            entityAttribute.Description = Utils.PropertyFromDataToString(obj["description"]);
            entityAttribute.DisplayName = Utils.PropertyFromDataToString(obj["displayName"]);
            entityAttribute.Explanation = Utils.PropertyFromDataToString(obj["explanation"]);

            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(EntityAttributePersistence), ctx, $"Both minimum and maximum are required for the Cardinality property.", nameof(FromData));
                }

                if (!CardinalitySettings.IsMinimumValid(minCardinality))
                {
                    Logger.Error(nameof(EntityAttributePersistence), ctx, $"Invalid minimum cardinality {minCardinality}.", nameof(FromData));
                }

                if (!CardinalitySettings.IsMaximumValid(maxCardinality))
                {
                    Logger.Error(nameof(EntityAttributePersistence), ctx, $"Invalid maximum cardinality {maxCardinality}.", nameof(FromData));
                }

                if (!string.IsNullOrWhiteSpace(minCardinality) &&
                    !string.IsNullOrWhiteSpace(maxCardinality) &&
                    CardinalitySettings.IsMinimumValid(minCardinality) &&
                    CardinalitySettings.IsMinimumValid(maxCardinality))
                {
                    entityAttribute.Cardinality = new CardinalitySettings(entityAttribute)
                    {
                        Minimum = minCardinality,
                        Maximum = maxCardinality
                    };
                }
            }

            entityAttribute.IsPolymorphicSource = (bool?)obj["isPolymorphicSource"];

            bool isProjection = obj["entity"] != null &&
                                !(obj["entity"] is JValue) &&
                                obj["entity"]["source"] != null;

            if (isProjection)
            {
                CdmProjection projection = ProjectionPersistence.FromData(ctx, obj["entity"]);
                projection.Owner = entityAttribute;

                CdmEntityReference inlineEntityRef = ctx.Corpus.MakeObject <CdmEntityReference>(CdmObjectType.EntityRef, null);
                inlineEntityRef.ExplicitReference = projection;
                entityAttribute.Entity            = inlineEntityRef;
            }
            else
            {
                entityAttribute.Entity = EntityReferencePersistence.FromData(ctx, obj["entity"]);
            }

            entityAttribute.Purpose = PurposeReferencePersistence.FromData(ctx, obj["purpose"]);
            Utils.AddListToCdmCollection(entityAttribute.AppliedTraits, Utils.CreateTraitReferenceList(ctx, obj["appliedTraits"]));
            // ignore resolution guidance if the entity is a projection
            if (obj["resolutionGuidance"] != null && isProjection)
            {
                Logger.Error(nameof(EntityAttributePersistence), ctx, $"The EntityAttribute {entityAttribute.Name} is projection based. Resolution guidance is not supported with a projection.");
            }
            else
            {
                entityAttribute.ResolutionGuidance = AttributeResolutionGuidancePersistence.FromData(ctx, obj["resolutionGuidance"]);
            }
            return(entityAttribute);
        }
Пример #8
0
        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);
        }