示例#1
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);
        }
示例#2
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);
     }
 }
        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((ResolveContext)ctx, Tag, nameof(FromData), null, CdmLogCode.ErrPersistCardinalityPropMissing);
                }

                if (!CardinalitySettings.IsMinimumValid(minCardinality))
                {
                    Logger.Error((ResolveContext)ctx, Tag, nameof(FromData), null, CdmLogCode.ErrPersistInvalidMinCardinality, minCardinality);
                }

                if (!CardinalitySettings.IsMaximumValid(maxCardinality))
                {
                    Logger.Error((ResolveContext)ctx, Tag, nameof(FromData), null, CdmLogCode.ErrPersistInvalidMaxCardinality, maxCardinality);
                }

                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)
            {
                Logger.Warning((ResolveContext)ctx, Tag, nameof(FromData), null, CdmLogCode.WarnPersistSymsProjNotExist);
            }

            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);
        }