Search in sources :

Example 1 with TreeList

use of org.apache.commons.collections.list.TreeList in project resource-catalogue by madgeek-arc.

the class FacetLabelService method createLabels.

@SuppressWarnings("unchecked")
public List<Facet> createLabels(List<Facet> facets) {
    // unchecked warning here
    List<Facet> enrichedFacets = new TreeList();
    FacetFilter ff = new FacetFilter();
    ff.setQuantity(maxQuantity);
    // ff.addFilter("active", "true");
    Map<String, String> providerNames = providerService.getAll(ff, null).getResults().stream().collect(Collectors.toMap(ProviderBundle::getId, p -> p.getProvider().getName()));
    Map<String, Vocabulary> allVocabularies = vocabularyService.getVocabulariesMap();
    Facet superCategories;
    Facet categories;
    Facet scientificDomains;
    for (Facet facet : facets) {
        if (facet.getField().equals("subcategories")) {
            categories = createCategoriesFacet(facet);
            superCategories = createSupercategoriesFacet(categories);
            enrichedFacets.add(superCategories);
            enrichedFacets.add(categories);
        }
        if (facet.getField().equals("scientific_subdomains")) {
            scientificDomains = createScientificDomainsFacet(facet);
            enrichedFacets.add(scientificDomains);
        }
        for (Value value : facet.getValues()) {
            switch(facet.getField()) {
                case "resource_providers":
                case "resource_organisation":
                    value.setLabel(providerNames.get(value.getValue()));
                    break;
                default:
                    if (allVocabularies.containsKey(value.getValue())) {
                        value.setLabel(allVocabularies.get(value.getValue()).getName());
                    } else {
                        try {
                            value.setLabel(toProperCase(toProperCase(value.getValue(), "-", "-"), "_", " "));
                        } catch (StringIndexOutOfBoundsException e) {
                            logger.info(e);
                        }
                    }
            }
        }
    }
    enrichedFacets.addAll(facets);
    // Swap position according to front-ends needs
    try {
        Collections.swap(enrichedFacets, 4, 5);
    } catch (IndexOutOfBoundsException e) {
        logger.info(e);
    }
    return enrichedFacets;
}
Also used : java.util(java.util) ProviderService(eu.einfracentral.registry.service.ProviderService) Facet(eu.openminted.registry.core.domain.Facet) Autowired(org.springframework.beans.factory.annotation.Autowired) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Collectors(java.util.stream.Collectors) Vocabulary(eu.einfracentral.domain.Vocabulary) Value(eu.openminted.registry.core.domain.Value) Component(org.springframework.stereotype.Component) ProviderBundle(eu.einfracentral.domain.ProviderBundle) Logger(org.apache.logging.log4j.Logger) TreeList(org.apache.commons.collections.list.TreeList) Authentication(org.springframework.security.core.Authentication) VocabularyService(eu.einfracentral.registry.service.VocabularyService) LogManager(org.apache.logging.log4j.LogManager) Vocabulary(eu.einfracentral.domain.Vocabulary) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Value(eu.openminted.registry.core.domain.Value) TreeList(org.apache.commons.collections.list.TreeList) Facet(eu.openminted.registry.core.domain.Facet)

Aggregations

ProviderBundle (eu.einfracentral.domain.ProviderBundle)1 Vocabulary (eu.einfracentral.domain.Vocabulary)1 ProviderService (eu.einfracentral.registry.service.ProviderService)1 VocabularyService (eu.einfracentral.registry.service.VocabularyService)1 Facet (eu.openminted.registry.core.domain.Facet)1 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)1 Value (eu.openminted.registry.core.domain.Value)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 TreeList (org.apache.commons.collections.list.TreeList)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Authentication (org.springframework.security.core.Authentication)1 Component (org.springframework.stereotype.Component)1