From 60a108f3773cdf0ab3ab491e74e9237bbb2a3796 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Tue, 6 Oct 2015 18:00:43 +0300 Subject: [PATCH 01/17] Add edit E-mail template page. --- HACKING.rst | 75 ++++++++++++- INSTALL.rst | 77 +++++++++++++ ...o-start-development-with-intellij-idea.rst | 101 ++++++++++++++++++ .../PredefinedConnectorProperties.java | 6 ++ .../common/entities/PredefinedConnectors.java | 10 +- libreplan-webapp/pom.xml | 8 ++ .../web/common/ConfigurationController.java | 86 ++++++++++++--- .../web/common/CustomMenuController.java | 6 ++ .../users/settings/SettingsController.java | 3 - .../src/main/resources/i18n/keys.pot | 18 ++++ 10 files changed, 372 insertions(+), 18 deletions(-) create mode 100644 doc/src/technical/howto-start-development-with-intellij-idea.rst diff --git a/HACKING.rst b/HACKING.rst index 2a3fa7121..b6aec7557 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -205,6 +205,79 @@ openSUSE * Go to http://localhost:8080/libreplan-webapp/ +Microsoft Windows +~~~~~~~~ + +* Download and install latest Java Development Kit 7u80 (JDK7u80):: + + # http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html + +* Download and install latest PostgreSQL database:: + + # http://www.enterprisedb.com/products-services-training/pgdownload#windows + +* Download and install Git + + # https://git-scm.com/download/win + +* Download Maven + + # https://maven.apache.org/download.cgi + +.. WARNING:: + + Check if latest Maven version is compatible with your JDK + +* Connect to database:: + + # Go to PostgreSQL bin folder and command window from here + # psql -U postgres + +* Use SQL sentences:: + + CREATE DATABASE libreplandev; + CREATE DATABASE libreplandevtest; + + CREATE USER libreplan WITH PASSWORD 'libreplan'; + + REVOKE ALL + ON ALL TABLES IN SCHEMA public + FROM PUBLIC; + + GRANT ALL PRIVILEGES ON DATABASE libreplan TO libreplan; + + GRANT SELECT, INSERT, UPDATE, DELETE + ON ALL TABLES IN SCHEMA public + TO libreplan; + +* Restore PostgreSQL dump - scripts/database/postgresql_1.4.1.backup + +* Download source code:: + + # Open GitBash + # git clone https://github.com/LibrePlan/libreplan.git + +* Set JAVA_HOME environment variable:: + + # You need to set it to your JDK installed directory (e.g. C:\Program Files\Java\jdk1.7.0_80) + +* Add path of unpacked distribution’s bin directory of Maven to 'Path' environment variable + + # (e.g. C:\Program Files\apache-maven-3.3.3\bin) + +* Compile project:: + + # cd libreplan + # mvn clean install + +* Launch application:: + + # cd libreplan-webapp + # mvn jetty:run + +* Go to http://localhost:8080/libreplan-webapp/ + + CutyCapt compilation -------------------- @@ -466,4 +539,4 @@ For MySQL users here are specific instructions. * Launch application:: $ cd libreplan-webapp/ - $ mvn -Pdev,mysql jetty:run + $ mvn -Pdev,mysql jetty:run \ No newline at end of file diff --git a/INSTALL.rst b/INSTALL.rst index 93be682a6..ab8a3d74b 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -117,6 +117,11 @@ Instructions depending on the distribution: If you have memory problems review the section `Fix memory errors`_. +Microsoft Windows +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + RPM Packages ~~~~~~~~~~~~ @@ -316,6 +321,78 @@ openSUSE * Go to http://localhost:8080/libreplan/ +Microsoft Windows +~~~~~~~~~~~ + +Instructions: + +* Download and install latest Java Runtime Environment 7u79 (JRE7u79):: + + # http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html + +* Download and install latest PostgreSQL database:: + + # http://www.enterprisedb.com/products-services-training/pgdownload#windows + +* Download and install Apache Tomcat 6:: + + # http://tomcat.apache.org/download-60.cgi + +.. NOTE:: + + In JDK folder there is JRE folder + +* Set up JDBC41 PostgreSQL Driver:: + + # Download latest driver: https://jdbc.postgresql.org/download.html + # Copy downloaded *.jar file to JRE location: (e.g. C:\Program Files\Java\jre7\lib\ext) + +* Download latest ``.war`` file from SourceForge.net (for PostgreSQL) and rename it to libreplan.war:: + + # http://sourceforge.net/projects/libreplan/files/LibrePlan/ + +* Create database:: + + CREATE DATABASE libreplan; + +* Use SQL sentences:: + + CREATE USER libreplan WITH PASSWORD 'libreplan'; + GRANT ALL PRIVILEGES ON DATABASE libreplan TO libreplan; + + REVOKE ALL + ON ALL TABLES IN SCHEMA public + FROM PUBLIC; + GRANT SELECT, INSERT, UPDATE, DELETE + ON ALL TABLES IN SCHEMA public + TO libreplan; + +* Restore PostgreSQL dump - scripts/database/postgresql_1.4.1.backup:: + +* Create an Environment Variable JRE_HOME + +# You need to set it to your JRE installed directory + +* Configure Apache Tomcat Server + + # Put libreplan.war file to Apache Tomcat webapps folder (e.g. C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\) + # Go to localhost folder (e.g. C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\Catalina\localhost\) and create there libreplan.xml file with this lines of code: + + + + + + +* Start Apache Tomcat server + + # Example location: C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\Tomcat6.exe + +* Go to http://localhost:8080/libreplan Logs ---- diff --git a/doc/src/technical/howto-start-development-with-intellij-idea.rst b/doc/src/technical/howto-start-development-with-intellij-idea.rst new file mode 100644 index 000000000..3bbb27083 --- /dev/null +++ b/doc/src/technical/howto-start-development-with-intellij-idea.rst @@ -0,0 +1,101 @@ +How To Start Development With JetBrains Intellij IDEA +====================================================== + +.. sectnum:: + +:Author: Perebykivskiy Vova +:Contact: vova@libreplan-enterprise.com +:Date: 09/09/2015 +:Copyright: + Some rights reserved. This document is distributed under the Creative + Commons Attribution-ShareAlike 3.0 licence, available in + http://creativecommons.org/licenses/by-sa/3.0/. +:Abstract: + Quick guide to start the development of LibrePlan_ using JetBrains Intellij IDEA_ IDE. + As this is the most common way of work among LibrePlan developers team. + +.. contents:: Table of Contents + +Download LibrePlan source code +------------------------------ + +* You need to download LibrePlan_ source code to start hacking on it. You have two +options: + +a) Clone Git repository (recommended):: + + git clone git://github.com/LibrePlan/libreplan.git + +b) Download last version source code:: + + http://sourceforge.net/projects/libreplan/files/LibrePlan/libreplan_*.tar.gz + +* Download latest libreplan_*.war file for your database (PostgreSQL or MySQL) + + http://sourceforge.net/projects/libreplan/files/LibrePlan/ + +You should review ``HACKING`` file to check that you have installed all the +requirements. + +Import LibrePlan project +------------------------ +* Run Intellij IDEA + +* Select Import Project + +* Select directory with source code of Libreplan + + # e.g. C\Users\PC-User\IdeaProjects\libreplan + +* Select *Import project from external model* > *Maven* and click *Next* + +* Then leave all as default + +* Then select profiles: dev and for PostgreSQL users - postgresql / Mysql users - mysql + +* Then leave all by default + +* Then choose your JDK + +* Then define project name or leave default name + + +Configure project to run +------------------------ + +* Go to *Run* > *Edit Configurations...* + +* Create a new *Maven Build* called *MavenConfig* + +* Change the following values: + + * Working directory: Choose ``libreplan-webapp`` folder in your workspace + * Command line: ``jetty:stop jetty:run`` + * Profiles (optional): ``-userguide -reports -i18n`` + (to disable userguide,reports and i18n profiles to save compilation time + as they are not mandatory to run LibrePlan) + * Mark the following checkboxes (recommended): + +* Resolve Workspace artifacts + +* In "Before launch" section choose "+" and add Build Artifact (war file) + +* Click *Run* and application will be available at + http://localhost:8080/libreplan-webapp/ + +Develop LibrePlan in Intellij IDEA using MySQL +---------------------------------------- + +* This tutorial works properly with PostgreSQL, but if you want to develop + LibrePlan using MySQL you have to do 2 small changes: + + * In section `Configure project to run`_ you have to set the *Profiles* to: + ``-dev -mysql -userguide -reports -i18n`` + +* Remember that the three last profiles that are being disabled is just to save + compilation time and not mandatory. However, to develop using MySQL you have + to set at least the first two: ``-dev`` and ``-mysql``. + + +.. _LibrePlan: http://www.libreplan.com/ +.. _JetBrains Intellij IDEA: https://www.jetbrains.com/idea/ \ No newline at end of file diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java index ef0b84200..0f6e71af1 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java @@ -27,6 +27,7 @@ import static org.libreplan.business.i18n.I18nHelper._; * * @author Miciele Ghiorghis * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ public class PredefinedConnectorProperties { @@ -51,4 +52,9 @@ public class PredefinedConnectorProperties { */ public static final String JIRA_CODE_PREFIX = "JIRA-"; + // Specific for E-mail + public static String HOST = _("Host"); + public static String USER_EMAIL = _("E-mail"); + public static String PORT = _("Port"); + } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java index b51adc8a1..1d6f01180 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java @@ -28,6 +28,7 @@ import java.util.List; * * @author Miciele Ghiorghis * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ public enum PredefinedConnectors { @@ -50,7 +51,14 @@ public enum PredefinedConnectors { ConnectorProperty .create(PredefinedConnectorProperties.JIRA_LABELS, ""), ConnectorProperty.create( - PredefinedConnectorProperties.JIRA_HOURS_TYPE, "Default")); + PredefinedConnectorProperties.JIRA_HOURS_TYPE, "Default")), + EMAIL("E-mail", + ConnectorProperty.create(PredefinedConnectorProperties.ACTIVATED, "N"), + ConnectorProperty.create(PredefinedConnectorProperties.HOST, ""), + ConnectorProperty.create(PredefinedConnectorProperties.PORT, ""), + ConnectorProperty.create(PredefinedConnectorProperties.USER_EMAIL, ""), + ConnectorProperty.create(PredefinedConnectorProperties.PASSWORD, "") + ); private String name; private List properties; diff --git a/libreplan-webapp/pom.xml b/libreplan-webapp/pom.xml index 078cb252d..029df0928 100644 --- a/libreplan-webapp/pom.xml +++ b/libreplan-webapp/pom.xml @@ -430,6 +430,14 @@ javax.servlet servlet-api + + + + javax.mail + mail + 1.5.0-b01 + + javax.ws.rs 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 a1ef7b11d..5d7e3542f 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,16 +23,9 @@ package org.libreplan.web.common; import static org.libreplan.web.I18nHelper._; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.ConcurrentModificationException; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; +import javax.mail.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -97,6 +90,7 @@ import org.zkoss.zul.impl.InputElement; * @author Susana Montes Pedreira * @author Cristina Alavarino Perez * @author Ignacio Diaz Teijido + * @author Vova Perebykivskiy */ public class ConfigurationController extends GenericForwardComposer { @@ -251,6 +245,7 @@ public class ConfigurationController extends GenericForwardComposer { public void cancel() throws InterruptedException { configurationModel.cancel(); + messages.clearMessages(); messages.showMessage(Level.INFO, _("Changes have been canceled")); reloadWindow(); reloadEntitySequences(); @@ -305,12 +300,18 @@ public class ConfigurationController extends GenericForwardComposer { String password = properties .get(PredefinedConnectorProperties.PASSWORD); - if (selectedConnector.getName().equals( - PredefinedConnectors.TIM.getName())) { + if ( selectedConnector.getName().equals( + PredefinedConnectors.TIM.getName()) ) { testTimConnection(url, username, password); - } else if (selectedConnector.getName().equals( - PredefinedConnectors.JIRA.getName())) { + } else if ( selectedConnector.getName().equals( + PredefinedConnectors.JIRA.getName()) ) { testJiraConnection(url, username, password); + } else if( selectedConnector.getName().equals( + PredefinedConnectors.EMAIL.getName()) ){ + String host = properties.get(PredefinedConnectorProperties.HOST); + String email = properties.get(PredefinedConnectorProperties.USER_EMAIL); + String port = properties.get(PredefinedConnectorProperties.PORT); + testEmailConnection(host, port, email, password); } else { throw new RuntimeException("Unknown connector"); } @@ -373,6 +374,65 @@ public class ConfigurationController extends GenericForwardComposer { } } + /** + * Test E-mail connection + * + * @param host + * the host + * @param port + * the port + * @param email + * the email + * @param password + * the password + */ + private void testEmailConnection(String host, String port, String email, String password){ + + String[] hostWords = host.split("\\."); + + // + "s" means that protocol coming with SSL + String protocol = hostWords[0] + "s"; + + Properties props = System.getProperties(); + + if ( hostWords[0].equals("pop") ){ + protocol = "pop3s"; + props.setProperty("mail.pop3s.port", port); + } + else if ( hostWords[0].equals("smtp") ){ props.setProperty("mail.smtps.port", port); } + else if ( hostWords[0].equals("imap") ){ props.setProperty("mail.imaps.port", port); } + + try { + Session session = Session.getInstance(props, null); + session.setDebug(true); + + if ( hostWords[0].equals("pop") || hostWords[0].equals("imap") ){ + Store store = session.getStore(protocol); + store.connect(host, email, password); + messages.clearMessages(); + if ( store.isConnected() ) messages.showMessage(Level.INFO, _("Connection successful!")); + } + else if ( hostWords[0].equals("smtp") ){ + Transport transport = session.getTransport(protocol); + transport.connect(host, email, password); + messages.clearMessages(); + if ( transport.isConnected() ) messages.showMessage(Level.INFO, _("Connection successful!")); + } + } + catch (AuthenticationFailedException e){ + LOG.error(e); + messages.showMessage(Level.ERROR, _("Invalid credentials")); + } + catch (MessagingException e){ + LOG.error(e); + messages.showMessage(Level.ERROR, _("Cannot connect")); + } + catch (Exception e){ + LOG.error(e); + messages.showMessage(Level.ERROR, _("Failed to connect")); + } + } + private boolean checkValidEntitySequenceRows() { Rows rows = entitySequencesGrid.getRows(); for (Row row : (List) rows.getChildren()) { diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java index c680966fb..6633074d9 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java @@ -59,6 +59,7 @@ import org.zkoss.zul.Vbox; * Controller for customMenu
* @author Lorenzo Tilve Álvaro * @author Fernando Bellas Permuy + * @author Vova Perebykivskiy */ public class CustomMenuController extends Div implements IMenuItemsRegister { @@ -420,6 +421,11 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { "/common/job_scheduling.zul", "19-scheduler.html")); } + if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EDIT_EMAIL_TEMPLATES)) { + configurationItems.add(subItem(_("Edit E-mail Templates"), + "/templates/email_templates.zul", + "email-templates.html")); + } if (!configurationItems.isEmpty()) { topItem(_("Configuration"), "/common/configuration.zul", "", diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/settings/SettingsController.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/settings/SettingsController.java index abf2f1625..6cfa2cf61 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/settings/SettingsController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/settings/SettingsController.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.logging.Filter; import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.labels.entities.Label; @@ -38,8 +37,6 @@ import org.libreplan.web.common.Level; import org.libreplan.web.common.MessagesForUser; import org.libreplan.web.common.components.bandboxsearch.BandboxSearch; import org.zkoss.zk.ui.Component; -import org.zkoss.zk.ui.Session; -import org.zkoss.zk.ui.Sessions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; diff --git a/libreplan-webapp/src/main/resources/i18n/keys.pot b/libreplan-webapp/src/main/resources/i18n/keys.pot index 5f9ef0927..54cbf38eb 100644 --- a/libreplan-webapp/src/main/resources/i18n/keys.pot +++ b/libreplan-webapp/src/main/resources/i18n/keys.pot @@ -889,6 +889,7 @@ msgstr "" #: libreplan-webapp/src/main/webapp/resources/worker/_edition.zul:122 #: libreplan-webapp/src/main/webapp/resources/worker/_edition.zul:158 #: libreplan-webapp/src/main/webapp/users/_editUser.zul:84 +#: libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java:56 msgid "E-mail" msgstr "" @@ -1363,6 +1364,7 @@ msgid "First expense" msgstr "" #: libreplan-webapp/src/main/webapp/common/configuration.zul:296 +#: libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java:55 msgid "Host" msgstr "" @@ -9212,3 +9214,19 @@ msgstr "" #: libreplan-business/src/main/java/org/libreplan/business/settings/entities/Language.java:36 msgid "Use browser language configuration" msgstr "" + +#: libreplan-business/src/main/java/org/libreplan/business/templates/entities/EmailTemplateEnum.java:17 +msgid "Task assigned to resource" +msgstr "" + +#: libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java:425 +msgid "Edit E-mail Templates" +msgstr "" + +#: libreplan-webapp/src/main/java/org/libreplan/web/templates/EmailTemplateController.java:72 +msgid "E-mail template saved" +msgstr "" + +#: libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java:57 +msgid "Port" +msgstr "" From 9adff9de0b0c227134aed5fb324dec057f1a7653 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Thu, 15 Oct 2015 17:54:14 +0300 Subject: [PATCH 02/17] Update how-to-start-with-IDEA Changed quartz scheduler version Add opportunity to Schedule E-mail class Add opportunity to test E-mail connector Minor changes to BaseCRUDController Add new strings for i18n Some changes to editJobScheduling form --- ...o-start-development-with-intellij-idea.rst | 2 +- .../common/entities/JobClassNameEnum.java | 5 +- .../PredefinedConnectorProperties.java | 4 +- .../common/entities/PredefinedConnectors.java | 6 +- .../web/common/BaseCRUDController.java | 3 +- .../web/common/ConfigurationController.java | 83 ++++++++++++------- .../web/common/JobSchedulerModel.java | 14 ++++ .../src/main/resources/i18n/keys.pot | 4 + .../main/webapp/common/_editJobScheduling.zul | 14 +++- pom.xml | 2 +- 10 files changed, 96 insertions(+), 41 deletions(-) diff --git a/doc/src/technical/howto-start-development-with-intellij-idea.rst b/doc/src/technical/howto-start-development-with-intellij-idea.rst index 3bbb27083..c43b95e99 100644 --- a/doc/src/technical/howto-start-development-with-intellij-idea.rst +++ b/doc/src/technical/howto-start-development-with-intellij-idea.rst @@ -84,7 +84,7 @@ Configure project to run http://localhost:8080/libreplan-webapp/ Develop LibrePlan in Intellij IDEA using MySQL ----------------------------------------- +---------------------------------------------- * This tutorial works properly with PostgreSQL, but if you want to develop LibrePlan using MySQL you have to do 2 small changes: diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/JobClassNameEnum.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/JobClassNameEnum.java index 038d7c413..26f4f041e 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/JobClassNameEnum.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/JobClassNameEnum.java @@ -29,8 +29,9 @@ package org.libreplan.business.common.entities; public enum JobClassNameEnum { IMPORT_ROSTER_FROM_TIM_JOB("org.libreplan.importers", "ImportRosterFromTimJob"), - EXPORT_TIMESHEET_TO_TIM_JOB("org.libreplan.importers","ExportTimesheetToTimJob"), - SYNC_ORDERELEMENTS_WITH_JIRA_ISSUES_JOB("org.libreplan.importers","JiraOrderElementSynchronizerJob"); + EXPORT_TIMESHEET_TO_TIM_JOB("org.libreplan.importers", "ExportTimesheetToTimJob"), + SYNC_ORDERELEMENTS_WITH_JIRA_ISSUES_JOB("org.libreplan.importers", "JiraOrderElementSynchronizerJob"), + SEND_EMAIL_JOB("org.libreplan.importers", "SendEmailJob"); private String packageName; private String name; diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java index 0f6e71af1..0e4c0a6d6 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java @@ -53,8 +53,10 @@ public class PredefinedConnectorProperties { public static final String JIRA_CODE_PREFIX = "JIRA-"; // Specific for E-mail + public static String PROTOCOL = _("Protocol"); public static String HOST = _("Host"); - public static String USER_EMAIL = _("E-mail"); public static String PORT = _("Port"); + public static String EMAIL_USERNAME = _("Username (optional)"); + public static String EMAIL_PASSWORD = _("Password (optional)"); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java index 1d6f01180..1d44db2ad 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java @@ -54,10 +54,12 @@ public enum PredefinedConnectors { PredefinedConnectorProperties.JIRA_HOURS_TYPE, "Default")), EMAIL("E-mail", ConnectorProperty.create(PredefinedConnectorProperties.ACTIVATED, "N"), + ConnectorProperty.create(PredefinedConnectorProperties.PROTOCOL, ""), ConnectorProperty.create(PredefinedConnectorProperties.HOST, ""), ConnectorProperty.create(PredefinedConnectorProperties.PORT, ""), - ConnectorProperty.create(PredefinedConnectorProperties.USER_EMAIL, ""), - ConnectorProperty.create(PredefinedConnectorProperties.PASSWORD, "") + ConnectorProperty.create(PredefinedConnectorProperties.EMAIL_USERNAME, ""), + ConnectorProperty.create(PredefinedConnectorProperties.EMAIL_PASSWORD, "") + ); private String name; diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/BaseCRUDController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/BaseCRUDController.java index 4589ee6fb..d9203150f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/BaseCRUDController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/BaseCRUDController.java @@ -227,9 +227,8 @@ public abstract class BaseCRUDController extends */ private void saveCommonActions() throws ValidationException { beforeSaving(); - + messagesForUser.clearMessages(); save(); - messagesForUser.showMessage( Level.INFO, _("{0} \"{1}\" saved", getEntityType(), getEntityBeingEdited() 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 5d7e3542f..f4a2d60f6 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 @@ -65,6 +65,7 @@ import org.zkoss.zk.ui.event.SelectEvent; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Button; import org.zkoss.zul.Combobox; +import org.zkoss.zul.Comboitem; import org.zkoss.zul.Constraint; import org.zkoss.zul.Grid; import org.zkoss.zul.Intbox; @@ -131,6 +132,8 @@ public class ConfigurationController extends GenericForwardComposer { private Connector selectedConnector; + private Combobox protocolsCombobox; + @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); @@ -309,9 +312,10 @@ public class ConfigurationController extends GenericForwardComposer { } else if( selectedConnector.getName().equals( PredefinedConnectors.EMAIL.getName()) ){ String host = properties.get(PredefinedConnectorProperties.HOST); - String email = properties.get(PredefinedConnectorProperties.USER_EMAIL); + username = properties.get(PredefinedConnectorProperties.EMAIL_USERNAME); + password = properties.get(PredefinedConnectorProperties.EMAIL_PASSWORD); String port = properties.get(PredefinedConnectorProperties.PORT); - testEmailConnection(host, port, email, password); + testEmailConnection(host, port, username, password); } else { throw new RuntimeException("Unknown connector"); } @@ -381,43 +385,36 @@ public class ConfigurationController extends GenericForwardComposer { * the host * @param port * the port - * @param email - * the email + * @param username + * the username * @param password * the password */ - private void testEmailConnection(String host, String port, String email, String password){ - - String[] hostWords = host.split("\\."); - - // + "s" means that protocol coming with SSL - String protocol = hostWords[0] + "s"; + private void testEmailConnection(String host, String port, String username, String password){ Properties props = System.getProperties(); - - if ( hostWords[0].equals("pop") ){ - protocol = "pop3s"; - props.setProperty("mail.pop3s.port", port); - } - else if ( hostWords[0].equals("smtp") ){ props.setProperty("mail.smtps.port", port); } - else if ( hostWords[0].equals("imap") ){ props.setProperty("mail.imaps.port", port); } + Transport transport = null; try { - Session session = Session.getInstance(props, null); - session.setDebug(true); + if ( protocolsCombobox.getSelectedItem().getLabel().equals("SMTP") ){ + props.setProperty("mail.smtp.port", port); + props.setProperty("mail.smtp.host", host); + Session session = Session.getInstance(props, null); - if ( hostWords[0].equals("pop") || hostWords[0].equals("imap") ){ - Store store = session.getStore(protocol); - store.connect(host, email, password); - messages.clearMessages(); - if ( store.isConnected() ) messages.showMessage(Level.INFO, _("Connection successful!")); + transport = session.getTransport("smtp"); + if ( username.equals("") && password == null ) transport.connect(); } - else if ( hostWords[0].equals("smtp") ){ - Transport transport = session.getTransport(protocol); - transport.connect(host, email, password); - messages.clearMessages(); - if ( transport.isConnected() ) messages.showMessage(Level.INFO, _("Connection successful!")); + else if ( protocolsCombobox.getSelectedItem().getLabel().equals("STARTTLS") ) { + props.setProperty("mail.smtps.port", port); + props.setProperty("mail.smtps.host", host); + Session session = Session.getInstance(props, null); + + transport = session.getTransport("smtps"); + if ( !username.equals("") && password != null ) transport.connect(host, username, password); } + + messages.clearMessages(); + if ( transport.isConnected() ) messages.showMessage(Level.INFO, _("Connection successful!")); } catch (AuthenticationFailedException e){ LOG.error(e); @@ -1155,6 +1152,28 @@ public class ConfigurationController extends GenericForwardComposer { private void appendValueTextbox(Row row, final ConnectorProperty property) { + if (property.getKey().equals( + PredefinedConnectorProperties.PROTOCOL + )){ + final Combobox combobox = new Combobox(); + combobox.setWidth("400px"); + + Comboitem comboitem = new Comboitem(); + comboitem.setLabel("SMTP"); + + Comboitem comboitem1 = new Comboitem(); + comboitem1.setLabel("STARTTLS"); + + combobox.getItems().add(comboitem); + combobox.getItems().add(comboitem1); + combobox.setSelectedIndex(0); + + row.appendChild(combobox); + + // Need for testing E-mail connection + protocolsCombobox= combobox; + } + final Textbox textbox = new Textbox(); textbox.setWidth("400px"); textbox.setConstraint(checkPropertyValue(property)); @@ -1172,8 +1191,10 @@ public class ConfigurationController extends GenericForwardComposer { property.setValue(value); } }); - if (property.getKey().equals( - PredefinedConnectorProperties.PASSWORD)) { + if ( property.getKey().equals( + PredefinedConnectorProperties.PASSWORD) || + property.getKey().equals( + PredefinedConnectorProperties.EMAIL_PASSWORD) ) { textbox.setType("password"); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/JobSchedulerModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/JobSchedulerModel.java index 5601cd3cb..0cea1d00a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/JobSchedulerModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/JobSchedulerModel.java @@ -19,6 +19,7 @@ package org.libreplan.web.common; +import java.util.ArrayList; import java.util.List; import org.libreplan.business.common.daos.IConnectorDAO; @@ -34,6 +35,7 @@ import org.libreplan.importers.IImportRosterFromTim; import org.libreplan.importers.IJiraOrderElementSynchronizer; import org.libreplan.importers.ISchedulerManager; import org.libreplan.importers.SynchronizationInfo; +import org.libreplan.importers.ISendEmail; import org.libreplan.web.common.concurrentdetection.OnConcurrentModification; import org.quartz.SchedulerException; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +44,8 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static org.libreplan.web.I18nHelper._; + /** * Model for UI operations related to {@link JobSchedulerConfiguration}. * @@ -75,6 +79,9 @@ public class JobSchedulerModel implements IJobSchedulerModel { private List synchronizationInfos; + @Autowired + private ISendEmail email; + @Override @Transactional(readOnly = true) public List getJobSchedulerConfigurations() { @@ -105,6 +112,13 @@ public class JobSchedulerModel implements IJobSchedulerModel { .syncOrderElementsWithJiraIssues(); return; } + if ( name.equals(JobClassNameEnum.SEND_EMAIL_JOB.getName()) ) { + synchronizationInfos = new ArrayList(); + synchronizationInfos.add(new SynchronizationInfo(_("Send E-mail"))); + email.sendEmail(); + return; + } + throw new RuntimeException("Unknown action"); } diff --git a/libreplan-webapp/src/main/resources/i18n/keys.pot b/libreplan-webapp/src/main/resources/i18n/keys.pot index 54cbf38eb..b8c60726b 100644 --- a/libreplan-webapp/src/main/resources/i18n/keys.pot +++ b/libreplan-webapp/src/main/resources/i18n/keys.pot @@ -9230,3 +9230,7 @@ msgstr "" #: libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java:57 msgid "Port" msgstr "" + +#: libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java:56 +msgid "Protocol" +msgstr "" \ No newline at end of file diff --git a/libreplan-webapp/src/main/webapp/common/_editJobScheduling.zul b/libreplan-webapp/src/main/webapp/common/_editJobScheduling.zul index fba176462..14a51777c 100644 --- a/libreplan-webapp/src/main/webapp/common/_editJobScheduling.zul +++ b/libreplan-webapp/src/main/webapp/common/_editJobScheduling.zul @@ -97,39 +97,51 @@ +
+
+ ${i18n:_("The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify “no specific value”. ")} +
+ ${i18n:_("For more details on cron expression click")} ${i18n:_('here')}.
diff --git a/pom.xml b/pom.xml index 7a65dfb8c..20e569f24 100644 --- a/pom.xml +++ b/pom.xml @@ -600,7 +600,7 @@ org.quartz-scheduler quartz - 1.8.0 + 1.8.6 org.slf4j From a43a2365bb8ca7c1a1428c04a1046ce25c090cec Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Thu, 15 Oct 2015 17:56:29 +0300 Subject: [PATCH 03/17] Add classes for E-mail scheduling. --- .../org/libreplan/importers/ISendEmail.java | 15 +++++++++++ .../org/libreplan/importers/SendEmail.java | 21 +++++++++++++++ .../org/libreplan/importers/SendEmailJob.java | 27 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 libreplan-webapp/src/main/java/org/libreplan/importers/ISendEmail.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/importers/SendEmail.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/ISendEmail.java b/libreplan-webapp/src/main/java/org/libreplan/importers/ISendEmail.java new file mode 100644 index 000000000..cff3fb483 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/ISendEmail.java @@ -0,0 +1,15 @@ +package org.libreplan.importers; + +import java.util.List; + +/** + * 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 new file mode 100644 index 000000000..45ef3ea0d --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmail.java @@ -0,0 +1,21 @@ +package org.libreplan.importers; + +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +/** + * Created by + * @author Vova Perebykivskiy + * on 13.10.15. + * + */ +@Component +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +public class SendEmail implements ISendEmail { + + @Override + public void sendEmail() { + System.out.println("SendEmail class!"); + } +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java new file mode 100644 index 000000000..32d2fde9e --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/SendEmailJob.java @@ -0,0 +1,27 @@ +package org.libreplan.importers; + +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.springframework.context.ApplicationContext; +import org.springframework.scheduling.quartz.QuartzJobBean; + +/** + * Created by + * @author Vova Perebykivskiy + * on 13.10.15. + * + */ + +public class SendEmailJob extends QuartzJobBean { + + @Override + protected void executeInternal(JobExecutionContext context) throws JobExecutionException { + ApplicationContext applicationContext = (ApplicationContext) context.getJobDetail(). + getJobDataMap().get("applicationContext"); + + ISendEmail sendEmail = (ISendEmail) applicationContext.getBean("sendEmail"); + + sendEmail.sendEmail(); + } + +} From e31a749f5a709525cdee5d11329222fe979dbd53 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Thu, 15 Oct 2015 18:08:19 +0300 Subject: [PATCH 04/17] Add edit E-mail template page. --- .../main/webapp/templates/email_templates.zul | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 libreplan-webapp/src/main/webapp/templates/email_templates.zul diff --git a/libreplan-webapp/src/main/webapp/templates/email_templates.zul b/libreplan-webapp/src/main/webapp/templates/email_templates.zul new file mode 100644 index 000000000..310ac5efe --- /dev/null +++ b/libreplan-webapp/src/main/webapp/templates/email_templates.zul @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +