use of eu.openminted.registry.core.domain.Facet in project resource-catalogue by madgeek-arc.
the class FacetLabelService method createCategoriesFacet.
Facet createCategoriesFacet(Facet subcategories) {
List<Value> categoriesValues = new ArrayList<>();
Map<String, Vocabulary> categoriesMap = new TreeMap<>();
for (Value value : subcategories.getValues()) {
Vocabulary parent = vocabularyService.getParent(value.getValue());
if (parent != null) {
categoriesMap.putIfAbsent(parent.getId(), parent);
}
}
for (Vocabulary category : categoriesMap.values()) {
Value value = new Value();
value.setValue(category.getId());
value.setLabel(category.getName());
categoriesValues.add(value);
}
Facet categories = new Facet();
categories.setField("categories");
categories.setLabel("Categories");
categories.setValues(categoriesValues);
return categories;
}
use of eu.openminted.registry.core.domain.Facet 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;
}
use of eu.openminted.registry.core.domain.Facet in project resource-catalogue by madgeek-arc.
the class FacetLabelService method createScientificDomainsFacet.
Facet createScientificDomainsFacet(Facet scientificSubdomains) {
List<Value> scientificDomainsValues = new ArrayList<>();
Map<String, Vocabulary> categoriesMap = new TreeMap<>();
for (Value value : scientificSubdomains.getValues()) {
Vocabulary parent = vocabularyService.getParent(value.getValue());
if (parent != null) {
categoriesMap.putIfAbsent(parent.getId(), parent);
}
}
for (Vocabulary category : categoriesMap.values()) {
Value value = new Value();
value.setValue(category.getId());
value.setLabel(category.getName());
scientificDomainsValues.add(value);
}
Facet scientificDomains = new Facet();
scientificDomains.setField("scientific_domains");
scientificDomains.setLabel("Scientific Domains");
scientificDomains.setValues(scientificDomainsValues);
return scientificDomains;
}
use of eu.openminted.registry.core.domain.Facet in project resource-catalogue by madgeek-arc.
the class FacetLabelService method createSupercategoriesFacet.
Facet createSupercategoriesFacet(Facet categories) {
List<Value> superCategoriesValues = new ArrayList<>();
Map<String, Vocabulary> categoriesMap = new TreeMap<>();
for (Value value : categories.getValues()) {
Vocabulary parent = vocabularyService.getParent(value.getValue());
if (parent != null) {
categoriesMap.putIfAbsent(parent.getId(), parent);
}
}
for (Vocabulary category : categoriesMap.values()) {
Value value = new Value();
value.setValue(category.getId());
value.setLabel(category.getName());
superCategoriesValues.add(value);
}
Facet superCategories = new Facet();
superCategories.setField("supercategories");
superCategories.setLabel("Supercategories");
superCategories.setValues(superCategoriesValues);
return superCategories;
}
use of eu.openminted.registry.core.domain.Facet in project resource-catalogue by madgeek-arc.
the class InfoController method getAllServicesNumbers.
// Get Info about #SPs, #Services etc.
@GetMapping(path = "all", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Map<Object, Object>> getAllServicesNumbers(@ApiIgnore Authentication authentication) {
Map<Object, Object> servicesInfo = new HashMap<>();
FacetFilter ff = new FacetFilter();
ff.addFilter("active", true);
servicesInfo.put("providers", (long) providerService.getAll(ff, authentication).getTotal());
ff.addFilter("latest", true);
Paging<InfraService> infraServices = infraService.getAll(ff, null);
servicesInfo.put("services", (long) infraServices.getTotal());
for (Facet f : infraServices.getFacets()) {
if (f.getField().equals("resourceType")) {
continue;
}
servicesInfo.putIfAbsent(f.getField(), (long) f.getValues().size());
}
return ResponseEntity.ok(servicesInfo);
}
Aggregations