Add possibility to disable E-mail sending with Maven compiler option.

This commit is contained in:
Vova Perebykivskiy 2015-11-10 11:56:42 +02:00 committed by Vova Perebykivskiy
parent 821290f75a
commit 878e067683
5 changed files with 42 additions and 19 deletions

View file

@ -506,6 +506,9 @@ example:
mvn -Ddefault.passwordsControl=false -Ddefault.exampleUsersDisabled=false clean install mvn -Ddefault.passwordsControl=false -Ddefault.exampleUsersDisabled=false clean install
* Set *default.emailSendingDisabled* to true::
mvn -Ddefault.emailSendingDisabled=true clean install
Tests Tests
----- -----

View file

@ -26,16 +26,19 @@ import org.apache.commons.lang.BooleanUtils;
/** /**
* This is a singleton that contains the compilation options passed from Maven. * This is a singleton that contains the compilation options passed from Maven.
* *
* Currently we have two options: * Currently we have three options:
* <ul> * <ul>
* <li>Enable/Disable the warning changing default password</li> * <li>Enable/Disable the warning changing default password</li>
* <li>Enable/Disable default users (such as wsreader, wswriter, * <li>Enable/Disable default users (such as wsreader, wswriter,
* wssubcontracting, manager, hresources, outsourcing and reports)</li> * wssubcontracting, manager, hresources, outsourcing and reports)</li>
* <li>Enable/Disable E-mail sending functionality</li>
* </ul> * </ul>
* *
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com> * @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
* @author Manuel Rego Casasnovas <rego@igalia.com> * @author Manuel Rego Casasnovas <rego@igalia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
*/ */
public class Configuration { public class Configuration {
private static final Configuration singleton = new Configuration(); private static final Configuration singleton = new Configuration();
@ -44,6 +47,8 @@ public class Configuration {
private Boolean exampleUsersDisabled; private Boolean exampleUsersDisabled;
private Boolean emailSendingDisabled;
private Configuration() { private Configuration() {
} }
@ -59,22 +64,13 @@ public class Configuration {
return singleton.getDefaultPasswordsControl() != null ? singleton return singleton.getDefaultPasswordsControl() != null ? singleton
.getDefaultPasswordsControl() : true; .getDefaultPasswordsControl() : true;
} }
public Boolean getDefaultPasswordsControl() {
return defaultPasswordsControl;
}
public void setDefaultPasswordsControl(Boolean defaultPasswordsControl) { public void setDefaultPasswordsControl(Boolean defaultPasswordsControl) {
this.defaultPasswordsControl = defaultPasswordsControl; this.defaultPasswordsControl = defaultPasswordsControl;
} }
public Boolean getDefaultPasswordsControl() {
return defaultPasswordsControl;
}
public void setExampleUsersDisabled(Boolean exampleUsersDisabled) {
this.exampleUsersDisabled = exampleUsersDisabled;
}
public Boolean getExampleUsersDisabled() {
return exampleUsersDisabled;
}
/** /**
* Returns the value of example users disabled compilation option * Returns the value of example users disabled compilation option
@ -82,5 +78,25 @@ public class Configuration {
public static boolean isExampleUsersDisabled() { public static boolean isExampleUsersDisabled() {
return BooleanUtils.isNotFalse(singleton.getExampleUsersDisabled()); return BooleanUtils.isNotFalse(singleton.getExampleUsersDisabled());
} }
public Boolean getExampleUsersDisabled() {
return exampleUsersDisabled;
}
public void setExampleUsersDisabled(Boolean exampleUsersDisabled) {
this.exampleUsersDisabled = exampleUsersDisabled;
}
/**
* Returns the value of E-mail sending disabled compilation option
*/
public static boolean isEmailSendingDisabled(){
return BooleanUtils.isNotFalse(singleton.getEmailSendingDisabled());
}
public Boolean getEmailSendingDisabled(){
return emailSendingDisabled;
}
public void setEmailSendingDisabled(Boolean emailSendingDisabled){
this.emailSendingDisabled = emailSendingDisabled;
}
} }

View file

@ -146,6 +146,9 @@
<property name="exampleUsersDisabled"> <property name="exampleUsersDisabled">
<value>${default.exampleUsersDisabled}</value> <value>${default.exampleUsersDisabled}</value>
</property> </property>
<property name="emailSendingDisabled">
<value>${default.emailSendingDisabled}</value>
</property>
</bean> </bean>
<bean id="scenarioManager" <bean id="scenarioManager"

View file

@ -19,6 +19,7 @@
package org.libreplan.importers; package org.libreplan.importers;
import org.libreplan.business.common.Configuration;
import org.libreplan.business.common.daos.IConnectorDAO; import org.libreplan.business.common.daos.IConnectorDAO;
import org.libreplan.business.common.entities.Connector; import org.libreplan.business.common.entities.Connector;
import org.libreplan.business.common.entities.ConnectorProperty; import org.libreplan.business.common.entities.ConnectorProperty;
@ -80,12 +81,11 @@ public class SendEmail implements ISendEmail {
@Override @Override
public void sendEmail() { public void sendEmail() {
if ( !Configuration.isEmailSendingDisabled() ){
notifications = emailNotificationModel.getAll(); notifications = emailNotificationModel.getAll();
for (int i = 0; i < notifications.size(); i++) composeMessageForUser(notifications.get(i));
for (int i = 0; i < notifications.size(); i++) composeMessageForUser(notifications.get(i)); deleteAllNotificationsAfterSending();
}
deleteAllNotificationsAfterSending();
} }
private void composeMessageForUser(EmailNotification notification){ private void composeMessageForUser(EmailNotification notification){

View file

@ -37,6 +37,7 @@
<default.passwordsControl>true</default.passwordsControl> <default.passwordsControl>true</default.passwordsControl>
<default.exampleUsersDisabled>true</default.exampleUsersDisabled> <default.exampleUsersDisabled>true</default.exampleUsersDisabled>
<default.emailSendingDisabled>false</default.emailSendingDisabled>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>