use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.
the class ProviderManagementAspect method updateServiceProviderStates.
// TODO: Probably no needed
/**
* This method is used to update a list of new providers with status
* 'Provider.States.ST_SUBMISSION' or 'Provider.States.REJECTED_ST'
* to status 'Provider.States.PENDING_2'
*
* @param infraService
*/
@Async
@CacheEvict(value = CACHE_PROVIDERS, allEntries = true)
public void updateServiceProviderStates(InfraService infraService) {
try {
ProviderBundle providerBundle = providerService.get(infraService.getService().getResourceOrganisation(), (Authentication) null);
if (providerBundle.getTemplateStatus().equals("no template status") || providerBundle.getTemplateStatus().equals("rejected template")) {
logger.debug("Updating state of Provider with id '{}' : '{}' --> to '{}'", infraService.getService().getResourceOrganisation(), providerBundle.getTemplateStatus(), "pending resource");
infraServiceService.verifyResource(infraService.getService().getId(), "pending resource", false, securityService.getAdminAccess());
}
} catch (RuntimeException e) {
logger.error(e);
}
}
use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.
the class ProviderManagementAspect method providerRegistrationEmails.
@AfterReturning(pointcut = "(execution(* eu.einfracentral.registry.manager.InfraServiceManager.verifyResource(String, " + "String, Boolean, org.springframework.security.core.Authentication)))", returning = "infraService")
public void providerRegistrationEmails(InfraService infraService) {
ProviderBundle providerBundle = providerService.get(infraService.getService().getResourceOrganisation());
logger.trace("Sending Registration emails");
registrationMailService.sendProviderMails(providerBundle);
}
use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.
the class ProviderRequestManager method sendMailsToProviders.
@Async
public void sendMailsToProviders(List<String> serviceIds, EmailMessage message, Authentication auth) {
boolean sendOnce = false;
Map<String, String> providersToBeMailed = new LinkedHashMap<>();
Map<String, String> providerContactNames = new LinkedHashMap<>();
List<String> serviceNames = new ArrayList<>();
for (String serviceId : serviceIds) {
InfraService service = infraServiceService.get(serviceId);
serviceNames.add(service.getService().getName());
List<String> providerIds = service.getService().getResourceProviders();
providerIds.add(service.getService().getResourceOrganisation());
for (String providerId : providerIds) {
ProviderBundle providerBundle = providerService.get(providerId, securityService.getAdminAccess());
providerContactNames.put(providerBundle.getProvider().getMainContact().getLastName(), providerBundle.getProvider().getMainContact().getFirstName());
providersToBeMailed.put(providerBundle.getProvider().getId(), providerBundle.getProvider().getMainContact().getEmail());
}
}
Map<String, Object> root = new HashMap<>();
StringWriter out1 = new StringWriter();
StringWriter out2 = new StringWriter();
for (Map.Entry<String, String> entry : providersToBeMailed.entrySet()) {
Map.Entry<String, String> fullname = providerContactNames.entrySet().iterator().next();
String key = fullname.getKey();
providerContactNames.remove(key);
String providerSubject = String.format("[%s] You have a new message from user [%s]-[%s], considering the Provider [%s]", projectName, message.getSenderName(), message.getSenderEmail(), entry.getKey());
String userSubject = String.format("[%s] Your message considering the CatRIS Services has been sent successfully", projectName);
root.put("providerContactLastName", fullname.getKey());
root.put("providerContactFirstName", fullname.getValue());
root.put("project", projectName);
root.put("provider", entry.getKey());
root.put("message", message);
root.put("services", serviceNames);
try {
Template temp = cfg.getTemplate("providerRequestProviderTemplate.ftl");
temp.process(root, out1);
String providerMail = out1.getBuffer().toString();
mailService.sendMail(entry.getValue(), providerSubject, providerMail);
logger.info("Recipient: {}\nTitle: {}\nMail body: \n{}", entry.getValue(), providerSubject, providerMail);
temp = cfg.getTemplate("providerRequestUserTemplate.ftl");
temp.process(root, out2);
String userMail = out2.getBuffer().toString();
if (!sendOnce) {
mailService.sendMail(message.getSenderEmail(), userSubject, userMail);
sendOnce = true;
}
logger.info("Recipient: {}\nTitle: {}\nMail body: \n{}", message.getSenderEmail(), userSubject, userMail);
out1.getBuffer().setLength(0);
out2.getBuffer().setLength(0);
out1.close();
out2.close();
} catch (IOException e) {
logger.error("Error finding mail template", e);
} catch (TemplateException e) {
logger.error("ERROR", e);
} catch (MessagingException e) {
logger.error("Could not send mail", e);
}
ProviderRequest providerRequest = new ProviderRequest();
message.setRecipientEmail(entry.getValue());
providerRequest.setDate(String.valueOf(System.currentTimeMillis()));
providerRequest.setMessage(message);
providerRequest.setProviderId(entry.getKey());
providerRequest.setRead(false);
add(providerRequest, auth);
}
}
use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.
the class StatisticsManager method providerCountriesMap.
private Map<String, Set<String>> providerCountriesMap() {
Map<String, Set<String>> providerCountries = new HashMap<>();
String[] world = vocabularyService.getRegion("WW");
String[] eu = vocabularyService.getRegion("EU");
FacetFilter ff = new FacetFilter();
ff.setQuantity(maxQuantity);
for (ProviderBundle providerBundle : providerService.getAll(ff, null).getResults()) {
Set<String> countries = new HashSet<>();
String country = providerBundle.getProvider().getLocation().getCountry();
if (country.equalsIgnoreCase("WW")) {
countries.addAll(Arrays.asList(world));
} else if (country.equalsIgnoreCase("EU")) {
countries.addAll(Arrays.asList(eu));
} else {
countries.add(country);
}
providerCountries.put(providerBundle.getId(), countries);
}
return providerCountries;
}
use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.
the class PendingProviderController method temporarySaveProvider.
@PutMapping(path = "/provider", produces = { MediaType.APPLICATION_JSON_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EPOT') or @securityService.isProviderAdmin(#auth, #provider)")
public ResponseEntity<Provider> temporarySaveProvider(@RequestBody Provider provider, @ApiIgnore Authentication auth) {
pendingProviderService.transformToPending(provider.getId(), auth);
ProviderBundle bundle = pendingProviderService.get(provider.getId());
bundle.setProvider(provider);
return new ResponseEntity<>(pendingProviderService.update(bundle, auth).getProvider(), HttpStatus.OK);
}
Aggregations