Beispiel #1
0
        public ContentCommandMiddlewareTests()
        {
            var schemaDef = new Schema("my-schema");

            schemaDef.AddField(new NumberField(1, "my-field1", Partitioning.Invariant,
                                               new NumberFieldProperties {
                IsRequired = true
            }));
            schemaDef.AddField(new NumberField(2, "my-field2", Partitioning.Invariant,
                                               new NumberFieldProperties {
                IsRequired = false
            }));

            content = new ContentDomainObject(contentId, -1);

            sut = new ContentCommandMiddleware(Handler, appProvider, A.Dummy <IAssetRepository>(), schemas, scriptEngine, A.Dummy <IContentRepository>());

            A.CallTo(() => app.LanguagesConfig).Returns(languagesConfig);
            A.CallTo(() => app.PartitionResolver).Returns(languagesConfig.ToResolver());

            A.CallTo(() => appProvider.FindAppByIdAsync(AppId)).Returns(app);

            A.CallTo(() => schema.SchemaDef).Returns(schemaDef);
            A.CallTo(() => schema.ScriptCreate).Returns("<create-script>");
            A.CallTo(() => schema.ScriptChange).Returns("<change-script>");
            A.CallTo(() => schema.ScriptUpdate).Returns("<update-script>");
            A.CallTo(() => schema.ScriptDelete).Returns("<delete-script>");

            A.CallTo(() => schemas.FindSchemaByIdAsync(SchemaId, false)).Returns(schema);
        }
Beispiel #2
0
        public GuardSchemaTests()
        {
            schema.AddField(new StringField(1, "field1", Partitioning.Invariant));
            schema.AddField(new StringField(2, "field2", Partitioning.Invariant));

            A.CallTo(() => schemas.FindSchemaByNameAsync(A <Guid> .Ignored, "new-schema"))
            .Returns(Task.FromResult <ISchemaEntity>(null));
        }
Beispiel #3
0
        public GraphQLTests()
        {
            schemaDef.AddField(new JsonField(1, "my-json", Partitioning.Invariant,
                                             new JsonFieldProperties()));

            schemaDef.AddField(new StringField(2, "my-string", Partitioning.Language,
                                               new StringFieldProperties()));

            schemaDef.AddField(new NumberField(3, "my-number", Partitioning.Invariant,
                                               new NumberFieldProperties()));

            schemaDef.AddField(new AssetsField(4, "my-assets", Partitioning.Invariant,
                                               new AssetsFieldProperties()));

            schemaDef.AddField(new BooleanField(5, "my-boolean", Partitioning.Invariant,
                                                new BooleanFieldProperties()));

            schemaDef.AddField(new DateTimeField(6, "my-datetime", Partitioning.Invariant,
                                                 new DateTimeFieldProperties()));

            schemaDef.AddField(new ReferencesField(7, "my-references", Partitioning.Invariant,
                                                   new ReferencesFieldProperties {
                SchemaId = schemaId
            }));

            schemaDef.AddField(new ReferencesField(9, "my-invalid", Partitioning.Invariant,
                                                   new ReferencesFieldProperties {
                SchemaId = Guid.NewGuid()
            }));

            schemaDef.AddField(new GeolocationField(10, "my-geolocation", Partitioning.Invariant,
                                                    new GeolocationFieldProperties()));

            schemaDef.AddField(new TagsField(11, "my-tags", Partitioning.Invariant,
                                             new TagsFieldProperties()));

            A.CallTo(() => app.Id).Returns(appId);
            A.CallTo(() => app.PartitionResolver).Returns(x => InvariantPartitioning.Instance);

            A.CallTo(() => schema.Id).Returns(schemaId);
            A.CallTo(() => schema.Name).Returns(schemaDef.Name);
            A.CallTo(() => schema.SchemaDef).Returns(schemaDef);
            A.CallTo(() => schema.IsPublished).Returns(true);
            A.CallTo(() => schema.ScriptQuery).Returns("<script-query>");

            var allSchemas = new List <ISchemaEntity> {
                schema
            };

            A.CallTo(() => schemaRepository.QueryAllAsync(appId)).Returns(allSchemas);

            sut = new CachingGraphQLService(cache, assetRepository, contentQuery, new FakeUrlGenerator(), schemaRepository);
        }
Beispiel #4
0
        public Schema BuildSchemaForSearch(SchemaHelperModel schemaModel)
        {
            var currentSchema = new Schema();

            foreach (var item in schemaModel.SearchFields)
            {
                currentSchema.AddField(item);
            }
            foreach (var item in schemaModel.TextFields)
            {
                currentSchema.AddSortableTextField(item.FIeldName, item.Weignt);
            }
            foreach (var item in schemaModel.NumericFieldName)
            {
                currentSchema.AddNumericField(item);
            }
            foreach (var item in schemaModel.TagFilterName)
            {
                currentSchema.AddTagField(item);
            }
            foreach (var item in schemaModel.GeoFilterName)
            {
                currentSchema.AddGeoField(item);
            }

            return(currentSchema);
        }
Beispiel #5
0
        public static Schema Dispatch(FieldAdded @event, Schema schema, FieldRegistry registry)
        {
            var partitioning =
                string.Equals(@event.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                Partitioning.Language :
                Partitioning.Invariant;

            return(schema.AddField(registry.CreateField(@event.FieldId.Id, @event.Name, partitioning, @event.Properties)));
        }
        private static void BuildField(this PropertyInfo propertyInfo, Schema scheme)
        {
            if (propertyInfo.IsDefined(typeof(RedisKeyValueAttribute)))
            {
                scheme.AddField(new Schema.TextField(propertyInfo.Name, sortable: false, noIndex: true));
                return;
            }

            if (propertyInfo.PropertyType.IsGenericType && (propertyInfo.PropertyType.GenericTypeArguments[0] == typeof(string) || propertyInfo.PropertyType.GenericTypeArguments[0] is { IsValueType : true }))
Beispiel #7
0
        public void CannotCreateCompleteRecordWithBrokenField()
        {
            var schema = new Schema();

            schema.AddField("field1", (FieldType)8, 0);

            var tableInfo = new TableInfo("table", schema);

            Assert.AreEqual(-1, tableInfo.RecordLength);
        }
Beispiel #8
0
        public static void AddFerromapasSchemaIfNotExists(KmlFile kmlFile)
        {
            Document document = (kmlFile.Root as Kml).Feature as Document;
            var      schemas  = ((SharpKml.Dom.Document)((SharpKml.Dom.Kml)kmlFile.Root).Feature).Schemas;

            Schema ferromapasEstacionSchema = KmlFileHelper.FindSchemaByName(kmlFile, "Ferromapas_Estacion");

            if (ferromapasEstacionSchema == null)
            {
                ferromapasEstacionSchema      = new Schema();
                ferromapasEstacionSchema.Name = "Ferromapas_Estacion";
                ferromapasEstacionSchema.AddField(KmlFileHelper.setSimpleField("Nombre", "String"));
                ferromapasEstacionSchema.AddField(KmlFileHelper.setSimpleField("Ferrocarril", "String"));
                ferromapasEstacionSchema.AddField(KmlFileHelper.setSimpleField("Ramal", "String"));
                ferromapasEstacionSchema.AddField(KmlFileHelper.setSimpleField("Progresiva", "String"));
                document.AddSchema(ferromapasEstacionSchema);
            }


            Schema ferromapasViaSchema = KmlFileHelper.FindSchemaByName(kmlFile, "Ferromapas_Via");

            if (ferromapasViaSchema == null)
            {
                ferromapasViaSchema      = new Schema();
                ferromapasViaSchema.Name = "Ferromapas_Via";
                ferromapasViaSchema.AddField(KmlFileHelper.setSimpleField("Nombre", "String"));
                ferromapasViaSchema.AddField(KmlFileHelper.setSimpleField("InicioProgresiva", "String"));
                document.AddSchema(ferromapasViaSchema);
            }

            Schema ferromapasCarpetaSchema = KmlFileHelper.FindSchemaByName(kmlFile, "Ferromapas_Carpeta");

            if (ferromapasCarpetaSchema == null)
            {
                ferromapasCarpetaSchema      = new Schema();
                ferromapasCarpetaSchema.Name = "Ferromapas_Carpeta";
                ferromapasCarpetaSchema.AddField(KmlFileHelper.setSimpleField("Nombre", "String"));
                ferromapasCarpetaSchema.AddField(KmlFileHelper.setSimpleField("Autores", "String"));
                ferromapasCarpetaSchema.AddField(KmlFileHelper.setSimpleField("Fuentes", "String"));
                document.AddSchema(ferromapasCarpetaSchema);
            }
        }
Beispiel #9
0
        public ODataQueryTests()
        {
            schemaDef.Update(new SchemaProperties {
                Hints = "The User"
            });

            schemaDef.AddField(new StringField(1, "firstName", Partitioning.Language,
                                               new StringFieldProperties {
                Label = "FirstName", IsRequired = true, AllowedValues = new[] { "1", "2" }
            }));
            schemaDef.AddField(new StringField(2, "lastName", Partitioning.Language,
                                               new StringFieldProperties {
                Hints = "Last Name", Editor = StringFieldEditor.Input
            }));

            schemaDef.AddField(new BooleanField(3, "isAdmin", Partitioning.Invariant,
                                                new BooleanFieldProperties()));

            schemaDef.AddField(new NumberField(4, "age", Partitioning.Invariant,
                                               new NumberFieldProperties {
                MinValue = 1, MaxValue = 10
            }));

            schemaDef.AddField(new DateTimeField(5, "birthday", Partitioning.Invariant,
                                                 new DateTimeFieldProperties()));

            schemaDef.AddField(new AssetsField(6, "pictures", Partitioning.Invariant,
                                               new AssetsFieldProperties()));

            schemaDef.AddField(new ReferencesField(7, "friends", Partitioning.Invariant,
                                                   new ReferencesFieldProperties()));

            schemaDef.AddField(new StringField(8, "dashed-field", Partitioning.Invariant,
                                               new StringFieldProperties()));

            var builder = new EdmModelBuilder(new MemoryCache(Options.Create(new MemoryCacheOptions())));

            var schema = A.Dummy <ISchemaEntity>();

            A.CallTo(() => schema.Id).Returns(Guid.NewGuid());
            A.CallTo(() => schema.Version).Returns(3);
            A.CallTo(() => schema.SchemaDef).Returns(schemaDef);

            var app = A.Dummy <IAppEntity>();

            A.CallTo(() => app.Id).Returns(Guid.NewGuid());
            A.CallTo(() => app.Version).Returns(3);
            A.CallTo(() => app.PartitionResolver).Returns(languagesConfig.ToResolver());

            edmModel = builder.BuildEdmModel(schema, app);
        }
Beispiel #10
0
        public static Schema AddArray(this Schema schema, long id, string name, Partitioning partitioning,
                                      Func <ArrayField, ArrayField>?handler = null, ArrayFieldProperties?properties = null, IFieldSettings?settings = null)
        {
            var field = Array(id, name, partitioning, properties, settings);

            if (handler != null)
            {
                field = handler(field);
            }

            return(schema.AddField(field));
        }
Beispiel #11
0
        protected void On(SchemaCreated @event, FieldRegistry registry)
        {
            Name = @event.Name;

            var schema = new Schema(@event.Name);

            if (@event.Properties != null)
            {
                schema = schema.Update(@event.Properties);
            }

            if (@event.Publish)
            {
                schema = schema.Publish();
            }

            if (@event.Fields != null)
            {
                foreach (var eventField in @event.Fields)
                {
                    TotalFields++;

                    var partitioning =
                        string.Equals(eventField.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                        Partitioning.Language :
                        Partitioning.Invariant;

                    var field = registry.CreateField(TotalFields, eventField.Name, partitioning, eventField.Properties);

                    if (eventField.IsHidden)
                    {
                        field = field.Hide();
                    }

                    if (eventField.IsDisabled)
                    {
                        field = field.Disable();
                    }

                    if (eventField.IsLocked)
                    {
                        field = field.Lock();
                    }

                    schema = schema.AddField(field);
                }
            }

            SchemaDef = schema;

            AppId = @event.AppId;
        }
Beispiel #12
0
        public ContentEnrichmentTests()
        {
            schema = new Schema("my-schema");

            schema.AddField(new StringField(1, "my-string", Partitioning.Language,
                                            new StringFieldProperties {
                DefaultValue = "en-string"
            }));

            schema.AddField(new NumberField(2, "my-number", Partitioning.Invariant,
                                            new NumberFieldProperties()));

            schema.AddField(new DateTimeField(3, "my-datetime", Partitioning.Invariant,
                                              new DateTimeFieldProperties {
                DefaultValue = Now
            }));

            schema.AddField(new BooleanField(4, "my-boolean", Partitioning.Invariant,
                                             new BooleanFieldProperties {
                DefaultValue = true
            }));
        }
Beispiel #13
0
        public static void Apply(this Schema schema, FieldAdded @event, FieldRegistry registry)
        {
            var partitioning =
                string.Equals(@event.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                Partitioning.Language :
                Partitioning.Invariant;

            var fieldId = @event.FieldId.Id;
            var field   = registry.CreateField(fieldId, @event.Name, partitioning, @event.Properties);

            schema.DeleteField(fieldId);
            schema.AddField(field);
        }
Beispiel #14
0
        public IEvent Migrate()
        {
            var schema = new Schema(Name, Properties, Singleton ? SchemaType.Singleton : SchemaType.Default);

            if (Publish)
            {
                schema = schema.Publish();
            }

            var totalFields = 0;

            if (Fields != null)
            {
                foreach (var eventField in Fields)
                {
                    totalFields++;

                    var partitioning = Partitioning.FromString(eventField.Partitioning);

                    var field =
                        eventField.Properties.CreateRootField(
                            totalFields,
                            eventField.Name, partitioning,
                            eventField);

                    if (field is ArrayField arrayField && eventField.Nested?.Length > 0)
                    {
                        foreach (var nestedEventField in eventField.Nested)
                        {
                            totalFields++;

                            var nestedField =
                                nestedEventField.Properties.CreateNestedField(
                                    totalFields,
                                    nestedEventField.Name,
                                    nestedEventField);

                            arrayField = arrayField.AddField(nestedField);
                        }

                        field = arrayField;
                    }

                    schema = schema.AddField(field);
                }
            }

            return(SimpleMapper.Map(this, new SchemaCreatedV2 {
                Schema = schema
            }));
        }
Beispiel #15
0
        public void CanAddField()
        {
            var schema = new Schema();

            Assert.DoesNotThrow(() =>
            {
                schema.AddField("field", FieldType.Integer, 0);
            });

            var fields = schema.Fields;
            var field  = fields.First();

            Assert.IsNotNull(fields);
            Assert.AreEqual(1, fields.Count);
            Assert.AreEqual(FieldType.Integer, field.Value.Type);
            Assert.AreEqual("field", field.Key);
        }
Beispiel #16
0
        public static Schema Create(SchemaCreated @event, FieldRegistry registry)
        {
            var schema = new Schema(@event.Name);

            if (@event.Properties != null)
            {
                schema.Update(@event.Properties);
            }

            if (@event.Fields != null)
            {
                var fieldId = 1;

                foreach (var eventField in @event.Fields)
                {
                    var partitioning =
                        string.Equals(eventField.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                        Partitioning.Language :
                        Partitioning.Invariant;

                    var field = registry.CreateField(fieldId, eventField.Name, partitioning, eventField.Properties);

                    if (eventField.IsHidden)
                    {
                        field.Hide();
                    }

                    if (eventField.IsDisabled)
                    {
                        field.Disable();
                    }

                    if (eventField.IsLocked)
                    {
                        field.Lock();
                    }

                    schema.AddField(field);

                    fieldId++;
                }
            }

            return(schema);
        }
        public ReferenceExtractionTests()
        {
            schema.AddField(new NumberField(1, "field1", Partitioning.Language));
            schema.AddField(new NumberField(2, "field2", Partitioning.Invariant));
            schema.AddField(new NumberField(3, "field3", Partitioning.Invariant));

            schema.AddField(new AssetsField(5, "assets1", Partitioning.Invariant));
            schema.AddField(new AssetsField(6, "assets2", Partitioning.Invariant));

            schema.AddField(new JsonField(4, "json", Partitioning.Language));

            schema.FieldsById[3].Hide();
        }
Beispiel #18
0
        public Schema ToSchema(FieldRegistry fieldRegistry)
        {
            var schema = new Schema(Name);

            if (Fields != null)
            {
                foreach (var fieldModel in Fields)
                {
                    var parititonKey = new Partitioning(fieldModel.Partitioning);

                    var field = fieldRegistry.CreateField(fieldModel.Id, fieldModel.Name, parititonKey, fieldModel.Properties);

                    if (fieldModel.IsDisabled)
                    {
                        field.Disable();
                    }

                    if (fieldModel.IsLocked)
                    {
                        field.Lock();
                    }

                    if (fieldModel.IsHidden)
                    {
                        field.Hide();
                    }

                    schema.AddField(field);
                }
            }

            if (IsPublished)
            {
                schema.Publish();
            }

            if (Properties != null)
            {
                schema.Update(Properties);
            }

            return(schema);
        }
Beispiel #19
0
        protected void On(FieldAdded @event)
        {
            if (@event.ParentFieldId != null)
            {
                var field = @event.Properties.CreateNestedField(@event.FieldId.Id, @event.Name);

                SchemaDef = SchemaDef.UpdateField(@event.ParentFieldId.Id, x => ((ArrayField)x).AddField(field));
            }
            else
            {
                var partitioning = Partitioning.FromString(@event.Partitioning);

                var field = @event.Properties.CreateRootField(@event.FieldId.Id, @event.Name, partitioning);

                SchemaDef = SchemaDef.DeleteField(@event.FieldId.Id);
                SchemaDef = SchemaDef.AddField(field);
            }

            SchemaFieldsTotal = Math.Max(SchemaFieldsTotal, @event.FieldId.Id);
        }
Beispiel #20
0
        public TableInfo GetTableInfo(string tableName, Transaction transaction)
        {
            var tableCatalogFile = new RecordFile(_tableCatalogInfo, transaction);
            var recordLength     = -1;

            while (tableCatalogFile.Next())
            {
                if (tableCatalogFile.GetString("tblname") == tableName)
                {
                    recordLength = tableCatalogFile.GetInt("reclength");
                    break;
                }
            }
            tableCatalogFile.Close();

            if (recordLength == -1)
            {
                return(null);
            }

            var fieldCatalogFile = new RecordFile(_fieldCatalogInfo, transaction);
            var schema           = new Schema();
            var offsets          = new Dictionary <string, int>();

            while (fieldCatalogFile.Next())
            {
                if (fieldCatalogFile.GetString("tblname") == tableName)
                {
                    var fieldName   = fieldCatalogFile.GetString("fldname");
                    int fieldType   = fieldCatalogFile.GetInt("type");
                    int fieldLength = fieldCatalogFile.GetInt("length");
                    int offset      = fieldCatalogFile.GetInt("offset");
                    offsets.Add(fieldName, offset);
                    schema.AddField(fieldName, (FieldType)fieldType, fieldLength);
                }
            }
            fieldCatalogFile.Close();

            return(new TableInfo(tableName, schema, offsets, recordLength));
        }
Beispiel #21
0
        public void Should_add_field()
        {
            var field = CreateField(1);

            var schema_1 = schema_0.AddField(field);

            Assert.Empty(schema_0.Fields);
            Assert.Equal(field, schema_1.FieldsById[1]);
        }
Beispiel #22
0
        public IEvent Migrate()
        {
            var schema = new Schema(Name, Properties, Singleton);

            if (Publish)
            {
                schema = schema.Publish();
            }

            var totalFields = 0;

            if (Fields != null)
            {
                foreach (var eventField in Fields)
                {
                    totalFields++;

                    var partitioning = Partitioning.FromString(eventField.Partitioning);

                    var field = eventField.Properties.CreateRootField(totalFields, eventField.Name, partitioning);

                    if (field is ArrayField arrayField && eventField.Nested?.Length > 0)
                    {
                        foreach (var nestedEventField in eventField.Nested)
                        {
                            totalFields++;

                            var nestedField = nestedEventField.Properties.CreateNestedField(totalFields, nestedEventField.Name);

                            if (nestedEventField.IsHidden)
                            {
                                nestedField = nestedField.Hide();
                            }

                            if (nestedEventField.IsDisabled)
                            {
                                nestedField = nestedField.Disable();
                            }

                            if (nestedEventField.IsLocked)
                            {
                                nestedField = nestedField.Lock();
                            }

                            arrayField = arrayField.AddField(nestedField);
                        }

                        field = arrayField;
                    }

                    if (eventField.IsHidden)
                    {
                        field = field.Hide();
                    }

                    if (eventField.IsDisabled)
                    {
                        field = field.Disable();
                    }

                    if (eventField.IsLocked)
                    {
                        field = field.Lock();
                    }

                    schema = schema.AddField(field);
                }
            }

            return(SimpleMapper.Map(this, new SchemaCreatedV2 {
                Schema = schema
            }));
        }
Beispiel #23
0
        public override bool ApplyEvent(IEvent @event)
        {
            var previousSchema = SchemaDef;

            switch (@event)
            {
            case SchemaCreated e:
            {
                SchemaDef         = e.Schema;
                SchemaFieldsTotal = e.Schema.MaxId();

                AppId = e.AppId;

                return(true);
            }

            case FieldAdded e:
            {
                if (e.ParentFieldId != null)
                {
                    var field = e.Properties.CreateNestedField(e.FieldId.Id, e.Name);

                    SchemaDef = SchemaDef.UpdateField(e.ParentFieldId.Id, x => ((ArrayField)x).AddField(field));
                }
                else
                {
                    var partitioning = Partitioning.FromString(e.Partitioning);

                    var field = e.Properties.CreateRootField(e.FieldId.Id, e.Name, partitioning);

                    SchemaDef = SchemaDef.DeleteField(e.FieldId.Id);
                    SchemaDef = SchemaDef.AddField(field);
                }

                SchemaFieldsTotal = Math.Max(SchemaFieldsTotal, e.FieldId.Id);

                break;
            }

            case SchemaUIFieldsConfigured e:
            {
                if (e.FieldsInLists != null)
                {
                    SchemaDef = SchemaDef.SetFieldsInLists(e.FieldsInLists);
                }

                if (e.FieldsInReferences != null)
                {
                    SchemaDef = SchemaDef.SetFieldsInReferences(e.FieldsInReferences);
                }

                break;
            }

            case SchemaCategoryChanged e:
            {
                SchemaDef = SchemaDef.ChangeCategory(e.Name);

                break;
            }

            case SchemaPreviewUrlsConfigured e:
            {
                SchemaDef = SchemaDef.SetPreviewUrls(e.PreviewUrls);

                break;
            }

            case SchemaScriptsConfigured e:
            {
                SchemaDef = SchemaDef.SetScripts(e.Scripts);

                break;
            }

            case SchemaPublished _:
            {
                SchemaDef = SchemaDef.Publish();

                break;
            }

            case SchemaUnpublished _:
            {
                SchemaDef = SchemaDef.Unpublish();

                break;
            }

            case SchemaUpdated e:
            {
                SchemaDef = SchemaDef.Update(e.Properties);

                break;
            }

            case SchemaFieldsReordered e:
            {
                SchemaDef = SchemaDef.ReorderFields(e.FieldIds, e.ParentFieldId?.Id);

                break;
            }

            case FieldUpdated e:
            {
                SchemaDef = SchemaDef.UpdateField(e.FieldId.Id, e.Properties, e.ParentFieldId?.Id);

                break;
            }

            case FieldLocked e:
            {
                SchemaDef = SchemaDef.LockField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldDisabled e:
            {
                SchemaDef = SchemaDef.DisableField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldEnabled e:
            {
                SchemaDef = SchemaDef.EnableField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldHidden e:
            {
                SchemaDef = SchemaDef.HideField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldShown e:
            {
                SchemaDef = SchemaDef.ShowField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldDeleted e:
            {
                SchemaDef = SchemaDef.DeleteField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case SchemaDeleted _:
            {
                IsDeleted = true;

                return(true);
            }
            }

            return(!ReferenceEquals(previousSchema, SchemaDef));
        }
        public Schema ToSchema(string name, bool isSingleton)
        {
            var schema = new Schema(name, Properties, isSingleton);

            if (IsPublished)
            {
                schema = schema.Publish();
            }

            if (Scripts != null)
            {
                schema = schema.ConfigureScripts(Scripts);
            }

            if (PreviewUrls != null)
            {
                schema = schema.ConfigurePreviewUrls(PreviewUrls);
            }

            if (FieldsInLists != null)
            {
                schema = schema.ConfigureFieldsInLists(FieldsInLists);
            }

            if (FieldsInReferences != null)
            {
                schema = schema.ConfigureFieldsInReferences(FieldsInReferences);
            }

            if (!string.IsNullOrWhiteSpace(Category))
            {
                schema = schema.ChangeCategory(Category);
            }

            var totalFields = 0;

            if (Fields != null)
            {
                foreach (var eventField in Fields)
                {
                    totalFields++;

                    var partitioning = Partitioning.FromString(eventField.Partitioning);

                    var field = eventField.Properties.CreateRootField(totalFields, eventField.Name, partitioning);

                    if (field is ArrayField arrayField && eventField.Nested?.Count > 0)
                    {
                        foreach (var nestedEventField in eventField.Nested)
                        {
                            totalFields++;

                            var nestedField = nestedEventField.Properties.CreateNestedField(totalFields, nestedEventField.Name);

                            if (nestedEventField.IsHidden)
                            {
                                nestedField = nestedField.Hide();
                            }

                            if (nestedEventField.IsDisabled)
                            {
                                nestedField = nestedField.Disable();
                            }

                            if (nestedEventField.IsLocked)
                            {
                                nestedField = nestedField.Lock();
                            }

                            arrayField = arrayField.AddField(nestedField);
                        }

                        field = arrayField;
                    }

                    if (eventField.IsHidden)
                    {
                        field = field.Hide();
                    }

                    if (eventField.IsDisabled)
                    {
                        field = field.Disable();
                    }

                    if (eventField.IsLocked)
                    {
                        field = field.Lock();
                    }

                    schema = schema.AddField(field);
                }
            }

            return(schema);
        }
Beispiel #25
0
 public static Schema AddUI(this Schema schema, long id, string name, Partitioning partitioning,
                            UIFieldProperties?properties = null, IFieldSettings?settings = null)
 {
     return(schema.AddField(UI(id, name, partitioning, properties, settings)));
 }
Beispiel #26
0
 public GuardSchemaFieldTests()
 {
     schema.AddField(new StringField(1, "field1", Partitioning.Invariant));
     schema.AddField(new StringField(2, "field2", Partitioning.Invariant));
 }
Beispiel #27
0
        protected void On(SchemaCreated @event, FieldRegistry registry)
        {
            Name = @event.Name;

            var schema = new Schema(@event.Name);

            if (@event.Properties != null)
            {
                schema = schema.Update(@event.Properties);
            }

            if (@event.Publish)
            {
                schema = schema.Publish();
            }

            if (@event.Fields != null)
            {
                foreach (var eventField in @event.Fields)
                {
                    TotalFields++;

                    var partitioning = Partitioning.FromString(eventField.Partitioning);

                    var field = registry.CreateRootField(TotalFields, eventField.Name, partitioning, eventField.Properties);

                    if (field is ArrayField arrayField && eventField.Nested?.Count > 0)
                    {
                        foreach (var nestedEventField in eventField.Nested)
                        {
                            TotalFields++;

                            var nestedField = registry.CreateNestedField(TotalFields, nestedEventField.Name, nestedEventField.Properties);

                            if (nestedEventField.IsHidden)
                            {
                                nestedField = nestedField.Hide();
                            }

                            if (nestedEventField.IsDisabled)
                            {
                                nestedField = nestedField.Disable();
                            }

                            arrayField = arrayField.AddField(nestedField);
                        }

                        field = arrayField;
                    }

                    if (eventField.IsHidden)
                    {
                        field = field.Hide();
                    }

                    if (eventField.IsDisabled)
                    {
                        field = field.Disable();
                    }

                    if (eventField.IsLocked)
                    {
                        field = field.Lock();
                    }

                    schema = schema.AddField(field);
                }
            }

            SchemaDef = schema;

            AppId = @event.AppId;
        }
Beispiel #28
0
        public async Task Should_add_error_if_validating_data_with_invalid_field()
        {
            schema.AddField(new NumberField(1, "my-field", Partitioning.Invariant,
                                            new NumberFieldProperties {
                MaxValue = 100
            }));

            var data =
                new NamedContentData()
                .AddField("my-field",
                          new ContentFieldData()
                          .AddValue(1000));

            await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("my-field must be less or equals than '100'.", "my-field")
            });
        }
Beispiel #29
0
        public static Schema MixedSchema()
        {
            var inv = Partitioning.Invariant;

            var schema = new Schema("user");

            schema.Publish();
            schema.Update(new SchemaProperties {
                Hints = "The User"
            });

            schema.AddField(new JsonField(1, "my-json", inv,
                                          new JsonFieldProperties()));

            schema.AddField(new AssetsField(2, "my-assets", inv,
                                            new AssetsFieldProperties()));

            schema.AddField(new StringField(3, "my-string1", inv,
                                            new StringFieldProperties {
                Label = "My String1", IsRequired = true, AllowedValues = new[] { "a", "b" }
            }));

            schema.AddField(new StringField(4, "my-string2", inv,
                                            new StringFieldProperties {
                Hints = "My String1"
            }));

            schema.AddField(new NumberField(5, "my-number", inv,
                                            new NumberFieldProperties {
                MinValue = 1, MaxValue = 10
            }));

            schema.AddField(new BooleanField(6, "my-boolean", inv,
                                             new BooleanFieldProperties()));

            schema.AddField(new DateTimeField(7, "my-datetime", inv,
                                              new DateTimeFieldProperties {
                Editor = DateTimeFieldEditor.DateTime
            }));

            schema.AddField(new DateTimeField(8, "my-date", inv,
                                              new DateTimeFieldProperties {
                Editor = DateTimeFieldEditor.Date
            }));

            schema.AddField(new GeolocationField(9, "my-geolocation", inv,
                                                 new GeolocationFieldProperties()));

            schema.AddField(new ReferencesField(10, "my-references", inv,
                                                new ReferencesFieldProperties()));

            schema.AddField(new TagsField(11, "my-tags", Partitioning.Language,
                                          new TagsFieldProperties()));

            schema.FieldsById[7].Hide();
            schema.FieldsById[8].Disable();
            schema.FieldsById[9].Lock();

            return(schema);
        }
Beispiel #30
0
        public void Should_throw_exception_if_adding_field_with_name_that_already_exists()
        {
            AddNumberField(1);

            Assert.Throws <ArgumentException>(() => sut.AddField(new NumberField(2, "my-field-1", Partitioning.Invariant)));
        }