Search in sources :

Example 6 with EmailMessage

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

the class PrintService method generaSchedeValutazione.

private void generaSchedeValutazione(String nodeRef, final String contextURL, final Locale locale, final String indirizzoEmail, final String userId) {
    try {
        Session adminCMISSession = cmisService.createAdminSession();
        Folder bando = (Folder) adminCMISSession.getObject(nodeRef);
        Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
        criteriaDomande.add(Restrictions.inTree(nodeRef));
        criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.CONFERMATA.getValue()));
        criteriaDomande.add(Restrictions.isNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
        OperationContext context = adminCMISSession.getDefaultContext();
        context.setMaxItemsPerPage(10000);
        ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(adminCMISSession, false, context);
        int domandeEstratte = 0;
        for (QueryResult queryResultDomande : domande) {
            String applicationAttach = competitionService.findAttachmentId(adminCMISSession, (String) queryResultDomande.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue(), JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_VALUTAZIONE);
            if (applicationAttach != null) {
                Document scheda = (Document) adminCMISSession.getObject(applicationAttach);
                if (scheda.getVersionLabel().equalsIgnoreCase("1.0")) {
                    scheda.deleteAllVersions();
                } else {
                    continue;
                }
            }
            try {
                printSchedaValutazione(adminCMISSession, (String) queryResultDomande.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue(), contextURL, userId, locale);
                domandeEstratte++;
            } catch (IOException e) {
                LOGGER.error("Error while generaSchedeValutazione", e);
            }
        }
        EmailMessage message = new EmailMessage();
        message.setBody("Il processo di estrazione delle schede relative bando " + bando.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString() + " è terminato.<br>Sono state estratte " + domandeEstratte + " schede.");
        message.setHtmlBody(true);
        message.setSubject(i18nService.getLabel("subject-info", locale) + "Schede di valutazione");
        message.setRecipients(Arrays.asList(indirizzoEmail));
        mailService.send(message);
    } catch (Exception e) {
        LOGGER.error("Error on Message for generaSchedeValutazione with id:" + nodeRef, e);
    }
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) Criteria(it.cnr.si.opencmis.criteria.Criteria) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) 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) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession)

Example 7 with EmailMessage

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

the class PrintService method generaSchedeAnonima.

private void generaSchedeAnonima(String nodeRef, final String contextURL, final Locale locale, final String indirizzoEmail, final String userId) {
    try {
        Session adminCMISSession = cmisService.createAdminSession();
        Folder bando = (Folder) adminCMISSession.getObject(nodeRef);
        Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
        criteriaDomande.add(Restrictions.inTree(nodeRef));
        criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.CONFERMATA.getValue()));
        OperationContext context = adminCMISSession.getDefaultContext();
        context.setMaxItemsPerPage(10000);
        ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(adminCMISSession, false, context);
        int schedeEstratte = 0, numeroScheda = getNumberOfSchedeAnonime(nodeRef, adminCMISSession).intValue();
        String messaggio = "";
        for (QueryResult queryResultDomande : domande) {
            String applicationAttach = competitionService.findAttachmentId(adminCMISSession, (String) queryResultDomande.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue(), JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_ANONIMA_SINTETICA_GENERATED);
            if (queryResultDomande.getPropertyById(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()) != null && queryResultDomande.getPropertyById(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()).getFirstValue() != null) {
                if (applicationAttach != null)
                    adminCMISSession.getObject(applicationAttach).delete();
                continue;
            }
            if (applicationAttach != null) {
                if (adminCMISSession.getObject(applicationAttach).getPropertyValue(JCONONPropertyIds.SCHEDA_ANONIMA_VALUTAZIONE_ESITO.value()) != null) {
                    messaggio = "<BR><b>Alcune schede risultano già valutate, pertanto non sono state estratte nuovamente.</b>";
                    continue;
                } else {
                    adminCMISSession.getObject(applicationAttach).delete();
                }
            }
            try {
                numeroScheda++;
                printSchedaAnonimaDiValutazione(adminCMISSession, (String) queryResultDomande.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue(), contextURL, userId, locale, numeroScheda);
                schedeEstratte++;
            } catch (IOException e) {
                LOGGER.error("Error while generaSchedeValutazione", e);
            }
        }
        EmailMessage message = new EmailMessage();
        message.setBody("Il processo di estrazione delle schede sintetiche anonime relative bando " + bando.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString() + " è terminato.<br>Sono state estratte " + schedeEstratte + " schede." + messaggio);
        message.setHtmlBody(true);
        message.setSubject(i18nService.getLabel("subject-info", locale) + "Schede Sintetiche Anonime");
        message.setRecipients(Arrays.asList(indirizzoEmail));
        mailService.send(message);
    } catch (Exception e) {
        LOGGER.error("Error on Message for generaSchedeValutazione with id:" + nodeRef, e);
    }
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) Criteria(it.cnr.si.opencmis.criteria.Criteria) 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) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession)

Example 8 with EmailMessage

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

the class CallService method sollecitaApplication.

public void sollecitaApplication(Session cmisSession) {
    Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_CALL.queryName());
    criteria.add(Restrictions.inTree(competitionService.getCompetitionFolder().getString("id")));
    ItemIterable<QueryResult> bandi = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
    for (QueryResult queryResult : bandi.getPage(Integer.MAX_VALUE)) {
        BigInteger numGiorniSollecito = (BigInteger) queryResult.getPropertyById(JCONONPropertyIds.CALL_NUM_GIORNI_MAIL_SOLLECITO.value()).getFirstValue();
        if (numGiorniSollecito == null)
            numGiorniSollecito = new BigInteger("8");
        Calendar dataLimite = Calendar.getInstance();
        dataLimite.add(Calendar.DAY_OF_YEAR, numGiorniSollecito.intValue());
        Calendar dataFineDomande = (Calendar) queryResult.getPropertyById(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value()).getFirstValue();
        if (dataFineDomande == null)
            continue;
        if (dataFineDomande.before(dataLimite) && dataFineDomande.after(Calendar.getInstance())) {
            Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
            criteriaDomande.addColumn(JCONONPropertyIds.APPLICATION_USER.value());
            criteriaDomande.addColumn(JCONONPropertyIds.APPLICATION_NOME.value());
            criteriaDomande.addColumn(JCONONPropertyIds.APPLICATION_COGNOME.value());
            criteriaDomande.add(Restrictions.inFolder((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue()));
            criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.PROVVISORIA.getValue()));
            ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
            for (QueryResult queryResultDomande : domande.getPage(Integer.MAX_VALUE)) {
                EmailMessage message = new EmailMessage();
                List<String> emailList = new ArrayList<String>();
                try {
                    CMISUser user = userService.loadUserForConfirm((String) queryResultDomande.getPropertyById(JCONONPropertyIds.APPLICATION_USER.value()).getFirstValue());
                    if (user != null && user.getEmail() != null) {
                        emailList.add(user.getEmail());
                        message.setRecipients(emailList);
                        message.setSubject(i18NService.getLabel("subject-info", Locale.ITALY) + i18NService.getLabel("subject-reminder-domanda", Locale.ITALY, queryResult.getPropertyById(JCONONPropertyIds.CALL_CODICE.value()).getFirstValue(), removeHtmlFromString((String) queryResult.getPropertyById(JCONONPropertyIds.CALL_DESCRIZIONE.value()).getFirstValue())));
                        Map<String, Object> templateModel = new HashMap<String, Object>();
                        templateModel.put("call", queryResult);
                        templateModel.put("folder", queryResultDomande);
                        templateModel.put("message", context.getBean("messageMethod", Locale.ITALY));
                        String body = Util.processTemplate(templateModel, "/pages/call/call.reminder.application.html.ftl");
                        message.setBody(body);
                        mailService.send(message);
                        LOGGER.info("Spedita mail a {} per il bando {}", user.getEmail(), message.getSubject());
                    }
                } catch (Exception e) {
                    LOGGER.error("Cannot send email for scheduler reminder application for call", e);
                }
            }
        }
    }
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) Criteria(it.cnr.si.opencmis.criteria.Criteria) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) ParseException(java.text.ParseException) AddressException(javax.mail.internet.AddressException) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) BigInteger(java.math.BigInteger) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject)

Example 9 with EmailMessage

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

the class CallService method esclusioniAsync.

@Async("threadPoolTaskExecutor")
public Long esclusioniAsync(Session session, MultipartHttpServletRequest mRequest, BindingSession bindingSession, String contextURL, Locale locale, String userId) throws IOException {
    final Long aLong = internalEsclusioni(session, mRequest, bindingSession, contextURL, locale, userId);
    CMISUser user = userService.loadUserForConfirm(userId);
    EmailMessage message = new EmailMessage();
    message.setBody(i18NService.getLabel("message.esclusioni.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 10 with EmailMessage

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

the class CallService method sollecitaProdotti.

public void sollecitaProdotti(Session cmisSession) {
    Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_CALL.queryName());
    Criteria criteriaProfile = criteria.createCriteria(JCONONPolicyType.JCONON_CALL_ASPECT_PRODUCTS_AFTER_COMMISSION.queryName(), JCONONPolicyType.JCONON_CALL_ASPECT_PRODUCTS_AFTER_COMMISSION.queryName());
    criteriaProfile.addJoinCriterion(Restrictions.eqProperty(criteria.prefix(PropertyIds.OBJECT_ID), criteriaProfile.prefix(PropertyIds.OBJECT_ID)));
    ItemIterable<QueryResult> bandi = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
    for (QueryResult queryResult : bandi.getPage(Integer.MAX_VALUE)) {
        Calendar dataInizioCaricamento = queryResult.<Calendar>getPropertyValueById(JCONONPropertyIds.CALL_SELECTED_PRODUCT_START_DATE.value());
        Calendar dataFineCaricamento = queryResult.<Calendar>getPropertyValueById(JCONONPropertyIds.CALL_SELECTED_PRODUCT_END_DATE.value());
        if (dataFineCaricamento == null || dataInizioCaricamento == null)
            continue;
        Calendar dataLimite = Calendar.getInstance();
        dataLimite.add(Calendar.DAY_OF_YEAR, 3);
        if (dataFineCaricamento.before(dataLimite) && dataFineCaricamento.after(Calendar.getInstance())) {
            Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
            criteriaDomande.add(Restrictions.inFolder((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue()));
            criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.CONFERMATA.getValue()));
            criteriaDomande.add(Restrictions.isNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
            ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
            for (QueryResult queryResultDomande : domande.getPage(Integer.MAX_VALUE)) {
                if (!Optional.ofNullable(competitionService.findAttachmentId(cmisSession, queryResultDomande.getPropertyValueById(PropertyIds.OBJECT_ID), JCONONDocumentType.JCONON_ATTACHMENT_CURRICULUM_PROD_SCELTI_MULTIPLO)).isPresent()) {
                    EmailMessage message = new EmailMessage();
                    List<String> emailList = new ArrayList<String>();
                    try {
                        CMISUser user = userService.loadUserForConfirm((String) queryResultDomande.getPropertyById(JCONONPropertyIds.APPLICATION_USER.value()).getFirstValue());
                        if (user != null && user.getEmail() != null) {
                            emailList.add(user.getEmail());
                            message.setRecipients(emailList);
                            message.setSubject(i18NService.getLabel("subject-info", Locale.ITALY) + i18NService.getLabel("subject-reminder-selectedproducts", Locale.ITALY, queryResult.getPropertyById(JCONONPropertyIds.CALL_CODICE.value()).getFirstValue(), removeHtmlFromString((String) queryResult.getPropertyById(JCONONPropertyIds.CALL_DESCRIZIONE.value()).getFirstValue())));
                            Map<String, Object> templateModel = new HashMap<String, Object>();
                            templateModel.put("call", queryResult);
                            templateModel.put("folder", queryResultDomande);
                            templateModel.put("message", context.getBean("messageMethod", Locale.ITALY));
                            String body = Util.processTemplate(templateModel, "/pages/call/call.reminder.selectedproducts.html.ftl");
                            message.setBody(body);
                            mailService.send(message);
                            LOGGER.info("Spedita mail a {} per il bando {} con testo {}", user.getEmail(), message.getSubject(), body);
                        }
                    } catch (Exception e) {
                        LOGGER.error("Cannot send email for scheduler reminder application for call", e);
                    }
                }
            }
        }
    }
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) Criteria(it.cnr.si.opencmis.criteria.Criteria) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) ParseException(java.text.ParseException) AddressException(javax.mail.internet.AddressException) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject)

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