From 1cafd835d9284fddfa093d87c76b8bb881c2efe1 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Tue, 3 Nov 2015 10:35:53 +0200 Subject: [PATCH] Add new connector property. Add DAOs for EmailNotification/Template. Add entities for EmailNotification/Template. Add models for EmailNotification/Template. Add Hibernate mapping for email tables. Some changes to resources mapping. Add classes for job scheduling of emails. Code refactoring. Test email button changes. Add solution to get welcome page URL from system. Remarks to method that adds new row to notification_queue table. New role in Spring security. New content of Edit E-mail templates page. --- .../PredefinedConnectorProperties.java | 1 + ...ueueDAO.java => EmailNotificationDAO.java} | 8 +- .../business/email/daos/EmailTemplateDAO.java | 38 +++- ...eueDAO.java => IEmailNotificationDAO.java} | 6 +- .../email/daos/IEmailTemplateDAO.java | 6 + .../email/entities/EmailNotification.java | 65 ++++++ .../email/entities/EmailTemplate.java | 24 ++- .../email/entities/EmailTemplateEnum.java | 3 +- .../email/entities/NotificationQueue.java | 59 ------ .../business/email/entities/Email.hbm.xml | 42 +++- .../resources/entities/Resources.hbm.xml | 2 +- .../org/libreplan/importers/SendEmail.java | 199 ++++++++++++++++-- .../org/libreplan/importers/SendEmailJob.java | 5 - .../BaseCalendarEditionController.java | 8 +- .../web/common/ConfigurationController.java | 148 +++++++++---- ...Model.java => EmailNotificationModel.java} | 43 ++-- .../web/email/EmailTemplateController.java | 16 +- .../web/email/EmailTemplateModel.java | 78 +++++-- ...odel.java => IEmailNotificationModel.java} | 9 +- .../web/email/IEmailTemplateModel.java | 24 ++- .../tabs/MultipleTabsPlannerController.java | 8 + .../taskedition/TaskPropertiesController.java | 46 ++-- ...ibreplan-webapp-spring-security-config.xml | 2 + .../src/main/webapp/email/email_templates.zul | 21 +- 24 files changed, 628 insertions(+), 233 deletions(-) rename libreplan-business/src/main/java/org/libreplan/business/email/daos/{NotificationQueueDAO.java => EmailNotificationDAO.java} (53%) rename libreplan-business/src/main/java/org/libreplan/business/email/daos/{INotificationQueueDAO.java => IEmailNotificationDAO.java} (54%) create mode 100644 libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailNotification.java delete mode 100644 libreplan-business/src/main/java/org/libreplan/business/email/entities/NotificationQueue.java rename libreplan-webapp/src/main/java/org/libreplan/web/email/{NotificationQueueModel.java => EmailNotificationModel.java} (55%) rename libreplan-webapp/src/main/java/org/libreplan/web/email/{INotificationQueueModel.java => IEmailNotificationModel.java} (72%) diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java index 0e4c0a6d6..9611c0384 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java @@ -56,6 +56,7 @@ public class PredefinedConnectorProperties { public static String PROTOCOL = _("Protocol"); public static String HOST = _("Host"); public static String PORT = _("Port"); + public static String EMAIL_SENDER = _("From address (no reply)"); public static String EMAIL_USERNAME = _("Username (optional)"); public static String EMAIL_PASSWORD = _("Password (optional)"); diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/daos/NotificationQueueDAO.java b/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailNotificationDAO.java similarity index 53% rename from libreplan-business/src/main/java/org/libreplan/business/email/daos/NotificationQueueDAO.java rename to libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailNotificationDAO.java index 56ede461a..57cdf2671 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/daos/NotificationQueueDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailNotificationDAO.java @@ -1,7 +1,7 @@ package org.libreplan.business.email.daos; import org.libreplan.business.common.daos.GenericDAOHibernate; -import org.libreplan.business.email.entities.NotificationQueue; +import org.libreplan.business.email.entities.EmailNotification; import org.springframework.stereotype.Repository; import java.util.List; @@ -12,10 +12,10 @@ import java.util.List; * on 19.10.15. */ @Repository -public class NotificationQueueDAO extends GenericDAOHibernate implements INotificationQueueDAO { +public class EmailNotificationDAO extends GenericDAOHibernate implements IEmailNotificationDAO { @Override - public List getAll() { - return list(NotificationQueue.class); + public List getAll() { + return list(EmailNotification.class); } } diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailTemplateDAO.java b/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailTemplateDAO.java index 5eae5c34a..a927d3dc7 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailTemplateDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailTemplateDAO.java @@ -4,6 +4,8 @@ import org.libreplan.business.common.daos.GenericDAOHibernate; import org.libreplan.business.email.entities.EmailTemplate; import org.springframework.stereotype.Repository; +import java.util.List; + /** * Created by * @author Vova Perebykivskiy @@ -12,20 +14,42 @@ import org.springframework.stereotype.Repository; @Repository public class EmailTemplateDAO extends GenericDAOHibernate implements IEmailTemplateDAO{ + @Override + public List getAll() { + return list(EmailTemplate.class); + } + @Override public String initializeContent() { - for ( int i = 0; i < list(EmailTemplate.class).size(); i++) - if ( list(EmailTemplate.class).get(i).getType() == 1 && list(EmailTemplate.class).get(i).getLanguage() == 3) - return list(EmailTemplate.class).get(i).getContent(); + try{ + List emailTemplates = list(EmailTemplate.class); + for ( int i = 0; i < emailTemplates.size(); i++) + if ( emailTemplates.get(i).getType().ordinal() == 0 && emailTemplates.get(i).getLanguage().ordinal() == 3) + return emailTemplates.get(i).getContent(); + }catch (Exception e){} + return " "; } + @Override + public String initializeSubject() { + try{ + List emailTemplates = list(EmailTemplate.class); + for ( int i = 0; i < emailTemplates.size(); i++) + if ( emailTemplates.get(i).getType().ordinal() == 0 && emailTemplates.get(i).getLanguage().ordinal() == 3) + return emailTemplates.get(i).getSubject(); + }catch (Exception e){} + + return " "; + } + + @Override public String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal) { for (int i = 0; i < list(EmailTemplate.class).size(); i++) - if (list(EmailTemplate.class).get(i).getLanguage() == languageOrdinal && + if (list(EmailTemplate.class).get(i).getLanguage().ordinal() == languageOrdinal && // emailTemplateTypeOrdinal + 1, because first value is 0 - list(EmailTemplate.class).get(i).getType() == emailTemplateTypeOrdinal + 1) + list(EmailTemplate.class).get(i).getType().ordinal() == emailTemplateTypeOrdinal + 1) return list(EmailTemplate.class).get(i).getContent(); return ""; } @@ -34,8 +58,8 @@ public class EmailTemplateDAO extends GenericDAOHibernate i public String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal) { for (int i = 0; i < list(EmailTemplate.class).size(); i++) // emailTemplateTypeOrdinal + 1, because first value is 0 - if ( list(EmailTemplate.class).get(i).getType() == emailTemplateTypeOrdinal + 1 && - list(EmailTemplate.class).get(i).getLanguage() == languageOrdinal ) + if ( list(EmailTemplate.class).get(i).getType().ordinal() == emailTemplateTypeOrdinal + 1 && + list(EmailTemplate.class).get(i).getLanguage().ordinal() == languageOrdinal ) return list(EmailTemplate.class).get(i).getContent(); return ""; } diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/daos/INotificationQueueDAO.java b/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailNotificationDAO.java similarity index 54% rename from libreplan-business/src/main/java/org/libreplan/business/email/daos/INotificationQueueDAO.java rename to libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailNotificationDAO.java index bf1d2758d..6e19ac1d0 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/daos/INotificationQueueDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailNotificationDAO.java @@ -1,7 +1,7 @@ package org.libreplan.business.email.daos; import org.libreplan.business.common.daos.IGenericDAO; -import org.libreplan.business.email.entities.NotificationQueue; +import org.libreplan.business.email.entities.EmailNotification; import java.util.List; @@ -11,6 +11,6 @@ import java.util.List; * on 19.10.15. * */ -public interface INotificationQueueDAO extends IGenericDAO { - List getAll(); +public interface IEmailNotificationDAO extends IGenericDAO { + List getAll(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailTemplateDAO.java b/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailTemplateDAO.java index 17ec6ef0f..dd43b5f14 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailTemplateDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailTemplateDAO.java @@ -3,6 +3,8 @@ package org.libreplan.business.email.daos; import org.libreplan.business.common.daos.IGenericDAO; import org.libreplan.business.email.entities.EmailTemplate; +import java.util.List; + /** * DAO interface for the EmailTemplate entity. * @@ -12,7 +14,11 @@ import org.libreplan.business.email.entities.EmailTemplate; */ public interface IEmailTemplateDAO extends IGenericDAO{ + List getAll(); + String initializeContent(); + String initializeSubject(); + String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal); String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailNotification.java b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailNotification.java new file mode 100644 index 000000000..fd550a702 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailNotification.java @@ -0,0 +1,65 @@ +package org.libreplan.business.email.entities; + +import org.libreplan.business.common.BaseEntity; + +import org.libreplan.business.planner.entities.TaskElement; +import org.libreplan.business.resources.entities.Resource; + + +import java.util.Date; + +/** + * EmailNotification entity representing table: notification_queue + * + * Created by + * @author Vova Perebykivskiy + * on 19.10.15. + */ +public class EmailNotification extends BaseEntity { + + private EmailTemplateEnum type; + + private Date updated; + + private Resource resource; + + private TaskElement task; + + private TaskElement project; + + + public EmailTemplateEnum getType() { + return type; + } + public void setType(EmailTemplateEnum type) { + this.type = type; + } + + public Date getUpdated() { + return updated; + } + public void setUpdated(Date updated) { + this.updated = updated; + } + + public Resource getResource() { + return resource; + } + public void setResource(Resource resource) { + this.resource = resource; + } + + public TaskElement getTask() { + return task; + } + public void setTask(TaskElement task) { + this.task = task; + } + + public TaskElement getProject() { + return project; + } + public void setProject(TaskElement project) { + this.project = project; + } +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java index 46228c231..bafdb32ed 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java @@ -1,31 +1,36 @@ package org.libreplan.business.email.entities; import org.libreplan.business.common.BaseEntity; +import org.libreplan.business.settings.entities.Language; /** + * EmailTemplate entity, represents a template that LibrePlan user may use. + * * Created by * @author Vova Perebykivskiy * on 29.09.15. */ public class EmailTemplate extends BaseEntity { - private Integer type; + private EmailTemplateEnum type = EmailTemplateEnum.TEMPLATE_TASK_ASSIGNED_TO_RESOURCE; - private Integer language; + private Language language = Language.ENGLISH_LANGUAGE; private String content; - public int getType() { + private String subject; + + public EmailTemplateEnum getType() { return type; } - public void setType(Integer type) { + public void setType(EmailTemplateEnum type) { this.type = type; } - public Integer getLanguage() { + public Language getLanguage() { return language; } - public void setLanguage(Integer language) { + public void setLanguage(Language language) { this.language = language; } @@ -35,4 +40,11 @@ public class EmailTemplate extends BaseEntity { public void setContent(String content) { this.content = content; } + + public String getSubject() { + return subject; + } + public void setSubject(String subject) { + this.subject = subject; + } } diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplateEnum.java b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplateEnum.java index b917b8320..53d51407a 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplateEnum.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplateEnum.java @@ -14,8 +14,7 @@ import static org.libreplan.business.i18n.I18nHelper._; */ public enum EmailTemplateEnum { - TEMPLATE_TASK_ASSIGNED_TO_RESOURCE(_("Task assigned to resource")), - TEMPLATE_TEMPLATE_1("Test template"); + TEMPLATE_TASK_ASSIGNED_TO_RESOURCE(_("Task assigned to resource")); private final String templateType; diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/entities/NotificationQueue.java b/libreplan-business/src/main/java/org/libreplan/business/email/entities/NotificationQueue.java deleted file mode 100644 index 9106d8222..000000000 --- a/libreplan-business/src/main/java/org/libreplan/business/email/entities/NotificationQueue.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.libreplan.business.email.entities; - -import org.libreplan.business.common.BaseEntity; - -import java.math.BigInteger; -import java.util.Date; - -/** - * Created by - * @author Vova Perebykivskiy - * on 19.10.15. - */ -public class NotificationQueue extends BaseEntity { - - private Integer type; - - private Date updated; - - private Long resource; - - private Long task; - - private Long project; - - public Integer getType() { - return type; - } - public void setType(Integer type) { - this.type = type; - } - - public Date getUpdated() { - return updated; - } - public void setUpdated(Date updated) { - this.updated = updated; - } - - public Long getResource() { - return resource; - } - public void setResource(Long resource) { - this.resource = resource; - } - - public Long getTask() { - return task; - } - public void setTask(Long task) { - this.task = task; - } - - public Long getProject() { - return project; - } - public void setProject(Long project) { - this.project = project; - } -} diff --git a/libreplan-business/src/main/resources/org/libreplan/business/email/entities/Email.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/email/entities/Email.hbm.xml index 95220c0e8..b248770e0 100644 --- a/libreplan-business/src/main/resources/org/libreplan/business/email/entities/Email.hbm.xml +++ b/libreplan-business/src/main/resources/org/libreplan/business/email/entities/Email.hbm.xml @@ -3,27 +3,55 @@ + 100 - - + + + + org.libreplan.business.email.entities.EmailTemplateEnum + + + + + + org.libreplan.business.settings.entities.Language + + + + + - + + 100 - + + + + org.libreplan.business.email.entities.EmailTemplateEnum + + + - - - + + + + + + + \ No newline at end of file diff --git a/libreplan-business/src/main/resources/org/libreplan/business/resources/entities/Resources.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/resources/entities/Resources.hbm.xml index 85eb2b513..833b6495e 100644 --- a/libreplan-business/src/main/resources/org/libreplan/business/resources/entities/Resources.hbm.xml +++ b/libreplan-business/src/main/resources/org/libreplan/business/resources/entities/Resources.hbm.xml @@ -59,7 +59,7 @@ - diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmail.java b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmail.java index bec7af064..cb85023a5 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmail.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmail.java @@ -1,34 +1,59 @@ package org.libreplan.importers; -import org.libreplan.business.email.daos.INotificationQueueDAO; -import org.libreplan.business.email.daos.NotificationQueueDAO; -import org.libreplan.business.email.entities.NotificationQueue; -import org.libreplan.business.users.daos.UserDAO; -import org.libreplan.business.users.entities.User; -import org.libreplan.web.email.EmailTemplateModel; -import org.libreplan.web.email.INotificationQueueModel; +import org.libreplan.business.common.daos.IConnectorDAO; +import org.libreplan.business.common.entities.Connector; +import org.libreplan.business.common.entities.ConnectorProperty; +import org.libreplan.business.email.entities.EmailNotification; +import org.libreplan.business.email.entities.EmailTemplate; +import org.libreplan.business.email.entities.EmailTemplateEnum; +import org.libreplan.business.resources.entities.Resource; +import org.libreplan.business.resources.entities.Worker; +import org.libreplan.business.settings.entities.Language; +import org.libreplan.web.email.IEmailNotificationModel; -import org.libreplan.web.email.NotificationQueueModel; -import org.libreplan.web.users.UserModel; +import org.libreplan.web.email.IEmailTemplateModel; +import org.libreplan.web.planner.tabs.MultipleTabsPlannerController; +import org.libreplan.web.resources.worker.IWorkerModel; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -import org.zkoss.zk.ui.util.GenericForwardComposer; -import java.util.List; +// TODO not importing all packages +import javax.mail.*; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; + +// TODO not importing all packages +import java.util.*; /** * Created by * @author Vova Perebykivskiy * on 13.10.15. - * */ @Component @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class SendEmail implements ISendEmail { - private INotificationQueueModel notificationQueueModel; + @Autowired + private IEmailNotificationModel emailNotificationModel; + + @Autowired + private IConnectorDAO connectorDAO; + + @Autowired + private IWorkerModel workerModel; + + @Autowired + private IEmailTemplateModel emailTemplateModel; + + private List notifications; + private List emailTemplates; + + @Override @@ -40,15 +65,155 @@ public class SendEmail implements ISendEmail { There must also be a flag like "sendingEmail" that can be set to false to make sure that the demo edition will not become the worlds biggest spammer. */ - // TODO nullPointer on getAll() + notifications = emailNotificationModel.getAll(); + + for (int i = 0; i < notifications.size(); i++) composeMessageForUser(notifications.get(i)); + + deleteAllNotificationsAfterSending(); + } + + private void composeMessageForUser(EmailNotification notification){ + + // Gather data about EmailTemplate needs to be used + Resource resource = notification.getResource(); + EmailTemplateEnum type = notification.getType(); + Locale locale; + Worker currentWorker = getCurrentWorker(resource.getId()); + + if ( currentWorker.getUser().getApplicationLanguage().equals(Language.BROWSER_LANGUAGE) ) { + locale = new Locale(System.getProperty("user.language")); + } else { + locale = new Locale(currentWorker.getUser().getApplicationLanguage().getLocale().getLanguage()); + } + + EmailTemplate currentEmailTemplate = findCurrentEmailTemplate(type, locale); - System.out.println("Start"); + // Modify text that will be composed + //List predefinedCommandsForTemplateTaskAssignedToResource; + String text = currentEmailTemplate.getContent(); + if ( type.equals(EmailTemplateEnum.TEMPLATE_TASK_ASSIGNED_TO_RESOURCE) ){ + text = text.replaceAll("\\{username\\}", currentWorker.getUser().getLoginName()); + text = text.replaceAll("\\{firstname\\}", currentWorker.getUser().getFirstName()); + text = text.replaceAll("\\{lastname\\}", currentWorker.getUser().getLastName()); + text = text.replaceAll("\\{project\\}", notification.getProject().getName()); + text = text.replaceAll("\\{resource\\}", notification.getResource().getName()); + text = text.replaceAll("\\{task\\}", notification.getTask().getName()); + text = text.replaceAll("\\{url\\}", MultipleTabsPlannerController.WELCOME_URL); + } - List notifications = notificationQueueModel.getAll(); + // Get/Set connection properties + List emailConnectorProperties = getEmailConnectorProperties(); - System.out.println("End of list."); + String receiver = currentWorker.getUser().getEmail(); + String protocol = null; + String host = null; + String port = null; + String sender = null; + String usrnme = null; + String psswrd = null; + + for (int i = 0; i < emailConnectorProperties.size(); i++){ + if (emailConnectorProperties.get(i).getValue() != null) + switch (i){ + case 1: { + protocol = emailConnectorProperties.get(1).getValue(); + break; + } + case 2: { + host = emailConnectorProperties.get(2).getValue(); + break; + } + case 3: { + port = emailConnectorProperties.get(3).getValue(); + break; + } + case 4: { + sender = emailConnectorProperties.get(4).getValue(); + break; + } + case 5: { + usrnme = emailConnectorProperties.get(5).getValue(); + break; + } + case 6: { + psswrd = emailConnectorProperties.get(6).getValue(); + break; + } + } + } + + // Set properties of connection + Properties properties = new Properties(); + + if ( protocol.equals("STARTTLS") ) { + properties.put("mail.smtp.host", host); + properties.put("mail.smtp.socketFactory.port", "465"); + properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + properties.put("mail.smtp.auth", "true"); + properties.put("mail.smtp.port", "465"); + } + else if ( protocol.equals("SMTP") ) { + properties.put("mail.smtp.auth", "true"); + properties.put("mail.smtp.starttls.enable", "true"); + properties.put("mail.smtp.host", host); + properties.put("mail.smtp.port", port); + } + + final String username = usrnme; + final String password = psswrd; + + Session mailSession = Session.getDefaultInstance(properties, + new javax.mail.Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + + // Send message + try{ + MimeMessage message = new MimeMessage(mailSession); + // TODO check from field + message.setFrom(new InternetAddress(sender)); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receiver)); + + String subject = currentEmailTemplate.getSubject(); + message.setSubject(subject); + + message.setText(text); + + // TODO delete me + mailSession.setDebug(true); + + Transport.send(message); + + }catch (MessagingException e){throw new RuntimeException(e);} } + private void deleteAllNotificationsAfterSending(){ + + } + private List getEmailConnectorProperties() { + + Connector connector = connectorDAO.findUniqueByName("E-mail"); + + List properties = connector.getProperties(); + + return properties; + } + private EmailTemplate findCurrentEmailTemplate(EmailTemplateEnum templateEnum, Locale locale){ + emailTemplates = emailTemplateModel.getAll(); + for (EmailTemplate item : emailTemplates) + if ( item.getType().equals(templateEnum) && item.getLanguage().getLocale().equals(locale) ) + return item; + return null; + } + private Worker getCurrentWorker(Long resourceID){ + List workerList = workerModel.getWorkers(); + for(int i = 0; i < workerList.size(); i++) + if ( workerList.get(i).getId().equals(resourceID) ) + return workerList.get(i); + return null; + } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java index 3e305accc..cb36b7517 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java @@ -1,14 +1,10 @@ package org.libreplan.importers; -import org.libreplan.business.email.entities.NotificationQueue; -import org.libreplan.web.email.INotificationQueueModel; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.context.ApplicationContext; import org.springframework.scheduling.quartz.QuartzJobBean; -import java.util.List; - /** * Created by * @author Vova Perebykivskiy @@ -24,7 +20,6 @@ public class SendEmailJob extends QuartzJobBean { getJobDataMap().get("applicationContext"); ISendEmail sendEmail = (ISendEmail) applicationContext.getBean("sendEmail"); - sendEmail.sendEmail(); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/calendars/BaseCalendarEditionController.java b/libreplan-webapp/src/main/java/org/libreplan/web/calendars/BaseCalendarEditionController.java index ff8060ac1..11c623946 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/calendars/BaseCalendarEditionController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/calendars/BaseCalendarEditionController.java @@ -835,8 +835,8 @@ public abstract class BaseCalendarEditionController extends comboItem.setLabel(parent.getName()); comboItem.setParent(comboParents); - if ((version.getParent()) != null - && (parent.getId().equals(version.getParent().getId()))) { + if ( (version.getParent() ) != null && + (parent.getId().equals(version.getParent().getId())) ) { comboParents.setSelectedItem(comboItem); } } @@ -845,7 +845,7 @@ public abstract class BaseCalendarEditionController extends new EventListener() { @Override public void onEvent(Event event) throws Exception { - if (comboParents.getSelectedItem() != null) { + if ( comboParents.getSelectedItem() != null ) { BaseCalendar parent = (BaseCalendar) comboParents .getSelectedItem().getValue(); version.setParent(parent); @@ -861,7 +861,7 @@ public abstract class BaseCalendarEditionController extends }, new Util.Setter() { @Override public void set(Comboitem comboItem) { - if (((comboItem != null)) && (comboItem.getValue() != null) + if ( ((comboItem != null)) && (comboItem.getValue() != null ) && (comboItem.getValue() instanceof BaseCalendar)) { BaseCalendar parent = (BaseCalendar) comboItem .getValue(); diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java index f4a2d60f6..b33ad48aa 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java @@ -24,7 +24,7 @@ package org.libreplan.web.common; import static org.libreplan.web.I18nHelper._; import java.util.*; - +// TODO not importing all packages import javax.mail.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -63,24 +63,8 @@ import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.SelectEvent; import org.zkoss.zk.ui.util.GenericForwardComposer; -import org.zkoss.zul.Button; -import org.zkoss.zul.Combobox; -import org.zkoss.zul.Comboitem; -import org.zkoss.zul.Constraint; -import org.zkoss.zul.Grid; -import org.zkoss.zul.Intbox; -import org.zkoss.zul.Label; -import org.zkoss.zul.Listbox; -import org.zkoss.zul.Listitem; -import org.zkoss.zul.ListitemRenderer; -import org.zkoss.zul.Messagebox; -import org.zkoss.zul.Radio; -import org.zkoss.zul.Radiogroup; -import org.zkoss.zul.Row; -import org.zkoss.zul.RowRenderer; -import org.zkoss.zul.Rows; -import org.zkoss.zul.SimpleListModel; -import org.zkoss.zul.Textbox; +// TODO not importing all packages +import org.zkoss.zul.*; import org.zkoss.zul.api.Window; import org.zkoss.zul.impl.InputElement; @@ -391,7 +375,6 @@ public class ConfigurationController extends GenericForwardComposer { * the password */ private void testEmailConnection(String host, String port, String username, String password){ - Properties props = System.getProperties(); Transport transport = null; @@ -402,7 +385,7 @@ public class ConfigurationController extends GenericForwardComposer { Session session = Session.getInstance(props, null); transport = session.getTransport("smtp"); - if ( username.equals("") && password == null ) transport.connect(); + if ( username.equals("") && password.equals("")) transport.connect(); } else if ( protocolsCombobox.getSelectedItem().getLabel().equals("STARTTLS") ) { props.setProperty("mail.smtps.port", port); @@ -415,6 +398,7 @@ public class ConfigurationController extends GenericForwardComposer { messages.clearMessages(); if ( transport.isConnected() ) messages.showMessage(Level.INFO, _("Connection successful!")); + else if ( transport.isConnected() == false ) messages.showMessage(Level.WARNING, _("Connection unsuccessful")); } catch (AuthenticationFailedException e){ LOG.error(e); @@ -1147,32 +1131,14 @@ public class ConfigurationController extends GenericForwardComposer { row.setValue(property); Util.appendLabel(row, _(property.getKey())); - appendValueTextbox(row, property); + + // FIXME this is not perfect solution for future + if ( property.getKey().equals("Protocol") ) appendValueCombobox(row, property); + else appendValueTextbox(row, property); } private void appendValueTextbox(Row row, final ConnectorProperty property) { - if (property.getKey().equals( - PredefinedConnectorProperties.PROTOCOL - )){ - final Combobox combobox = new Combobox(); - combobox.setWidth("400px"); - - Comboitem comboitem = new Comboitem(); - comboitem.setLabel("SMTP"); - - Comboitem comboitem1 = new Comboitem(); - comboitem1.setLabel("STARTTLS"); - - combobox.getItems().add(comboitem); - combobox.getItems().add(comboitem1); - combobox.setSelectedIndex(0); - - row.appendChild(combobox); - - // Need for testing E-mail connection - protocolsCombobox= combobox; - } final Textbox textbox = new Textbox(); textbox.setWidth("400px"); @@ -1201,6 +1167,102 @@ public class ConfigurationController extends GenericForwardComposer { row.appendChild(textbox); } + private void appendValueCombobox(Row row, + final ConnectorProperty property){ + + final Combobox combobox = new Combobox(); + combobox.setWidth("400px"); + final List protocols = new ArrayList(); + protocols.add("SMTP"); + protocols.add("STARTTLS"); + + for (String item : protocols){ + Comboitem comboitem = new Comboitem(); + comboitem.setValue(item); + comboitem.setLabel(item); + comboitem.setParent(combobox); + + if ( (!property.getValue().equals("")) && + (item.equals(property.getValue())) ){ + combobox.setSelectedItem(comboitem); + } + } + + combobox.addEventListener(Events.ON_SELECT, + new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + if (combobox.getSelectedItem() != null){ + property.setValue(combobox.getSelectedItem().getValue().toString()); + } + } + }); + + Util.bind(combobox, new Util.Getter() { + @Override + public Comboitem get() { + return combobox.getSelectedItem(); + } + }, new Util.Setter(){ + + @Override + public void set(Comboitem item) { + if ( (item != null) && (item.getValue() != null) && + (item.getValue() instanceof String) ){ + property.setValue(combobox.getSelectedItem().getValue().toString()); + } + } + }); + + + row.appendChild(combobox); + + // Need for testing E-mail connection + protocolsCombobox= combobox; + + + + + /*final Combobox combobox = new Combobox(); + combobox.setWidth("400px"); + + + // TODO make get/set + + Util.bind(combobox, new Util.Getter() { + + @Override + public Comboitem get() { + Comboitem comboitem = new Comboitem(); + comboitem.setLabel("SMTP"); + return comboitem; + } + }, new Util.Setter() { + + @Override + public void set(Comboitem value) { + property.setValue("comboitem" *//*value.getLabel()*//*); + value.setLabel(property.getValue()); + } + }); + + + Comboitem comboitem = new Comboitem(); + comboitem.setLabel("SMTP"); + + Comboitem comboitem1 = new Comboitem(); + comboitem1.setLabel("STARTTLS"); + + combobox.getItems().add(comboitem); + combobox.getItems().add(comboitem1); + combobox.setSelectedIndex(0); + + row.appendChild(combobox); + + // Need for testing E-mail connection + protocolsCombobox= combobox;*/ + } + public Constraint checkPropertyValue( final ConnectorProperty property) { final String key = property.getKey(); diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/email/NotificationQueueModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailNotificationModel.java similarity index 55% rename from libreplan-webapp/src/main/java/org/libreplan/web/email/NotificationQueueModel.java rename to libreplan-webapp/src/main/java/org/libreplan/web/email/EmailNotificationModel.java index e258020f7..ab05a8d7c 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/email/NotificationQueueModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailNotificationModel.java @@ -1,12 +1,14 @@ package org.libreplan.web.email; import org.libreplan.business.common.exceptions.ValidationException; -import org.libreplan.business.email.daos.INotificationQueueDAO; +import org.libreplan.business.email.daos.EmailNotificationDAO; +import org.libreplan.business.email.daos.IEmailNotificationDAO; +import org.libreplan.business.email.entities.EmailTemplate; import org.libreplan.business.email.entities.EmailTemplateEnum; -import org.libreplan.business.email.entities.NotificationQueue; +import org.libreplan.business.email.entities.EmailNotification; +import org.libreplan.business.planner.entities.Task; import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.resources.entities.Resource; -import org.libreplan.web.common.concurrentdetection.OnConcurrentModification; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; @@ -25,10 +27,10 @@ import java.util.List; @Service @Scope(BeanDefinition.SCOPE_PROTOTYPE) -public class NotificationQueueModel implements INotificationQueueModel { +public class EmailNotificationModel implements IEmailNotificationModel { @Autowired - private INotificationQueueDAO notificationQueueDAO; + private IEmailNotificationDAO emailNotificationDAO; private EmailTemplateEnum type; @@ -38,54 +40,45 @@ public class NotificationQueueModel implements INotificationQueueModel { private TaskElement task; - private Long project; + private TaskElement project; - private NotificationQueue notificationQueue; + private EmailNotification emailNotification = new EmailNotification(); @Override @Transactional public void confirmSave() throws ValidationException { - notificationQueue = new NotificationQueue(); - - // + 1 because first ordinal = 0 - notificationQueue.setType(type.ordinal() + 1); - notificationQueue.setUpdated(updated); - notificationQueue.setResource(resource.getId()); - notificationQueue.setTask(task.getId()); - notificationQueue.setProject(project); - - notificationQueueDAO.save(notificationQueue); + emailNotificationDAO.save(emailNotification); } @Override @Transactional - public List getAll() { - return notificationQueueDAO.getAll(); + public List getAll() { + return emailNotificationDAO.getAll(); } @Override public void setType(EmailTemplateEnum type) { - this.type = type; + this.emailNotification.setType(type); } @Override public void setUpdated(Date updated) { - this.updated = updated; + this.emailNotification.setUpdated(updated); } @Override public void setResource(Resource resource) { - this.resource = resource; + this.emailNotification.setResource(resource); } @Override public void setTask(TaskElement task) { - this.task = task; + this.emailNotification.setTask(task); } @Override - public void setProject(Long project) { - this.project = project; + public void setProject(TaskElement project) { + this.emailNotification.setProject(project); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailTemplateController.java b/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailTemplateController.java index ca6016f15..5926e3852 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailTemplateController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailTemplateController.java @@ -1,7 +1,7 @@ package org.libreplan.web.email; +import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.ValidationException; -import org.libreplan.business.email.entities.NotificationQueue; import org.libreplan.business.settings.entities.Language; import org.libreplan.business.email.entities.EmailTemplateEnum; @@ -18,6 +18,7 @@ import org.zkoss.zul.Listitem; import org.zkoss.zul.ListitemRenderer; import org.zkoss.zul.Textbox; +// TODO not importing all packages import java.util.*; import static org.libreplan.web.I18nHelper._; @@ -38,6 +39,8 @@ public class EmailTemplateController extends GenericForwardComposer{ private Textbox contentsTextbox; + private Textbox subjectTextbox; + public static ListitemRenderer languagesRenderer = new ListitemRenderer() { @Override @@ -58,18 +61,20 @@ public class EmailTemplateController extends GenericForwardComposer{ comp.setVariable("emailTemplateController", this, true); messages = new MessagesForUser(messagesContainer); contentsTextbox.setValue(getInitialContentData()); + subjectTextbox.setValue(getInitialSubjectData()); } public boolean save(){ try { setSelectedContent(); + setSelectedSubject(); emailTemplateModel.confirmSave(); messages.clearMessages(); messages.showMessage(Level.INFO, _("E-mail template saved")); return true; } catch (ValidationException e) { messages.showInvalidValues(e); - } + } catch (InstanceNotFoundException e) {} return false; } @@ -138,6 +143,13 @@ public class EmailTemplateController extends GenericForwardComposer{ return emailTemplateModel.initializeContent(); } + public void setSelectedSubject(){ + emailTemplateModel.setSubject(subjectTextbox.getValue()); + } + public String getInitialSubjectData(){ + return emailTemplateModel.initializeSubject(); + } + private void getContentDataBySelectedLanguage(){ contentsTextbox.setValue(emailTemplateModel.getContentBySelectedLanguage(getSelectedLanguage().ordinal(), getSelectedEmailTemplateEnum().ordinal())); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailTemplateModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailTemplateModel.java index 0b01d7805..d66901ede 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailTemplateModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailTemplateModel.java @@ -1,5 +1,6 @@ package org.libreplan.web.email; +import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.settings.entities.Language; import org.libreplan.business.email.daos.IEmailTemplateDAO; import org.libreplan.business.email.entities.EmailTemplate; @@ -11,6 +12,8 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + /** * Created by * @author Vova Perebykivskiy @@ -30,47 +33,86 @@ public class EmailTemplateModel implements IEmailTemplateModel { private String content; - private EmailTemplate emailTemplate; + private String subject; + + private EmailTemplate emailTemplate = new EmailTemplate(); @Override @Transactional - public void confirmSave(){ - emailTemplate = new EmailTemplate(); + public void confirmSave() throws InstanceNotFoundException { - // + 1 because first ordinal = 0 - emailTemplate.setType(emailTemplateEnum.ordinal() + 1); - emailTemplate.setLanguage(language.ordinal()); - emailTemplate.setContent(content); + /* If current EmailTemplate entity (id) is existing in DB than it needs to update. + * Else current EmailTemplate entity (id) is creating and getting new values from form. + */ + List emailTemplates = emailTemplateDAO.getAll(); + EmailTemplate emailTemplateFromDatabase = null; + + for (int i = 0; i < emailTemplates.size(); i++) { + if ( emailTemplate.getLanguage() == emailTemplates.get(i).getLanguage() && + emailTemplate.getType() == emailTemplates.get(i).getType() ) { + emailTemplateFromDatabase = emailTemplateDAO.find(emailTemplates.get(i).getId()); + } + } + + if ( emailTemplateFromDatabase != null ){ + EmailTemplate temporaryEntity = emailTemplate; + emailTemplate = emailTemplateFromDatabase; + + emailTemplate.setType(temporaryEntity.getType()); + emailTemplate.setLanguage(temporaryEntity.getLanguage()); + emailTemplate.setContent(temporaryEntity.getContent()); + emailTemplate.setSubject(temporaryEntity.getSubject()); + } else { + EmailTemplate temporaryEntity = emailTemplate; + emailTemplate = new EmailTemplate(); + + emailTemplate.setType(temporaryEntity.getType()); + emailTemplate.setLanguage(temporaryEntity.getLanguage()); + emailTemplate.setContent(temporaryEntity.getContent()); + emailTemplate.setSubject(temporaryEntity.getSubject()); + } emailTemplateDAO.save(emailTemplate); } @Override - public Language getLanguage() { - return language; + @Transactional + public List getAll() { + return emailTemplateDAO.getAll(); } @Override - public void setLanguage(Language language){ this.language = language; } + public Language getLanguage() { + return this.emailTemplate.getLanguage(); + } + @Override + public void setLanguage(Language language){ this.emailTemplate.setLanguage(language);} @Override public EmailTemplateEnum getEmailTemplateEnum() { - return emailTemplateEnum; + return this.emailTemplate.getType(); } - @Override public void setEmailTemplateEnum(EmailTemplateEnum emailTemplateEnum) { - this.emailTemplateEnum = emailTemplateEnum; + this.emailTemplate.setType(emailTemplateEnum); } @Override public String getContent() { - return content; + return this.emailTemplate.getContent(); + } + @Override + public void setContent(String content) { + this.emailTemplate.setContent(content); } @Override - public void setContent(String content) { - this.content = content; + public String getSubject() { + return this.emailTemplate.getSubject(); + } + @Override + public void setSubject(String subject) { + this.emailTemplate.setSubject(subject); } @Override @@ -79,6 +121,10 @@ public class EmailTemplateModel implements IEmailTemplateModel { return emailTemplateDAO.initializeContent(); } + @Override + @Transactional + public String initializeSubject() { return emailTemplateDAO.initializeSubject(); } + @Override @Transactional public String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal) { diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/email/INotificationQueueModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailNotificationModel.java similarity index 72% rename from libreplan-webapp/src/main/java/org/libreplan/web/email/INotificationQueueModel.java rename to libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailNotificationModel.java index 03fcb663a..a91d6d60e 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/email/INotificationQueueModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailNotificationModel.java @@ -2,7 +2,8 @@ package org.libreplan.web.email; import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.email.entities.EmailTemplateEnum; -import org.libreplan.business.email.entities.NotificationQueue; +import org.libreplan.business.email.entities.EmailNotification; +import org.libreplan.business.planner.entities.Task; import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.resources.entities.Resource; @@ -14,16 +15,16 @@ import java.util.List; * @author Vova Perebykivskiy * on 21.10.15. */ -public interface INotificationQueueModel { +public interface IEmailNotificationModel { void confirmSave() throws ValidationException; - List getAll(); + List getAll(); void setType(EmailTemplateEnum type); void setUpdated(Date date); void setResource(Resource resource); void setTask(TaskElement task); - void setProject(Long project); + void setProject(TaskElement project); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailTemplateModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailTemplateModel.java index c0c268f1e..3ecd3712b 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailTemplateModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailTemplateModel.java @@ -1,9 +1,13 @@ package org.libreplan.web.email; +import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.ValidationException; +import org.libreplan.business.email.entities.EmailTemplate; import org.libreplan.business.settings.entities.Language; import org.libreplan.business.email.entities.EmailTemplateEnum; +import java.util.List; + /** * Model E-mail Templates * @@ -13,7 +17,18 @@ import org.libreplan.business.email.entities.EmailTemplateEnum; */ public interface IEmailTemplateModel { - void confirmSave() throws ValidationException; + void confirmSave() throws ValidationException, InstanceNotFoundException; + + List getAll(); + + String initializeContent(); + String initializeSubject(); + + String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal); + String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal); + + String getContent(); + void setContent(String content); Language getLanguage(); void setLanguage(Language language); @@ -21,9 +36,6 @@ public interface IEmailTemplateModel { EmailTemplateEnum getEmailTemplateEnum(); void setEmailTemplateEnum(EmailTemplateEnum emailTemplateEnum); - String getContent(); - void setContent(String content); - String initializeContent(); - String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal); - String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal); + String getSubject(); + void setSubject(String subject); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/tabs/MultipleTabsPlannerController.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/tabs/MultipleTabsPlannerController.java index de74b9be5..dc5a5bc2b 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/tabs/MultipleTabsPlannerController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/tabs/MultipleTabsPlannerController.java @@ -67,6 +67,7 @@ import org.zkoss.ganttz.extensions.TabProxy; import org.zkoss.ganttz.util.LongOperationFeedback; import org.zkoss.ganttz.util.LongOperationFeedback.ILongOperation; import org.zkoss.zk.ui.Desktop; +import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; @@ -84,6 +85,9 @@ import org.zkoss.zk.ui.util.Composer; public class MultipleTabsPlannerController implements Composer, IGlobalViewEntryPoints { + // TODO i18n + public static String WELCOME_URL = "-- no URL provided --"; + private final class TabWithLoadingFeedback extends TabProxy { private boolean feedback = true; @@ -419,6 +423,10 @@ public class MultipleTabsPlannerController implements Composer, @Override @Transactional(readOnly=true) public void doAfterCompose(org.zkoss.zk.ui.Component comp) { + + Execution execution = Executions.getCurrent(); + WELCOME_URL = "http://" + execution.getServerName() + ":" + execution.getServerPort() + Executions.encodeURL("/planner/index.zul"); + tabsSwitcher = (TabSwitcher) comp; breadcrumbs = comp.getPage().getFellow("breadcrumbs"); tabsSwitcher diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/taskedition/TaskPropertiesController.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/taskedition/TaskPropertiesController.java index 4e6537ba5..e6435340f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/taskedition/TaskPropertiesController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/taskedition/TaskPropertiesController.java @@ -41,13 +41,15 @@ import org.libreplan.business.planner.entities.PositionConstraintType; import org.libreplan.business.planner.entities.Task; import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.planner.entities.TaskPositionConstraint; +import org.libreplan.business.resources.entities.Resource; import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.scenarios.IScenarioManager; +import org.libreplan.business.users.entities.User; import org.libreplan.business.users.entities.UserRole; import org.libreplan.business.workingday.IntraDayDate; import org.libreplan.web.I18nHelper; import org.libreplan.web.common.Util; -import org.libreplan.web.email.INotificationQueueModel; +import org.libreplan.web.email.IEmailNotificationModel; import org.libreplan.web.orders.IOrderModel; import org.libreplan.web.planner.allocation.AllocationResult; import org.libreplan.web.resources.worker.IWorkerModel; @@ -126,7 +128,7 @@ public class TaskPropertiesController extends GenericForwardComposer { public static AllocationResult allocationResult; - private INotificationQueueModel notificationQueueModel; + private IEmailNotificationModel emailNotificationModel; private IOrderModel orderModel; @@ -431,7 +433,7 @@ public class TaskPropertiesController extends GenericForwardComposer { } public void accept() { - addNewRowToNotificationQueueWithEmailTemplateTypeOne(); + addNewRowToEmailNotificationeWithEmailTemplateTypeOne(); boolean ok = true; if (currentTaskElement instanceof ITaskPositionConstrained) { @@ -729,7 +731,7 @@ public class TaskPropertiesController extends GenericForwardComposer { } - private void addNewRowToNotificationQueueWithEmailTemplateTypeOne(){ + private void addNewRowToEmailNotificationeWithEmailTemplateTypeOne(){ if ( allocationResult != null ) { @@ -738,38 +740,40 @@ public class TaskPropertiesController extends GenericForwardComposer { * Then send valid data to notification_queue table */ List workersList = workerModel.getWorkers(); + Worker currentWorker; + Resource currentResource; + User currentUser; for (int i = 0; i < workersList.size(); i++) - for (int j = 0; j < allocationResult.getSpecificAllocations().size(); j++) + for (int j = 0; j < allocationResult.getSpecificAllocations().size(); j++){ - if ( workersList.get(i).getId().equals(allocationResult.getSpecificAllocations().get(j).getResource().getId()) ){ + currentWorker = workersList.get(i); + currentResource = allocationResult.getSpecificAllocations().get(j).getResource(); - workersList.get(i).setUser(workerModel.getBoundUserFromDB(workersList.get(i))); + if ( currentWorker.getId().equals(currentResource.getId()) ){ - if ( workersList.get(i).getUser() != null && - workersList.get(i).getUser().isInRole(UserRole.ROLE_EMAIL_TASK_ASSIGNED_TO_RESOURCE) == true ) { + workersList.get(i).setUser(workerModel.getBoundUserFromDB(currentWorker)); + currentUser = currentWorker.getUser(); - notificationQueueModel.setType(EmailTemplateEnum.TEMPLATE_TASK_ASSIGNED_TO_RESOURCE); + if ( currentUser != null && + currentUser.isInRole(UserRole.ROLE_EMAIL_TASK_ASSIGNED_TO_RESOURCE) ) { - notificationQueueModel.setUpdated(new Date()); + emailNotificationModel.setType(EmailTemplateEnum.TEMPLATE_TASK_ASSIGNED_TO_RESOURCE); - notificationQueueModel.setResource(allocationResult.getSpecificAllocations().get(i).getResource()); + emailNotificationModel.setUpdated(new Date()); - notificationQueueModel.setTask(currentTaskElement.getTaskSource().getTask()); + emailNotificationModel.setResource(allocationResult.getSpecificAllocations().get(j).getResource()); - List orderList = orderModel.getOrders(); + emailNotificationModel.setTask(currentTaskElement.getTaskSource().getTask()); - for (int k = 0; k < orderList.size(); k++) - - if ( orderList.get(k).getCode().equals(currentTaskElement.getProjectCode()) ) - - notificationQueueModel.setProject(orderList.get(k).getId()); - - notificationQueueModel.confirmSave(); + emailNotificationModel.setProject(currentTaskElement.getParent().getTaskSource().getTask()); + emailNotificationModel.confirmSave(); } + } + } } } diff --git a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml index 76c1333e1..8cea71490 100644 --- a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml +++ b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml @@ -55,6 +55,8 @@ + + @@ -42,11 +43,29 @@ itemRenderer="@{emailTemplateController.emailTemplateEnumRenderer}" selectedItem="@{emailTemplateController.selectedEmailTemplateEnum}"/> + +