use of eu.einfracentral.domain.Provider 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.Provider in project resource-catalogue by madgeek-arc.
the class AbstractSyncService method syncVerify.
@Override
public void syncVerify(T t) {
boolean retryKey = true;
if (active) {
HttpEntity<T> request = new HttpEntity<>(t, createHeaders());
URI uri;
logger.info("Verifying resource with id: {} - Host: {}", t.getId(), host);
try {
if (t instanceof Provider) {
uri = new URI(host + controller + "/verifyProvider/" + t.getId() + "?active=true&status=approved%20provider").normalize();
} else {
uri = new URI(host + controller + "/verifyResource/" + t.getId() + "?active=true&status=approved%20resource").normalize();
}
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
restTemplate.setRequestFactory(requestFactory);
ResponseEntity<?> re = restTemplate.exchange(uri.normalize(), HttpMethod.PATCH, request, t.getClass());
if (re.getStatusCode() != HttpStatus.OK) {
logger.error("Verifying {} with id '{}' from host '{}' returned code '{}'\nResponse body:\n{}", t.getClass(), t.getId(), host, re.getStatusCodeValue(), re.getBody());
} else {
retryKey = false;
}
} catch (URISyntaxException e) {
logger.error("could not create URI for host: {}", host, e);
} catch (HttpServerErrorException e) {
logger.error("Failed to patch {} with id {} to host {}\nMessage: {}", t.getClass(), t.getId(), host, e.getResponseBodyAsString());
} catch (RuntimeException re) {
logger.error("syncVerify failed, check if token has expired!\n{}: {}", t.getClass(), t, re);
}
if (retryKey) {
try {
queue.add(Pair.with(t, "verify"));
} catch (IllegalStateException e) {
logger.info("No space is currently available in the Queue");
}
}
}
}
Aggregations