← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7301: Made message conversatio controller more robust

 

------------------------------------------------------------
revno: 7301
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-06-14 20:00:34 +0200
message:
  Made message conversatio controller more robust
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java


--
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/api/controller/MessageConversationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java	2012-05-31 17:02:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java	2012-06-14 18:00:34 +0000
@@ -104,9 +104,16 @@
         List<User> users = new ArrayList<User>( message.getUsers() );
         message.getUsers().clear();
 
-        for ( User user : users )
+        for ( User u : users )
         {
-            user = userService.getUser( user.getUid() );
+            User user  = userService.getUser( u.getUid() );
+            
+            if ( user == null )
+            {
+                ContextUtils.conflictResponse( response, "User does not exist: " + u.getUid() );
+                return;
+            }
+            
             message.getUsers().add( user );
         }
 
@@ -130,8 +137,16 @@
         String metaData = MessageService.META_USER_AGENT + request.getHeader( ContextUtils.HEADER_USER_AGENT );
 
         MessageConversation messageConversation = messageService.getMessageConversation( uid );
-
-        messageService.sendReply( messageConversation, body, metaData );
+        
+        if ( messageConversation == null )
+        {
+            ContextUtils.conflictResponse( response, "Message conversation does not exist: " + uid );
+            return;
+        }
+
+        messageService.sendReply( messageConversation, body, metaData );        
+
+        response.setStatus( HttpServletResponse.SC_CREATED );
     }
 
     //--------------------------------------------------------------------------
@@ -145,5 +160,7 @@
         String metaData = MessageService.META_USER_AGENT + request.getHeader( ContextUtils.HEADER_USER_AGENT );
 
         messageService.sendFeedback( subject, body, metaData );
+        
+        response.setStatus( HttpServletResponse.SC_CREATED );
     }
 }