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.
This commit is contained in:
Vova Perebykivskiy 2015-11-03 10:35:53 +02:00 committed by Vova Perebykivskiy
parent 2c7ae3ef58
commit 1cafd835d9
24 changed files with 628 additions and 233 deletions

View file

@ -56,6 +56,7 @@ public class PredefinedConnectorProperties {
public static String PROTOCOL = _("Protocol"); public static String PROTOCOL = _("Protocol");
public static String HOST = _("Host"); public static String HOST = _("Host");
public static String PORT = _("Port"); 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_USERNAME = _("Username (optional)");
public static String EMAIL_PASSWORD = _("Password (optional)"); public static String EMAIL_PASSWORD = _("Password (optional)");

View file

@ -1,7 +1,7 @@
package org.libreplan.business.email.daos; package org.libreplan.business.email.daos;
import org.libreplan.business.common.daos.GenericDAOHibernate; 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 org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -12,10 +12,10 @@ import java.util.List;
* on 19.10.15. * on 19.10.15.
*/ */
@Repository @Repository
public class NotificationQueueDAO extends GenericDAOHibernate<NotificationQueue, Long> implements INotificationQueueDAO { public class EmailNotificationDAO extends GenericDAOHibernate<EmailNotification, Long> implements IEmailNotificationDAO {
@Override @Override
public List<NotificationQueue> getAll() { public List<EmailNotification> getAll() {
return list(NotificationQueue.class); return list(EmailNotification.class);
} }
} }

View file

@ -4,6 +4,8 @@ import org.libreplan.business.common.daos.GenericDAOHibernate;
import org.libreplan.business.email.entities.EmailTemplate; import org.libreplan.business.email.entities.EmailTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* Created by * Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com> * @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
@ -12,20 +14,42 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public class EmailTemplateDAO extends GenericDAOHibernate<EmailTemplate, Long> implements IEmailTemplateDAO{ public class EmailTemplateDAO extends GenericDAOHibernate<EmailTemplate, Long> implements IEmailTemplateDAO{
@Override
public List<EmailTemplate> getAll() {
return list(EmailTemplate.class);
}
@Override @Override
public String initializeContent() { public String initializeContent() {
for ( int i = 0; i < list(EmailTemplate.class).size(); i++) try{
if ( list(EmailTemplate.class).get(i).getType() == 1 && list(EmailTemplate.class).get(i).getLanguage() == 3) List<EmailTemplate> emailTemplates = list(EmailTemplate.class);
return list(EmailTemplate.class).get(i).getContent(); 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 " "; return " ";
} }
@Override
public String initializeSubject() {
try{
List<EmailTemplate> 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 @Override
public String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal) { public String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal) {
for (int i = 0; i < list(EmailTemplate.class).size(); i++) 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 // 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 list(EmailTemplate.class).get(i).getContent();
return ""; return "";
} }
@ -34,8 +58,8 @@ public class EmailTemplateDAO extends GenericDAOHibernate<EmailTemplate, Long> i
public String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal) { public String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal) {
for (int i = 0; i < list(EmailTemplate.class).size(); i++) for (int i = 0; i < list(EmailTemplate.class).size(); i++)
// emailTemplateTypeOrdinal + 1, because first value is 0 // emailTemplateTypeOrdinal + 1, because first value is 0
if ( list(EmailTemplate.class).get(i).getType() == emailTemplateTypeOrdinal + 1 && if ( list(EmailTemplate.class).get(i).getType().ordinal() == emailTemplateTypeOrdinal + 1 &&
list(EmailTemplate.class).get(i).getLanguage() == languageOrdinal ) list(EmailTemplate.class).get(i).getLanguage().ordinal() == languageOrdinal )
return list(EmailTemplate.class).get(i).getContent(); return list(EmailTemplate.class).get(i).getContent();
return ""; return "";
} }

View file

@ -1,7 +1,7 @@
package org.libreplan.business.email.daos; package org.libreplan.business.email.daos;
import org.libreplan.business.common.daos.IGenericDAO; 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; import java.util.List;
@ -11,6 +11,6 @@ import java.util.List;
* on 19.10.15. * on 19.10.15.
* *
*/ */
public interface INotificationQueueDAO extends IGenericDAO<NotificationQueue, Long> { public interface IEmailNotificationDAO extends IGenericDAO<EmailNotification, Long> {
List<NotificationQueue> getAll(); List<EmailNotification> getAll();
} }

View file

@ -3,6 +3,8 @@ package org.libreplan.business.email.daos;
import org.libreplan.business.common.daos.IGenericDAO; import org.libreplan.business.common.daos.IGenericDAO;
import org.libreplan.business.email.entities.EmailTemplate; import org.libreplan.business.email.entities.EmailTemplate;
import java.util.List;
/** /**
* DAO interface for the <code>EmailTemplate</code> entity. * DAO interface for the <code>EmailTemplate</code> entity.
* *
@ -12,7 +14,11 @@ import org.libreplan.business.email.entities.EmailTemplate;
*/ */
public interface IEmailTemplateDAO extends IGenericDAO<EmailTemplate, Long>{ public interface IEmailTemplateDAO extends IGenericDAO<EmailTemplate, Long>{
List<EmailTemplate> getAll();
String initializeContent(); String initializeContent();
String initializeSubject();
String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal); String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal);
String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal); String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal);
} }

View file

@ -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 <vova@libreplan-enterprise.com>
* 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;
}
}

View file

@ -1,31 +1,36 @@
package org.libreplan.business.email.entities; package org.libreplan.business.email.entities;
import org.libreplan.business.common.BaseEntity; 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 * Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com> * @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* on 29.09.15. * on 29.09.15.
*/ */
public class EmailTemplate extends BaseEntity { 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; private String content;
public int getType() { private String subject;
public EmailTemplateEnum getType() {
return type; return type;
} }
public void setType(Integer type) { public void setType(EmailTemplateEnum type) {
this.type = type; this.type = type;
} }
public Integer getLanguage() { public Language getLanguage() {
return language; return language;
} }
public void setLanguage(Integer language) { public void setLanguage(Language language) {
this.language = language; this.language = language;
} }
@ -35,4 +40,11 @@ public class EmailTemplate extends BaseEntity {
public void setContent(String content) { public void setContent(String content) {
this.content = content; this.content = content;
} }
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
} }

View file

@ -14,8 +14,7 @@ import static org.libreplan.business.i18n.I18nHelper._;
*/ */
public enum EmailTemplateEnum { public enum EmailTemplateEnum {
TEMPLATE_TASK_ASSIGNED_TO_RESOURCE(_("Task assigned to resource")), TEMPLATE_TASK_ASSIGNED_TO_RESOURCE(_("Task assigned to resource"));
TEMPLATE_TEMPLATE_1("Test template");
private final String templateType; private final String templateType;

View file

@ -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 <vova@libreplan-enterprise.com>
* 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;
}
}

View file

@ -3,27 +3,55 @@
<hibernate-mapping package="org.libreplan.business.email.entities" default-access="field"> <hibernate-mapping package="org.libreplan.business.email.entities" default-access="field">
<class name="org.libreplan.business.email.entities.EmailTemplate" abstract="true" table="email_template"> <class name="org.libreplan.business.email.entities.EmailTemplate" abstract="true" table="email_template">
<id name="id" access="property" type="long"> <id name="id" access="property" type="long">
<generator class="hilo" > <generator class="hilo" >
<param name="max_lo">100</param> <param name="max_lo">100</param>
</generator> </generator>
</id> </id>
<property name="type" column="type" type="int"/>
<property name="language" column="language" type="int"/> <property name="type" column="type">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.libreplan.business.email.entities.EmailTemplateEnum</param>
</type>
</property>
<property name="language" column="language">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.libreplan.business.settings.entities.Language</param>
</type>
</property>
<property name="content" column="content" /> <property name="content" column="content" />
<property name="subject" column="subject" />
</class> </class>
<class name="org.libreplan.business.email.entities.NotificationQueue" abstract="true" table="notification_queue"> <class name="EmailNotification" abstract="true" table="notification_queue">
<id name="id" access="property" type="long"> <id name="id" access="property" type="long">
<generator class="hilo"> <generator class="hilo">
<param name="max_lo">100</param> <param name="max_lo">100</param>
</generator> </generator>
</id> </id>
<property name="type" column="type" type="int"/>
<property name="type" column="type">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.libreplan.business.email.entities.EmailTemplateEnum</param>
</type>
</property>
<property name="updated" column="updated"/> <property name="updated" column="updated"/>
<property name="resource" column="resource" type="long"/>
<property name="task" column="task" type="long"/> <many-to-one name="resource"
<property name="project" column="project" type="long"/> class="org.libreplan.business.resources.entities.Resource" column="resource" lazy="false"/>
<many-to-one name="task"
class="org.libreplan.business.planner.entities.TaskElement" column="task" lazy="false"/>
<many-to-one name="project"
class="org.libreplan.business.planner.entities.TaskElement" column="project" lazy="false"/>
</class> </class>
</hibernate-mapping> </hibernate-mapping>

View file

@ -59,7 +59,7 @@
<property name="surname"/> <property name="surname"/>
<property name="nif"/> <property name="nif"/>
<many-to-one name="user" cascade="save-update" <many-to-one name="user" cascade="save-update" access="property" lazy="false"
class="org.libreplan.business.users.entities.User" class="org.libreplan.business.users.entities.User"
column="user_id" unique="true" /> column="user_id" unique="true" />

View file

@ -1,34 +1,59 @@
package org.libreplan.importers; package org.libreplan.importers;
import org.libreplan.business.email.daos.INotificationQueueDAO; import org.libreplan.business.common.daos.IConnectorDAO;
import org.libreplan.business.email.daos.NotificationQueueDAO; import org.libreplan.business.common.entities.Connector;
import org.libreplan.business.email.entities.NotificationQueue; import org.libreplan.business.common.entities.ConnectorProperty;
import org.libreplan.business.users.daos.UserDAO; import org.libreplan.business.email.entities.EmailNotification;
import org.libreplan.business.users.entities.User; import org.libreplan.business.email.entities.EmailTemplate;
import org.libreplan.web.email.EmailTemplateModel; import org.libreplan.business.email.entities.EmailTemplateEnum;
import org.libreplan.web.email.INotificationQueueModel; 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.email.IEmailTemplateModel;
import org.libreplan.web.users.UserModel; 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.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; 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 * Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com> * @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* on 13.10.15. * on 13.10.15.
*
*/ */
@Component @Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE) @Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class SendEmail implements ISendEmail { 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<EmailNotification> notifications;
private List<EmailTemplate> emailTemplates;
@Override @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. 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<String> 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<NotificationQueue> notifications = notificationQueueModel.getAll(); // Get/Set connection properties
List<ConnectorProperty> 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<ConnectorProperty> getEmailConnectorProperties() {
Connector connector = connectorDAO.findUniqueByName("E-mail");
List<ConnectorProperty> 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<Worker> workerList = workerModel.getWorkers();
for(int i = 0; i < workerList.size(); i++)
if ( workerList.get(i).getId().equals(resourceID) )
return workerList.get(i);
return null;
} }
} }

View file

@ -1,14 +1,10 @@
package org.libreplan.importers; package org.libreplan.importers;
import org.libreplan.business.email.entities.NotificationQueue;
import org.libreplan.web.email.INotificationQueueModel;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean; import org.springframework.scheduling.quartz.QuartzJobBean;
import java.util.List;
/** /**
* Created by * Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com> * @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
@ -24,7 +20,6 @@ public class SendEmailJob extends QuartzJobBean {
getJobDataMap().get("applicationContext"); getJobDataMap().get("applicationContext");
ISendEmail sendEmail = (ISendEmail) applicationContext.getBean("sendEmail"); ISendEmail sendEmail = (ISendEmail) applicationContext.getBean("sendEmail");
sendEmail.sendEmail(); sendEmail.sendEmail();
} }

View file

@ -835,8 +835,8 @@ public abstract class BaseCalendarEditionController extends
comboItem.setLabel(parent.getName()); comboItem.setLabel(parent.getName());
comboItem.setParent(comboParents); comboItem.setParent(comboParents);
if ((version.getParent()) != null if ( (version.getParent() ) != null &&
&& (parent.getId().equals(version.getParent().getId()))) { (parent.getId().equals(version.getParent().getId())) ) {
comboParents.setSelectedItem(comboItem); comboParents.setSelectedItem(comboItem);
} }
} }

View file

@ -24,7 +24,7 @@ package org.libreplan.web.common;
import static org.libreplan.web.I18nHelper._; import static org.libreplan.web.I18nHelper._;
import java.util.*; import java.util.*;
// TODO not importing all packages
import javax.mail.*; import javax.mail.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; 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.Events;
import org.zkoss.zk.ui.event.SelectEvent; import org.zkoss.zk.ui.event.SelectEvent;
import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button; // TODO not importing all packages
import org.zkoss.zul.Combobox; import org.zkoss.zul.*;
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;
import org.zkoss.zul.api.Window; import org.zkoss.zul.api.Window;
import org.zkoss.zul.impl.InputElement; import org.zkoss.zul.impl.InputElement;
@ -391,7 +375,6 @@ public class ConfigurationController extends GenericForwardComposer {
* the password * the password
*/ */
private void testEmailConnection(String host, String port, String username, String password){ private void testEmailConnection(String host, String port, String username, String password){
Properties props = System.getProperties(); Properties props = System.getProperties();
Transport transport = null; Transport transport = null;
@ -402,7 +385,7 @@ public class ConfigurationController extends GenericForwardComposer {
Session session = Session.getInstance(props, null); Session session = Session.getInstance(props, null);
transport = session.getTransport("smtp"); 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") ) { else if ( protocolsCombobox.getSelectedItem().getLabel().equals("STARTTLS") ) {
props.setProperty("mail.smtps.port", port); props.setProperty("mail.smtps.port", port);
@ -415,6 +398,7 @@ public class ConfigurationController extends GenericForwardComposer {
messages.clearMessages(); messages.clearMessages();
if ( transport.isConnected() ) messages.showMessage(Level.INFO, _("Connection successful!")); if ( transport.isConnected() ) messages.showMessage(Level.INFO, _("Connection successful!"));
else if ( transport.isConnected() == false ) messages.showMessage(Level.WARNING, _("Connection unsuccessful"));
} }
catch (AuthenticationFailedException e){ catch (AuthenticationFailedException e){
LOG.error(e); LOG.error(e);
@ -1147,32 +1131,14 @@ public class ConfigurationController extends GenericForwardComposer {
row.setValue(property); row.setValue(property);
Util.appendLabel(row, _(property.getKey())); 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, private void appendValueTextbox(Row row,
final ConnectorProperty property) { 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(); final Textbox textbox = new Textbox();
textbox.setWidth("400px"); textbox.setWidth("400px");
@ -1201,6 +1167,102 @@ public class ConfigurationController extends GenericForwardComposer {
row.appendChild(textbox); row.appendChild(textbox);
} }
private void appendValueCombobox(Row row,
final ConnectorProperty property){
final Combobox combobox = new Combobox();
combobox.setWidth("400px");
final List<String> protocols = new ArrayList<String>();
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<Comboitem>() {
@Override
public Comboitem get() {
return combobox.getSelectedItem();
}
}, new Util.Setter<Comboitem>(){
@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<Comboitem>() {
@Override
public Comboitem get() {
Comboitem comboitem = new Comboitem();
comboitem.setLabel("SMTP");
return comboitem;
}
}, new Util.Setter<Comboitem>() {
@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( public Constraint checkPropertyValue(
final ConnectorProperty property) { final ConnectorProperty property) {
final String key = property.getKey(); final String key = property.getKey();

View file

@ -1,12 +1,14 @@
package org.libreplan.web.email; package org.libreplan.web.email;
import org.libreplan.business.common.exceptions.ValidationException; 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.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.planner.entities.TaskElement;
import org.libreplan.business.resources.entities.Resource; 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.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@ -25,10 +27,10 @@ import java.util.List;
@Service @Service
@Scope(BeanDefinition.SCOPE_PROTOTYPE) @Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class NotificationQueueModel implements INotificationQueueModel { public class EmailNotificationModel implements IEmailNotificationModel {
@Autowired @Autowired
private INotificationQueueDAO notificationQueueDAO; private IEmailNotificationDAO emailNotificationDAO;
private EmailTemplateEnum type; private EmailTemplateEnum type;
@ -38,54 +40,45 @@ public class NotificationQueueModel implements INotificationQueueModel {
private TaskElement task; private TaskElement task;
private Long project; private TaskElement project;
private NotificationQueue notificationQueue; private EmailNotification emailNotification = new EmailNotification();
@Override @Override
@Transactional @Transactional
public void confirmSave() throws ValidationException { public void confirmSave() throws ValidationException {
notificationQueue = new NotificationQueue(); emailNotificationDAO.save(emailNotification);
// + 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);
} }
@Override @Override
@Transactional @Transactional
public List<NotificationQueue> getAll() { public List<EmailNotification> getAll() {
return notificationQueueDAO.getAll(); return emailNotificationDAO.getAll();
} }
@Override @Override
public void setType(EmailTemplateEnum type) { public void setType(EmailTemplateEnum type) {
this.type = type; this.emailNotification.setType(type);
} }
@Override @Override
public void setUpdated(Date updated) { public void setUpdated(Date updated) {
this.updated = updated; this.emailNotification.setUpdated(updated);
} }
@Override @Override
public void setResource(Resource resource) { public void setResource(Resource resource) {
this.resource = resource; this.emailNotification.setResource(resource);
} }
@Override @Override
public void setTask(TaskElement task) { public void setTask(TaskElement task) {
this.task = task; this.emailNotification.setTask(task);
} }
@Override @Override
public void setProject(Long project) { public void setProject(TaskElement project) {
this.project = project; this.emailNotification.setProject(project);
} }
} }

View file

@ -1,7 +1,7 @@
package org.libreplan.web.email; package org.libreplan.web.email;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.common.exceptions.ValidationException; 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.settings.entities.Language;
import org.libreplan.business.email.entities.EmailTemplateEnum; 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.ListitemRenderer;
import org.zkoss.zul.Textbox; import org.zkoss.zul.Textbox;
// TODO not importing all packages
import java.util.*; import java.util.*;
import static org.libreplan.web.I18nHelper._; import static org.libreplan.web.I18nHelper._;
@ -38,6 +39,8 @@ public class EmailTemplateController extends GenericForwardComposer{
private Textbox contentsTextbox; private Textbox contentsTextbox;
private Textbox subjectTextbox;
public static ListitemRenderer languagesRenderer = new ListitemRenderer() { public static ListitemRenderer languagesRenderer = new ListitemRenderer() {
@Override @Override
@ -58,18 +61,20 @@ public class EmailTemplateController extends GenericForwardComposer{
comp.setVariable("emailTemplateController", this, true); comp.setVariable("emailTemplateController", this, true);
messages = new MessagesForUser(messagesContainer); messages = new MessagesForUser(messagesContainer);
contentsTextbox.setValue(getInitialContentData()); contentsTextbox.setValue(getInitialContentData());
subjectTextbox.setValue(getInitialSubjectData());
} }
public boolean save(){ public boolean save(){
try { try {
setSelectedContent(); setSelectedContent();
setSelectedSubject();
emailTemplateModel.confirmSave(); emailTemplateModel.confirmSave();
messages.clearMessages(); messages.clearMessages();
messages.showMessage(Level.INFO, _("E-mail template saved")); messages.showMessage(Level.INFO, _("E-mail template saved"));
return true; return true;
} catch (ValidationException e) { } catch (ValidationException e) {
messages.showInvalidValues(e); messages.showInvalidValues(e);
} } catch (InstanceNotFoundException e) {}
return false; return false;
} }
@ -138,6 +143,13 @@ public class EmailTemplateController extends GenericForwardComposer{
return emailTemplateModel.initializeContent(); return emailTemplateModel.initializeContent();
} }
public void setSelectedSubject(){
emailTemplateModel.setSubject(subjectTextbox.getValue());
}
public String getInitialSubjectData(){
return emailTemplateModel.initializeSubject();
}
private void getContentDataBySelectedLanguage(){ private void getContentDataBySelectedLanguage(){
contentsTextbox.setValue(emailTemplateModel.getContentBySelectedLanguage(getSelectedLanguage().ordinal(), getSelectedEmailTemplateEnum().ordinal())); contentsTextbox.setValue(emailTemplateModel.getContentBySelectedLanguage(getSelectedLanguage().ordinal(), getSelectedEmailTemplateEnum().ordinal()));
} }

View file

@ -1,5 +1,6 @@
package org.libreplan.web.email; package org.libreplan.web.email;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.settings.entities.Language; import org.libreplan.business.settings.entities.Language;
import org.libreplan.business.email.daos.IEmailTemplateDAO; import org.libreplan.business.email.daos.IEmailTemplateDAO;
import org.libreplan.business.email.entities.EmailTemplate; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** /**
* Created by * Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com> * @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
@ -30,47 +33,86 @@ public class EmailTemplateModel implements IEmailTemplateModel {
private String content; private String content;
private EmailTemplate emailTemplate; private String subject;
private EmailTemplate emailTemplate = new EmailTemplate();
@Override @Override
@Transactional @Transactional
public void confirmSave(){ public void confirmSave() throws InstanceNotFoundException {
/* 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<EmailTemplate> 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 = new EmailTemplate();
// + 1 because first ordinal = 0 emailTemplate.setType(temporaryEntity.getType());
emailTemplate.setType(emailTemplateEnum.ordinal() + 1); emailTemplate.setLanguage(temporaryEntity.getLanguage());
emailTemplate.setLanguage(language.ordinal()); emailTemplate.setContent(temporaryEntity.getContent());
emailTemplate.setContent(content); emailTemplate.setSubject(temporaryEntity.getSubject());
}
emailTemplateDAO.save(emailTemplate); emailTemplateDAO.save(emailTemplate);
} }
@Override @Override
public Language getLanguage() { @Transactional
return language; public List<EmailTemplate> getAll() {
return emailTemplateDAO.getAll();
} }
@Override @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 @Override
public EmailTemplateEnum getEmailTemplateEnum() { public EmailTemplateEnum getEmailTemplateEnum() {
return emailTemplateEnum; return this.emailTemplate.getType();
} }
@Override @Override
public void setEmailTemplateEnum(EmailTemplateEnum emailTemplateEnum) { public void setEmailTemplateEnum(EmailTemplateEnum emailTemplateEnum) {
this.emailTemplateEnum = emailTemplateEnum; this.emailTemplate.setType(emailTemplateEnum);
} }
@Override @Override
public String getContent() { public String getContent() {
return content; return this.emailTemplate.getContent();
}
@Override
public void setContent(String content) {
this.emailTemplate.setContent(content);
} }
@Override @Override
public void setContent(String content) { public String getSubject() {
this.content = content; return this.emailTemplate.getSubject();
}
@Override
public void setSubject(String subject) {
this.emailTemplate.setSubject(subject);
} }
@Override @Override
@ -79,6 +121,10 @@ public class EmailTemplateModel implements IEmailTemplateModel {
return emailTemplateDAO.initializeContent(); return emailTemplateDAO.initializeContent();
} }
@Override
@Transactional
public String initializeSubject() { return emailTemplateDAO.initializeSubject(); }
@Override @Override
@Transactional @Transactional
public String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal) { public String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal) {

View file

@ -2,7 +2,8 @@ package org.libreplan.web.email;
import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.common.exceptions.ValidationException;
import org.libreplan.business.email.entities.EmailTemplateEnum; 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.planner.entities.TaskElement;
import org.libreplan.business.resources.entities.Resource; import org.libreplan.business.resources.entities.Resource;
@ -14,16 +15,16 @@ import java.util.List;
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com> * @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* on 21.10.15. * on 21.10.15.
*/ */
public interface INotificationQueueModel { public interface IEmailNotificationModel {
void confirmSave() throws ValidationException; void confirmSave() throws ValidationException;
List<NotificationQueue> getAll(); List<EmailNotification> getAll();
void setType(EmailTemplateEnum type); void setType(EmailTemplateEnum type);
void setUpdated(Date date); void setUpdated(Date date);
void setResource(Resource resource); void setResource(Resource resource);
void setTask(TaskElement task); void setTask(TaskElement task);
void setProject(Long project); void setProject(TaskElement project);
} }

View file

@ -1,9 +1,13 @@
package org.libreplan.web.email; package org.libreplan.web.email;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.common.exceptions.ValidationException; 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.settings.entities.Language;
import org.libreplan.business.email.entities.EmailTemplateEnum; import org.libreplan.business.email.entities.EmailTemplateEnum;
import java.util.List;
/** /**
* Model E-mail Templates * Model E-mail Templates
* *
@ -13,7 +17,18 @@ import org.libreplan.business.email.entities.EmailTemplateEnum;
*/ */
public interface IEmailTemplateModel { public interface IEmailTemplateModel {
void confirmSave() throws ValidationException; void confirmSave() throws ValidationException, InstanceNotFoundException;
List<EmailTemplate> 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(); Language getLanguage();
void setLanguage(Language language); void setLanguage(Language language);
@ -21,9 +36,6 @@ public interface IEmailTemplateModel {
EmailTemplateEnum getEmailTemplateEnum(); EmailTemplateEnum getEmailTemplateEnum();
void setEmailTemplateEnum(EmailTemplateEnum emailTemplateEnum); void setEmailTemplateEnum(EmailTemplateEnum emailTemplateEnum);
String getContent(); String getSubject();
void setContent(String content); void setSubject(String subject);
String initializeContent();
String getContentBySelectedLanguage(int languageOrdinal, int emailTemplateTypeOrdinal);
String getContentBySelectedTemplate(int emailTemplateTypeOrdinal, int languageOrdinal);
} }

View file

@ -67,6 +67,7 @@ import org.zkoss.ganttz.extensions.TabProxy;
import org.zkoss.ganttz.util.LongOperationFeedback; import org.zkoss.ganttz.util.LongOperationFeedback;
import org.zkoss.ganttz.util.LongOperationFeedback.ILongOperation; import org.zkoss.ganttz.util.LongOperationFeedback.ILongOperation;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
@ -84,6 +85,9 @@ import org.zkoss.zk.ui.util.Composer;
public class MultipleTabsPlannerController implements Composer, public class MultipleTabsPlannerController implements Composer,
IGlobalViewEntryPoints { IGlobalViewEntryPoints {
// TODO i18n
public static String WELCOME_URL = "-- no URL provided --";
private final class TabWithLoadingFeedback extends TabProxy { private final class TabWithLoadingFeedback extends TabProxy {
private boolean feedback = true; private boolean feedback = true;
@ -419,6 +423,10 @@ public class MultipleTabsPlannerController implements Composer,
@Override @Override
@Transactional(readOnly=true) @Transactional(readOnly=true)
public void doAfterCompose(org.zkoss.zk.ui.Component comp) { 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; tabsSwitcher = (TabSwitcher) comp;
breadcrumbs = comp.getPage().getFellow("breadcrumbs"); breadcrumbs = comp.getPage().getFellow("breadcrumbs");
tabsSwitcher tabsSwitcher

View file

@ -41,13 +41,15 @@ import org.libreplan.business.planner.entities.PositionConstraintType;
import org.libreplan.business.planner.entities.Task; import org.libreplan.business.planner.entities.Task;
import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.planner.entities.TaskElement;
import org.libreplan.business.planner.entities.TaskPositionConstraint; 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.resources.entities.Worker;
import org.libreplan.business.scenarios.IScenarioManager; import org.libreplan.business.scenarios.IScenarioManager;
import org.libreplan.business.users.entities.User;
import org.libreplan.business.users.entities.UserRole; import org.libreplan.business.users.entities.UserRole;
import org.libreplan.business.workingday.IntraDayDate; import org.libreplan.business.workingday.IntraDayDate;
import org.libreplan.web.I18nHelper; import org.libreplan.web.I18nHelper;
import org.libreplan.web.common.Util; 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.orders.IOrderModel;
import org.libreplan.web.planner.allocation.AllocationResult; import org.libreplan.web.planner.allocation.AllocationResult;
import org.libreplan.web.resources.worker.IWorkerModel; import org.libreplan.web.resources.worker.IWorkerModel;
@ -126,7 +128,7 @@ public class TaskPropertiesController extends GenericForwardComposer {
public static AllocationResult allocationResult; public static AllocationResult allocationResult;
private INotificationQueueModel notificationQueueModel; private IEmailNotificationModel emailNotificationModel;
private IOrderModel orderModel; private IOrderModel orderModel;
@ -431,7 +433,7 @@ public class TaskPropertiesController extends GenericForwardComposer {
} }
public void accept() { public void accept() {
addNewRowToNotificationQueueWithEmailTemplateTypeOne(); addNewRowToEmailNotificationeWithEmailTemplateTypeOne();
boolean ok = true; boolean ok = true;
if (currentTaskElement instanceof ITaskPositionConstrained) { if (currentTaskElement instanceof ITaskPositionConstrained) {
@ -729,7 +731,7 @@ public class TaskPropertiesController extends GenericForwardComposer {
} }
private void addNewRowToNotificationQueueWithEmailTemplateTypeOne(){ private void addNewRowToEmailNotificationeWithEmailTemplateTypeOne(){
if ( allocationResult != null ) { if ( allocationResult != null ) {
@ -738,35 +740,37 @@ public class TaskPropertiesController extends GenericForwardComposer {
* Then send valid data to notification_queue table */ * Then send valid data to notification_queue table */
List<Worker> workersList = workerModel.getWorkers(); List<Worker> workersList = workerModel.getWorkers();
Worker currentWorker;
Resource currentResource;
User currentUser;
for (int i = 0; i < workersList.size(); i++) 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).setUser(workerModel.getBoundUserFromDB(currentWorker));
workersList.get(i).getUser().isInRole(UserRole.ROLE_EMAIL_TASK_ASSIGNED_TO_RESOURCE) == true ) { 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<Order> orderList = orderModel.getOrders(); emailNotificationModel.setTask(currentTaskElement.getTaskSource().getTask());
for (int k = 0; k < orderList.size(); k++) emailNotificationModel.setProject(currentTaskElement.getParent().getTaskSource().getTask());
if ( orderList.get(k).getCode().equals(currentTaskElement.getProjectCode()) ) emailNotificationModel.confirmSave();
}
notificationQueueModel.setProject(orderList.get(k).getId());
notificationQueueModel.confirmSave();
} }
} }

View file

@ -55,6 +55,8 @@
<!-- Pages --> <!-- Pages -->
<intercept-url pattern="/templates/*" <intercept-url pattern="/templates/*"
access="ROLE_SUPERUSER,ROLE_TEMPLATES" /> access="ROLE_SUPERUSER,ROLE_TEMPLATES" />
<intercept-url pattern="/email/*"
access="ROLE_SUPERUSER"/>
<intercept-url pattern="/resources/worker/worker.zul" <intercept-url pattern="/resources/worker/worker.zul"
access="ROLE_SUPERUSER,ROLE_WORKERS" /> access="ROLE_SUPERUSER,ROLE_WORKERS" />
<intercept-url pattern="/resources/machine/*" <intercept-url pattern="/resources/machine/*"

View file

@ -23,6 +23,7 @@
<grid> <grid>
<columns> <columns>
<column width="220px"></column> <column width="220px"></column>
<column width="420px"></column>
</columns> </columns>
<rows> <rows>
<row> <row>
@ -42,11 +43,29 @@
itemRenderer="@{emailTemplateController.emailTemplateEnumRenderer}" itemRenderer="@{emailTemplateController.emailTemplateEnumRenderer}"
selectedItem="@{emailTemplateController.selectedEmailTemplateEnum}"/> selectedItem="@{emailTemplateController.selectedEmailTemplateEnum}"/>
</row> </row>
<row>
<label value="${i18n:_('E-mail subject')}"/>
<textbox id="subjectTextbox"
width="400px;" />
</row>
<row> <row>
<label value="${i18n:_('Template contents')}"/> <label value="${i18n:_('Template contents')}"/>
<textbox id="contentsTextbox" <textbox id="contentsTextbox"
rows="15" width="600px;" rows="15" width="400px;"
tabindex="11"/> tabindex="11"/>
<vbox>
<!--//TODO i18n-->
<label value="${i18n:_('Possible content values:')}"/>
<label value="${i18n:_('{username}')}"/>
<label value="${i18n:_('{firstname}')}"/>
<label value="${i18n:_('{lastname}')}"/>
<label value="${i18n:_('{project}')}"/>
<label value="${i18n:_('{resource}')}"/>
<label value="${i18n:_('{task}')}"/>
<label value="${i18n:_('{url}')}"/>
</vbox>
</row> </row>
</rows> </rows>
</grid> </grid>