Search in sources :

Example 6 with ProviderBundle

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);
    }
}
Also used : ProviderBundle(eu.einfracentral.domain.ProviderBundle) Async(org.springframework.scheduling.annotation.Async) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 7 with ProviderBundle

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);
}
Also used : ProviderBundle(eu.einfracentral.domain.ProviderBundle) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 8 with 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);
    }
}
Also used : TemplateException(freemarker.template.TemplateException) MessagingException(javax.mail.MessagingException) ProviderBundle(eu.einfracentral.domain.ProviderBundle) IOException(java.io.IOException) Template(freemarker.template.Template) ProviderRequest(eu.einfracentral.domain.ProviderRequest) InfraService(eu.einfracentral.domain.InfraService) StringWriter(java.io.StringWriter) Async(org.springframework.scheduling.annotation.Async)

Example 9 with ProviderBundle

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;
}
Also used : FacetFilter(eu.openminted.registry.core.domain.FacetFilter) ProviderBundle(eu.einfracentral.domain.ProviderBundle)

Example 10 with ProviderBundle

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ProviderBundle(eu.einfracentral.domain.ProviderBundle) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ProviderBundle (eu.einfracentral.domain.ProviderBundle)11 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 ResponseEntity (org.springframework.http.ResponseEntity)3 InfraService (eu.einfracentral.domain.InfraService)2 ProviderService (eu.einfracentral.registry.service.ProviderService)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Async (org.springframework.scheduling.annotation.Async)2 Authentication (org.springframework.security.core.Authentication)2 Component (org.springframework.stereotype.Component)2 JWT (com.nimbusds.jwt.JWT)1 Provider (eu.einfracentral.domain.Provider)1 ProviderRequest (eu.einfracentral.domain.ProviderRequest)1 Vocabulary (eu.einfracentral.domain.Vocabulary)1 ResourceException (eu.einfracentral.exception.ResourceException)1 PendingResourceService (eu.einfracentral.registry.service.PendingResourceService)1