From 9adff9de0b0c227134aed5fb324dec057f1a7653 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Thu, 15 Oct 2015 17:54:14 +0300 Subject: [PATCH] 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