use of eu.einfracentral.domain.ProviderBundle 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.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.
the class CSVController method providersToCSV.
// Downloads a csv file with Provider entries
@GetMapping(path = "providers", produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EPOT')")
public ResponseEntity<String> providersToCSV(@ApiIgnore Authentication auth, HttpServletResponse response) {
FacetFilter ff = new FacetFilter();
ff.setQuantity(maxQuantity);
Paging<ProviderBundle> providers = providerService.getAll(ff, auth);
String csvData = listProvidersToCSV(providers.getResults());
response.setHeader("Content-disposition", "attachment; filename=" + "providers.csv");
return ResponseEntity.ok(csvData);
}
use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.
the class PendingProviderController method temporarySavePending.
@PutMapping(path = "/pending", produces = { MediaType.APPLICATION_JSON_VALUE })
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<Provider> temporarySavePending(@RequestBody Provider provider, @ApiIgnore Authentication auth) {
ProviderBundle bundle = new ProviderBundle();
if (provider.getId() == null || provider.getId().equals("")) {
provider.setId(idCreator.createProviderId(provider));
}
try {
bundle = pendingProviderService.get(provider.getId());
bundle.setProvider(provider);
bundle = pendingProviderService.update(bundle, auth);
} catch (ResourceException e) {
logger.debug("Pending Provider with id '{}' does not exist. Creating it...", provider.getId());
bundle.setProvider(provider);
bundle = pendingProviderService.add(bundle, auth);
}
return new ResponseEntity<>(bundle.getProvider(), HttpStatus.OK);
}
use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.
the class OIDCSecurityService method providerIsActiveAndUserIsAdmin.
public boolean providerIsActiveAndUserIsAdmin(Authentication auth, String serviceId) {
InfraService service = infraServiceService.get(serviceId);
// List<String> providerIds = service.getService().getResourceProviders();
// providerIds.add(service.getService().getResourceOrganisation());
List<String> providerIds = Collections.singletonList(service.getService().getResourceOrganisation());
for (String providerId : providerIds) {
ProviderBundle provider = providerManager.get(providerId);
if (provider != null && provider.isActive()) {
if (isProviderAdmin(auth, providerId)) {
return true;
}
}
}
return false;
}
use of eu.einfracentral.domain.ProviderBundle 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