Search in sources :

Example 1 with AttachmentBean

use of it.cnr.cool.mail.model.AttachmentBean 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)

Aggregations

WriterException (com.google.zxing.WriterException)1 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)1 AttachmentBean (it.cnr.cool.mail.model.AttachmentBean)1 EmailMessage (it.cnr.cool.mail.model.EmailMessage)1 CMISUser (it.cnr.cool.security.service.impl.alfresco.CMISUser)1 CMISApplicationException (it.cnr.cool.web.scripts.exception.CMISApplicationException)1 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)1 ParseException (java.text.ParseException)1 BindingSession (org.apache.chemistry.opencmis.client.bindings.spi.BindingSession)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 PDImageXObject (org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1