Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static CdmAttributeGroupDefinition FromData(CdmCorpusContext ctx, JToken obj, string entityName = null)
        {
            if (obj == null)
            {
                return(null);
            }
            var attributeGroup = ctx.Corpus.MakeObject <CdmAttributeGroupDefinition>(CdmObjectType.AttributeGroupDef, (string)obj["attributeGroupName"]);

            if (obj["explanation"] != null)
            {
                attributeGroup.Explanation = (string)obj["explanation"];
            }
            attributeGroup.AttributeContext = AttributeContextReferencePersistence.FromData(ctx, obj["attributeContext"]);
            Utils.AddListToCdmCollection(attributeGroup.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, obj["exhibitsTraits"]));
            if (obj["members"] != null)
            {
                foreach (var att in obj["members"])
                {
                    attributeGroup.Members.Add(Utils.CreateAttribute(ctx, att, entityName));
                }
            }

            return(attributeGroup);
        }
        public static CdmAttributeContext FromData(CdmCorpusContext ctx, dynamic obj)
        {
            if (obj == null)
            {
                return(null);
            }

            CdmAttributeContext attributeContext = ctx.Corpus.MakeObject <CdmAttributeContext>(CdmObjectType.AttributeContextDef, obj.Value <string>("name"), false);

            attributeContext.Type = MapTypeNameToEnum(obj.Value <string>("type"));
            if (obj.Value <string>("parent") != null)
            {
                attributeContext.Parent = AttributeContextReferencePersistence.FromData(ctx, obj.Value <string>("parent"));
            }
            string explanation = obj.Value <string>("explanation");

            if (!string.IsNullOrEmpty(explanation))
            {
                attributeContext.Explanation = explanation;
            }
            if (obj.Value <string>("definition") != null)
            {
                switch (attributeContext.Type)
                {
                case CdmAttributeContextType.Entity:
                case CdmAttributeContextType.EntityReferenceExtends:
                    attributeContext.Definition = EntityReferencePersistence.FromData(ctx, obj.Value <string>("definition"));
                    break;

                case CdmAttributeContextType.AttributeGroup:
                    attributeContext.Definition = AttributeGroupReferencePersistence.FromData(ctx, obj.Value <string>("definition"));
                    break;

                case CdmAttributeContextType.AddedAttributeSupporting:
                case CdmAttributeContextType.AddedAttributeIdentity:
                case CdmAttributeContextType.AddedAttributeExpansionTotal:
                case CdmAttributeContextType.AddedAttributeSelectedType:
                case CdmAttributeContextType.AttributeDefinition:
                    attributeContext.Definition = AttributeReferencePersistence.FromData(ctx, obj.Value <string>("definition"));
                    break;
                }
            }
            // i know the trait collection names look wrong. but I wanted to use the def baseclass
            Utils.AddListToCdmCollection(attributeContext.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, obj.Value <JToken>("appliedTraits")));
            if (obj.Value <JToken>("contents") != null)
            {
                for (int i = 0; i < obj.Value <JToken>("contents").Count; i++)
                {
                    JToken ct = obj.Value <JToken>("contents")[i];
                    if (ct is JValue)
                    {
                        attributeContext.Contents.Add(AttributeReferencePersistence.FromData(ctx, (string)ct));
                    }
                    else
                    {
                        attributeContext.Contents.Add(FromData(ctx, ct));
                    }
                }
            }
            return(attributeContext);
        }
        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);
        }