Search in sources :

Example 1 with EmailMessage

use of it.cnr.cool.mail.model.EmailMessage in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method schedeNonAnonime.

public void schedeNonAnonime(PrintParameterModel item) {
    final Session adminSession = cmisService.createAdminSession();
    final String idCall = Optional.ofNullable(item.getIds()).map(List::stream).map(Stream::findFirst).orElseThrow(() -> new ClientMessageException("ID CALL NOT FOUND")).orElseThrow(() -> new ClientMessageException("ID CALL NOT FOUND"));
    final String callCodice = adminSession.getObject(idCall).getPropertyValue(JCONONPropertyIds.CALL_CODICE.value());
    String messageBody = schedeNonAnonime(adminSession, idCall, item.getContextURL());
    EmailMessage message = new EmailMessage();
    message.setBody("<b>Il processo di controllo delle schede anonime relative al bando " + callCodice + " è terminato.</b><br>" + messageBody);
    message.setHtmlBody(true);
    message.setSubject(i18nService.getLabel("subject-info", Locale.ITALIAN) + "Controllo delle schede anonime - " + callCodice);
    message.setRecipients(Arrays.asList(item.getIndirizzoEmail()));
    mailService.send(message);
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) Stream(java.util.stream.Stream) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession)

Example 2 with EmailMessage

use of it.cnr.cool.mail.model.EmailMessage in project cool-jconon by consiglionazionaledellericerche.

the class CallService method convocazioniAsync.

@Async("threadPoolTaskExecutor")
public Long convocazioniAsync(Session session, MultipartHttpServletRequest mRequest, BindingSession bindingSession, String contextURL, Locale locale, String userId) throws IOException {
    final Long aLong = convocazioni(session, mRequest, bindingSession, contextURL, locale, userId);
    CMISUser user = userService.loadUserForConfirm(userId);
    EmailMessage message = new EmailMessage();
    message.setBody(i18NService.getLabel("message.convocazioni.async.email.body", locale, aLong));
    message.setHtmlBody(true);
    message.setSubject(i18NService.getLabel("subject-info", locale));
    message.setRecipients(Arrays.asList(user.getEmail()));
    mailService.send(message);
    return aLong;
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) Async(org.springframework.scheduling.annotation.Async)

Example 3 with EmailMessage

use of it.cnr.cool.mail.model.EmailMessage in project cool-jconon by consiglionazionaledellericerche.

the class CallService method comunicazioniAsync.

@Async("threadPoolTaskExecutor")
public Long comunicazioniAsync(Session session, MultipartHttpServletRequest mRequest, BindingSession bindingSession, String contextURL, Locale locale, String userId) throws IOException {
    final Long aLong = comunicazioni(session, mRequest, bindingSession, contextURL, locale, userId);
    CMISUser user = userService.loadUserForConfirm(userId);
    EmailMessage message = new EmailMessage();
    message.setBody(i18NService.getLabel("message.comunicazioni.async.email.body", locale, aLong));
    message.setHtmlBody(true);
    message.setSubject(i18NService.getLabel("subject-info", locale));
    message.setRecipients(Arrays.asList(user.getEmail()));
    mailService.send(message);
    return aLong;
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) Async(org.springframework.scheduling.annotation.Async)

Example 4 with EmailMessage

use of it.cnr.cool.mail.model.EmailMessage in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method printApplication.

public void printApplication(String nodeRef, final String contextURL, final Locale locale, final boolean email) {
    try {
        LOGGER.info("Start print application width id: " + nodeRef);
        Session cmisSession = cmisService.createAdminSession();
        Folder application = (Folder) cmisSession.getObject(nodeRef);
        Boolean confirmed = isConfirmed(application);
        Folder call = (Folder) cmisSession.getObject(application.getParentId());
        application.refresh();
        CMISUser applicationUser;
        try {
            applicationUser = userService.loadUserForConfirm(application.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()));
        } catch (CoolUserFactoryException e) {
            throw new ClientMessageException("User not found of application " + nodeRef, e);
        }
        String nameRicevutaReportModel = getNameRicevutaReportModel(cmisSession, application, locale);
        byte[] stampaByte = getRicevutaReportModel(cmisSession, application, contextURL, nameRicevutaReportModel, false);
        InputStream is = new ByteArrayInputStream(stampaByte);
        archiviaRicevutaReportModel(cmisSession, application, is, nameRicevutaReportModel, confirmed);
        /**
         * Spedisco la mail con la stampa allegata
         */
        if (email) {
            Map<String, Object> mailModel = new HashMap<String, Object>();
            List<String> emailList = new ArrayList<String>();
            emailList.add(applicationUser.getEmail());
            mailModel.put("contextURL", contextURL);
            mailModel.put("folder", application);
            mailModel.put("call", call);
            mailModel.put("message", context.getBean("messageMethod", locale));
            mailModel.put("email_comunicazione", applicationUser.getEmail());
            EmailMessage message = new EmailMessage();
            message.setRecipients(emailList);
            message.setCcRecipients(getCcRecipientsForPrint(confirmed));
            message.setBccRecipients(getBccRecipientsForPrint(confirmed));
            String body;
            if (confirmed) {
                body = Util.processTemplate(mailModel, "/pages/application/application.registration.html.ftl");
                message.setSubject(i18nService.getLabel("subject-info", locale) + i18nService.getLabel("subject-confirm-domanda", locale, call.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString()));
                Map<String, Object> properties = new HashMap<String, Object>();
                properties.put(JCONONPropertyIds.APPLICATION_DUMMY.value(), "{\"stampa_archiviata\" : true}");
                application.updateProperties(properties);
            } else {
                body = Util.processTemplate(mailModel, "/pages/application/application.print.html.ftl");
                message.setSubject(i18nService.getLabel("subject-info", locale) + i18nService.getLabel("subject-print-domanda", locale, call.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString()));
            }
            message.setBody(body);
            message.setAttachments(Arrays.asList(new AttachmentBean(nameRicevutaReportModel, stampaByte)));
            mailService.send(message);
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info("End print application width id: " + nodeRef);
    } catch (Exception t) {
        LOGGER.error("Error while print application width id:" + nodeRef, t);
    }
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) AttachmentBean(it.cnr.cool.mail.model.AttachmentBean) JSONException(org.json.JSONException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) WriterException(com.google.zxing.WriterException) ParseException(java.text.ParseException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession)

Example 5 with EmailMessage

use of it.cnr.cool.mail.model.EmailMessage in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method extractionApplication.

public void extractionApplication(PrintParameterModel item) {
    String objectId = extractionApplication(cmisService.createAdminSession(), item.getIds(), item.getType(), item.getQueryType(), item.getContextURL(), item.getUserId());
    EmailMessage message = new EmailMessage();
    message.setBody("<b>Il processo di estrazione è terminato.</b><br>È possibile scaricare il file dal seguente <a href=\"" + item.getContextURL() + "/rest/content?deleteAfterDownload=true&nodeRef=" + objectId + "\">link</a>");
    message.setHtmlBody(true);
    message.setSubject(i18nService.getLabel("subject-info", Locale.ITALIAN) + "Estrazione");
    message.setRecipients(Arrays.asList(item.getIndirizzoEmail()));
    mailService.send(message);
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage)

Aggregations

EmailMessage (it.cnr.cool.mail.model.EmailMessage)10 CMISUser (it.cnr.cool.security.service.impl.alfresco.CMISUser)6 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)6 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)5 ParseException (java.text.ParseException)5 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 Criteria (it.cnr.si.opencmis.criteria.Criteria)4 BindingSession (org.apache.chemistry.opencmis.client.bindings.spi.BindingSession)4 WriterException (com.google.zxing.WriterException)3 CMISApplicationException (it.cnr.cool.web.scripts.exception.CMISApplicationException)3 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 Async (org.springframework.scheduling.annotation.Async)3 JsonObject (com.google.gson.JsonObject)2 MessagingException (javax.mail.MessagingException)2 AddressException (javax.mail.internet.AddressException)2 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)2 EmailException (org.apache.commons.mail.EmailException)2