← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14410: minor fixes to crudController, renderService

 

------------------------------------------------------------
revno: 14410
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-03-25 16:38:36 +0100
message:
  minor fixes to crudController, renderService
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/RenderService.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/user/UserController.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java	2014-03-25 13:20:56 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java	2014-03-25 15:38:36 +0000
@@ -53,6 +53,32 @@
         configureObjectMapper();
     }
 
+    //--------------------------------------------------------------------------
+    // RenderService
+    //--------------------------------------------------------------------------
+
+    @Override
+    public <T> void toJson( OutputStream output, T value ) throws IOException
+    {
+        jsonMapper.writeValue( output, value );
+    }
+
+    @Override
+    public <T> void toJson( OutputStream output, T value, Class<?> klass ) throws IOException
+    {
+        jsonMapper.writerWithView( klass ).writeValue( output, value );
+    }
+
+    @Override
+    public <T> T fromJson( InputStream input, Class<T> klass ) throws IOException
+    {
+        return jsonMapper.readValue( input, klass );
+    }
+
+    //--------------------------------------------------------------------------
+    // Helpers
+    //--------------------------------------------------------------------------
+
     private void configureObjectMapper()
     {
         jsonMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );
@@ -73,17 +99,4 @@
 
         jsonMapper.getJsonFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES );
     }
-
-    @Override
-    public void toJson( OutputStream output, Object value ) throws IOException
-    {
-        jsonMapper.writeValue( output, value );
-    }
-
-    @Override
-    @SuppressWarnings( "unchecked" )
-    public <T> T fromJson( InputStream input, Class<?> clazz ) throws IOException
-    {
-        return (T) jsonMapper.readValue( input, clazz );
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/RenderService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/RenderService.java	2014-03-25 13:20:56 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/RenderService.java	2014-03-25 15:38:36 +0000
@@ -28,8 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.fasterxml.jackson.core.JsonParseException;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -39,7 +37,9 @@
  */
 public interface RenderService
 {
-    void toJson( OutputStream output, Object value ) throws IOException;
-
-    <T> T fromJson( InputStream input, Class<?> clazz ) throws IOException;
+    <T> void toJson( OutputStream output, T value ) throws IOException;
+
+    <T> void toJson( OutputStream output, T value, Class<?> klass ) throws IOException;
+
+    <T> T fromJson( InputStream input, Class<T> klass ) throws IOException;
 }

=== 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	2014-03-25 13:20:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2014-03-25 15:38:36 +0000
@@ -29,7 +29,6 @@
  */
 
 import com.google.common.collect.Maps;
-import org.hisp.dhis.api.controller.exception.NotFoundException;
 import org.hisp.dhis.api.utils.WebUtils;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObject;
@@ -48,6 +47,7 @@
 import org.hisp.dhis.user.CurrentUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
 import org.springframework.ui.Model;
 import org.springframework.util.StringUtils;
 import org.springframework.web.HttpRequestMethodNotSupportedException;
@@ -99,7 +99,36 @@
     //--------------------------------------------------------------------------
 
     @RequestMapping( method = RequestMethod.GET )
-    public String getObjectList(
+    public String getObjectListHtml(
+        @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request )
+    {
+        WebOptions options = new WebOptions( parameters );
+        WebMetaData metaData = new WebMetaData();
+        List<T> entityList = getEntityList( metaData, options );
+        String viewClass = options.getViewClass( "basic" );
+
+        postProcessEntities( entityList );
+        postProcessEntities( entityList, options, parameters );
+
+        ReflectionUtils.invokeSetterMethod( ExchangeClasses.getAllExportMap().get( getEntityClass() ), metaData, entityList );
+
+        if ( viewClass.equals( "basic" ) )
+        {
+            handleLinksAndAccess( options, metaData, entityList, false );
+        }
+        else
+        {
+            handleLinksAndAccess( options, metaData, entityList, true );
+        }
+
+        model.addAttribute( "model", metaData );
+        model.addAttribute( "viewClass", viewClass );
+
+        return StringUtils.uncapitalize( getEntitySimpleName() ) + "List";
+    }
+
+    @RequestMapping( method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE } )
+    public void getObjectListJson(
         @RequestParam( required = false ) String include,
         @RequestParam( required = false ) String exclude,
         @RequestParam( value = "filter", required = false ) List<String> filters,
@@ -139,15 +168,6 @@
             }
         }
 
-        if ( options.getViewClass( "basic" ).equals( "basic" ) )
-        {
-            handleLinksAndAccess( options, metaData, entityList, false );
-        }
-        else
-        {
-            handleLinksAndAccess( options, metaData, entityList, true );
-        }
-
         postProcessEntities( entityList );
         postProcessEntities( entityList, options, parameters );
 
@@ -177,42 +197,19 @@
         {
             ReflectionUtils.invokeSetterMethod( ExchangeClasses.getAllExportMap().get( getEntityClass() ), metaData, entityList );
 
-            model.addAttribute( "model", metaData );
-            model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
-        }
-
-        return StringUtils.uncapitalize( getEntitySimpleName() ) + "List";
-    }
-
-    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
-    public String getObject( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
-        Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
-    {
-        WebOptions options = new WebOptions( parameters );
-        T entity = getEntity( uid );
-
-        if ( entity == null )
-        {
-            throw new NotFoundException( uid );
-        }
-
-        if ( options.hasLinks() )
-        {
-            WebUtils.generateLinks( entity );
-        }
-
-        if ( sharingService.isSupported( getEntityClass() ) )
-        {
-            addAccessProperties( entity );
-        }
-
-        postProcessEntity( entity );
-        postProcessEntity( entity, options, parameters );
-
-        model.addAttribute( "model", entity );
-        model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
-
-        return StringUtils.uncapitalize( getEntitySimpleName() );
+            String viewClass = options.getViewClass( "basic" );
+
+            if ( viewClass.equals( "basic" ) )
+            {
+                handleLinksAndAccess( options, metaData, entityList, false );
+            }
+            else
+            {
+                handleLinksAndAccess( options, metaData, entityList, true );
+            }
+
+            renderService.toJson( response.getOutputStream(), metaData, JacksonUtils.getViewClass( viewClass ) );
+        }
     }
 
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java	2014-03-25 11:29:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java	2014-03-25 15:38:36 +0000
@@ -41,6 +41,7 @@
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -65,13 +66,13 @@
 
     @Override
     @PreAuthorize( "hasRole('ALL') or hasRole('F_USER_VIEW')" )
-    public String getObjectList(
+    public void getObjectList(
         @RequestParam( required = false ) String include,
         @RequestParam( required = false ) String exclude,
         @RequestParam( value = "filter", required = false ) List<String> filters,
-        @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request ) throws IOException
+        @RequestParam Map<String, String> parameters, ModelAndView modelAndView, HttpServletResponse response, HttpServletRequest request ) throws IOException
     {
-        return super.getObjectList( include, exclude, filters, parameters, model, response, request );
+        super.getObjectList( include, exclude, filters, parameters, modelAndView, response, request );
     }
 
     @Override