From 821290f75a310e3077822a0c9a2b0430d0e782c7 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Mon, 9 Nov 2015 13:05:43 +0200 Subject: [PATCH] Visual improvements to root pom file. Add license header to many files. Add new strings to i18n. Code refactoring. Add few comments to classes. Add new method for NotificationModel. Optimizing imports. Manually add constraints for email/username at E-mail connector page. A lot of changes to SendEmail class. --- .../email/daos/EmailNotificationDAO.java | 34 ++++ .../business/email/daos/EmailTemplateDAO.java | 23 +++ .../email/daos/IEmailNotificationDAO.java | 23 ++- .../email/daos/IEmailTemplateDAO.java | 20 ++ .../email/entities/EmailNotification.java | 24 ++- .../email/entities/EmailTemplate.java | 21 ++ .../email/entities/EmailTemplateEnum.java | 21 +- libreplan-webapp/pom.xml | 3 + .../org/libreplan/importers/ISendEmail.java | 24 ++- .../org/libreplan/importers/SendEmail.java | 81 ++++---- .../org/libreplan/importers/SendEmailJob.java | 21 ++ .../web/common/ConfigurationController.java | 187 ++++++++++-------- .../web/email/EmailNotificationModel.java | 33 +++- .../web/email/EmailTemplateController.java | 26 ++- .../web/email/EmailTemplateModel.java | 21 ++ .../web/email/IEmailNotificationModel.java | 24 ++- .../web/email/IEmailTemplateModel.java | 21 +- .../tabs/MultipleTabsPlannerController.java | 1 - .../taskedition/TaskPropertiesController.java | 6 +- .../src/main/resources/i18n/keys.pot | 10 +- .../src/main/webapp/email/email_templates.zul | 21 +- 21 files changed, 510 insertions(+), 135 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailNotificationDAO.java b/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailNotificationDAO.java index 57cdf2671..2aad7ebc9 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailNotificationDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailNotificationDAO.java @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.email.daos; import org.libreplan.business.common.daos.GenericDAOHibernate; @@ -7,6 +26,8 @@ import org.springframework.stereotype.Repository; import java.util.List; /** + * Dao for {@link EmailNotification} + * * Created by * @author Vova Perebykivskiy * on 19.10.15. @@ -18,4 +39,17 @@ public class EmailNotificationDAO extends GenericDAOHibernate getAll() { return list(EmailNotification.class); } + + @Override + public boolean deleteAll() { + List notifications = list(EmailNotification.class); + for (Object item : notifications){ + getSession().delete(item); + } + getSession().getTransaction().commit(); + + if ( list(EmailNotification.class).size() == 0 ) return true; + return false; + } + } 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 a927d3dc7..df4751ff5 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 @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.email.daos; import org.libreplan.business.common.daos.GenericDAOHibernate; @@ -7,6 +26,8 @@ import org.springframework.stereotype.Repository; import java.util.List; /** + * DAO for {@link EmailTemplate} + * * Created by * @author Vova Perebykivskiy * on 24.09.15. @@ -24,6 +45,7 @@ public class EmailTemplateDAO extends GenericDAOHibernate i try{ List emailTemplates = list(EmailTemplate.class); for ( int i = 0; i < emailTemplates.size(); i++) + // language.ordinal.equals(3) - English if ( emailTemplates.get(i).getType().ordinal() == 0 && emailTemplates.get(i).getLanguage().ordinal() == 3) return emailTemplates.get(i).getContent(); }catch (Exception e){} @@ -36,6 +58,7 @@ public class EmailTemplateDAO extends GenericDAOHibernate i try{ List emailTemplates = list(EmailTemplate.class); for ( int i = 0; i < emailTemplates.size(); i++) + // language.ordinal.equals(3) - English if ( emailTemplates.get(i).getType().ordinal() == 0 && emailTemplates.get(i).getLanguage().ordinal() == 3) return emailTemplates.get(i).getSubject(); }catch (Exception e){} diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailNotificationDAO.java b/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailNotificationDAO.java index 6e19ac1d0..5b4a545a1 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailNotificationDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailNotificationDAO.java @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.email.daos; import org.libreplan.business.common.daos.IGenericDAO; @@ -6,11 +25,13 @@ import org.libreplan.business.email.entities.EmailNotification; import java.util.List; /** + * Contract for {@link EmailNotificationDAO} + * * Created by * @author Vova Perebykivskiy * on 19.10.15. - * */ public interface IEmailNotificationDAO extends IGenericDAO { List getAll(); + boolean deleteAll(); } 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 dd43b5f14..57acd30a9 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 @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.email.daos; import org.libreplan.business.common.daos.IGenericDAO; @@ -7,6 +26,7 @@ import java.util.List; /** * DAO interface for the EmailTemplate entity. + * Contract for {@link EmailTemplateDAO} * * Created by * @author Vova Perebykivskiy 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 index fd550a702..817fb4dc2 100644 --- 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 @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.email.entities; import org.libreplan.business.common.BaseEntity; @@ -5,11 +24,12 @@ 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 + * EmailNotification entity representing table: notification_queue. + * This class is intended to work as a Hibernate component. + * It represents the Email notification to be send to user. * * Created by * @author Vova Perebykivskiy 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 bafdb32ed..a4f6d2c10 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,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.email.entities; import org.libreplan.business.common.BaseEntity; @@ -5,6 +24,8 @@ import org.libreplan.business.settings.entities.Language; /** * EmailTemplate entity, represents a template that LibrePlan user may use. + * This class is intended to work as a Hibernate component. + * It represents the E-mail template to be modified by admin and send to user. * * Created by * @author Vova Perebykivskiy 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 53d51407a..1402115fa 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 @@ -1,9 +1,28 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.email.entities; import static org.libreplan.business.i18n.I18nHelper._; /** - * Available E-mail templates + * Available E-mail templates. * * Created by * @author Vova Perebykivskiy diff --git a/libreplan-webapp/pom.xml b/libreplan-webapp/pom.xml index 029df0928..f80cf8816 100644 --- a/libreplan-webapp/pom.xml +++ b/libreplan-webapp/pom.xml @@ -11,6 +11,7 @@ LibrePlan Web Client Module + reports @@ -71,6 +72,7 @@ + userguide @@ -195,6 +197,7 @@ + i18n diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/ISendEmail.java b/libreplan-webapp/src/main/java/org/libreplan/importers/ISendEmail.java index cff3fb483..7fe5cbba0 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/ISendEmail.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/ISendEmail.java @@ -1,15 +1,33 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.importers; -import java.util.List; /** + * Sends E-mail to users with data that storing in notification_queue table + * * Created by * @author Vova Perebykivskiy * on 13.10.15. - * */ public interface ISendEmail { void sendEmail(); - } 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 cb85023a5..9b651ae0a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmail.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmail.java @@ -1,5 +1,23 @@ -package org.libreplan.importers; +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.libreplan.importers; import org.libreplan.business.common.daos.IConnectorDAO; import org.libreplan.business.common.entities.Connector; @@ -21,15 +39,21 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -// TODO not importing all packages -import javax.mail.*; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Transport; +import javax.mail.Session; +import javax.mail.PasswordAuthentication; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; -// TODO not importing all packages -import java.util.*; +import java.util.List; +import java.util.Locale; +import java.util.Properties; /** + * Sends E-mail to users with data that storing in notification_queue table + * * Created by * @author Vova Perebykivskiy * on 13.10.15. @@ -54,16 +78,8 @@ public class SendEmail implements ISendEmail { private List emailTemplates; - - @Override public void sendEmail() { - /* - // TODO - 1. check all added classes to identity (Licenses, annotations, comments, ...) - 2. the mvn compile flags -Ddefault.passwordsControl=false -Ddefault.exampleUsersDisabled=false are used to compile the demo version of LibrePlan. - 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. - */ notifications = emailNotificationModel.getAll(); @@ -90,7 +106,6 @@ public class SendEmail implements ISendEmail { // Modify text that will be composed - //List predefinedCommandsForTemplateTaskAssignedToResource; String text = currentEmailTemplate.getContent(); if ( type.equals(EmailTemplateEnum.TEMPLATE_TASK_ASSIGNED_TO_RESOURCE) ){ @@ -115,7 +130,6 @@ public class SendEmail implements ISendEmail { 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(); @@ -148,15 +162,14 @@ public class SendEmail implements ISendEmail { Properties properties = new Properties(); if ( protocol.equals("STARTTLS") ) { + properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.host", host); - properties.put("mail.smtp.socketFactory.port", "465"); + properties.put("mail.smtp.socketFactory.port", port); properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.put("mail.smtp.auth", "true"); - properties.put("mail.smtp.port", "465"); + properties.put("mail.smtp.port", port); } 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); } @@ -164,7 +177,8 @@ public class SendEmail implements ISendEmail { final String username = usrnme; final String password = psswrd; - Session mailSession = Session.getDefaultInstance(properties, + /* It is very important to use Session.getInstance instead of Session.getDefaultInstance */ + Session mailSession = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); @@ -172,28 +186,27 @@ public class SendEmail implements ISendEmail { }); // 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)); + try{ + MimeMessage message = new MimeMessage(mailSession); - String subject = currentEmailTemplate.getSubject(); - message.setSubject(subject); + message.setFrom(new InternetAddress(sender)); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receiver)); - message.setText(text); + String subject = currentEmailTemplate.getSubject(); + message.setSubject(subject); - // TODO delete me - mailSession.setDebug(true); + message.setText(text); - Transport.send(message); + Transport.send(message); - }catch (MessagingException e){throw new RuntimeException(e);} + }catch (MessagingException e){throw new RuntimeException(e);} } + private void deleteAllNotificationsAfterSending(){ - + emailNotificationModel.deleteAll(); } + private List getEmailConnectorProperties() { Connector connector = connectorDAO.findUniqueByName("E-mail"); @@ -202,6 +215,7 @@ public class SendEmail implements ISendEmail { return properties; } + private EmailTemplate findCurrentEmailTemplate(EmailTemplateEnum templateEnum, Locale locale){ emailTemplates = emailTemplateModel.getAll(); for (EmailTemplate item : emailTemplates) @@ -209,6 +223,7 @@ public class SendEmail implements ISendEmail { return item; return null; } + private Worker getCurrentWorker(Long resourceID){ List workerList = workerModel.getWorkers(); for(int i = 0; i < workerList.size(); i++) 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 cb36b7517..fa7dab5b8 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.importers; import org.quartz.JobExecutionContext; @@ -6,6 +25,8 @@ import org.springframework.context.ApplicationContext; import org.springframework.scheduling.quartz.QuartzJobBean; /** + * Sends E-mail to users with data that storing in notification_queue table + * * Created by * @author Vova Perebykivskiy * on 13.10.15. 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 b33ad48aa..791c43203 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 @@ -23,9 +23,23 @@ package org.libreplan.web.common; import static org.libreplan.web.I18nHelper._; -import java.util.*; -// TODO not importing all packages -import javax.mail.*; +import java.util.List; +import java.util.ConcurrentModificationException; +import java.util.Comparator; +import java.util.Properties; +import java.util.ArrayList; +import java.util.Set; +import java.util.Map; +import java.util.Collections; +import java.util.HashSet; +import java.util.Arrays; + +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.AuthenticationFailedException; +import javax.mail.MessagingException; + + import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -63,8 +77,27 @@ 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; -// TODO not importing all packages -import org.zkoss.zul.*; + + +import org.zkoss.zul.ListitemRenderer; +import org.zkoss.zul.Listbox; +import org.zkoss.zul.Grid; +import org.zkoss.zul.Combobox; +import org.zkoss.zul.Intbox; +import org.zkoss.zul.Textbox; +import org.zkoss.zul.Radiogroup; +import org.zkoss.zul.Listitem; +import org.zkoss.zul.Row; +import org.zkoss.zul.Constraint; +import org.zkoss.zul.RowRenderer; +import org.zkoss.zul.Comboitem; +import org.zkoss.zul.Radio; +import org.zkoss.zul.Button; +import org.zkoss.zul.Label; +import org.zkoss.zul.Rows; +import org.zkoss.zul.SimpleListModel; +import org.zkoss.zul.Messagebox; + import org.zkoss.zul.api.Window; import org.zkoss.zul.impl.InputElement; @@ -118,6 +151,10 @@ public class ConfigurationController extends GenericForwardComposer { private Combobox protocolsCombobox; + private Textbox emailUsernameTextbox; + + private Textbox emailPasswordTextbox; + @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); @@ -202,32 +239,38 @@ public class ConfigurationController extends GenericForwardComposer { } public void save() throws InterruptedException { - ConstraintChecker.isValid(configurationWindow); - if (checkValidEntitySequenceRows()) { - try { - configurationModel.confirm(); - configurationModel.init(); - messages.showMessage(Level.INFO, _("Changes saved")); - if (getSelectedConnector() != null - && !configurationModel - .scheduleOrUnscheduleJobs(getSelectedConnector())) { - messages.showMessage( - Level.ERROR, - _("Scheduling or unscheduling of jobs for this connector is not completed")); + + if ( getSelectedConnector().getName().equals("E-mail") && emailUsernamePasswordIsEmpty() == true) { + messages.showMessage(Level.ERROR, _("E-mail username/password - empty")); + } else { + ConstraintChecker.isValid(configurationWindow); + if (checkValidEntitySequenceRows()) { + try { + configurationModel.confirm(); + configurationModel.init(); + messages.showMessage(Level.INFO, _("Changes saved")); + if (getSelectedConnector() != null + && !configurationModel + .scheduleOrUnscheduleJobs(getSelectedConnector())) { + messages.showMessage( + Level.ERROR, + _("Scheduling or unscheduling of jobs for this connector is not completed")); + } + reloadWindow(); + reloadEntitySequences(); + reloadConnectors(); + } catch (ValidationException e) { + messages.showInvalidValues(e); + } catch (ConcurrentModificationException e) { + messages.showMessage(Level.ERROR, e.getMessage()); + configurationModel.init(); + reloadWindow(); + reloadEntitySequences(); + reloadConnectors(); } - reloadWindow(); - reloadEntitySequences(); - reloadConnectors(); - } catch (ValidationException e) { - messages.showInvalidValues(e); - } catch (ConcurrentModificationException e) { - messages.showMessage(Level.ERROR, e.getMessage()); - configurationModel.init(); - reloadWindow(); - reloadEntitySequences(); - reloadConnectors(); } } + } public void cancel() throws InterruptedException { @@ -1132,7 +1175,7 @@ public class ConfigurationController extends GenericForwardComposer { Util.appendLabel(row, _(property.getKey())); - // FIXME this is not perfect solution for future + // FIXME this is not perfect solution if ( property.getKey().equals("Protocol") ) appendValueCombobox(row, property); else appendValueTextbox(row, property); } @@ -1157,6 +1200,7 @@ public class ConfigurationController extends GenericForwardComposer { property.setValue(value); } }); + if ( property.getKey().equals( PredefinedConnectorProperties.PASSWORD) || property.getKey().equals( @@ -1164,6 +1208,13 @@ public class ConfigurationController extends GenericForwardComposer { textbox.setType("password"); } + // Need for method emailUsernamePasswordIsEmpty() + if ( property.getKey().equals( + PredefinedConnectorProperties.EMAIL_USERNAME) ) emailUsernameTextbox = textbox; + + if ( property.getKey().equals( + PredefinedConnectorProperties.EMAIL_PASSWORD) ) emailPasswordTextbox = textbox; + row.appendChild(textbox); } @@ -1218,49 +1269,7 @@ public class ConfigurationController extends GenericForwardComposer { 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;*/ + protocolsCombobox = combobox; } public Constraint checkPropertyValue( @@ -1269,27 +1278,33 @@ public class ConfigurationController extends GenericForwardComposer { return new Constraint() { @Override public void validate(Component comp, Object value) { - if (key.equals(PredefinedConnectorProperties.ACTIVATED)) { - if (!((String) value).equalsIgnoreCase("Y") - && !((String) value).equalsIgnoreCase("N")) { + if ( key.equals(PredefinedConnectorProperties.ACTIVATED) ) { + if ( !((String) value).equalsIgnoreCase("Y") + && !((String) value).equalsIgnoreCase("N") ) { throw new WrongValueException(comp, _( "Only {0} allowed", "Y/N")); } - } else if (key + } else if ( key .equals(PredefinedConnectorProperties.SERVER_URL) || key.equals(PredefinedConnectorProperties.USERNAME) || key.equals(PredefinedConnectorProperties.PASSWORD) - || key.equals(PredefinedConnectorProperties.JIRA_HOURS_TYPE)) { + || key.equals(PredefinedConnectorProperties.JIRA_HOURS_TYPE) ) { ((InputElement) comp).setConstraint("no empty:" + _("cannot be empty")); - } else if (key + } else if ( key .equals(PredefinedConnectorProperties.TIM_NR_DAYS_TIMESHEET) - || key.equals(PredefinedConnectorProperties.TIM_NR_DAYS_ROSTER)) { - if (!isNumeric((String) value)) { + || key.equals(PredefinedConnectorProperties.TIM_NR_DAYS_ROSTER) ) { + if ( !isNumeric((String) value) ) { throw new WrongValueException(comp, _("Only digits allowed")); } } + + // Validate E-mail connector + if ( key.equals(PredefinedConnectorProperties.HOST) || + key.equals(PredefinedConnectorProperties.PORT) || + key.equals(PredefinedConnectorProperties.EMAIL_SENDER) ) + ((InputElement) comp).setConstraint("no empty:" + _("cannot be empty")); } }; } @@ -1306,4 +1321,16 @@ public class ConfigurationController extends GenericForwardComposer { }; } + private boolean emailUsernamePasswordIsEmpty(){ + + if ( protocolsCombobox.getSelectedItem().getLabel().equals("STARTTLS") && + emailUsernameTextbox.getValue() != null && + emailPasswordTextbox.getValue() != null && + emailUsernameTextbox.getValue().length() != 0 && + emailPasswordTextbox.getValue().length() != 0 ) + return false; + + else return true; + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailNotificationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailNotificationModel.java index ab05a8d7c..49d6c3a2a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailNotificationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/email/EmailNotificationModel.java @@ -1,12 +1,31 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.web.email; import org.libreplan.business.common.exceptions.ValidationException; -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.EmailNotification; -import org.libreplan.business.planner.entities.Task; + import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.resources.entities.Resource; import org.springframework.beans.factory.annotation.Autowired; @@ -19,10 +38,11 @@ import java.util.Date; import java.util.List; /** + * Model for operations related to {@link EmailNotification}. + * * Created by * @author Vova Perebykivskiy * on 21.10.15. - * */ @Service @@ -56,6 +76,11 @@ public class EmailNotificationModel implements IEmailNotificationModel { return emailNotificationDAO.getAll(); } + @Override + public boolean deleteAll() { + return emailNotificationDAO.deleteAll(); + } + @Override public void setType(EmailTemplateEnum type) { this.emailNotification.setType(type); 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 5926e3852..903207579 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,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.web.email; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -18,8 +37,10 @@ import org.zkoss.zul.Listitem; import org.zkoss.zul.ListitemRenderer; import org.zkoss.zul.Textbox; -// TODO not importing all packages -import java.util.*; +import java.util.List; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import static org.libreplan.web.I18nHelper._; @@ -85,6 +106,7 @@ public class EmailTemplateController extends GenericForwardComposer{ public Language getSelectedLanguage() { return emailTemplateModel.getLanguage(); } + public void setSelectedLanguage(Language language){ emailTemplateModel.setLanguage(language); 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 d66901ede..c54985bf2 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,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.web.email; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -15,6 +34,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; /** + * Model for operations related to {@link EmailTemplate}. + * * Created by * @author Vova Perebykivskiy * on 25.09.15. diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailNotificationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailNotificationModel.java index a91d6d60e..f4ed94648 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailNotificationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailNotificationModel.java @@ -1,9 +1,27 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + 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.EmailNotification; -import org.libreplan.business.planner.entities.Task; import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.resources.entities.Resource; @@ -11,6 +29,8 @@ import java.util.Date; import java.util.List; /** + * Contract for {@link EmailNotification} + * * Created by * @author Vova Perebykivskiy * on 21.10.15. @@ -21,6 +41,8 @@ public interface IEmailNotificationModel { List getAll(); + boolean deleteAll(); + void setType(EmailTemplateEnum type); void setUpdated(Date date); void setResource(Resource resource); 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 3ecd3712b..09f9f0491 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,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.web.email; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -9,7 +28,7 @@ import org.libreplan.business.email.entities.EmailTemplateEnum; import java.util.List; /** - * Model E-mail Templates + * Contract for {@link EmailTemplate} * * Created by * @author Vova Perebykivskiy 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 dc5a5bc2b..ba4ff4365 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 @@ -85,7 +85,6 @@ 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 { 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 e6435340f..4934390af 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 @@ -433,7 +433,7 @@ public class TaskPropertiesController extends GenericForwardComposer { } public void accept() { - addNewRowToEmailNotificationeWithEmailTemplateTypeOne(); + EmailNotificationAddNewWithTaskAssignedToResource(); boolean ok = true; if (currentTaskElement instanceof ITaskPositionConstrained) { @@ -730,8 +730,7 @@ public class TaskPropertiesController extends GenericForwardComposer { return Util.getMoneyFormat(); } - - private void addNewRowToEmailNotificationeWithEmailTemplateTypeOne(){ + private void EmailNotificationAddNewWithTaskAssignedToResource(){ if ( allocationResult != null ) { @@ -771,7 +770,6 @@ public class TaskPropertiesController extends GenericForwardComposer { emailNotificationModel.confirmSave(); } - } } } diff --git a/libreplan-webapp/src/main/resources/i18n/keys.pot b/libreplan-webapp/src/main/resources/i18n/keys.pot index b8c60726b..b50895554 100644 --- a/libreplan-webapp/src/main/resources/i18n/keys.pot +++ b/libreplan-webapp/src/main/resources/i18n/keys.pot @@ -9233,4 +9233,12 @@ msgstr "" #: libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java:56 msgid "Protocol" -msgstr "" \ No newline at end of file +msgstr "" + +#: libreplan-webapp/src/main/webapp/email/email_templates.zul:56 +msgid "Possible content values:" +msgstr "" + +#: libreplan-webapp/src/main/webapp/java/org/libreplan/web/planner/tabs/MultipleTabsPlannerController:90 +msgid "-- no URL provided --" +msgstr "" diff --git a/libreplan-webapp/src/main/webapp/email/email_templates.zul b/libreplan-webapp/src/main/webapp/email/email_templates.zul index 2d24cb818..bf96c6eaa 100644 --- a/libreplan-webapp/src/main/webapp/email/email_templates.zul +++ b/libreplan-webapp/src/main/webapp/email/email_templates.zul @@ -1,3 +1,23 @@ + + + @@ -55,7 +75,6 @@ rows="15" width="400px;" tabindex="11"/> -