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;
}
Aggregations