Exemple #1
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);
        }
Exemple #2
0
        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 (!StringUtils.IsBlankByCdmStandard(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));
                    }
                }
            }
            if (obj.Value <JToken>("lineage") != null)
            {
                attributeContext.Lineage = new CdmCollection <CdmAttributeContextReference>(ctx, attributeContext, CdmObjectType.AttributeContextRef);
                for (int i = 0; i < obj.Value <JToken>("lineage").Count; i++)
                {
                    JToken ct = obj.Value <JToken>("lineage")[i];
                    attributeContext.Lineage.Add(AttributeContextReferencePersistence.FromData(ctx, ct));
                }
            }

            return(attributeContext);
        }