Example #1
0
        public static CdmLocalEntityDeclarationDefinition FromData(CdmCorpusContext ctx, string prefixPath, JToken obj)
        {
            var localDec = ctx.Corpus.MakeObject <CdmLocalEntityDeclarationDefinition>(
                CdmObjectType.LocalEntityDeclarationDef,
                (string)obj["entityName"]);

            string entityPath = obj.Value <string>("entityPath");

            // Check for the old format, it has to be there then.
            if (entityPath == null)
            {
                entityPath = obj.Value <string>("entitySchema");

                if (entityPath == null)
                {
                    Logger.Error(nameof(LocalEntityDeclarationPersistence), ctx, "Couldn't find entity path or similar.", "FromData");
                }
            }

            localDec.EntityPath = entityPath;

            if (!string.IsNullOrWhiteSpace(obj.Value <string>("lastChildFileModifiedTime")))
            {
                localDec.LastChildFileModifiedTime = DateTimeOffset.Parse(obj.Value <string>("lastChildFileModifiedTime"));
            }

            if (!string.IsNullOrWhiteSpace(obj.Value <string>("lastFileModifiedTime")))
            {
                localDec.LastFileModifiedTime = DateTimeOffset.Parse(obj.Value <string>("lastFileModifiedTime"));
            }

            if (!string.IsNullOrWhiteSpace(obj.Value <string>("lastFileStatusCheckTime")))
            {
                localDec.LastFileStatusCheckTime = DateTimeOffset.Parse(obj.Value <string>("lastFileStatusCheckTime"));
            }

            if (obj["explanation"] != null)
            {
                localDec.Explanation = (string)obj["explanation"];
            }

            if (obj["exhibitsTraits"] != null)
            {
                Utils.AddListToCdmCollection(localDec.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, obj["exhibitsTraits"]));
            }

            if (obj["dataPartitions"] != null)
            {
                foreach (var dataPartition in obj["dataPartitions"])
                {
                    localDec.DataPartitions.Add(DataPartitionPersistence.FromData(ctx, dataPartition));
                }
            }

            if (obj["dataPartitionPatterns"] != null)
            {
                foreach (var pattern in obj["dataPartitionPatterns"])
                {
                    localDec.DataPartitionPatterns.Add(DataPartitionPatternPersistence.FromData(ctx, pattern));
                }
            }

            return(localDec);
        }
        public static CdmLocalEntityDeclarationDefinition FromData(CdmCorpusContext ctx, string prefixPath, JToken obj)
        {
            var localDec = ctx.Corpus.MakeObject <CdmLocalEntityDeclarationDefinition>(
                CdmObjectType.LocalEntityDeclarationDef,
                (string)obj["entityName"]);

            string entityPath = obj.Value <string>("entityPath");

            // Check for the old format, it has to be there then.
            if (entityPath == null)
            {
                entityPath = obj.Value <string>("entitySchema");

                if (entityPath == null)
                {
                    Logger.Error(ctx, Tag, nameof(FromData), null, CdmLogCode.ErrPersistEntityPathNotFound, (string)obj["entityName"]);
                }
            }

            localDec.EntityPath = entityPath;

            if (!string.IsNullOrWhiteSpace(obj.Value <string>("lastChildFileModifiedTime")))
            {
                localDec.LastChildFileModifiedTime = DateTimeOffset.Parse(obj["lastChildFileModifiedTime"].ToString());
            }

            if (!string.IsNullOrWhiteSpace(obj.Value <string>("lastFileModifiedTime")))
            {
                localDec.LastFileModifiedTime = DateTimeOffset.Parse(obj["lastFileModifiedTime"].ToString());
            }

            if (!string.IsNullOrWhiteSpace(obj.Value <string>("lastFileStatusCheckTime")))
            {
                localDec.LastFileStatusCheckTime = DateTimeOffset.Parse(obj["lastFileStatusCheckTime"].ToString());
            }

            if (obj["explanation"] != null)
            {
                localDec.Explanation = (string)obj["explanation"];
            }

            Utils.AddListToCdmCollection(localDec.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, obj["exhibitsTraits"]));

            if (obj["dataPartitions"] != null)
            {
                foreach (var dataPartition in obj["dataPartitions"])
                {
                    var dataPartitionDef = DataPartitionPersistence.FromData(ctx, dataPartition);
                    if (dataPartitionDef.IsIncremental)
                    {
                        ErrorMessage((ResolveContext)ctx, nameof(FromData), null, dataPartitionDef, true);
                    }
                    else
                    {
                        localDec.DataPartitions.Add(dataPartitionDef);
                    }
                }
            }

            if (obj["dataPartitionPatterns"] != null)
            {
                foreach (var pattern in obj["dataPartitionPatterns"])
                {
                    var dataPartitionPatternDef = DataPartitionPatternPersistence.FromData(ctx, pattern);
                    if (dataPartitionPatternDef.IsIncremental)
                    {
                        ErrorMessage((ResolveContext)ctx, nameof(FromData), null, dataPartitionPatternDef, true);
                    }
                    else
                    {
                        localDec.DataPartitionPatterns.Add(dataPartitionPatternDef);
                    }
                }
            }

            if (obj["incrementalPartitions"] != null)
            {
                foreach (var incrementalPartition in obj["incrementalPartitions"])
                {
                    var incrementalPartitionDef = DataPartitionPersistence.FromData(ctx, incrementalPartition);
                    if (!incrementalPartitionDef.IsIncremental)
                    {
                        ErrorMessage((ResolveContext)ctx, nameof(FromData), null, incrementalPartitionDef, false);
                    }
                    else
                    {
                        localDec.IncrementalPartitions.Add(incrementalPartitionDef);
                    }
                }
            }

            if (obj["incrementalPartitionPatterns"] != null)
            {
                foreach (var incrementalPattern in obj["incrementalPartitionPatterns"])
                {
                    var incrementalPartitionPatternDef = DataPartitionPatternPersistence.FromData(ctx, incrementalPattern);
                    if (!incrementalPartitionPatternDef.IsIncremental)
                    {
                        ErrorMessage((ResolveContext)ctx, nameof(FromData), null, incrementalPartitionPatternDef, false);
                    }
                    else
                    {
                        localDec.IncrementalPartitionPatterns.Add(incrementalPartitionPatternDef);
                    }
                }
            }

            return(localDec);
        }