dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34119
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17521: Notifications. Added system setting for system notifications email address. Impl feature for send...
------------------------------------------------------------
revno: 17521
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-11-18 13:55:20 +0100
message:
Notifications. Added system setting for system notifications email address. Impl feature for sending email to system email address, so far for failures during background processes such as analytics table generation.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DataMartTask.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java 2014-11-05 23:43:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java 2014-11-18 12:55:20 +0000
@@ -73,6 +73,8 @@
int sendMessage( String subject, String text, String metaData, Set<User> users, User sender, boolean includeFeedbackRecipients, boolean forceNotifications );
int sendFeedback( String subject, String text, String metaData );
+
+ int sendSystemNotification( String subject, String text );
void sendReply( MessageConversation conversation, String text, String metaData );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-10-25 12:07:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-11-18 12:55:20 +0000
@@ -103,6 +103,7 @@
final String KEY_LAST_SUCCESSFUL_RESOURCE_TABLES_UPDATE = "keyLastSuccessfulResourceTablesUpdate";
final String KEY_HELP_PAGE_LINK = "helpPageLink";
final String KEY_ACCEPTANCE_REQUIRED_FOR_APPROVAL = "keyAcceptanceRequiredForApproval";
+ final String KEY_SYSTEM_NOTIFICATIONS_EMAIL = "keySystemNotificationsEmail";
final String DEFAULT_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY = "lastMonth";
final String DEFAULT_FLAG = "dhis2";
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java 2014-08-25 16:24:21 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java 2014-11-18 12:55:20 +0000
@@ -39,6 +39,7 @@
import org.hisp.dhis.system.notification.NotificationLevel;
import org.hisp.dhis.system.notification.Notifier;
import org.hisp.dhis.system.util.Clock;
+import org.hisp.dhis.system.util.DebugUtils;
import org.springframework.beans.factory.annotation.Autowired;
/**
@@ -88,7 +89,11 @@
{
notifier.notify( taskId, NotificationLevel.ERROR, "Process failed: " + ex.getMessage(), true );
- messageService.sendFeedback( "Resource table process failed", "Resource table process failed, please check the logs.", null );
+ messageService.sendSystemNotification(
+ "Resource table process failed",
+ "Resource table process failed, please check the logs. " +
+ "Message: " + ex.getMessage() + " " +
+ "Cause: " + DebugUtils.getStackTrace( ex.getCause() ) );
throw ex;
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java 2014-08-25 16:24:21 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java 2014-11-18 12:55:20 +0000
@@ -157,12 +157,11 @@
{
notifier.notify( taskId, ERROR, "Process failed: " + ex.getMessage(), true );
- messageService.sendFeedback(
+ messageService.sendSystemNotification(
"Analytics table process failed",
"Analytics table process failed, please check the logs. " +
"Message: " + ex.getMessage() + " " +
- "Cause: " + DebugUtils.getStackTrace( ex.getCause() ),
- null );
+ "Cause: " + DebugUtils.getStackTrace( ex.getCause() ) );
throw ex;
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2014-11-05 23:43:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2014-11-18 12:55:20 +0000
@@ -33,18 +33,24 @@
import java.util.List;
import java.util.Set;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.configuration.ConfigurationService;
import org.hisp.dhis.dataset.CompleteDataSetRegistration;
import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.system.util.ValidationUtils;
import org.hisp.dhis.system.velocity.VelocityManager;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
+import com.google.common.collect.Sets;
+
/**
* @author Lars Helge Overland
*/
@@ -83,6 +89,20 @@
this.configurationService = configurationService;
}
+ private SystemSettingManager systemSettingManager;
+
+ public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+ {
+ this.systemSettingManager = systemSettingManager;
+ }
+
+ private MessageSender emailMessageSender;
+
+ public void setEmailMessageSender( MessageSender emailMessageSender )
+ {
+ this.emailMessageSender = emailMessageSender;
+ }
+
private List<MessageSender> messageSenders;
@Autowired
@@ -166,6 +186,37 @@
{
return sendMessage( subject, text, metaData, new HashSet<User>(), null, true, false );
}
+
+ @Override
+ public int sendSystemNotification( String subject, String text )
+ {
+ String email = (String) systemSettingManager.getSystemSetting( SystemSettingManager.KEY_SYSTEM_NOTIFICATIONS_EMAIL );
+ String appTitle = (String) systemSettingManager.getSystemSetting( SystemSettingManager.KEY_APPLICATION_TITLE );
+
+ // ---------------------------------------------------------------------
+ // Send email to system notification email address
+ // ---------------------------------------------------------------------
+
+ if ( email != null && ValidationUtils.emailIsValid( email ) )
+ {
+ User user = new User();
+ UserCredentials credentials = new UserCredentials();
+ credentials.setUsername( email );
+ user.setEmail( email );
+
+ User sender = new User();
+ sender.setFirstName( StringUtils.trimToEmpty( appTitle ) );
+ sender.setSurname( email );
+
+ emailMessageSender.sendMessage( subject, text, sender, Sets.newHashSet( user ), true );
+ }
+
+ // ---------------------------------------------------------------------
+ // Send feedback
+ // ---------------------------------------------------------------------
+
+ return sendFeedback( subject, text, null );
+ }
@Override
public void sendReply( MessageConversation conversation, String text, String metaData )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java 2014-11-08 23:03:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java 2014-11-18 12:55:20 +0000
@@ -110,7 +110,7 @@
text = sender == null ? text : ( text + LB + LB +
sender.getName() + LB +
- sender.getOrganisationUnitsName() + LB +
+ ( sender.getOrganisationUnitsName() != null ? ( sender.getOrganisationUnitsName() + LB ) : StringUtils.EMPTY ) +
( sender.getEmail() != null ? ( sender.getEmail() + LB ) : StringUtils.EMPTY ) +
( sender.getPhoneNumber() != null ? ( sender.getPhoneNumber() + LB ) : StringUtils.EMPTY ) );
@@ -119,15 +119,13 @@
Email email = getEmail( hostName, port, username, password, tls, from );
email.setSubject( customizeTitle( DEFAULT_SUBJECT_PREFIX ) + subject );
email.setMsg( text );
-
+
boolean hasRecipients = false;
for ( User user : users )
{
- boolean emailNotification = (Boolean) userService.getUserSettingValue( user, KEY_MESSAGE_EMAIL_NOTIFICATION, false );
+ boolean doSend = forceSend || (Boolean) userService.getUserSettingValue( user, KEY_MESSAGE_EMAIL_NOTIFICATION, false );
- boolean doSend = forceSend || emailNotification;
-
if ( doSend && user.getEmail() != null && !user.getEmail().trim().isEmpty() )
{
email.addBcc( user.getEmail() );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-11-10 10:28:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-11-18 12:55:20 +0000
@@ -629,6 +629,8 @@
<property name="messageConversationStore" ref="org.hisp.dhis.message.MessageConversationStore" />
<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
<property name="configurationService" ref="org.hisp.dhis.configuration.ConfigurationService" />
+ <property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
+ <property name="emailMessageSender" ref="emailMessageSender" />
</bean>
<bean id="emailMessageSender" class="org.hisp.dhis.message.EmailMessageSender">
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DataMartTask.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DataMartTask.java 2014-07-11 19:12:01 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DataMartTask.java 2014-11-18 12:55:20 +0000
@@ -47,6 +47,7 @@
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.system.notification.Notifier;
import org.hisp.dhis.system.util.ConversionUtils;
+import org.hisp.dhis.system.util.DebugUtils;
import org.springframework.beans.factory.annotation.Autowired;
/**
@@ -114,7 +115,11 @@
{
notifier.notify( taskId, ERROR, "Process failed: " + ex.getMessage(), true );
- messageService.sendFeedback( "Data mart process failed", "Data mart process failed, please check the logs.", null );
+ messageService.sendSystemNotification(
+ "Data mart process failed",
+ "Data mart process failed, please check the logs. " +
+ "Message: " + ex.getMessage() + " " +
+ "Cause: " + DebugUtils.getStackTrace( ex.getCause() ) );
throw ex;
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java 2014-10-25 12:07:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java 2014-11-18 12:55:20 +0000
@@ -126,7 +126,8 @@
map.put( KEY_DATABASE_SERVER_CPUS, systemSettingManager.getSystemSetting( KEY_DATABASE_SERVER_CPUS, DEFAULT_DATABASE_SERVER_CPUS ) );
map.put( KEY_HELP_PAGE_LINK, systemSettingManager.getSystemSetting( KEY_HELP_PAGE_LINK, DEFAULT_HELP_PAGE_LINK ) );
map.put( KEY_HIDE_UNAPPROVED_DATA_IN_ANALYTICS, systemSettingManager.getSystemSetting( KEY_HIDE_UNAPPROVED_DATA_IN_ANALYTICS, false ) );
- map.put( KEY_ACCEPTANCE_REQUIRED_FOR_APPROVAL, systemSettingManager.getSystemSetting( KEY_ACCEPTANCE_REQUIRED_FOR_APPROVAL, false ) );
+ map.put( KEY_ACCEPTANCE_REQUIRED_FOR_APPROVAL, systemSettingManager.getSystemSetting( KEY_ACCEPTANCE_REQUIRED_FOR_APPROVAL, false ) );
+ map.put( KEY_SYSTEM_NOTIFICATIONS_EMAIL, systemSettingManager.getSystemSetting( KEY_SYSTEM_NOTIFICATIONS_EMAIL ) );
map.put( SYSPROP_PORTAL, defaultIfEmpty( System.getProperty( SYSPROP_PORTAL ), String.valueOf( false ) ) );
invocation.getStack().push( map );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java 2014-11-14 11:34:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java 2014-11-18 12:55:20 +0000
@@ -38,6 +38,7 @@
import static org.hisp.dhis.setting.SystemSettingManager.KEY_MULTI_ORGANISATION_UNIT_FORMS;
import static org.hisp.dhis.setting.SystemSettingManager.KEY_OMIT_INDICATORS_ZERO_NUMERATOR_DATAMART;
import static org.hisp.dhis.setting.SystemSettingManager.KEY_PHONE_NUMBER_AREA_CODE;
+import static org.hisp.dhis.setting.SystemSettingManager.KEY_SYSTEM_NOTIFICATIONS_EMAIL;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.configuration.Configuration;
@@ -170,6 +171,13 @@
{
this.offlineOrganisationUnitLevel = offlineOrganisationUnitLevel;
}
+
+ private String systemNotificationsEmail;
+
+ public void setSystemNotificationsEmail( String systemNotificationsEmail )
+ {
+ this.systemNotificationsEmail = systemNotificationsEmail;
+ }
private String phoneNumberAreaCode;
@@ -237,6 +245,7 @@
systemSettingManager.saveSystemSetting( KEY_GOOGLE_ANALYTICS_UA, googleAnalyticsUA );
systemSettingManager.saveSystemSetting( KEY_ANALYTICS_MAINTENANCE_MODE, analyticsMaintenanceMode );
systemSettingManager.saveSystemSetting( KEY_HELP_PAGE_LINK, StringUtils.trimToNull( helpPageLink ) );
+ systemSettingManager.saveSystemSetting( KEY_SYSTEM_NOTIFICATIONS_EMAIL, systemNotificationsEmail );
Configuration configuration = configurationService.getConfiguration();
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2014-10-25 12:30:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2014-11-18 12:55:20 +0000
@@ -122,4 +122,5 @@
automatic=Automatic
detect_based_on_web_server=detect based on web server
help_page_link = Help page link
-acceptance_required_before_approval=Acceptance required before approval
\ No newline at end of file
+acceptance_required_before_approval=Acceptance required before approval
+system_notifications_email_address=System notifications email address
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm 2014-10-07 12:05:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm 2014-11-18 12:55:20 +0000
@@ -9,6 +9,7 @@
infrastructuralPeriodType: getFieldValue('infrastructuralPeriodType'),
feedbackRecipients: getFieldValue('feedbackRecipients'),
offlineOrganisationUnitLevel: getFieldValue('offlineOrganisationUnitLevel'),
+ systemNotificationsEmail: getFieldValue('systemNotificationsEmail'),
omitIndicatorsZeroNumeratorDataMart: jQuery('#omitIndicatorsZeroNumeratorDataMart').is(':checked'),
factorDeviation: getFieldValue('factorDeviation'),
phoneNumberAreaCode: getFieldValue('phoneNumberAreaCode'),
@@ -110,6 +111,11 @@
</select>
</div>
+<div class="settingLabel">$i18n.getString( "system_notifications_email_address" )</div>
+<div class="setting">
+ <input type="text" id="systemNotificationsEmail" name="systemNotificationsEmail" value="$!keySystemNotificationsEmail"/>
+</div>
+
<div class="settingLabel">$i18n.getString( "data_analysis_factor" )</div>
<div class="setting">
<input type="text" id="factorDeviation" name="factorDeviation" value="$!factorDeviation"/>