Search in sources :

Example 1 with FacetFilter

use of eu.openminted.registry.core.domain.FacetFilter in project resource-catalogue by madgeek-arc.

the class EICAuthoritiesMapper method mapAuthorities.

private void mapAuthorities(String admins) {
    userRolesMap = new HashMap<>();
    FacetFilter ff = new FacetFilter();
    ff.setQuantity(maxQuantity);
    try {
        List<ProviderBundle> providers = providerService.getAll(ff, securityService.getAdminAccess()).getResults();
        providers.addAll(pendingProviderService.getAll(ff, null).getResults());
        userRolesMap = providers.stream().distinct().map(providerBundle -> {
            if (providerBundle.getProvider() != null && providerBundle.getProvider().getUsers() != null) {
                return providerBundle.getProvider();
            }
            return null;
        }).filter(Objects::nonNull).flatMap((Function<Provider, Stream<String>>) provider -> provider.getUsers().stream().filter(Objects::nonNull).map(u -> {
            if (u.getId() != null && !"".equals(u.getId())) {
                return u.getId();
            }
            return u.getEmail().toLowerCase();
        })).filter(Objects::nonNull).distinct().collect(Collectors.toMap(Function.identity(), a -> new SimpleGrantedAuthority("ROLE_PROVIDER")));
    } catch (Exception e) {
        logger.warn("There are no Provider entries in DB");
    }
    userRolesMap.putAll(Arrays.stream(epotAdmins.replace(" ", "").split(",")).map(String::toLowerCase).collect(Collectors.toMap(Function.identity(), a -> new SimpleGrantedAuthority("ROLE_EPOT"))));
    userRolesMap.putAll(Arrays.stream(admins.replace(" ", "").split(",")).map(String::toLowerCase).collect(Collectors.toMap(Function.identity(), a -> new SimpleGrantedAuthority("ROLE_ADMIN"))));
}
Also used : SecurityService(eu.einfracentral.service.SecurityService) java.util(java.util) Provider(eu.einfracentral.domain.Provider) Autowired(org.springframework.beans.factory.annotation.Autowired) PropertySource(org.springframework.context.annotation.PropertySource) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UnauthorizedUserException(org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException) OIDCAuthoritiesMapper(org.mitre.openid.connect.client.OIDCAuthoritiesMapper) Function(java.util.function.Function) AuthoritiesMapper(eu.einfracentral.service.AuthoritiesMapper) ServiceException(eu.openminted.registry.core.service.ServiceException) Value(org.springframework.beans.factory.annotation.Value) JWT(com.nimbusds.jwt.JWT) ProviderService(eu.einfracentral.registry.service.ProviderService) UserInfo(org.mitre.openid.connect.model.UserInfo) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Component(org.springframework.stereotype.Component) ProviderBundle(eu.einfracentral.domain.ProviderBundle) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) PendingResourceService(eu.einfracentral.registry.service.PendingResourceService) Authentication(org.springframework.security.core.Authentication) LogManager(org.apache.logging.log4j.LogManager) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) ProviderBundle(eu.einfracentral.domain.ProviderBundle) Stream(java.util.stream.Stream) UnauthorizedUserException(org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException) ServiceException(eu.openminted.registry.core.service.ServiceException) Provider(eu.einfracentral.domain.Provider)

Example 2 with FacetFilter

use of eu.openminted.registry.core.domain.FacetFilter in project resource-catalogue by madgeek-arc.

the class ProviderController method getAll.

@ApiOperation(value = "Filter a list of Providers based on a set of filters or get a list of all Providers in the Catalogue.")
@ApiImplicitParams({ @ApiImplicitParam(name = "query", value = "Keyword to refine the search", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "from", value = "Starting index in the result set", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "quantity", value = "Quantity to be fetched", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "order", value = "asc / desc", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "orderField", value = "Order field", dataType = "string", paramType = "query") })
@GetMapping(path = "all", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public ResponseEntity<Paging<Provider>> getAll(@ApiIgnore @RequestParam Map<String, Object> allRequestParams, @ApiIgnore Authentication auth) {
    FacetFilter ff = new FacetFilter();
    ff.setKeyword(allRequestParams.get("query") != null ? (String) allRequestParams.remove("query") : "");
    ff.setFrom(allRequestParams.get("from") != null ? Integer.parseInt((String) allRequestParams.remove("from")) : 0);
    ff.setQuantity(allRequestParams.get("quantity") != null ? Integer.parseInt((String) allRequestParams.remove("quantity")) : 10);
    Map<String, Object> sort = new HashMap<>();
    Map<String, Object> order = new HashMap<>();
    String orderDirection = allRequestParams.get("order") != null ? (String) allRequestParams.remove("order") : "asc";
    String orderField = allRequestParams.get("orderField") != null ? (String) allRequestParams.remove("orderField") : null;
    if (orderField != null) {
        order.put("order", orderDirection);
        sort.put(orderField, order);
        ff.setOrderBy(sort);
    }
    ff.setFilter(allRequestParams);
    List<Provider> providerList = new LinkedList<>();
    Paging<ProviderBundle> providerBundlePaging = providerManager.getAll(ff, auth);
    for (ProviderBundle providerBundle : providerBundlePaging.getResults()) {
        providerList.add(providerBundle.getProvider());
    }
    Paging<Provider> providerPaging = new Paging<>(providerBundlePaging.getTotal(), providerBundlePaging.getFrom(), providerBundlePaging.getTo(), providerList, providerBundlePaging.getFacets());
    return new ResponseEntity<>(providerPaging, HttpStatus.OK);
}
Also used : FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Paging(eu.openminted.registry.core.domain.Paging) ResponseEntity(org.springframework.http.ResponseEntity) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with FacetFilter

use of eu.openminted.registry.core.domain.FacetFilter in project resource-catalogue by madgeek-arc.

the class ProviderController method getAllProviderBundles.

// Filter a list of Providers based on a set of filters or get a list of all Providers in the Catalogue.
@ApiImplicitParams({ @ApiImplicitParam(name = "query", value = "Keyword to refine the search", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "from", value = "Starting index in the result set", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "quantity", value = "Quantity to be fetched", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "order", value = "asc / desc", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "orderField", value = "Order field", dataType = "string", paramType = "query") })
@GetMapping(path = "bundle/all", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EPOT')")
public ResponseEntity<Paging<ProviderBundle>> getAllProviderBundles(@ApiIgnore @RequestParam Map<String, Object> allRequestParams, @ApiIgnore Authentication auth, @RequestParam(required = false) Set<String> status, @RequestParam(required = false) Set<String> templateStatus, @RequestParam(required = false) Set<String> auditState) {
    FacetFilter ff = new FacetFilter();
    ff.setKeyword(allRequestParams.get("query") != null ? (String) allRequestParams.remove("query") : "");
    ff.setFrom(allRequestParams.get("from") != null ? Integer.parseInt((String) allRequestParams.remove("from")) : 0);
    ff.setQuantity(allRequestParams.get("quantity") != null ? Integer.parseInt((String) allRequestParams.remove("quantity")) : 10);
    Map<String, Object> sort = new HashMap<>();
    Map<String, Object> order = new HashMap<>();
    String orderDirection = allRequestParams.get("order") != null ? (String) allRequestParams.remove("order") : "asc";
    String orderField = allRequestParams.get("orderField") != null ? (String) allRequestParams.remove("orderField") : null;
    if (orderField != null) {
        order.put("order", orderDirection);
        sort.put(orderField, order);
        ff.setOrderBy(sort);
    }
    if (status != null) {
        ff.addFilter("status", status);
    }
    if (templateStatus != null) {
        ff.addFilter("templateStatus", templateStatus);
    }
    int quantity = ff.getQuantity();
    int from = ff.getFrom();
    List<Map<String, Object>> records = providerManager.createQueryForProviderFilters(ff, orderDirection, orderField);
    List<ProviderBundle> ret = new ArrayList<>();
    Paging<ProviderBundle> retPaging = providerManager.getAll(ff, auth);
    for (Map<String, Object> record : records) {
        for (Map.Entry<String, Object> entry : record.entrySet()) {
            ret.add(providerManager.get((String) entry.getValue()));
        }
    }
    if (auditState == null) {
        return ResponseEntity.ok(providerManager.createCorrectQuantityFacets(ret, retPaging, quantity, from));
    } else {
        Paging<ProviderBundle> retWithAuditState = providerManager.determineAuditState(auditState, ff, quantity, from, ret, auth);
        return ResponseEntity.ok(retWithAuditState);
    }
}
Also used : FacetFilter(eu.openminted.registry.core.domain.FacetFilter) MultiValueMap(org.springframework.util.MultiValueMap) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with FacetFilter

use of eu.openminted.registry.core.domain.FacetFilter in project resource-catalogue by madgeek-arc.

the class ProviderController method getRandomProviders.

@ApiImplicitParams({ @ApiImplicitParam(name = "query", value = "Keyword to refine the search", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "from", value = "Starting index in the result set", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "quantity", value = "Quantity to be fetched", dataType = "string", paramType = "query") })
@GetMapping(path = "randomProviders", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EPOT')")
public ResponseEntity<Paging<ProviderBundle>> getRandomProviders(@ApiIgnore @RequestParam Map<String, Object> allRequestParams, @ApiIgnore Authentication auth) {
    FacetFilter ff = new FacetFilter();
    ff.setKeyword(allRequestParams.get("query") != null ? (String) allRequestParams.remove("query") : "");
    ff.setFrom(allRequestParams.get("from") != null ? Integer.parseInt((String) allRequestParams.remove("from")) : 0);
    ff.setQuantity(allRequestParams.get("quantity") != null ? Integer.parseInt((String) allRequestParams.remove("quantity")) : 10);
    ff.setFilter(allRequestParams);
    List<ProviderBundle> providerList = new LinkedList<>();
    Paging<ProviderBundle> providerBundlePaging = providerManager.getRandomProviders(ff, auditingInterval, auth);
    for (ProviderBundle providerBundle : providerBundlePaging.getResults()) {
        providerList.add(providerBundle);
    }
    Paging<ProviderBundle> providerPaging = new Paging<>(providerBundlePaging.getTotal(), providerBundlePaging.getFrom(), providerBundlePaging.getTo(), providerList, providerBundlePaging.getFacets());
    return new ResponseEntity<>(providerPaging, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Paging(eu.openminted.registry.core.domain.Paging) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with FacetFilter

use of eu.openminted.registry.core.domain.FacetFilter in project resource-catalogue by madgeek-arc.

the class ServiceController method getSharedResources.

// REVISE: returns InfraService (sensitive data)
// Given a provider id, return all the Resources he is a resourceProvider
@ApiImplicitParams({ @ApiImplicitParam(name = "query", value = "Keyword to refine the search", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "from", value = "Starting index in the result set", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "quantity", value = "Quantity to be fetched", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "order", value = "asc / desc", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "orderField", value = "Order field", dataType = "string", paramType = "query") })
@GetMapping(path = "getSharedResources/{id}", produces = { MediaType.APPLICATION_JSON_VALUE })
public // @PreAuthorize("hasRole('ROLE_ADMIN') or @securityService.isProviderAdmin(#auth,#id)")
ResponseEntity<Paging<InfraService>> getSharedResources(@ApiIgnore @RequestParam MultiValueMap<String, Object> allRequestParams, @RequestParam(required = false) Boolean active, @PathVariable String id, @ApiIgnore Authentication auth) {
    FacetFilter ff = FacetFilterUtils.createMultiFacetFilter(allRequestParams);
    ff.addFilter("latest", true);
    ff.addFilter("resource_providers", id);
    return ResponseEntity.ok(infraService.getAll(ff, null));
}
Also used : FacetFilter(eu.openminted.registry.core.domain.FacetFilter) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams)

Aggregations

FacetFilter (eu.openminted.registry.core.domain.FacetFilter)41 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)13 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 ResponseEntity (org.springframework.http.ResponseEntity)8 InfraService (eu.einfracentral.domain.InfraService)6 ValidationException (eu.einfracentral.exception.ValidationException)5 Collectors (java.util.stream.Collectors)5 CacheEvict (org.springframework.cache.annotation.CacheEvict)5 Authentication (org.springframework.security.core.Authentication)5 ProviderBundle (eu.einfracentral.domain.ProviderBundle)4 Vocabulary (eu.einfracentral.domain.Vocabulary)4 ResourceException (eu.einfracentral.exception.ResourceException)4 ProviderService (eu.einfracentral.registry.service.ProviderService)4 Paging (eu.openminted.registry.core.domain.Paging)4 java.util (java.util)4 ArrayList (java.util.ArrayList)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 Event (eu.einfracentral.domain.Event)3