Esempio n. 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["traitGroupReference"] != null)
         {
             return(TraitGroupReferencePersistence.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);
     }
 }
Esempio n. 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);
        }