← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19604: Use WebMessage in EmailController

 

------------------------------------------------------------
revno: 19604
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-07-10 09:31:20 +0700
message:
  Use WebMessage in EmailController
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EmailController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemEmailSettings.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EmailController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EmailController.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EmailController.java	2015-07-10 02:31:20 +0000
@@ -28,19 +28,22 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import javax.servlet.http.HttpServletResponse;
-
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
 import org.hisp.dhis.email.Email;
 import org.hisp.dhis.email.EmailService;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.service.WebMessageService;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * @author Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
  */
@@ -59,12 +62,15 @@
 
     @Autowired
     private CurrentUserService currentUserService;
-    
+
     @Autowired
     private SystemSettingManager systemSettingManager;
 
+    @Autowired
+    private WebMessageService webMessageService;
+
     @RequestMapping( value = "/test", method = RequestMethod.POST )
-    public void sendTestEmail( HttpServletResponse response )
+    public void sendTestEmail( HttpServletResponse response, HttpServletRequest request ) throws WebMessageException
     {
         String userEmail = currentUserService.getCurrentUser().getEmail();
         boolean smtpConfigured = emailService.emailEnabled();
@@ -72,41 +78,37 @@
 
         if ( !smtpConfigured )
         {
-            ContextUtils.conflictResponse( response, "Could not send test email, SMTP server not configured" );
-            return;
+            throw new WebMessageException( WebMessageUtils.conflict( "Could not send test email, SMTP server not configured" ) );
         }
-        
+
         if ( !userEmailConfigured )
         {
-            ContextUtils.conflictResponse( response, "Could not send test email, no email configured for current user" );
-            return;
+            throw new WebMessageException( WebMessageUtils.conflict( "Could not send test email, no email configured for current user" ) );
         }
-        
+
         emailService.sendTestEmail();
 
-        ContextUtils.okResponse( response, "Test email was sent to " + userEmail );
+        webMessageService.send( WebMessageUtils.ok( "Test email was sent to " + userEmail ), response, request );
     }
-    
+
     @RequestMapping( value = "/notification", method = RequestMethod.POST )
-    public void sendSystemNotificationEmail( @RequestBody Email email, HttpServletResponse response )
+    public void sendSystemNotificationEmail( @RequestBody Email email, HttpServletResponse response, HttpServletRequest request ) throws WebMessageException
     {
         boolean smtpConfigured = emailService.emailEnabled();
         boolean systemNotificationEmailValid = systemSettingManager.systemNotificationEmailValid();
 
         if ( !smtpConfigured )
         {
-            ContextUtils.conflictResponse( response, "Could not send email, SMTP server not configured" );
-            return;
+            throw new WebMessageException( WebMessageUtils.conflict( "Could not send email, SMTP server not configured" ) );
         }
-        
+
         if ( !systemNotificationEmailValid )
         {
-            ContextUtils.conflictResponse( response, "Could not send email, system notification email address not set or not valid" );
-            return;
+            throw new WebMessageException( WebMessageUtils.conflict( "Could not send email, system notification email address not set or not valid" ) );
         }
-        
+
         emailService.sendSystemEmail( email );
-        
-        ContextUtils.okResponse( response, "System notification email sent" );
+
+        webMessageService.send( WebMessageUtils.ok( "System notification email sent" ), response, request );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemEmailSettings.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemEmailSettings.vm	2014-06-20 15:48:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemEmailSettings.vm	2015-07-10 02:31:20 +0000
@@ -26,7 +26,8 @@
           		setHeaderDelayMessage ( xhr.responseText )
           	},
           	error: function( xhr, status, error ) {
-          		setHeaderDelayMessage( xhr.responseText );
+							var errorText = JSON.parse( xhr.responseText );
+          		setHeaderDelayMessage( errorText );
           	}
         });
     });