<commit_before>/*
 * Copyright 2015-2017 Hewlett Packard Enterprise Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.frontend.find.core.configuration;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.hp.autonomy.frontend.configuration.ConfigException;
import com.hp.autonomy.frontend.configuration.ConfigurationComponent;
import com.hp.autonomy.types.requests.idol.actions.tags.FieldPath;
import lombok.Builder;
import lombok.Getter;
import lombok.Singular;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@SuppressWarnings("InstanceVariableOfConcreteClass")
@Builder(toBuilder = true)
@Getter
@JsonDeserialize(builder = UiCustomization.UiCustomizationBuilder.class)
public class UiCustomization implements ConfigurationComponent<UiCustomization> {
    private final UiCustomizationOptions options;
    private final Collection<String> filterOrder;
    @Singular("defaultDeselectedDatabase")
    private final Collection<String> defaultDeselectedDatabases;
    @Singular("parametricNeverShowItem")
    private final Collection<FieldPath> parametricNeverShow;
    @Singular("parametricAlwaysShowItem")
    private final Collection<FieldPath> parametricAlwaysShow;
    @Singular("parametricOrderItem")
    private final Collection<FieldPath> parametricOrder;
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
    private final Map<String, String> specialUrlPrefixes;
    private final String errorCallSupportString;
    private final Boolean openSharedDashboardQueryAsNewSearch;

    @Override
    public UiCustomization merge(final UiCustomization uiCustomization) {
        if(uiCustomization == null) {
            return this;
        } else {
            final Map<String, String> specialUrlPrefixes = new HashMap<>(uiCustomization.specialUrlPrefixes);
            specialUrlPrefixes.putAll(this.specialUrlPrefixes);
            return builder()
                .options(Optional.ofNullable(options).map(o -> o.merge(uiCustomization.options)).orElse(uiCustomization.options))
                .parametricNeverShow(CollectionUtils.isNotEmpty(parametricNeverShow)
                                         ? parametricNeverShow
                                         : uiCustomization.parametricNeverShow)
                .parametricAlwaysShow(CollectionUtils.isNotEmpty(parametricAlwaysShow)
                                          ? parametricAlwaysShow
                                          : uiCustomization.parametricAlwaysShow)
                .parametricOrder(CollectionUtils.isNotEmpty(parametricOrder)
                                     ? parametricOrder
                                     : uiCustomization.parametricOrder)
                .specialUrlPrefixes(specialUrlPrefixes)
                .errorCallSupportString(uiCustomization.errorCallSupportString)
                .defaultDeselectedDatabases(CollectionUtils.isNotEmpty(defaultDeselectedDatabases)
                                            ? defaultDeselectedDatabases
                                            : uiCustomization.defaultDeselectedDatabases)
                .filterOrder(CollectionUtils.isNotEmpty(filterOrder)
                                            ? filterOrder
                                            : uiCustomization.filterOrder)
                .openSharedDashboardQueryAsNewSearch(openSharedDashboardQueryAsNewSearch != null
                                            ? openSharedDashboardQueryAsNewSearch
                                            : uiCustomization.openSharedDashboardQueryAsNewSearch)
                .build();
        }
    }

    @Override
    public void basicValidate(final String section) throws ConfigException {}

    @SuppressWarnings("WeakerAccess")
    @JsonPOJOBuilder(withPrefix = "")
    public static class UiCustomizationBuilder {
        @SuppressWarnings("FieldMayBeFinal")
        private Map<String, String> specialUrlPrefixes = new HashMap<>();

        @SuppressWarnings("unused")
        @JsonAnySetter<commit_msg>(FIND-1487) Fix the config.json uiCustomization.errorCallSupportString not being propagated correctly (which meant that the custom 'contact support' error messages weren't appearing)<commit_after>/*
 * Copyright 2015-2017 Hewlett Packard Enterprise Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.frontend.find.core.configuration;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.hp.autonomy.frontend.configuration.ConfigException;
import com.hp.autonomy.frontend.configuration.ConfigurationComponent;
import com.hp.autonomy.types.requests.idol.actions.tags.FieldPath;
import lombok.Builder;
import lombok.Getter;
import lombok.Singular;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@SuppressWarnings("InstanceVariableOfConcreteClass")
@Builder(toBuilder = true)
@Getter
@JsonDeserialize(builder = UiCustomization.UiCustomizationBuilder.class)
public class UiCustomization implements ConfigurationComponent<UiCustomization> {
    private final UiCustomizationOptions options;
    private final Collection<String> filterOrder;
    @Singular("defaultDeselectedDatabase")
    private final Collection<String> defaultDeselectedDatabases;
    @Singular("parametricNeverShowItem")
    private final Collection<FieldPath> parametricNeverShow;
    @Singular("parametricAlwaysShowItem")
    private final Collection<FieldPath> parametricAlwaysShow;
    @Singular("parametricOrderItem")
    private final Collection<FieldPath> parametricOrder;
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
    private final Map<String, String> specialUrlPrefixes;
    private final String errorCallSupportString;
    private final Boolean openSharedDashboardQueryAsNewSearch;

    @Override
    public UiCustomization merge(final UiCustomization uiCustomization) {
        if(uiCustomization == null) {
            return this;
        } else {
            final Map<String, String> specialUrlPrefixes = new HashMap<>(uiCustomization.specialUrlPrefixes);
            specialUrlPrefixes.putAll(this.specialUrlPrefixes);
            return builder()
                .options(Optional.ofNullable(options).map(o -> o.merge(uiCustomization.options)).orElse(uiCustomization.options))
                .parametricNeverShow(CollectionUtils.isNotEmpty(parametricNeverShow)
                                         ? parametricNeverShow
                                         : uiCustomization.parametricNeverShow)
                .parametricAlwaysShow(CollectionUtils.isNotEmpty(parametricAlwaysShow)
                                          ? parametricAlwaysShow
                                          : uiCustomization.parametricAlwaysShow)
                .parametricOrder(CollectionUtils.isNotEmpty(parametricOrder)
                                     ? parametricOrder
                                     : uiCustomization.parametricOrder)
                .specialUrlPrefixes(specialUrlPrefixes)
                .errorCallSupportString(errorCallSupportString != null ? errorCallSupportString : uiCustomization.errorCallSupportString)
                .defaultDeselectedDatabases(CollectionUtils.isNotEmpty(defaultDeselectedDatabases)
                                            ? defaultDeselectedDatabases
                                            : uiCustomization.defaultDeselectedDatabases)
                .filterOrder(CollectionUtils.isNotEmpty(filterOrder)
                                            ? filterOrder
                                            : uiCustomization.filterOrder)
                .openSharedDashboardQueryAsNewSearch(openSharedDashboardQueryAsNewSearch != null
                                            ? openSharedDashboardQueryAsNewSearch
                                            : uiCustomization.openSharedDashboardQueryAsNewSearch)
                .build();
        }
    }

    @Override
    public void basicValidate(final String section) throws ConfigException {}

    @SuppressWarnings("WeakerAccess")
    @JsonPOJOBuilder(withPrefix = "")
    public static class UiCustomizationBuilder {
        @SuppressWarnings("FieldMayBeFinal")
        private Map<String, String> specialUrlPrefixes = new HashMap<>();

        @SuppressWarnings("unused")
        @JsonAnySetter
{'fraction_non_alphanumeric': 0.06979542719614922, 'fraction_numerical': 0.0024067388688327317, 'mean_word_length': 2.8267057346169944, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2502855', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2071, 'n_words': 385}