Ejemplo n.º 1
0
        private IEnumerable <FieldConverter> GenerateConverters(QueryContext context)
        {
            if (!context.IsFrontendClient)
            {
                yield return(FieldConverters.ExcludeHidden());

                yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeHidden()));
            }

            yield return(FieldConverters.ExcludeChangedTypes());

            yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeChangedTypes()));

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

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

            if (!context.IsFrontendClient)
            {
                yield return(FieldConverters.ResolveFallbackLanguages(context.App.LanguagesConfig));

                if (context.Languages?.Any() == true)
                {
                    yield return(FieldConverters.FilterLanguages(context.App.LanguagesConfig, context.Languages));
                }

                if (context.AssetUrlsToResolve?.Any() == true)
                {
                    yield return(FieldConverters.ResolveAssetUrls(context.AssetUrlsToResolve, assetUrlGenerator));
                }
            }
        }
Ejemplo n.º 2
0
        private IEnumerable<FieldConverter> GenerateConverters(QueryContext context, bool checkType)
        {
            if (!context.IsFrontendClient)
            {
                yield return FieldConverters.ExcludeHidden();
            }

            if (checkType)
            {
                yield return FieldConverters.ExcludeChangedTypes();
            }

            yield return FieldConverters.ResolveInvariant(context.App.LanguagesConfig);
            yield return FieldConverters.ResolveLanguages(context.App.LanguagesConfig);

            if (!context.IsFrontendClient)
            {
                yield return FieldConverters.ResolveFallbackLanguages(context.App.LanguagesConfig);

                if (context.Languages?.Any() == true)
                {
                    yield return FieldConverters.FilterLanguages(context.App.LanguagesConfig, context.Languages);
                }
            }
        }
Ejemplo n.º 3
0
        public void Should_return_null_values_any_value_is_invalid()
        {
            var source =
                new ContentFieldData()
                .AddValue("en", "EN")
                .AddValue("de", 0);

            var result = FieldConverters.ExcludeChangedTypes()(source, numberField);

            Assert.Null(result);
        }
Ejemplo n.º 4
0
        public void Should_return_same_values_if_all_values_are_valid()
        {
            var source =
                new ContentFieldData()
                .AddValue("en", null)
                .AddValue("de", 1);

            var result = FieldConverters.ExcludeChangedTypes()(source, numberField);

            Assert.Same(source, result);
        }
Ejemplo n.º 5
0
        public ConvertData(IUrlGenerator urlGenerator, IJsonSerializer jsonSerializer,
                           IAssetRepository assetRepository, IContentRepository contentRepository)
        {
            this.urlGenerator      = urlGenerator;
            this.jsonSerializer    = jsonSerializer;
            this.assetRepository   = assetRepository;
            this.contentRepository = contentRepository;

            excludedChangedField = FieldConverters.ExcludeChangedTypes(jsonSerializer);
            excludedHiddenField  = FieldConverters.ExcludeHidden;
        }
Ejemplo n.º 6
0
        public void Should_return_null_when_excluding_changed_types_and_one_value_is_invalid()
        {
            var field = Fields.Number(1, "number", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddLocalized("en", "EN")
                .AddLocalized("de", 0);

            var result = FieldConverters.ExcludeChangedTypes(TestUtils.DefaultSerializer)(source, field);

            Assert.Null(result);
        }
Ejemplo n.º 7
0
        public void Should_return_field_data_when_excluding_changed_types_and_all_values_are_valid()
        {
            var field = Fields.Number(1, "number", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddLocalized("en", null)
                .AddLocalized("de", 1);

            var result = FieldConverters.ExcludeChangedTypes(TestUtils.DefaultSerializer)(source, field);

            Assert.Equal(source, result);
        }
Ejemplo n.º 8
0
        public void Should_return_same_values_when_excluding_changed_types_if_all_values_are_valid()
        {
            var field = Fields.Number(1, "number", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddValue("en", null)
                .AddValue("de", 1);

            var result = FieldConverters.ExcludeChangedTypes()(source, field);

            Assert.Same(source, result);
        }
Ejemplo n.º 9
0
        private IEnumerable <FieldConverter> GenerateConverters(Context context, ValueConverter?cleanReferences)
        {
            if (!context.IsFrontendClient)
            {
                yield return(FieldConverters.ExcludeHidden());

                yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeHidden()));
            }

            yield return(FieldConverters.ExcludeChangedTypes());

            yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeChangedTypes()));

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

                yield return(FieldConverters.ForNestedName2Name(cleanReferences));
            }

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

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

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

                var languages = context.Languages();

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

                var assetUrls = context.AssetUrls();

                if (assetUrls.Any())
                {
                    yield return(FieldConverters.ResolveAssetUrls(assetUrls.ToList(), assetUrlGenerator));
                }
            }
        }
Ejemplo n.º 10
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));
        }