Search in sources :

Example 1 with Facet

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;
}
Also used : Vocabulary(eu.einfracentral.domain.Vocabulary) Value(eu.openminted.registry.core.domain.Value) Facet(eu.openminted.registry.core.domain.Facet)

Example 2 with Facet

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

Example 3 with Facet

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;
}
Also used : Vocabulary(eu.einfracentral.domain.Vocabulary) Value(eu.openminted.registry.core.domain.Value) Facet(eu.openminted.registry.core.domain.Facet)

Example 4 with Facet

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;
}
Also used : Vocabulary(eu.einfracentral.domain.Vocabulary) Value(eu.openminted.registry.core.domain.Value) Facet(eu.openminted.registry.core.domain.Facet)

Example 5 with Facet

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);
}
Also used : InfraService(eu.einfracentral.domain.InfraService) HashMap(java.util.HashMap) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Facet(eu.openminted.registry.core.domain.Facet) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Facet (eu.openminted.registry.core.domain.Facet)5 Vocabulary (eu.einfracentral.domain.Vocabulary)4 Value (eu.openminted.registry.core.domain.Value)4 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)2 InfraService (eu.einfracentral.domain.InfraService)1 ProviderBundle (eu.einfracentral.domain.ProviderBundle)1 ProviderService (eu.einfracentral.registry.service.ProviderService)1 VocabularyService (eu.einfracentral.registry.service.VocabularyService)1 java.util (java.util)1 HashMap (java.util.HashMap)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 GetMapping (org.springframework.web.bind.annotation.GetMapping)1