← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7105: converted MessageConversationController to use AbstractCrudController

 

------------------------------------------------------------
revno: 7105
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-05-30 12:54:11 +0200
message:
  converted MessageConversationController to use AbstractCrudController
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java
  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-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java	2012-05-28 18:21:41 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java	2012-05-30 10:54:11 +0000
@@ -45,6 +45,7 @@
 import org.hisp.dhis.mapping.MapLegend;
 import org.hisp.dhis.mapping.MapLegendSet;
 import org.hisp.dhis.mapping.MapView;
+import org.hisp.dhis.message.MessageConversation;
 import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
@@ -121,9 +122,9 @@
         exportClasses.put( UserGroup.class, "userGroups" );
         exportClasses.put( UserAuthorityGroup.class, "userRoles" );
 
+        exportClasses.put( MessageConversation.class, "messageConversations" );
+
         importClasses = exportClasses;
-
-        // exportClasses.put( "messageConversations", MessageConversation.class );
     }
 
     public static Map<Class<? extends IdentifiableObject>, String> getExportMap()

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2012-05-29 17:21:17 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2012-05-30 10:54:11 +0000
@@ -108,7 +108,7 @@
     //-------------------------------------------------------------------------------------------------------
 
     @RequestMapping( method = RequestMethod.POST, headers = { "Content-Type=application/xml, text/xml" } )
-    public void postXmlObject( HttpServletResponse response, InputStream input ) throws Exception
+    public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
     {
         throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
     }

=== 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-27 21:50:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java	2012-05-30 10:54:11 +0000
@@ -28,27 +28,23 @@
  */
 
 import org.hisp.dhis.api.utils.ContextUtils;
-import org.hisp.dhis.api.utils.IdentifiableObjectParams;
-import org.hisp.dhis.api.utils.WebLinkPopulator;
+import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.dxf2.message.Message;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
-import org.hisp.dhis.dxf2.message.Message;
-import org.hisp.dhis.common.Pager;
 import org.hisp.dhis.message.MessageConversation;
-import org.hisp.dhis.message.MessageConversations;
 import org.hisp.dhis.message.MessageService;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -57,6 +53,7 @@
 @Controller
 @RequestMapping( value = MessageConversationController.RESOURCE_PATH )
 public class MessageConversationController
+    extends AbstractCrudController<MessageConversation>
 {
     public static final String RESOURCE_PATH = "/messageConversations";
 
@@ -66,67 +63,41 @@
     @Autowired
     private UserService userService;
 
-    //-------------------------------------------------------------------------------------------------------
-    // GET
-    //-------------------------------------------------------------------------------------------------------
-
-    @RequestMapping( method = RequestMethod.GET )
-    public String getMessageConversations( IdentifiableObjectParams params, Model model, HttpServletRequest request )
+    @Override
+    protected List<MessageConversation> getEntityList( WebMetaData metaData, WebOptions options )
     {
-        MessageConversations messageConversations = new MessageConversations();
-
-        if ( params.isPaging() )
-        {
-            int total = messageService.getMessageConversationCount();
-
-            Pager pager = new Pager( params.getPage(), total );
-            messageConversations.setPager( pager );
-
-            List<MessageConversation> list = new ArrayList<MessageConversation>(
-                messageService.getMessageConversations( pager.getOffset(), pager.getPageSize() ) );
-
-            messageConversations.setMessageConversations( list );
+        List<MessageConversation> entityList;
+
+        Date lastUpdated = options.getLastUpdated();
+
+        if ( lastUpdated != null )
+        {
+            entityList = new ArrayList<MessageConversation>( manager.getByLastUpdated( getEntityClass(), lastUpdated ) );
+        }
+        else if ( options.hasPaging() )
+        {
+            int count = manager.getCount( getEntityClass() );
+
+            Pager pager = new Pager( options.getPage(), count );
+            metaData.setPager( pager );
+
+            entityList = new ArrayList<MessageConversation>( messageService.getMessageConversations( pager.getOffset(), pager.getPageSize() ) );
         }
         else
         {
-            messageConversations.setMessageConversations( new ArrayList<MessageConversation>( messageService.getMessageConversations( 0, 1000 ) ) );
-        }
-
-        if ( params.hasLinks() )
-        {
-            WebLinkPopulator listener = new WebLinkPopulator( request );
-            listener.addLinks( messageConversations );
-        }
-
-        model.addAttribute( "model", messageConversations );
-
-        return "messages";
-    }
-
-    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
-    public String getMessageConversation( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request )
-    {
-        MessageConversation messageConversation = messageService.getMessageConversation( uid );
-
-        if ( params.hasLinks() )
-        {
-            WebLinkPopulator listener = new WebLinkPopulator( request );
-            listener.addLinks( messageConversation );
-        }
-
-        model.addAttribute( "model", messageConversation );
-        model.addAttribute( "viewClass", "detailed" );
-
-        return "message";
+            entityList = new ArrayList<MessageConversation>( manager.getAll( getEntityClass() ) );
+        }
+
+        return entityList;
     }
 
     //-------------------------------------------------------------------------------------------------------
     // POST for new MessageConversation
     //-------------------------------------------------------------------------------------------------------
 
-    @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} )
+    @Override
     @PreAuthorize( "hasRole('ALL') or hasRole('F_SEND_MESSAGE')" )
-    public void postMessageConversationXML( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws IOException
+    public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
     {
         Message message = JacksonUtils.fromXml( input, Message.class );
 
@@ -148,19 +119,13 @@
         response.setHeader( "Location", MessageConversationController.RESOURCE_PATH + "/" + m.getUid() );
     }
 
-    @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} )
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_SEND_MESSAGE')" )
-    public void postMessageConversationJSON( HttpServletResponse response, InputStream input ) throws Exception
-    {
-    }
-
     //-------------------------------------------------------------------------------------------------------
     // POST for reply on existing MessageConversation
     //-------------------------------------------------------------------------------------------------------
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.POST )
     public void postMessageConversationReply( @PathVariable( "uid" ) String uid, @RequestBody String body,
-                                              HttpServletRequest request, HttpServletResponse response ) throws Exception
+        HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
         String metaData = MessageService.META_USER_AGENT + request.getHeader( ContextUtils.HEADER_USER_AGENT );
 
@@ -175,7 +140,7 @@
 
     @RequestMapping( value = "/feedback", method = RequestMethod.POST )
     public void postMessageConversationFeedback( @RequestParam( "subject" ) String subject, @RequestBody String body,
-                                                 HttpServletRequest request, HttpServletResponse response ) throws Exception
+        HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
         String metaData = MessageService.META_USER_AGENT + request.getHeader( ContextUtils.HEADER_USER_AGENT );