Exemplo n.º 1
0
        private IEnumerable <FieldConverter> GenerateConverters(Context context, ValueConverter?cleanReferences)
        {
            if (!context.IsFrontendClient)
            {
                yield return(excludedHiddenField);

                yield return(excludedHiddenValue);
            }

            yield return(excludedChangedField);

            yield return(excludedChangedValue);

            if (cleanReferences != null)
            {
                yield return(FieldConverters.ForValues(cleanReferences));

                yield return(FieldConverters.ForValues(ValueConverters.ForNested(cleanReferences)));
            }

            yield return(FieldConverters.ResolveInvariant(context.App.Languages));

            yield return(FieldConverters.ResolveLanguages(context.App.Languages));

            if (!context.IsFrontendClient)
            {
                if (context.ShouldResolveLanguages())
                {
                    yield return(FieldConverters.ResolveFallbackLanguages(context.App.Languages));
                }

                var languages = context.Languages();

                if (languages.Any())
                {
                    yield return(FieldConverters.FilterLanguages(context.App.Languages, languages));
                }

                var assetUrls = context.AssetUrls().ToList();

                if (assetUrls.Count > 0)
                {
                    var appId = context.App.NamedId();

                    var resolveAssetUrls = ValueConverters.ResolveAssetUrls(appId, assetUrls, urlGenerator);

                    yield return(FieldConverters.ForValues(resolveAssetUrls));

                    yield return(FieldConverters.ForValues(ValueConverters.ForNested(resolveAssetUrls)));
                }
            }
        }
Exemplo n.º 2
0
        public DataConverter(IJsonSerializer serializer)
        {
            var decoder = ValueConverters.DecodeJson(serializer);

            decodeJsonConverters = new[]
            {
                FieldConverters.ForValues(decoder, ValueConverters.ForNested(decoder))
            };

            var encoder = ValueConverters.EncodeJson(serializer);

            encodeJsonConverters = new[]
            {
                FieldConverters.ForValues(encoder, ValueConverters.ForNested(encoder))
            };
        }
Exemplo n.º 3
0
        public void Should_cleanup_deleted_ids()
        {
            var id1 = DomainId.NewGuid();
            var id2 = DomainId.NewGuid();

            var source =
                new NamedContentData()
                .AddField("references",
                          new ContentFieldData()
                          .AddJsonValue(JsonValue.Array(id1, id2)))
                .AddField("assets",
                          new ContentFieldData()
                          .AddJsonValue(JsonValue.Array(id1)))
                .AddField("array",
                          new ContentFieldData()
                          .AddJsonValue(
                              JsonValue.Array(
                                  JsonValue.Object()
                                  .Add("nested", JsonValue.Array(id1, id2)))));

            var expected =
                new NamedContentData()
                .AddField("references",
                          new ContentFieldData()
                          .AddJsonValue(JsonValue.Array(id2)))
                .AddField("assets",
                          new ContentFieldData()
                          .AddJsonValue(JsonValue.Array()))
                .AddField("array",
                          new ContentFieldData()
                          .AddJsonValue(
                              JsonValue.Array(
                                  JsonValue.Object()
                                  .Add("nested", JsonValue.Array(id2)))));

            var cleaner = ValueReferencesConverter.CleanReferences(new HashSet <DomainId> {
                id2
            });
            var cleanNested = ValueConverters.ForNested(cleaner);

            var converter = FieldConverters.ForValues(cleaner, cleanNested);

            var actual = source.ConvertName2Name(schema, converter);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public ConvertData(IUrlGenerator urlGenerator, IJsonSerializer jsonSerializer,
                           IAssetRepository assetRepository, IContentRepository contentRepository)
        {
            Guard.NotNull(urlGenerator, nameof(urlGenerator));
            Guard.NotNull(jsonSerializer, nameof(jsonSerializer));
            Guard.NotNull(assetRepository, nameof(assetRepository));
            Guard.NotNull(contentRepository, nameof(contentRepository));

            this.urlGenerator      = urlGenerator;
            this.assetRepository   = assetRepository;
            this.contentRepository = contentRepository;

            excludedChangedField = FieldConverters.ExcludeChangedTypes(jsonSerializer);
            excludedChangedValue = FieldConverters.ForValues(ValueConverters.ForNested(ValueConverters.ExcludeChangedTypes(jsonSerializer)));

            excludedHiddenField = FieldConverters.ExcludeHidden;
            excludedHiddenValue = FieldConverters.ForValues(ValueConverters.ForNested(ValueConverters.ExcludeHidden));
        }
        public void Should_convert_name_to_id()
        {
            var input =
                new NamedContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddValue("en", "EN"))
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("iv", 1))
                .AddField("array",
                          new ContentFieldData()
                          .AddValue("iv",
                                    JsonValue.Array(
                                        JsonValue.Object()
                                        .Add("nested1", 100)
                                        .Add("nested2", 200)
                                        .Add("invalid", 300))))
                .AddField("invalid",
                          new ContentFieldData()
                          .AddValue("iv", 2));

            var hideRoot   = FieldConverters.ExcludeHidden;
            var hideNested = FieldConverters.ForValues(ValueConverters.ForNested(ValueConverters.ExcludeHidden));

            var actual = input.ConvertName2IdCloned(schema, hideRoot, hideNested);

            var expected =
                new IdContentData()
                .AddField(1,
                          new ContentFieldData()
                          .AddValue("en", "EN"))
                .AddField(7,
                          new ContentFieldData()
                          .AddValue("iv",
                                    JsonValue.Array(
                                        JsonValue.Object()
                                        .Add("72", 200))));

            Assert.Equal(expected, actual);
        }