<commit_before>/**
 * Copyright 2020 interactive instruments GmbH
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package de.ii.ldproxy.target.html;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import de.ii.ldproxy.ogcapi.application.I18n;
import de.ii.ldproxy.ogcapi.domain.Collections;
import de.ii.ldproxy.ogcapi.domain.*;

import java.util.*;
import java.util.stream.Collectors;

public class OgcApiCollectionsView extends LdproxyView {
    private final List<OgcApiCollection> collections;
    public String dataSourceUrl;
    public String keywords;
    public List<String> crs;
    public Metadata metadata;
    public String collectionsTitle;
    public String supportedCrsTitle;
    public String additionalLinksTitle;
    public String expertInformationTitle;
    public String none;
    public String moreInformation;

    public OgcApiCollectionsView(OgcApiApiDataV2 apiData, Collections collections,
                                 final List<NavigationDTO> breadCrumbs, String urlPrefix,
                                 HtmlConfig htmlConfig, boolean noIndex, I18n i18n, Optional<Locale> language, Optional<String> dataSourceUrl) {
        super("collections.mustache", Charsets.UTF_8, apiData, breadCrumbs, htmlConfig, noIndex, urlPrefix,
                collections.getLinks(),
                collections
                        .getTitle()
                        .orElse(apiData.getId()),
                collections
                        .getDescription()
                        .orElse("") );
        this.collections = collections.getCollections();
        this.crs = collections
                .getCrs();

        if (dataSourceUrl.isPresent()) {
            this.dataSourceUrl = dataSourceUrl.get();
        }

        this.collectionsTitle = i18n.get("collectionsTitle", language);
        this.supportedCrsTitle = i18n.get("supportedCrsTitle", language);
        this.additionalLinksTitle = i18n.get("additionalLinksTitle", language);
        this.expertInformationTitle = i18n.get ("expertInformationTitle", language);
        this.none = i18n.get ("none", language);
        this.moreInformation = i18n.get("moreInformation", language);
    }

    public List<OgcApiLink> getLinks() {
        return links
                .stream()
                .filter(link -> !link.getRel().matches("^(?:self|alternate|home)$"))
                .collect(Collectors.toList());
    }

    public List<Map<String, String>> getCollections() {
        return collections.stream()
                .map(collection -> ImmutableMap.of("title", collection.getTitle().orElse(collection.getId()),
                        "id", collection.getId(),
                        "hrefcollection", collection.getLinks()
                                .stream()
                                .filter(link -> link.getRel().equalsIgnoreCase("self"))
                                .findFirst()
                                .map(link -> link.getHref())
                                .orElse(""),
                        "hrefitems", collection.getLinks()
                                .stream()
                                .filter(link -> link.getRel().equalsIgnoreCase("self"))
                                .findFirst()
                                .map(link -> link.getHref() + "/items")
                                .orElse("")))
                .collect(Collectors.toList());
    }
}
<commit_msg>sort collections by title in HTML<commit_after>/**
 * Copyright 2020 interactive instruments GmbH
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package de.ii.ldproxy.target.html;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import de.ii.ldproxy.ogcapi.application.I18n;
import de.ii.ldproxy.ogcapi.domain.Collections;
import de.ii.ldproxy.ogcapi.domain.*;

import java.util.*;
import java.util.stream.Collectors;

public class OgcApiCollectionsView extends LdproxyView {
    private final List<OgcApiCollection> collections;
    public String dataSourceUrl;
    public String keywords;
    public List<String> crs;
    public Metadata metadata;
    public String collectionsTitle;
    public String supportedCrsTitle;
    public String additionalLinksTitle;
    public String expertInformationTitle;
    public String none;
    public String moreInformation;

    public OgcApiCollectionsView(OgcApiApiDataV2 apiData, Collections collections,
                                 final List<NavigationDTO> breadCrumbs, String urlPrefix,
                                 HtmlConfig htmlConfig, boolean noIndex, I18n i18n, Optional<Locale> language, Optional<String> dataSourceUrl) {
        super("collections.mustache", Charsets.UTF_8, apiData, breadCrumbs, htmlConfig, noIndex, urlPrefix,
                collections.getLinks(),
                collections
                        .getTitle()
                        .orElse(apiData.getId()),
                collections
                        .getDescription()
                        .orElse("") );
        this.collections = collections.getCollections();
        this.crs = collections
                .getCrs();

        if (dataSourceUrl.isPresent()) {
            this.dataSourceUrl = dataSourceUrl.get();
        }

        this.collectionsTitle = i18n.get("collectionsTitle", language);
        this.supportedCrsTitle = i18n.get("supportedCrsTitle", language);
        this.additionalLinksTitle = i18n.get("additionalLinksTitle", language);
        this.expertInformationTitle = i18n.get ("expertInformationTitle", language);
        this.none = i18n.get ("none", language);
        this.moreInformation = i18n.get("moreInformation", language);
    }

    public List<OgcApiLink> getLinks() {
        return links
                .stream()
                .filter(link -> !link.getRel().matches("^(?:self|alternate|home)$"))
                .collect(Collectors.toList());
    }

    public List<Map<String, String>> getCollections() {

        Comparator<OgcApiCollection> byTitle = Comparator.comparing(
                collection -> collection.getTitle().orElse(collection.getId())
        );

        return collections.stream()
                .sorted(byTitle)
                .map(collection -> ImmutableMap.of("title", collection.getTitle().orElse(collection.getId()),
                        "id", collection.getId(),
                        "hrefcollection", collection.getLinks()
                                .stream()
                                .filter(link -> link.getRel().equalsIgnoreCase("self"))
                                .findFirst()
                                .map(link -> link.getHref())
                                .orElse(""),
                        "hrefitems", collection.getLinks()
                                .stream()
                                .filter(link -> link.getRel().equalsIgnoreCase("self"))
                                .findFirst()
                                .map(link -> link.getHref() + "/items")
                                .orElse("")))
                .collect(Collectors.toList());
    }
}

{'fraction_non_alphanumeric': 0.10597534833869239, 'fraction_numerical': 0.007502679528403001, 'mean_word_length': 1.928599450765006, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6991603', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1855, 'n_words': 407}