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