/// <summary> /// Converts a JSON object to an Attribute object /// </summary> public static CdmAttributeItem CreateAttribute(CdmCorpusContext ctx, dynamic obj, string entityName = null) { if (obj == null) { return(null); } if (obj is JValue) { return(AttributeGroupReferencePersistence.FromData(ctx, obj)); } else { if (obj["attributeGroupReference"] != null) { return(AttributeGroupReferencePersistence.FromData(ctx, obj, entityName)); } else if (obj["entity"] != null) { return(EntityAttributePersistence.FromData(ctx, obj)); } else if (obj["name"] != null) { return(TypeAttributePersistence.FromData(ctx, obj, entityName)); } } return(null); }
public static TableEntity ToData(CdmEntityDefinition instance, CdmCorpusContext ctx, ResolveOptions resOpt, CopyOptions options) { var properties = CreateTablePropertyBags(instance, resOpt, options); var columns = new List <DataColumn>(); foreach (var attribute in instance.Attributes) { columns.Add(TypeAttributePersistence.ToData(attribute as CdmTypeAttributeDefinition, ctx, resOpt, options)); } var storageDescriptor = new StorageDescriptor { Source = new DataSource(), Format = new FormatInfo(), Columns = columns }; TableProperties teProperties = new TableProperties { Properties = properties, Partitioning = new TablePartitioning(), StorageDescriptor = storageDescriptor }; return(new TableEntity { Name = instance.EntityName, Type = SASEntityType.TABLE, Properties = teProperties }); }
/// <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 CdmEntityDefinition FromData(CdmCorpusContext ctx, string name, TableEntity table) { if (table == null) { return(null); } TableProperties teProperties = ((JToken)table.Properties).ToObject <TableProperties>(); var entity = ctx.Corpus.MakeObject <CdmEntityDefinition>(CdmObjectType.EntityDef, name); entity.DisplayName = entity.EntityName; if (teProperties.Properties != null) { if (teProperties.Properties.ContainsKey("cdm:explanation")) { entity.Explanation = teProperties.Properties["cdm:explanation"].ToObject <string>(); } if (teProperties.Properties.ContainsKey("cdm:cdmSchemas")) { entity.CdmSchemas = teProperties.Properties["cdm:cdmSchemas"].ToObject <List <string> >(); } if (teProperties.Properties.ContainsKey("cdm:sourceName")) { entity.SourceName = teProperties.Properties["cdm:sourceName"].ToObject <string>(); } if (teProperties.Properties.ContainsKey("cdm:description")) { entity.SourceName = teProperties.Properties["cdm:description"].ToObject <string>(); } if (teProperties.Properties.ContainsKey("cdm:version")) { entity.Version = teProperties.Properties["cdm:version"].ToObject <string>(); } if (teProperties.Properties.ContainsKey("cdm:traits")) { Utils.AddListToCdmCollection(entity.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, teProperties.Properties["cdm:traits"])); } } if (teProperties.StorageDescriptor != null && teProperties.StorageDescriptor.Columns != null) { foreach (var attribute in teProperties.StorageDescriptor.Columns) { var typeAttribute = TypeAttributePersistence.FromData(ctx, attribute, name); if (typeAttribute != null) { entity.Attributes.Add(typeAttribute); } else { Logger.Error((ResolveContext)ctx, Tag, nameof(FromData), null, CdmLogCode.ErrPersistSymsAttrConversionFailure, name, attribute.Name); return(null); } } } else { Logger.Error((ResolveContext)ctx, Tag, nameof(FromData), null, CdmLogCode.ErrPersistSymsAttrConversionError, name); return(null); } return(entity); }