From 21015fd1e09d203e3dbe987cc6c07ec526d521b9 Mon Sep 17 00:00:00 2001 From: Salvatore La Manna Date: Wed, 21 Oct 2020 15:49:31 +0200 Subject: [PATCH] =?UTF-8?q?Annullamento=20conformit=C3=A0=20errate=20prati?= =?UTF-8?q?che=20di=20tipo=20B=20e=20C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mwg/sismica/bo/util/PuliziaDatabase.java | 247 +++++-- .../portos/bo/model/impl/AvvisoImpl.java | 13 +- .../scheduler/SchedulerGeneraDocumento.java | 23 - .../hook/events/StartupAction.java | 79 +- .../hook/listener/DLFileEntryListener.java | 23 +- .../messaging/SendMailMessageListener.java | 124 ++-- .../mailmanager/portlet/EmailPortlet.java | 52 +- .../portlet/EmailTemplatesPortlet.java | 165 +++-- .../impl/EmailAttachmentLocalServiceImpl.java | 149 ++-- .../service/impl/EmailServiceImpl.java | 4 +- .../impl/EmailTemplateServiceImpl.java | 63 +- .../portos/mailmanager/util/MailEngine.java | 684 +++++++++--------- .../mailmanager/util/MailManagerUtil.java | 2 +- .../mailmanager/util/MailSenderUtil.java | 8 +- .../portos/mailmanager/util/VelocityUtil.java | 64 +- .../docroot/WEB-INF/src/service.properties | 4 +- 16 files changed, 914 insertions(+), 790 deletions(-) diff --git a/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/PuliziaDatabase.java b/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/PuliziaDatabase.java index eee9fc45..ae4f1b4f 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/PuliziaDatabase.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/PuliziaDatabase.java @@ -5,94 +5,231 @@ */ package it.mwg.sismica.bo.util; +import flexjson.JSONSerializer; import it.tref.liferay.portos.bo.model.Avviso; -import it.tref.liferay.portos.bo.model.Collaudo; import it.tref.liferay.portos.bo.model.ControlloPratica; -import it.tref.liferay.portos.bo.model.Delega; import it.tref.liferay.portos.bo.model.DettPratica; -import it.tref.liferay.portos.bo.model.DocAggiuntiva; -import it.tref.liferay.portos.bo.model.DocPratica; -import it.tref.liferay.portos.bo.model.FineLavori; import it.tref.liferay.portos.bo.model.IntPratica; -import it.tref.liferay.portos.bo.model.Soggetto; +import it.tref.liferay.portos.bo.model.Sorteggio; import it.tref.liferay.portos.bo.service.AvvisoLocalServiceUtil; -import it.tref.liferay.portos.bo.service.CollaudoLocalServiceUtil; -import it.tref.liferay.portos.bo.service.DelegaLocalServiceUtil; +import it.tref.liferay.portos.bo.service.ConfigurazioneLocalServiceUtil; +import it.tref.liferay.portos.bo.service.ControlloPraticaLocalServiceUtil; import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; -import it.tref.liferay.portos.bo.service.DocAggiuntivaLocalServiceUtil; -import it.tref.liferay.portos.bo.service.DocPraticaLocalServiceUtil; -import it.tref.liferay.portos.bo.service.FineLavoriLocalServiceUtil; import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil; -import it.tref.liferay.portos.bo.service.SoggettoLocalServiceUtil; +import it.tref.liferay.portos.bo.service.SorteggioLocalServiceUtil; +import it.tref.liferay.portos.bo.shared.util.ConfigurazioneConstants; +import it.tref.liferay.portos.bo.shared.util.StatoPraticaConstants; +import it.tref.liferay.portos.bo.util.AvvisoUtil; +import it.tref.liferay.portos.bo.util.WorkflowConstants; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.liferay.portal.kernel.cache.CacheRegistryUtil; import com.liferay.portal.kernel.cache.MultiVMPoolUtil; import com.liferay.portal.kernel.cache.SingleVMPoolUtil; -import com.liferay.portal.kernel.dao.jdbc.DataAccess; -import com.liferay.portal.kernel.dao.orm.QueryUtil; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.kernel.repository.model.FileEntry; +import com.liferay.portal.kernel.repository.model.Folder; import com.liferay.portal.kernel.servlet.DirectServletRegistryUtil; -import com.liferay.portal.kernel.util.StringUtil; +import com.liferay.portal.kernel.util.StringPool; +import com.liferay.portal.kernel.util.UniqueList; import com.liferay.portal.kernel.util.Validator; -import com.liferay.portal.model.Group; -import com.liferay.portal.model.Organization; -import com.liferay.portal.model.User; -import com.liferay.portal.service.ClassNameLocalServiceUtil; +import com.liferay.portal.security.permission.ActionKeys; import com.liferay.portal.service.ServiceContext; -import com.liferay.portlet.documentlibrary.model.DLFileEntry; -import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata; -import com.liferay.portlet.documentlibrary.model.DLFolder; -import com.liferay.portlet.documentlibrary.model.DLSyncConstants; import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil; -import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil; -import com.liferay.portlet.dynamicdatamapping.model.DDMContent; -import com.liferay.portlet.dynamicdatamapping.model.DDMStorageLink; -import com.liferay.portlet.messageboards.model.MBDiscussion; public class PuliziaDatabase { private static final Log _log = LogFactoryUtil.getLog(PuliziaDatabase.class); private static final int SLICE = 1000; - public static List pulisci(ServiceContext serviceContext) { + public static List pulisci(ServiceContext serviceContext) throws SystemException { List esito = new ArrayList<>(); - int numeroPratiche = 0; + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + Date min = null; + Date max = null; try { - List pratiche = null; - int start = 0; - do { - pratiche = IntPraticaLocalServiceUtil.getIntPraticas(start, start + SLICE); - for (IntPratica pratica : pratiche) { - List avvisi = AvvisoLocalServiceUtil.findByIntPratica(pratica.getIntPraticaId(), - QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); - int noFile = 0; - for (Avviso avviso : avvisi) { - if (0 == avviso.getFileEntryIdBase()) { - AvvisoLocalServiceUtil.deleteAvviso(avviso); - noFile++; - } + min = sdf.parse("2020-09-25 18:43:49"); + max = sdf.parse("2020-09-25 18:44:15"); + } catch (ParseException e) { + esitoLog(esito, "Errore date: " + e.getMessage()); + return esito; + } + + long companyId = serviceContext.getCompanyId(); + long folderId = ConfigurazioneLocalServiceUtil.findByC_ChiaveLong(companyId, + ConfigurazioneConstants.TEMPLATE_FOLDER_ID); + + long templateAnnullamentoId = 0; + try { + Folder folder = DLAppLocalServiceUtil.getFolder(folderId); + FileEntry template = DLAppLocalServiceUtil.getFileEntry(folder.getGroupId(), folderId, "ATAP"); + templateAnnullamentoId = template.getFileEntryId(); + } catch (PortalException e1) { + } + if (Validator.isNull(templateAnnullamentoId)) { + esitoLog(esito, "Template ATAP non trovato"); + return esito; + } + String descLongAnnullamento = "Annullamento d'ufficio"; + + long templateConformitaId = ConfigurazioneLocalServiceUtil.findByC_ChiaveLong(companyId, + "conf.geniocivile.avviso.template.id.deposito.B2"); + String descLongConformita = "Avviso di conformità"; + + List sbagliati = new ArrayList<>(); + List inviate = new UniqueList<>(); + List conformi = new UniqueList<>(); + int start = 0; + List avvisi = new ArrayList<>(); + do { + avvisi = AvvisoLocalServiceUtil.getAvvisos(start, start + SLICE); + for (Avviso avviso : avvisi) { + if (avviso.getDtAvviso().after(min) && avviso.getDtAvviso().before(max) + && avviso.getTipoDocumento().equalsIgnoreCase(StatoPraticaConstants.CONFORME)) { + sbagliati.add(avviso); + } else if (avviso.getFileEntryIdTemplate() == templateAnnullamentoId) { + inviate.add(avviso.getIntPraticaId()); + } else if (avviso.getFileEntryIdTemplate() == templateConformitaId) { + conformi.add(avviso.getIntPraticaId()); + } + } + start += SLICE; + } while (avvisi.size() > 0); + + SimpleDateFormat dfmt = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); + JSONSerializer jsonSerializer = new JSONSerializer(); + + int noIntPratica = 0; + int annullatiA = 0; + int annullatiB = 0; + int annullatiC = 0; + for (Avviso avviso : sbagliati) { + long intPraticaId = avviso.getIntPraticaId(); + if (!inviate.contains(intPraticaId)) { + IntPratica intPratica = null; + try { + intPratica = IntPraticaLocalServiceUtil.getIntPratica(intPraticaId); + } catch (PortalException e) { + } + if (Validator.isNull(intPratica)) { + noIntPratica++; + } else { + Map parameters = new HashMap<>(); + parameters.put("dataProtocolloAnnullato", dfmt.format(avviso.getDtProtocollo())); + parameters.put("numeroProtocolloAnnullato", avviso.getProtocollo()); + + DettPratica dettPratica = DettPraticaLocalServiceUtil + .getLastCompletedByIntPratica(intPraticaId); + List controlli = ControlloPraticaLocalServiceUtil + .findByIntPraticaId_Status(intPraticaId, WorkflowConstants.STATUS_PENDING); + long controlloPraticaId = 0; + if (controlli.size() > 0) { + controlloPraticaId = controlli.get(controlli.size() - 1).getPrimaryKey(); } - if (noFile > 0) { - esitoLog(esito, - "Pratica " + pratica.getNumeroProgetto() + "(" + pratica.getIntPraticaId() - + ") - " + avvisi.size() + " avvisi, eliminati: " + noFile); + ServiceContext ctx = new ServiceContext(); + ctx.setCompanyId(intPratica.getCompanyId()); + ctx.setScopeGroupId(intPratica.getGroupId()); + ctx.setUserId(intPratica.getUserId()); + ctx.setGroupPermissions(new String[] { ActionKeys.VIEW }); + + String jsonParameters = StringPool.BLANK; + + switch (intPratica.getTipoProcedura().toUpperCase()) { + case "A": + annullatiA++; + break; + case "B": + case "B1": + Sorteggio sorteggio = SorteggioLocalServiceUtil.findByIntPratica(intPratica + .getIntPraticaId()); + if (Validator.isNull(sorteggio)) { + jsonParameters = jsonSerializer.serialize(parameters); + try { + AvvisoLocalServiceUtil.addAvviso(intPraticaId, descLongAnnullamento, + new Date(), AvvisoUtil.TIPO_AVVISO_DIRETTO, "MA", + templateAnnullamentoId, dettPratica.getPrimaryKey(), + DettPratica.class.getName(), StringPool.BLANK, jsonParameters, + controlloPraticaId, serviceContext); + if (!conformi.contains(intPraticaId)) { + AvvisoLocalServiceUtil.addAvviso(intPratica.getIntPraticaId(), + descLongConformita, new Date(), AvvisoUtil.TIPO_AVVISO_DIRETTO, + StatoPraticaConstants.CONFORME, templateConformitaId, + dettPratica.getDettPraticaId(), DettPratica.class.getName(), + controlloPraticaId, serviceContext); + } + } catch (PortalException e) { + esitoLog(esito, + "Errore nell'invio per pratica " + intPratica.getNumeroProgetto() + + ", " + e.getMessage()); + } + esitoLog(esito, "Pratica " + + intPratica.getNumeroProgetto() + + " (" + + intPraticaId + + "), procedura " + + intPratica.getTipoProcedura() + + ", invio annullamento" + + (conformi.contains(intPraticaId) ? ", conformità già inviata" + : " e conformità")); + annullatiB++; + } else { + esitoLog(esito, "Pratica " + intPratica.getNumeroProgetto() + " (" + intPraticaId + + "), procedura " + intPratica.getTipoProcedura() + + ", non invio perché sorteggiata"); + } + break; + case "C": + Avviso valido = null; + avvisi = AvvisoLocalServiceUtil.findByIntPraticaId_tipoDocumento(intPraticaId, + StatoPraticaConstants.VIDIMATA); + for (Avviso presente : avvisi) { + if (presente.getPrimaryKey() != avviso.getPrimaryKey()) { + if ((presente.getPrimaryKey() <= avviso.getPrimaryKey()) + && (Validator.isNull(valido) || (valido.getPrimaryKey() > presente + .getPrimaryKey()))) { + valido = presente; + } + } + } + if (Validator.isNotNull(valido)) { + parameters.put("dataProtocolloValido", dfmt.format(valido.getDtProtocollo())); + parameters.put("numeroProtocolloValido", valido.getProtocollo()); + jsonParameters = jsonSerializer.serialize(parameters); + try { + AvvisoLocalServiceUtil.addAvviso(intPraticaId, descLongAnnullamento, + new Date(), AvvisoUtil.TIPO_AVVISO_DIRETTO, "MA", + templateAnnullamentoId, dettPratica.getPrimaryKey(), + DettPratica.class.getName(), StringPool.BLANK, jsonParameters, + controlloPraticaId, serviceContext); + } catch (PortalException e) { + esitoLog(esito, + "Errore nell'invio per pratica " + intPratica.getNumeroProgetto() + + ", " + e.getMessage()); + } + } + esitoLog(esito, "Pratica " + intPratica.getNumeroProgetto() + " (" + intPraticaId + + "), procedura " + intPratica.getTipoProcedura() + ", " + jsonParameters); + annullatiC++; + break; } } - start += SLICE; - numeroPratiche += pratiche.size(); - } while (pratiche.size() > 0); - esitoLog(esito, numeroPratiche + " pratiche"); - } catch (Exception e) { - esitoLog(esito, "Interrotto per errore: " + e.getMessage()); + } } + _log.info(sbagliati.size() + " avvisi"); + _log.info("Procedura A = " + annullatiA); + _log.info("Procedura B = " + annullatiB); + _log.info("Procedura C = " + annullatiC); + _log.info("IntPratica non esistente = " + noIntPratica); return esito; } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/model/impl/AvvisoImpl.java b/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/model/impl/AvvisoImpl.java index aeee0166..dcccc32a 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/model/impl/AvvisoImpl.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/model/impl/AvvisoImpl.java @@ -124,11 +124,14 @@ public class AvvisoImpl extends AvvisoBaseImpl { public String getDescriptionOggettoProtocollo() throws PortalException, SystemException { - String tipoDocumento = AvvisoUtil.getAllTipoDocumento().containsKey(this.getTipoDocumento()) ? AvvisoUtil - .getAllTipoDocumento().get(this.getTipoDocumento()) - : "label.admingeniocivile.avviso.tipoDocumento.avvisomanuale"; - - String fullDescription = LanguageUtil.get(LocaleUtil.ITALIAN, tipoDocumento); + String fullDescription = LanguageUtil.get(LocaleUtil.ITALIAN, + "label.admingeniocivile.avviso.tipoDocumento.avvisomanuale"); + if (AvvisoUtil.getAllTipoDocumento().containsKey(this.getTipoDocumento())) { + fullDescription = LanguageUtil.get(LocaleUtil.ITALIAN, + AvvisoUtil.getAllTipoDocumento().get(this.getTipoDocumento())); + } else if (Validator.isNotNull(this.getDescLong())) { + fullDescription = this.getDescLong(); + } if (this.getTipoDocumento().equalsIgnoreCase(StatoPraticaConstants.VIDIMATA)) { diff --git a/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/scheduler/SchedulerGeneraDocumento.java b/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/scheduler/SchedulerGeneraDocumento.java index ee742d3e..82b76465 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/scheduler/SchedulerGeneraDocumento.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/scheduler/SchedulerGeneraDocumento.java @@ -132,29 +132,6 @@ public class SchedulerGeneraDocumento implements MessageListener { if (Validator.isNotNull(avviso.getJsonParameters())) { JSONDeserializer> deserializer = JSONFactoryUtil.createJSONDeserializer(); parameters.putAll(deserializer.deserialize(avviso.getJsonParameters())); - - // TODO vedere se vann oaggiunti dati presi in altro modo - // if - // (parameters.containsKey(WorkflowConstants.WORKFLOW_PARAM_NAME_DELEGATO_OUT)) - // { - // User user = null; - // String delegato = - // GetterUtil.getString(parameters.get(WorkflowConstants.WORKFLOW_PARAM_NAME_DELEGATO_OUT)); - // List expandoValues = - // ExpandoValueLocalServiceUtil.getColumnValues(companyId, - // User.class.getName(), - // Constants.CUSTOM_FIELD_TABLE_NAME, - // Constants.CUSTOM_FIELD_GC_USERID, delegato, - // QueryUtil.ALL_POS, - // QueryUtil.ALL_POS); - // if (expandoValues != null && !expandoValues.isEmpty()) { - // ExpandoValue expandoValue = expandoValues.get(0); - // user = - // UserLocalServiceUtil.fetchUserById(expandoValue.getClassPK()); - // } - // parameters.put(WorkflowConstants.WORKFLOW_PARAM_NAME_DELEGATO, - // user.getFullName()); - // } } Object bean; diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/hook/events/StartupAction.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/hook/events/StartupAction.java index 334e5715..e5067fea 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/hook/events/StartupAction.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/hook/events/StartupAction.java @@ -22,63 +22,62 @@ import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil; public class StartupAction extends SimpleAction { - private final static Log _log = LogFactoryUtil.getLog(StartupAction.class); + private final static Log _log = LogFactoryUtil.getLog(StartupAction.class); - @Override - public void run(String[] ids) throws ActionException { + @Override + public void run(String[] ids) throws ActionException { - for (String id : ids) { + for (String id : ids) { - long companyId = GetterUtil.getLong(id); + long companyId = GetterUtil.getLong(id); - try { + try { - Company company = CompanyLocalServiceUtil.getCompany(companyId); + Company company = CompanyLocalServiceUtil.getCompany(companyId); - Group companyGroup = company.getGroup(); - User userDefault = company.getDefaultUser(); + Group companyGroup = company.getGroup(); + User userDefault = company.getDefaultUser(); - // Folders + // Folders - String[] groupActions = {ActionKeys.VIEW}; - String[] guestActions = {ActionKeys.VIEW}; + String[] groupActions = { ActionKeys.VIEW }; + String[] guestActions = { ActionKeys.VIEW }; - addDLFolderIfNotExists(userDefault.getUserId(), companyGroup.getGroupId(), companyGroup.getGroupId(), - DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, EmailConstants.DEFAULT_ATTACHMENTS_FOLDER_NAME, true, - groupActions, guestActions); + addDLFolderIfNotExists(userDefault.getUserId(), companyGroup.getGroupId(), + companyGroup.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, + EmailConstants.DEFAULT_ATTACHMENTS_FOLDER_NAME, true, groupActions, guestActions); - } catch (Exception e) { - _log.error(e, e); - } - } - } + } catch (Exception e) { + _log.error(e, e); + } + } + } - private DLFolder addDLFolderIfNotExists(long userId, long groupId, long repositoryId, long parentFolderId, - String name, boolean hidden, String[] groupActions, String[] guestActions) throws PortalException, - SystemException { + private DLFolder addDLFolderIfNotExists(long userId, long groupId, long repositoryId, + long parentFolderId, String name, boolean hidden, String[] groupActions, String[] guestActions) + throws PortalException, SystemException { - DLFolder dlFolder = null; + DLFolder dlFolder = null; - try { - dlFolder = DLFolderLocalServiceUtil.getFolder(groupId, parentFolderId, name); - } catch (PortalException e) { + try { + dlFolder = DLFolderLocalServiceUtil.getFolder(groupId, parentFolderId, name); + } catch (PortalException e) { - ServiceContext serviceContext = new ServiceContext(); + ServiceContext serviceContext = new ServiceContext(); - if (groupActions != null) { - serviceContext.setGroupPermissions(groupActions); - } + if (groupActions != null) { + serviceContext.setGroupPermissions(groupActions); + } - if (guestActions != null) { - serviceContext.setGuestPermissions(guestActions); - } + if (guestActions != null) { + serviceContext.setGuestPermissions(guestActions); + } - dlFolder = - DLFolderLocalServiceUtil.addFolder(userId, groupId, repositoryId, false, parentFolderId, name, - StringPool.BLANK, hidden, serviceContext); - } + dlFolder = DLFolderLocalServiceUtil.addFolder(userId, groupId, repositoryId, false, + parentFolderId, name, StringPool.BLANK, hidden, serviceContext); + } - return dlFolder; - } + return dlFolder; + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/hook/listener/DLFileEntryListener.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/hook/listener/DLFileEntryListener.java index c8c616fe..ad4d6f93 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/hook/listener/DLFileEntryListener.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/hook/listener/DLFileEntryListener.java @@ -10,17 +10,18 @@ import com.liferay.portlet.documentlibrary.model.DLFileEntry; public class DLFileEntryListener extends BaseModelListener { - @Override - public void onBeforeRemove(DLFileEntry model) throws ModelListenerException { + @Override + public void onBeforeRemove(DLFileEntry model) throws ModelListenerException { - try { - EmailAttachment emailAttachment = EmailAttachmentLocalServiceUtil.fetchByFileEntryId(model.getFileEntryId()); - if (emailAttachment != null) { - throw new ModelListenerException(); - } - } catch (SystemException e) { - throw new ModelListenerException(e); - } - } + try { + EmailAttachment emailAttachment = EmailAttachmentLocalServiceUtil.fetchByFileEntryId(model + .getFileEntryId()); + if (emailAttachment != null) { + throw new ModelListenerException(); + } + } catch (SystemException e) { + throw new ModelListenerException(e); + } + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/messaging/SendMailMessageListener.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/messaging/SendMailMessageListener.java index d090313a..591400f9 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/messaging/SendMailMessageListener.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/messaging/SendMailMessageListener.java @@ -25,93 +25,93 @@ import java.util.Date; public class SendMailMessageListener implements MessageListener { - private static final String _LOCK_CLASS_NAME = SendMailMessageListener.class.getName(); + private static final String _LOCK_CLASS_NAME = SendMailMessageListener.class.getName(); - private static final Log _log = LogFactoryUtil.getLog(SendMailMessageListener.class); + private static final Log _log = LogFactoryUtil.getLog(SendMailMessageListener.class); - @Override - public void receive(Message message) throws MessageListenerException { + @Override + public void receive(Message message) throws MessageListenerException { - try { + try { - ActionableDynamicQuery actionableDynamicQuery = new EmailActionableDynamicQuery() { + ActionableDynamicQuery actionableDynamicQuery = new EmailActionableDynamicQuery() { - @Override - protected void addCriteria(DynamicQuery dynamicQuery) { - dynamicQuery.add(PropertyFactoryUtil.forName("sent").eq(false)); - dynamicQuery.add(PropertyFactoryUtil.forName("cancel").eq(false)); - } + @Override + protected void addCriteria(DynamicQuery dynamicQuery) { + dynamicQuery.add(PropertyFactoryUtil.forName("sent").eq(false)); + dynamicQuery.add(PropertyFactoryUtil.forName("cancel").eq(false)); + } - @Override - protected void performAction(Object obj) throws PortalException, SystemException { + @Override + protected void performAction(Object obj) throws PortalException, SystemException { - Email email = (Email) obj; + Email email = (Email) obj; - try { + try { - MailSenderUtil.sendMail(email); + MailSenderUtil.sendMail(email); - EmailLocalServiceUtil.markAsSent(email.getEmailId(), new Date(), StringPool.BLANK); - } catch (Exception e) { - EmailLocalServiceUtil.updateStatusMessage(email.getEmailId(), e.getMessage()); - } - } - }; + EmailLocalServiceUtil.markAsSent(email.getEmailId(), new Date(), StringPool.BLANK); + } catch (Exception e) { + EmailLocalServiceUtil.updateStatusMessage(email.getEmailId(), e.getMessage()); + } + } + }; - long count = actionableDynamicQuery.performCount(); + long count = actionableDynamicQuery.performCount(); - if (count > 0) { + if (count > 0) { - String owner = PortalUUIDUtil.generate(); + String owner = PortalUUIDUtil.generate(); - if (tryLock(owner)) { + if (tryLock(owner)) { - try { - actionableDynamicQuery.performActions(); - } finally { - unlock(owner); - } - } - } + try { + actionableDynamicQuery.performActions(); + } finally { + unlock(owner); + } + } + } - } catch (Exception e) { - _log.error(e, e); - } - } + } catch (Exception e) { + _log.error(e, e); + } + } - private boolean tryLock(String owner) { + private boolean tryLock(String owner) { - try { + try { - Lock lock = null; + Lock lock = null; - while (true) { - try { - lock = LockLocalServiceUtil.lock(_LOCK_CLASS_NAME, _LOCK_CLASS_NAME, owner); + while (true) { + try { + lock = LockLocalServiceUtil.lock(_LOCK_CLASS_NAME, _LOCK_CLASS_NAME, owner); - break; - } catch (SystemException se) { + break; + } catch (SystemException se) { - try { - Thread.sleep(50); - } catch (InterruptedException ie) { - } - } - } + try { + Thread.sleep(50); + } catch (InterruptedException ie) { + } + } + } - if (!lock.isNew()) { - throw new DuplicateLockException(lock); - } + if (!lock.isNew()) { + throw new DuplicateLockException(lock); + } - } catch (DuplicateLockException e) { - return false; - } + } catch (DuplicateLockException e) { + return false; + } - return true; - } + return true; + } - private void unlock(String owner) throws SystemException { + private void unlock(String owner) throws SystemException { - LockLocalServiceUtil.unlock(_LOCK_CLASS_NAME, _LOCK_CLASS_NAME, owner); - } + LockLocalServiceUtil.unlock(_LOCK_CLASS_NAME, _LOCK_CLASS_NAME, owner); + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/portlet/EmailPortlet.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/portlet/EmailPortlet.java index ffbdbc4d..37a10988 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/portlet/EmailPortlet.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/portlet/EmailPortlet.java @@ -20,45 +20,45 @@ import javax.portlet.ActionResponse; */ public class EmailPortlet extends MVCPortlet { - private static Log _log = LogFactoryUtil.getLog(EmailPortlet.class); + private static Log _log = LogFactoryUtil.getLog(EmailPortlet.class); - public void editEmail(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { + public void editEmail(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { - _log.debug("editEmail - Inizio metodo"); + _log.debug("editEmail - Inizio metodo"); - ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); + ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); - long emailId = ParamUtil.getLong(actionRequest, "emailId"); + long emailId = ParamUtil.getLong(actionRequest, "emailId"); - String from = ParamUtil.getString(actionRequest, "from"); - String[] to = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "to")); - String[] cc = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "cc")); - String[] ccn = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "ccn")); + String from = ParamUtil.getString(actionRequest, "from"); + String[] to = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "to")); + String[] cc = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "cc")); + String[] ccn = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "ccn")); - String subject = ParamUtil.getString(actionRequest, "subject"); - String body = ParamUtil.getString(actionRequest, "body"); + String subject = ParamUtil.getString(actionRequest, "subject"); + String body = ParamUtil.getString(actionRequest, "body"); - EmailServiceUtil.updateEmail(emailId, from, to, cc, ccn, subject, body, serviceContext); + EmailServiceUtil.updateEmail(emailId, from, to, cc, ccn, subject, body, serviceContext); - } + } - public void annullaEmail(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException, - SystemException { + public void annullaEmail(ActionRequest actionRequest, ActionResponse actionResponse) + throws PortalException, SystemException { - _log.debug("annullaEmail - inizio metodo"); + _log.debug("annullaEmail - inizio metodo"); - ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); - long emailId = ParamUtil.getLong(actionRequest, "emailId"); - EmailServiceUtil.cancelEmail(emailId, serviceContext); - } + ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); + long emailId = ParamUtil.getLong(actionRequest, "emailId"); + EmailServiceUtil.cancelEmail(emailId, serviceContext); + } - public void resendEmail(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { + public void resendEmail(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { - _log.debug("reinviaEmail - Inizio metodo"); + _log.debug("reinviaEmail - Inizio metodo"); - ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); - long emailId = ParamUtil.getLong(actionRequest, "emailId"); - EmailServiceUtil.resendEmail(emailId, serviceContext); - } + ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); + long emailId = ParamUtil.getLong(actionRequest, "emailId"); + EmailServiceUtil.resendEmail(emailId, serviceContext); + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/portlet/EmailTemplatesPortlet.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/portlet/EmailTemplatesPortlet.java index dc5fb655..29588a0b 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/portlet/EmailTemplatesPortlet.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/portlet/EmailTemplatesPortlet.java @@ -36,117 +36,114 @@ import javax.portlet.ActionResponse; */ public class EmailTemplatesPortlet extends MVCPortlet { - private static Log _log = LogFactoryUtil.getLog(EmailTemplatesPortlet.class); + private static Log _log = LogFactoryUtil.getLog(EmailTemplatesPortlet.class); - public void editTemplateEmail(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException, - SystemException { + public void editTemplateEmail(ActionRequest actionRequest, ActionResponse actionResponse) + throws PortalException, SystemException { - String cmd = ParamUtil.getString(actionRequest, Constants.CMD); + String cmd = ParamUtil.getString(actionRequest, Constants.CMD); - ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); + ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); - long emailTemplateId = ParamUtil.getLong(actionRequest, "emailTemplateId"); + long emailTemplateId = ParamUtil.getLong(actionRequest, "emailTemplateId"); - String templateName = ParamUtil.getString(actionRequest, "templateName"); + String templateName = ParamUtil.getString(actionRequest, "templateName"); - String from = ParamUtil.getString(actionRequest, "from"); - String[] to = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "to")); - String[] cc = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "cc")); - String[] ccn = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "ccn")); + String from = ParamUtil.getString(actionRequest, "from"); + String[] to = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "to")); + String[] cc = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "cc")); + String[] ccn = StringUtil.splitAndTrim(ParamUtil.getString(actionRequest, "ccn")); - String subject = ParamUtil.getString(actionRequest, "subject"); - String body = ParamUtil.getString(actionRequest, "body"); + String subject = ParamUtil.getString(actionRequest, "subject"); + String body = ParamUtil.getString(actionRequest, "body"); - Boolean attachmentPermitted = ParamUtil.getBoolean(actionRequest, "attachmentPermitted"); + Boolean attachmentPermitted = ParamUtil.getBoolean(actionRequest, "attachmentPermitted"); - try { - EmailTemplate emailTemplate = null; - if (cmd.equals(Constants.ADD)) { - emailTemplate = - EmailTemplateServiceUtil.addEmailTemplate(templateName, from, to, cc, ccn, subject, body, - attachmentPermitted, serviceContext); - emailTemplateId = emailTemplate.getEmailTemplateId(); - } else if (cmd.equals(Constants.UPDATE)) { - emailTemplate = - EmailTemplateServiceUtil.updateEmailTemplate(emailTemplateId, templateName, from, to, cc, ccn, subject, - body, attachmentPermitted, serviceContext); - } - emailTemplateId = emailTemplate.getEmailTemplateId(); + try { + EmailTemplate emailTemplate = null; + if (cmd.equals(Constants.ADD)) { + emailTemplate = EmailTemplateServiceUtil.addEmailTemplate(templateName, from, to, cc, ccn, + subject, body, attachmentPermitted, serviceContext); + emailTemplateId = emailTemplate.getEmailTemplateId(); + } else if (cmd.equals(Constants.UPDATE)) { + emailTemplate = EmailTemplateServiceUtil.updateEmailTemplate(emailTemplateId, templateName, + from, to, cc, ccn, subject, body, attachmentPermitted, serviceContext); + } + emailTemplateId = emailTemplate.getEmailTemplateId(); - } catch (PortalException e) { - SessionErrors.add(actionRequest, e.getClass()); - } + } catch (PortalException e) { + SessionErrors.add(actionRequest, e.getClass()); + } - if (SessionErrors.isEmpty(actionRequest)) { - actionResponse.setRenderParameter("emailTemplateId", String.valueOf(emailTemplateId)); - actionResponse.setRenderParameter("mvcPath", "/html/email_templates/edit.jsp"); - } else { - actionResponse.setRenderParameter("mvcPath", "/html/email_templates/edit.jsp"); - PortalUtil.copyRequestParameters(actionRequest, actionResponse); - } + if (SessionErrors.isEmpty(actionRequest)) { + actionResponse.setRenderParameter("emailTemplateId", String.valueOf(emailTemplateId)); + actionResponse.setRenderParameter("mvcPath", "/html/email_templates/edit.jsp"); + } else { + actionResponse.setRenderParameter("mvcPath", "/html/email_templates/edit.jsp"); + PortalUtil.copyRequestParameters(actionRequest, actionResponse); + } - } + } - public void deleteEmailTemplate(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException, - SystemException { + public void deleteEmailTemplate(ActionRequest actionRequest, ActionResponse actionResponse) + throws PortalException, SystemException { - long emailTemplateId = ParamUtil.getLong(actionRequest, "emailTemplateId"); - EmailTemplateServiceUtil.deleteEmailTemplate(emailTemplateId); + long emailTemplateId = ParamUtil.getLong(actionRequest, "emailTemplateId"); + EmailTemplateServiceUtil.deleteEmailTemplate(emailTemplateId); - } + } - public void addEmailByTemplate(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException, - SystemException { + public void addEmailByTemplate(ActionRequest actionRequest, ActionResponse actionResponse) + throws PortalException, SystemException { - UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); - ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); + UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); + ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); - long emailTemplateId = ParamUtil.getLong(actionRequest, "emailTemplateId"); - EmailTemplate emailTemplate = EmailTemplateLocalServiceUtil.getEmailTemplate(emailTemplateId); + long emailTemplateId = ParamUtil.getLong(actionRequest, "emailTemplateId"); + EmailTemplate emailTemplate = EmailTemplateLocalServiceUtil.getEmailTemplate(emailTemplateId); - String sendModeStr = ParamUtil.getString(actionRequest, "sendMode"); - SendTemplateMode sendMode = SendTemplateMode.parse(sendModeStr); + String sendModeStr = ParamUtil.getString(actionRequest, "sendMode"); + SendTemplateMode sendMode = SendTemplateMode.parse(sendModeStr); - String className = ParamUtil.getString(actionRequest, "className"); - long classPK = ParamUtil.getLong(actionRequest, "classPK"); + String className = ParamUtil.getString(actionRequest, "className"); + long classPK = ParamUtil.getLong(actionRequest, "classPK"); - try { + try { - // eventuali allegati email - List fileAttachments = null; - if (emailTemplate.getAttachmentPermitted()) { - fileAttachments = MailUtil.getEmailFileAttachments(uploadPortletRequest); - } + // eventuali allegati email + List fileAttachments = null; + if (emailTemplate.getAttachmentPermitted()) { + fileAttachments = MailUtil.getEmailFileAttachments(uploadPortletRequest); + } - if (sendMode == SendTemplateMode.REVIEW) { + if (sendMode == SendTemplateMode.REVIEW) { - String templateParamJSON = ParamUtil.getString(actionRequest, "templateParamJSON"); - JSONObject templateParamJSONObj = JSONFactoryUtil.createJSONObject(templateParamJSON); - MailManagerUtil.addEmailByTemplate(className, classPK, emailTemplateId, templateParamJSONObj, fileAttachments, - serviceContext); + String templateParamJSON = ParamUtil.getString(actionRequest, "templateParamJSON"); + JSONObject templateParamJSONObj = JSONFactoryUtil.createJSONObject(templateParamJSON); + MailManagerUtil.addEmailByTemplate(className, classPK, emailTemplateId, templateParamJSONObj, + fileAttachments, serviceContext); - } else if (sendMode == SendTemplateMode.EDIT) { + } else if (sendMode == SendTemplateMode.EDIT) { - String from = ParamUtil.getString(actionRequest, "from"); - String to = ParamUtil.getString(actionRequest, "to"); - String cc = ParamUtil.getString(actionRequest, "cc"); - String ccn = ParamUtil.getString(actionRequest, "ccn"); - String subject = ParamUtil.getString(actionRequest, "subject"); - String body = ParamUtil.getString(actionRequest, "body"); + String from = ParamUtil.getString(actionRequest, "from"); + String to = ParamUtil.getString(actionRequest, "to"); + String cc = ParamUtil.getString(actionRequest, "cc"); + String ccn = ParamUtil.getString(actionRequest, "ccn"); + String subject = ParamUtil.getString(actionRequest, "subject"); + String body = ParamUtil.getString(actionRequest, "body"); - EmailLocalServiceUtil.addEmail(className, classPK, from, StringUtil.split(to, StringPool.COMMA), - StringUtil.split(cc, StringPool.COMMA), StringUtil.split(ccn, StringPool.COMMA), subject, body, true, - fileAttachments, serviceContext); - } - UploadPortletRequestUtil.copyRequestParameters(uploadPortletRequest, actionResponse); - actionResponse.setRenderParameter("mvcPath", "/html/email_templates/send_popup/close_popup.jsp"); - } catch (Exception ex) { - UploadPortletRequestUtil.copyRequestParameters(uploadPortletRequest, actionResponse); - throw new SystemException("Error add email by template.", ex); - } + EmailLocalServiceUtil.addEmail(className, classPK, from, + StringUtil.split(to, StringPool.COMMA), StringUtil.split(cc, StringPool.COMMA), + StringUtil.split(ccn, StringPool.COMMA), subject, body, true, fileAttachments, + serviceContext); + } + UploadPortletRequestUtil.copyRequestParameters(uploadPortletRequest, actionResponse); + actionResponse.setRenderParameter("mvcPath", "/html/email_templates/send_popup/close_popup.jsp"); + } catch (Exception ex) { + UploadPortletRequestUtil.copyRequestParameters(uploadPortletRequest, actionResponse); + throw new SystemException("Error add email by template.", ex); + } - - - } + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailAttachmentLocalServiceImpl.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailAttachmentLocalServiceImpl.java index a39c4d08..b8680503 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailAttachmentLocalServiceImpl.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailAttachmentLocalServiceImpl.java @@ -13,7 +13,6 @@ package it.tref.liferay.portos.mailmanager.service.impl; - import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.repository.model.FileEntry; @@ -41,13 +40,15 @@ import java.util.List; * The implementation of the email attachment local service. * *

- * All custom service methods should be put in this class. Whenever methods are added, rerun - * ServiceBuilder to copy their definitions into the - * {@link it.noovle.azimut.icf.mailmanager.service.EmailAttachmentLocalService} interface. + * All custom service methods should be put in this class. Whenever methods are + * added, rerun ServiceBuilder to copy their definitions into the + * {@link it.noovle.azimut.icf.mailmanager.service.EmailAttachmentLocalService} + * interface. * *

- * This is a local service. Methods of this service will not have security checks based on the - * propagated JAAS credentials because this service can only be accessed from within the same VM. + * This is a local service. Methods of this service will not have security + * checks based on the propagated JAAS credentials because this service can only + * be accessed from within the same VM. *

* * @author @@ -55,96 +56,96 @@ import java.util.List; * @see it.noovle.azimut.icf.mailmanager.service.EmailAttachmentLocalServiceUtil */ public class EmailAttachmentLocalServiceImpl extends EmailAttachmentLocalServiceBaseImpl { - /* - * NOTE FOR DEVELOPERS: - * - * Never reference this interface directly. Always use {@link - * it.noovle.azimut.icf.mailmanager.service.EmailAttachmentLocalServiceUtil} to access the - * email attachment local service. - */ - public EmailAttachment addEmailAttachment(long companyId, long emailId, long folderId, String fileName, File file) - throws PortalException, SystemException { + /* + * NOTE FOR DEVELOPERS: + * + * Never reference this interface directly. Always use {@link + * it.noovle.azimut.icf.mailmanager.service.EmailAttachmentLocalServiceUtil} + * to access the email attachment local service. + */ + public EmailAttachment addEmailAttachment(long companyId, long emailId, long folderId, String fileName, + File file) throws PortalException, SystemException { - Company company = companyLocalService.getCompany(companyId); + Company company = companyLocalService.getCompany(companyId); - User defaultUser = company.getDefaultUser(); + User defaultUser = company.getDefaultUser(); - validate(emailId, fileName, file); + validate(emailId, fileName, file); - Folder folder = dlAppLocalService.getFolder(folderId); + Folder folder = dlAppLocalService.getFolder(folderId); - String sourceFileName = file.getName(); - String mimeType = MimeTypesUtil.getContentType(sourceFileName); + String sourceFileName = file.getName(); + String mimeType = MimeTypesUtil.getContentType(sourceFileName); - String title = fileName; - if (Validator.isNull(title)) { - title = file.getName(); - } + String title = fileName; + if (Validator.isNull(title)) { + title = file.getName(); + } - ServiceContext serviceContext = new ServiceContext(); - serviceContext.setGroupPermissions(new String[] {ActionKeys.VIEW}); - serviceContext.setGuestPermissions(new String[] {ActionKeys.VIEW}); + ServiceContext serviceContext = new ServiceContext(); + serviceContext.setGroupPermissions(new String[] { ActionKeys.VIEW }); + serviceContext.setGuestPermissions(new String[] { ActionKeys.VIEW }); - FileEntry fileEntry = - dlAppLocalService.addFileEntry(defaultUser.getUserId(), folder.getRepositoryId(), folder.getFolderId(), - sourceFileName, mimeType, title, StringPool.BLANK, StringPool.BLANK, file, serviceContext); + FileEntry fileEntry = dlAppLocalService.addFileEntry(defaultUser.getUserId(), + folder.getRepositoryId(), folder.getFolderId(), sourceFileName, mimeType, title, + StringPool.BLANK, StringPool.BLANK, file, serviceContext); - EmailAttachment emailAttachment = - emailAttachmentLocalService.createEmailAttachment(new EmailAttachmentPK(emailId, fileEntry.getFileEntryId())); + EmailAttachment emailAttachment = emailAttachmentLocalService + .createEmailAttachment(new EmailAttachmentPK(emailId, fileEntry.getFileEntryId())); - return emailAttachmentLocalService.addEmailAttachment(emailAttachment); - } + return emailAttachmentLocalService.addEmailAttachment(emailAttachment); + } - @Override - public EmailAttachment deleteEmailAttachment(EmailAttachmentPK emailAttachmentPK) throws PortalException, - SystemException { - EmailAttachment emailAttachment = emailAttachmentLocalService.getEmailAttachment(emailAttachmentPK); - return deleteEmailAttachment(emailAttachment); - } + @Override + public EmailAttachment deleteEmailAttachment(EmailAttachmentPK emailAttachmentPK) throws PortalException, + SystemException { + EmailAttachment emailAttachment = emailAttachmentLocalService.getEmailAttachment(emailAttachmentPK); + return deleteEmailAttachment(emailAttachment); + } - @Override - public EmailAttachment deleteEmailAttachment(EmailAttachment emailAttachment) throws SystemException { + @Override + public EmailAttachment deleteEmailAttachment(EmailAttachment emailAttachment) throws SystemException { - super.deleteEmailAttachment(emailAttachment); + super.deleteEmailAttachment(emailAttachment); - // File Entry + // File Entry - try { - dlAppLocalService.deleteFileEntry(emailAttachment.getFileEntryId()); - } catch (PortalException e) { - } + try { + dlAppLocalService.deleteFileEntry(emailAttachment.getFileEntryId()); + } catch (PortalException e) { + } - return emailAttachment; - } + return emailAttachment; + } - public List findByEmailId(long emailId) throws SystemException { - return emailAttachmentPersistence.findByEmailId(emailId); - } + public List findByEmailId(long emailId) throws SystemException { + return emailAttachmentPersistence.findByEmailId(emailId); + } - public List findByEmailId(long emailId, int start, int end) throws SystemException { - return emailAttachmentPersistence.findByEmailId(emailId); - } + public List findByEmailId(long emailId, int start, int end) throws SystemException { + return emailAttachmentPersistence.findByEmailId(emailId); + } - public int countByEmailId(long emailId) throws SystemException { - return emailAttachmentPersistence.countByEmailId(emailId); - } + public int countByEmailId(long emailId) throws SystemException { + return emailAttachmentPersistence.countByEmailId(emailId); + } - public EmailAttachment fetchByFileEntryId(long fileEntryId) throws SystemException { - return emailAttachmentPersistence.fetchByFileEntryId(fileEntryId); - } + public EmailAttachment fetchByFileEntryId(long fileEntryId) throws SystemException { + return emailAttachmentPersistence.fetchByFileEntryId(fileEntryId); + } - private void validate(long emailId, String fileName, File file) throws PortalException, SystemException { + private void validate(long emailId, String fileName, File file) throws PortalException, SystemException { - if (Validator.isNull(emailId)) { - throw new NoSuchEmailException(); - } + if (Validator.isNull(emailId)) { + throw new NoSuchEmailException(); + } - if (Validator.isNull(fileName) && Validator.isNull(file)) { - throw new EmailAttachmentTitleException(); - } + if (Validator.isNull(fileName) && Validator.isNull(file)) { + throw new EmailAttachmentTitleException(); + } - if (Validator.isNull(file) || (Validator.isNotNull(file) && !FileUtil.exists(file))) { - throw new EmailAttachmentFileException(); - } - } + if (Validator.isNull(file) || (Validator.isNotNull(file) && !FileUtil.exists(file))) { + throw new EmailAttachmentFileException(); + } + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailServiceImpl.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailServiceImpl.java index 521ab479..74c68e82 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailServiceImpl.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailServiceImpl.java @@ -61,6 +61,6 @@ public class EmailServiceImpl extends EmailServiceBaseImpl { public Email cancelEmail(long emailId, ServiceContext serviceContext) throws PortalException, SystemException { EmailPermission.check(getPermissionChecker(), serviceContext.getScopeGroupId(), ActionKeys.ADMIN_EMAIL); - return emailLocalService.cancelEmail(emailId); - } + return emailLocalService.cancelEmail(emailId); + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailTemplateServiceImpl.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailTemplateServiceImpl.java index d638247a..45e4e8ca 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailTemplateServiceImpl.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/service/impl/EmailTemplateServiceImpl.java @@ -26,13 +26,15 @@ import it.tref.liferay.portos.mailmanager.service.base.EmailTemplateServiceBaseI * The implementation of the email template remote service. * *

- * All custom service methods should be put in this class. Whenever methods are added, rerun - * ServiceBuilder to copy their definitions into the - * {@link it.noovle.azimut.icf.mailmanager.service.EmailTemplateService} interface. + * All custom service methods should be put in this class. Whenever methods are + * added, rerun ServiceBuilder to copy their definitions into the + * {@link it.noovle.azimut.icf.mailmanager.service.EmailTemplateService} + * interface. * *

- * This is a remote service. Methods of this service are expected to have security checks based on - * the propagated JAAS credentials because this service can be accessed remotely. + * This is a remote service. Methods of this service are expected to have + * security checks based on the propagated JAAS credentials because this service + * can be accessed remotely. *

* * @author @@ -40,39 +42,40 @@ import it.tref.liferay.portos.mailmanager.service.base.EmailTemplateServiceBaseI * @see it.noovle.azimut.icf.mailmanager.service.EmailTemplateServiceUtil */ public class EmailTemplateServiceImpl extends EmailTemplateServiceBaseImpl { - /* - * NOTE FOR DEVELOPERS: - * - * Never reference this interface directly. Always use {@link - * it.noovle.azimut.icf.mailmanager.service.EmailTemplateServiceUtil} to access the email - * template remote service. - */ + /* + * NOTE FOR DEVELOPERS: + * + * Never reference this interface directly. Always use {@link + * it.noovle.azimut.icf.mailmanager.service.EmailTemplateServiceUtil} to + * access the email template remote service. + */ - public EmailTemplate addEmailTemplate(String templateName, String from, String[] to, String[] cc, String[] ccn, - String subject, String body, boolean attachmentPermitted, ServiceContext serviceContext) throws SystemException, - PortalException { + public EmailTemplate addEmailTemplate(String templateName, String from, String[] to, String[] cc, + String[] ccn, String subject, String body, boolean attachmentPermitted, + ServiceContext serviceContext) throws SystemException, PortalException { - EmailTemplatePermission.check(getPermissionChecker(), serviceContext.getScopeGroupId(), ActionKeys.ADD_ENTRY); + EmailTemplatePermission.check(getPermissionChecker(), serviceContext.getScopeGroupId(), + ActionKeys.ADD_ENTRY); - return emailTemplateLocalService.addEmailTemplate(templateName, from, to, cc, ccn, subject, body, - attachmentPermitted, serviceContext); - } + return emailTemplateLocalService.addEmailTemplate(templateName, from, to, cc, ccn, subject, body, + attachmentPermitted, serviceContext); + } - public EmailTemplate updateEmailTemplate(long emailTemplateId, String templateName, String from, String[] to, - String[] cc, String[] ccn, String subject, String body, boolean attachmentPermitted, ServiceContext serviceContext) - throws SystemException, PortalException { + public EmailTemplate updateEmailTemplate(long emailTemplateId, String templateName, String from, + String[] to, String[] cc, String[] ccn, String subject, String body, boolean attachmentPermitted, + ServiceContext serviceContext) throws SystemException, PortalException { - EmailTemplateEntryPermission.check(getPermissionChecker(), emailTemplateId, ActionKeys.UPDATE); + EmailTemplateEntryPermission.check(getPermissionChecker(), emailTemplateId, ActionKeys.UPDATE); - return emailTemplateLocalService.updateEmailTemplate(emailTemplateId, templateName, from, to, cc, ccn, subject, - body, attachmentPermitted, serviceContext); - } + return emailTemplateLocalService.updateEmailTemplate(emailTemplateId, templateName, from, to, cc, + ccn, subject, body, attachmentPermitted, serviceContext); + } - public EmailTemplate deleteEmailTemplate(long emailTemplateId) throws PortalException, SystemException { + public EmailTemplate deleteEmailTemplate(long emailTemplateId) throws PortalException, SystemException { - EmailTemplateEntryPermission.check(getPermissionChecker(), emailTemplateId, ActionKeys.DELETE); + EmailTemplateEntryPermission.check(getPermissionChecker(), emailTemplateId, ActionKeys.DELETE); - return emailTemplateLocalService.deleteEmailTemplate(emailTemplateId); - } + return emailTemplateLocalService.deleteEmailTemplate(emailTemplateId); + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailEngine.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailEngine.java index e22be439..ed938df1 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailEngine.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailEngine.java @@ -65,470 +65,476 @@ import javax.mail.internet.MimeMultipart; */ public class MailEngine { - public static Session getSession() { - return getSession(false); - } + public static Session getSession() { + return getSession(false); + } - public static Session getSession(Account account) { - Properties properties = _getProperties(account); + public static Session getSession(Account account) { + Properties properties = _getProperties(account); - Session session = Session.getInstance(properties); + Session session = Session.getInstance(properties); - if (_log.isDebugEnabled()) { - session.setDebug(true); + if (_log.isDebugEnabled()) { + session.setDebug(true); - session.getProperties().list(System.out); - } + session.getProperties().list(System.out); + } - return session; - } + return session; + } - public static Session getSession(boolean cache) { - Session session = null; + public static Session getSession(boolean cache) { + Session session = null; - try { - session = MailServiceUtil.getSession(); - } catch (SystemException se) { - if (_log.isWarnEnabled()) { - _log.warn(se, se); - } - - session = InfrastructureUtil.getMailSession(); - } + try { + session = MailServiceUtil.getSession(); + } catch (SystemException se) { + if (_log.isWarnEnabled()) { + _log.warn(se, se); + } - if (_log.isDebugEnabled()) { - session.setDebug(true); + session = InfrastructureUtil.getMailSession(); + } - session.getProperties().list(System.out); - } + if (_log.isDebugEnabled()) { + session.setDebug(true); - return session; - } - - public static void send(byte[] bytes) throws MailEngineException { - try { - Session session = getSession(); + session.getProperties().list(System.out); + } - Message message = new MimeMessage(session, new UnsyncByteArrayInputStream(bytes)); + return session; + } - _send(session, message, null, _BATCH_SIZE); - } catch (Exception e) { - throw new MailEngineException(e); - } - } + public static void send(byte[] bytes) throws MailEngineException { + try { + Session session = getSession(); - public static void send(InternetAddress from, InternetAddress to, String subject, String body) - throws MailEngineException { + Message message = new MimeMessage(session, new UnsyncByteArrayInputStream(bytes)); - send(from, new InternetAddress[] {to}, null, null, subject, body, false, null, null, null); - } + _send(session, message, null, _BATCH_SIZE); + } catch (Exception e) { + throw new MailEngineException(e); + } + } - public static void send(InternetAddress from, InternetAddress to, String subject, String body, boolean htmlFormat) - throws MailEngineException { + public static void send(InternetAddress from, InternetAddress to, String subject, String body) + throws MailEngineException { - send(from, new InternetAddress[] {to}, null, null, subject, body, htmlFormat, null, null, null); - } + send(from, new InternetAddress[] { to }, null, null, subject, body, false, null, null, null); + } - public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, - InternetAddress[] bulkAddresses, String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, - String messageId, String inReplyTo) throws MailEngineException { + public static void send(InternetAddress from, InternetAddress to, String subject, String body, + boolean htmlFormat) throws MailEngineException { - send(from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, messageId, inReplyTo, null); - } + send(from, new InternetAddress[] { to }, null, null, subject, body, htmlFormat, null, null, null); + } - public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, - InternetAddress[] bulkAddresses, String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, - String messageId, String inReplyTo, List fileAttachments) throws MailEngineException { + public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, + InternetAddress[] bcc, InternetAddress[] bulkAddresses, String subject, String body, + boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo) + throws MailEngineException { - send(from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, messageId, inReplyTo, fileAttachments, - null); - } + send(from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, messageId, inReplyTo, null); + } - public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, - InternetAddress[] bulkAddresses, String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, - String messageId, String inReplyTo, List fileAttachments, SMTPAccount smtpAccount) - throws MailEngineException { + public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, + InternetAddress[] bcc, InternetAddress[] bulkAddresses, String subject, String body, + boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo, + List fileAttachments) throws MailEngineException { - long startTime = System.currentTimeMillis(); + send(from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, messageId, inReplyTo, + fileAttachments, null); + } - if (_log.isDebugEnabled()) { - _log.debug("From: " + from); - _log.debug("To: " + Arrays.toString(to)); - _log.debug("CC: " + Arrays.toString(cc)); - _log.debug("BCC: " + Arrays.toString(bcc)); - _log.debug("List Addresses: " + Arrays.toString(bulkAddresses)); - _log.debug("Subject: " + subject); - _log.debug("Body: " + body); - _log.debug("HTML Format: " + htmlFormat); - _log.debug("Reply to: " + Arrays.toString(replyTo)); - _log.debug("Message ID: " + messageId); - _log.debug("In Reply To: " + inReplyTo); + public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, + InternetAddress[] bcc, InternetAddress[] bulkAddresses, String subject, String body, + boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo, + List fileAttachments, SMTPAccount smtpAccount) throws MailEngineException { - if ((fileAttachments != null) && _log.isDebugEnabled()) { - for (int i = 0; i < fileAttachments.size(); i++) { - - FileAttachment fileAttachment = fileAttachments.get(i); - if (fileAttachment instanceof it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) { - ((it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) fileAttachment).generateFile(); - } - File file = fileAttachment.getFile(); + long startTime = System.currentTimeMillis(); - if (file == null) { - continue; - } + if (_log.isDebugEnabled()) { + _log.debug("From: " + from); + _log.debug("To: " + Arrays.toString(to)); + _log.debug("CC: " + Arrays.toString(cc)); + _log.debug("BCC: " + Arrays.toString(bcc)); + _log.debug("List Addresses: " + Arrays.toString(bulkAddresses)); + _log.debug("Subject: " + subject); + _log.debug("Body: " + body); + _log.debug("HTML Format: " + htmlFormat); + _log.debug("Reply to: " + Arrays.toString(replyTo)); + _log.debug("Message ID: " + messageId); + _log.debug("In Reply To: " + inReplyTo); - _log.debug("Attachment " + i + " file " + file.getAbsolutePath() + " and file name " - + fileAttachment.getFileName()); - } - } - } + if ((fileAttachments != null) && _log.isDebugEnabled()) { + for (int i = 0; i < fileAttachments.size(); i++) { - try { - InternetAddressUtil.validateAddress(from); + FileAttachment fileAttachment = fileAttachments.get(i); + if (fileAttachment instanceof it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) { + ((it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) fileAttachment) + .generateFile(); + } + File file = fileAttachment.getFile(); - if (ArrayUtil.isNotEmpty(to)) { - InternetAddressUtil.validateAddresses(to); - } + if (file == null) { + continue; + } - if (ArrayUtil.isNotEmpty(cc)) { - InternetAddressUtil.validateAddresses(cc); - } + _log.debug("Attachment " + i + " file " + file.getAbsolutePath() + " and file name " + + fileAttachment.getFileName()); + } + } + } - if (ArrayUtil.isNotEmpty(bcc)) { - InternetAddressUtil.validateAddresses(bcc); - } + try { + InternetAddressUtil.validateAddress(from); - if (ArrayUtil.isNotEmpty(replyTo)) { - InternetAddressUtil.validateAddresses(replyTo); - } + if (ArrayUtil.isNotEmpty(to)) { + InternetAddressUtil.validateAddresses(to); + } - if (ArrayUtil.isNotEmpty(bulkAddresses)) { - InternetAddressUtil.validateAddresses(bulkAddresses); - } + if (ArrayUtil.isNotEmpty(cc)) { + InternetAddressUtil.validateAddresses(cc); + } - Session session = null; + if (ArrayUtil.isNotEmpty(bcc)) { + InternetAddressUtil.validateAddresses(bcc); + } - if (smtpAccount == null) { - session = getSession(); - } else { - session = getSession(smtpAccount); - } + if (ArrayUtil.isNotEmpty(replyTo)) { + InternetAddressUtil.validateAddresses(replyTo); + } - Message message = new LiferayMimeMessage(session); + if (ArrayUtil.isNotEmpty(bulkAddresses)) { + InternetAddressUtil.validateAddresses(bulkAddresses); + } - message.addHeader("X-Auto-Response-Suppress", "AutoReply, DR, NDR, NRN, OOF, RN"); + Session session = null; - message.setFrom(from); + if (smtpAccount == null) { + session = getSession(); + } else { + session = getSession(smtpAccount); + } - if (ArrayUtil.isNotEmpty(to)) { - message.setRecipients(Message.RecipientType.TO, to); - } + Message message = new LiferayMimeMessage(session); - if (ArrayUtil.isNotEmpty(cc)) { - message.setRecipients(Message.RecipientType.CC, cc); - } + message.addHeader("X-Auto-Response-Suppress", "AutoReply, DR, NDR, NRN, OOF, RN"); - if (ArrayUtil.isNotEmpty(bcc)) { - message.setRecipients(Message.RecipientType.BCC, bcc); - } + message.setFrom(from); - subject = GetterUtil.getString(subject); + if (ArrayUtil.isNotEmpty(to)) { + message.setRecipients(Message.RecipientType.TO, to); + } - message.setSubject(subject); + if (ArrayUtil.isNotEmpty(cc)) { + message.setRecipients(Message.RecipientType.CC, cc); + } - if ((fileAttachments != null) && (fileAttachments.size() > 0)) { - MimeMultipart rootMultipart = new MimeMultipart(_MULTIPART_TYPE_MIXED); + if (ArrayUtil.isNotEmpty(bcc)) { + message.setRecipients(Message.RecipientType.BCC, bcc); + } - MimeMultipart messageMultipart = new MimeMultipart(_MULTIPART_TYPE_ALTERNATIVE); + subject = GetterUtil.getString(subject); - MimeBodyPart messageBodyPart = new MimeBodyPart(); + message.setSubject(subject); - messageBodyPart.setContent(messageMultipart); + if ((fileAttachments != null) && (fileAttachments.size() > 0)) { + MimeMultipart rootMultipart = new MimeMultipart(_MULTIPART_TYPE_MIXED); - rootMultipart.addBodyPart(messageBodyPart); + MimeMultipart messageMultipart = new MimeMultipart(_MULTIPART_TYPE_ALTERNATIVE); - if (htmlFormat) { - MimeBodyPart bodyPart = new MimeBodyPart(); + MimeBodyPart messageBodyPart = new MimeBodyPart(); - bodyPart.setContent(body, _TEXT_HTML); + messageBodyPart.setContent(messageMultipart); - messageMultipart.addBodyPart(bodyPart); - } else { - MimeBodyPart bodyPart = new MimeBodyPart(); + rootMultipart.addBodyPart(messageBodyPart); - bodyPart.setText(body); + if (htmlFormat) { + MimeBodyPart bodyPart = new MimeBodyPart(); - messageMultipart.addBodyPart(bodyPart); - } + bodyPart.setContent(body, _TEXT_HTML); - for (int i = 0; i < fileAttachments.size(); i++) { - FileAttachment fileAttachment = fileAttachments.get(i); + messageMultipart.addBodyPart(bodyPart); + } else { + MimeBodyPart bodyPart = new MimeBodyPart(); - File file = fileAttachment.getFile(); + bodyPart.setText(body); - if (file == null) { - continue; - } + messageMultipart.addBodyPart(bodyPart); + } - MimeBodyPart mimeBodyPart = new MimeBodyPart(); + for (int i = 0; i < fileAttachments.size(); i++) { + FileAttachment fileAttachment = fileAttachments.get(i); - DataSource dataSource = new FileDataSource(file); + File file = fileAttachment.getFile(); - mimeBodyPart.setDataHandler(new DataHandler(dataSource)); - mimeBodyPart.setDisposition(Part.ATTACHMENT); + if (file == null) { + continue; + } - if (fileAttachment.getFileName() != null) { - mimeBodyPart.setFileName(fileAttachment.getFileName()); - } else { - mimeBodyPart.setFileName(file.getName()); - } + MimeBodyPart mimeBodyPart = new MimeBodyPart(); - rootMultipart.addBodyPart(mimeBodyPart); - } + DataSource dataSource = new FileDataSource(file); - message.setContent(rootMultipart); + mimeBodyPart.setDataHandler(new DataHandler(dataSource)); + mimeBodyPart.setDisposition(Part.ATTACHMENT); - message.saveChanges(); - } else { - if (htmlFormat) { - message.setContent(body, _TEXT_HTML); - } else { - message.setContent(body, _TEXT_PLAIN); - } - } + if (fileAttachment.getFileName() != null) { + mimeBodyPart.setFileName(fileAttachment.getFileName()); + } else { + mimeBodyPart.setFileName(file.getName()); + } - message.setSentDate(new Date()); + rootMultipart.addBodyPart(mimeBodyPart); + } - if (ArrayUtil.isNotEmpty(replyTo)) { - message.setReplyTo(replyTo); - } + message.setContent(rootMultipart); - if (messageId != null) { - message.setHeader("Message-ID", messageId); - } + message.saveChanges(); + } else { + if (htmlFormat) { + message.setContent(body, _TEXT_HTML); + } else { + message.setContent(body, _TEXT_PLAIN); + } + } - if (inReplyTo != null) { - message.setHeader("In-Reply-To", inReplyTo); - message.setHeader("References", inReplyTo); - } + message.setSentDate(new Date()); - int batchSize = GetterUtil.getInteger(PropsUtil.get(PropsKeys.MAIL_BATCH_SIZE), _BATCH_SIZE); + if (ArrayUtil.isNotEmpty(replyTo)) { + message.setReplyTo(replyTo); + } - _send(session, message, bulkAddresses, batchSize); - } catch (SendFailedException sfe) { - _log.error(sfe); + if (messageId != null) { + message.setHeader("Message-ID", messageId); + } - // if (_isThrowsExceptionOnFailure()) { - // throw new MailEngineException(sfe); - // } - throw new MailEngineException(sfe); - } catch (Exception e) { - throw new MailEngineException(e); - } + if (inReplyTo != null) { + message.setHeader("In-Reply-To", inReplyTo); + message.setHeader("References", inReplyTo); + } - if (_log.isDebugEnabled()) { - _log.debug("Sending mail takes " + (System.currentTimeMillis() - startTime) + " ms"); - } - } + int batchSize = GetterUtil.getInteger(PropsUtil.get(PropsKeys.MAIL_BATCH_SIZE), _BATCH_SIZE); - public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, - String subject, String body) throws MailEngineException { + _send(session, message, bulkAddresses, batchSize); + } catch (SendFailedException sfe) { + _log.error(sfe); - send(from, to, cc, bcc, subject, body, false, null, null, null); - } + // if (_isThrowsExceptionOnFailure()) { + // throw new MailEngineException(sfe); + // } + throw new MailEngineException(sfe); + } catch (Exception e) { + throw new MailEngineException(e); + } - public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, - String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo) - throws MailEngineException { + if (_log.isDebugEnabled()) { + _log.debug("Sending mail takes " + (System.currentTimeMillis() - startTime) + " ms"); + } + } - send(from, to, cc, bcc, null, subject, body, htmlFormat, replyTo, messageId, inReplyTo, null); - } + public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, + InternetAddress[] bcc, String subject, String body) throws MailEngineException { - public static void - send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, String subject, String body) - throws MailEngineException { + send(from, to, cc, bcc, subject, body, false, null, null, null); + } - send(from, to, cc, null, subject, body, false, null, null, null); - } + public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, + InternetAddress[] bcc, String subject, String body, boolean htmlFormat, + InternetAddress[] replyTo, String messageId, String inReplyTo) throws MailEngineException { - public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, String subject, - String body, boolean htmlFormat) throws MailEngineException { + send(from, to, cc, bcc, null, subject, body, htmlFormat, replyTo, messageId, inReplyTo, null); + } - send(from, to, cc, null, subject, body, htmlFormat, null, null, null); - } + public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, String subject, + String body) throws MailEngineException { - public static void send(InternetAddress from, InternetAddress[] to, String subject, String body) - throws MailEngineException { + send(from, to, cc, null, subject, body, false, null, null, null); + } - send(from, to, null, null, subject, body, false, null, null, null); - } + public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, String subject, + String body, boolean htmlFormat) throws MailEngineException { - public static void send(InternetAddress from, InternetAddress[] to, String subject, String body, boolean htmlFormat) - throws MailEngineException { + send(from, to, cc, null, subject, body, htmlFormat, null, null, null); + } - send(from, to, null, null, subject, body, htmlFormat, null, null, null); - } + public static void send(InternetAddress from, InternetAddress[] to, String subject, String body) + throws MailEngineException { - public static void send(MailMessage mailMessage) throws MailEngineException { + send(from, to, null, null, subject, body, false, null, null, null); + } - send(mailMessage.getFrom(), mailMessage.getTo(), mailMessage.getCC(), mailMessage.getBCC(), mailMessage - .getBulkAddresses(), mailMessage.getSubject(), mailMessage.getBody(), mailMessage.isHTMLFormat(), mailMessage - .getReplyTo(), mailMessage.getMessageId(), mailMessage.getInReplyTo(), mailMessage.getFileAttachments(), - mailMessage.getSMTPAccount()); - } + public static void send(InternetAddress from, InternetAddress[] to, String subject, String body, + boolean htmlFormat) throws MailEngineException { - public static void send(String from, String to, String subject, String body) throws MailEngineException { + send(from, to, null, null, subject, body, htmlFormat, null, null, null); + } - try { - send(new InternetAddress(from), new InternetAddress(to), subject, body); - } catch (AddressException ae) { - throw new MailEngineException(ae); - } - } + public static void send(MailMessage mailMessage) throws MailEngineException { - private static Address[] _getBatchAddresses(Address[] addresses, int index, int batchSize) { + send(mailMessage.getFrom(), mailMessage.getTo(), mailMessage.getCC(), mailMessage.getBCC(), + mailMessage.getBulkAddresses(), mailMessage.getSubject(), mailMessage.getBody(), + mailMessage.isHTMLFormat(), mailMessage.getReplyTo(), mailMessage.getMessageId(), + mailMessage.getInReplyTo(), mailMessage.getFileAttachments(), mailMessage.getSMTPAccount()); + } - if ((batchSize == _BATCH_SIZE) && (index == 0)) { - return addresses; - } else if (batchSize == _BATCH_SIZE) { - return null; - } + public static void send(String from, String to, String subject, String body) throws MailEngineException { - int start = index * batchSize; + try { + send(new InternetAddress(from), new InternetAddress(to), subject, body); + } catch (AddressException ae) { + throw new MailEngineException(ae); + } + } - if (start > addresses.length) { - return null; - } + private static Address[] _getBatchAddresses(Address[] addresses, int index, int batchSize) { - int end = ((index + 1) * batchSize); + if ((batchSize == _BATCH_SIZE) && (index == 0)) { + return addresses; + } else if (batchSize == _BATCH_SIZE) { + return null; + } - if (end > addresses.length) { - end = addresses.length; - } + int start = index * batchSize; - return ArrayUtil.subset(addresses, start, end); - } + if (start > addresses.length) { + return null; + } - private static Properties _getProperties(Account account) { - Properties properties = new Properties(); + int end = ((index + 1) * batchSize); - String protocol = account.getProtocol(); + if (end > addresses.length) { + end = addresses.length; + } - properties.setProperty("mail.transport.protocol", protocol); - properties.setProperty("mail." + protocol + ".host", account.getHost()); - properties.setProperty("mail." + protocol + ".port", String.valueOf(account.getPort())); + return ArrayUtil.subset(addresses, start, end); + } - if (account.isRequiresAuthentication()) { - properties.setProperty("mail." + protocol + ".auth", "true"); - properties.setProperty("mail." + protocol + ".user", account.getUser()); - properties.setProperty("mail." + protocol + ".password", account.getPassword()); - } + private static Properties _getProperties(Account account) { + Properties properties = new Properties(); - if (account.isSecure()) { - properties.setProperty("mail." + protocol + ".socketFactory.class", "javax.net.ssl.SSLSocketFactory"); - properties.setProperty("mail." + protocol + ".socketFactory.fallback", "false"); - properties.setProperty("mail." + protocol + ".socketFactory.port", String.valueOf(account.getPort())); - } + String protocol = account.getProtocol(); - return properties; - } + properties.setProperty("mail.transport.protocol", protocol); + properties.setProperty("mail." + protocol + ".host", account.getHost()); + properties.setProperty("mail." + protocol + ".port", String.valueOf(account.getPort())); - private static String _getSMTPProperty(Session session, String suffix) { - String protocol = GetterUtil.getString(session.getProperty("mail.transport.protocol")); + if (account.isRequiresAuthentication()) { + properties.setProperty("mail." + protocol + ".auth", "true"); + properties.setProperty("mail." + protocol + ".user", account.getUser()); + properties.setProperty("mail." + protocol + ".password", account.getPassword()); + } - if (protocol.equals(Account.PROTOCOL_SMTPS)) { - return session.getProperty("mail.smtps." + suffix); - } else { - return session.getProperty("mail.smtp." + suffix); - } - } + if (account.isSecure()) { + properties.setProperty("mail." + protocol + ".socketFactory.class", + "javax.net.ssl.SSLSocketFactory"); + properties.setProperty("mail." + protocol + ".socketFactory.fallback", "false"); + properties.setProperty("mail." + protocol + ".socketFactory.port", + String.valueOf(account.getPort())); + } - // private static boolean _isThrowsExceptionOnFailure() { - // return GetterUtil.getBoolean(PropsUtil.get(PropsKeys.MAIL_THROWS_EXCEPTION_ON_FAILURE)); - // } + return properties; + } - private static void _send(Session session, Message message, InternetAddress[] bulkAddresses, int batchSize) - throws MailEngineException { + private static String _getSMTPProperty(Session session, String suffix) { + String protocol = GetterUtil.getString(session.getProperty("mail.transport.protocol")); - try { - boolean smtpAuth = GetterUtil.getBoolean(_getSMTPProperty(session, "auth"), false); - String smtpHost = _getSMTPProperty(session, "host"); - int smtpPort = GetterUtil.getInteger(_getSMTPProperty(session, "port"), Account.PORT_SMTP); - String user = _getSMTPProperty(session, "user"); - String password = _getSMTPProperty(session, "password"); + if (protocol.equals(Account.PROTOCOL_SMTPS)) { + return session.getProperty("mail.smtps." + suffix); + } else { + return session.getProperty("mail.smtp." + suffix); + } + } - if (smtpAuth && Validator.isNotNull(user) && Validator.isNotNull(password)) { + // private static boolean _isThrowsExceptionOnFailure() { + // return + // GetterUtil.getBoolean(PropsUtil.get(PropsKeys.MAIL_THROWS_EXCEPTION_ON_FAILURE)); + // } - String protocol = GetterUtil.getString(session.getProperty("mail.transport.protocol"), Account.PROTOCOL_SMTP); + private static void _send(Session session, Message message, InternetAddress[] bulkAddresses, int batchSize) + throws MailEngineException { - Transport transport = session.getTransport(protocol); + try { + boolean smtpAuth = GetterUtil.getBoolean(_getSMTPProperty(session, "auth"), false); + String smtpHost = _getSMTPProperty(session, "host"); + int smtpPort = GetterUtil.getInteger(_getSMTPProperty(session, "port"), Account.PORT_SMTP); + String user = _getSMTPProperty(session, "user"); + String password = _getSMTPProperty(session, "password"); - transport.connect(smtpHost, smtpPort, user, password); + if (smtpAuth && Validator.isNotNull(user) && Validator.isNotNull(password)) { - Address[] addresses = null; + String protocol = GetterUtil.getString(session.getProperty("mail.transport.protocol"), + Account.PROTOCOL_SMTP); - if (ArrayUtil.isNotEmpty(bulkAddresses)) { - addresses = bulkAddresses; - } else { - addresses = message.getAllRecipients(); - } + Transport transport = session.getTransport(protocol); - for (int i = 0;; i++) { - Address[] batchAddresses = _getBatchAddresses(addresses, i, batchSize); + transport.connect(smtpHost, smtpPort, user, password); - if (ArrayUtil.isEmpty(batchAddresses)) { - break; - } + Address[] addresses = null; - transport.sendMessage(message, batchAddresses); - } + if (ArrayUtil.isNotEmpty(bulkAddresses)) { + addresses = bulkAddresses; + } else { + addresses = message.getAllRecipients(); + } - transport.close(); - } else { - if (ArrayUtil.isNotEmpty(bulkAddresses)) { - int curBatch = 0; + for (int i = 0;; i++) { + Address[] batchAddresses = _getBatchAddresses(addresses, i, batchSize); - Address[] portion = _getBatchAddresses(bulkAddresses, curBatch, batchSize); + if (ArrayUtil.isEmpty(batchAddresses)) { + break; + } - while (ArrayUtil.isNotEmpty(portion)) { - Transport.send(message, portion); + transport.sendMessage(message, batchAddresses); + } - curBatch++; + transport.close(); + } else { + if (ArrayUtil.isNotEmpty(bulkAddresses)) { + int curBatch = 0; - portion = _getBatchAddresses(bulkAddresses, curBatch, batchSize); - } - } else { - Transport.send(message); - } - } - } catch (MessagingException me) { - if (me.getNextException() instanceof SocketException) { - if (_log.isWarnEnabled()) { - _log.warn("Failed to connect to a valid mail server. Please " + "make sure one is properly configured. " - + me.getMessage()); - } - } else { - LogUtil.log(_log, me); - } + Address[] portion = _getBatchAddresses(bulkAddresses, curBatch, batchSize); - // if (_isThrowsExceptionOnFailure()) { - // throw new MailEngineException(me); - // } + while (ArrayUtil.isNotEmpty(portion)) { + Transport.send(message, portion); - throw new MailEngineException(me); - } - } + curBatch++; - private static final int _BATCH_SIZE = 0; + portion = _getBatchAddresses(bulkAddresses, curBatch, batchSize); + } + } else { + Transport.send(message); + } + } + } catch (MessagingException me) { + if (me.getNextException() instanceof SocketException) { + if (_log.isWarnEnabled()) { + _log.warn("Failed to connect to a valid mail server. Please " + + "make sure one is properly configured. " + me.getMessage()); + } + } else { + LogUtil.log(_log, me); + } - private static final String _MULTIPART_TYPE_ALTERNATIVE = "alternative"; + // if (_isThrowsExceptionOnFailure()) { + // throw new MailEngineException(me); + // } - private static final String _MULTIPART_TYPE_MIXED = "mixed"; + throw new MailEngineException(me); + } + } - private static final String _TEXT_HTML = "text/html;charset=\"UTF-8\""; + private static final int _BATCH_SIZE = 0; - private static final String _TEXT_PLAIN = "text/plain;charset=\"UTF-8\""; + private static final String _MULTIPART_TYPE_ALTERNATIVE = "alternative"; - private static Log _log = LogFactoryUtil.getLog(MailEngine.class); + private static final String _MULTIPART_TYPE_MIXED = "mixed"; + + private static final String _TEXT_HTML = "text/html;charset=\"UTF-8\""; + + private static final String _TEXT_PLAIN = "text/plain;charset=\"UTF-8\""; + + private static Log _log = LogFactoryUtil.getLog(MailEngine.class); } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailManagerUtil.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailManagerUtil.java index e0aeda5b..c83e1081 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailManagerUtil.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailManagerUtil.java @@ -97,7 +97,7 @@ public class MailManagerUtil { if (Validator.isNull(ccn)) { ccn = emailTemplate.getCcn(); } - + return EmailLocalServiceUtil.addEmail(className, classPK, emailTemplate.getFrom(), StringUtil.split(to, StringPool.COMMA), StringUtil.split(cc, StringPool.COMMA), StringUtil.split(ccn, StringPool.COMMA), subject, body, true, fileAttachments, sendSync, diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailSenderUtil.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailSenderUtil.java index 5647819c..d1197188 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailSenderUtil.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/MailSenderUtil.java @@ -29,13 +29,13 @@ import javax.mail.internet.InternetAddress; import org.apache.commons.lang.StringUtils; public class MailSenderUtil { - - private static final Log _log = LogFactoryUtil.getLog(MailSenderUtil.class.getName()); + + private static final Log _log = LogFactoryUtil.getLog(MailSenderUtil.class); public static void sendMail(Email email) throws Exception { - + _log.info("sendMail to: " + StringUtils.join(email.getToArray(), ", ")); - + InternetAddress from = toInternetAddress(email.getFrom()); InternetAddress[] to = toInternetAddresses(email.getToArray()); InternetAddress[] cc = toInternetAddresses(email.getCcArray()); diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/VelocityUtil.java b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/VelocityUtil.java index d97c0ebf..02e8b406 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/VelocityUtil.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/mailmanager/util/VelocityUtil.java @@ -13,57 +13,57 @@ import org.apache.velocity.runtime.RuntimeConstants; public class VelocityUtil { - public static VelocityContext fromJSONObjectOneLevelDepth(JSONObject jsonObject) { + public static VelocityContext fromJSONObjectOneLevelDepth(JSONObject jsonObject) { - VelocityContext velocityContext = new VelocityContext(); + VelocityContext velocityContext = new VelocityContext(); - while (jsonObject.keys().hasNext()) { + while (jsonObject.keys().hasNext()) { - String key = jsonObject.keys().next(); + String key = jsonObject.keys().next(); - velocityContext.put(key, jsonObject.getString(key)); + velocityContext.put(key, jsonObject.getString(key)); - } + } - return velocityContext; + return velocityContext; - } + } - public static String evaluate(String input) throws Exception { - return evaluate(input, null); - } + public static String evaluate(String input) throws Exception { + return evaluate(input, null); + } - public static String evaluate(String input, JSONObject variables) throws Exception { + public static String evaluate(String input, JSONObject variables) throws Exception { - VelocityEngine velocityEngine = new VelocityEngine(); + VelocityEngine velocityEngine = new VelocityEngine(); - velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, - com.liferay.portal.kernel.util.PropsUtil.get(PropsKeys.VELOCITY_ENGINE_LOGGER)); + velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, + com.liferay.portal.kernel.util.PropsUtil.get(PropsKeys.VELOCITY_ENGINE_LOGGER)); - velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM + ".log4j.category", - com.liferay.portal.kernel.util.PropsUtil.get(PropsKeys.VELOCITY_ENGINE_LOGGER_CATEGORY)); + velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM + ".log4j.category", + com.liferay.portal.kernel.util.PropsUtil.get(PropsKeys.VELOCITY_ENGINE_LOGGER_CATEGORY)); - velocityEngine.init(); + velocityEngine.init(); - VelocityContext velocityContext = new VelocityContext(); + VelocityContext velocityContext = new VelocityContext(); - if (variables != null) { + if (variables != null) { - Iterator iteratiorKeys = variables.keys(); + Iterator iteratiorKeys = variables.keys(); - while (iteratiorKeys.hasNext()) { - String key = iteratiorKeys.next(); - if (Validator.isNotNull(key)) { - velocityContext.put(key, variables.getString(key)); - } - } - } + while (iteratiorKeys.hasNext()) { + String key = iteratiorKeys.next(); + if (Validator.isNotNull(key)) { + velocityContext.put(key, variables.getString(key)); + } + } + } - UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter(); + UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter(); - velocityEngine.evaluate(velocityContext, unsyncStringWriter, VelocityUtil.class.getName(), input); + velocityEngine.evaluate(velocityContext, unsyncStringWriter, VelocityUtil.class.getName(), input); - return unsyncStringWriter.toString(); - } + return unsyncStringWriter.toString(); + } } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/service.properties b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/service.properties index 2113aa67..70da1d5d 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/service.properties +++ b/liferay-plugins-sdk-6.2/portlets/portos-mail-manager-portlet/docroot/WEB-INF/src/service.properties @@ -13,8 +13,8 @@ ## build.namespace=portos_Mail - build.number=75 - build.date=1592823810355 + build.number=76 + build.date=1603286289030 build.auto.upgrade=true ##