← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15542: minor changes to web-api filter

 

------------------------------------------------------------
revno: 15542
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-03 16:33:29 +0200
message:
  minor changes to web-api filter
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.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/filter/DefaultFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java	2014-06-03 07:51:25 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java	2014-06-03 14:33:29 +0000
@@ -50,9 +50,6 @@
  */
 public class DefaultFilterService implements FilterService
 {
-    private static final List<String> IDENTIFIABLE_PROPERTIES =
-        Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" );
-
     @Autowired
     private ParserService parserService;
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java	2014-06-02 22:47:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java	2014-06-03 14:33:29 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Lists;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.node.types.CollectionNode;
 
@@ -38,6 +39,9 @@
  */
 public interface FilterService
 {
+    static final List<String> IDENTIFIABLE_PROPERTIES =
+        Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" );
+
     /**
      * Filter a list of objects based on un-parsed filter string.
      *

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-03 09:33:52 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-03 14:33:29 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.base.Joiner;
 import com.google.common.collect.Lists;
 import org.hisp.dhis.acl.Access;
 import org.hisp.dhis.acl.AclService;
@@ -45,12 +46,10 @@
 import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException;
 import org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException;
 import org.hisp.dhis.importexport.ImportStrategy;
-import org.hisp.dhis.node.NodeHint;
 import org.hisp.dhis.node.NodeService;
 import org.hisp.dhis.node.types.ComplexNode;
 import org.hisp.dhis.node.types.RootNode;
 import org.hisp.dhis.node.types.SimpleNode;
-import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.hisp.dhis.user.CurrentUserService;
@@ -74,7 +73,6 @@
 import java.io.InputStream;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -83,6 +81,8 @@
  */
 public abstract class AbstractCrudController<T extends IdentifiableObject>
 {
+    private static final String DEFAULT_LIST_INCLUDE = Joiner.on( "," ).join( FilterService.IDENTIFIABLE_PROPERTIES );
+
     //--------------------------------------------------------------------------
     // Dependencies
     //--------------------------------------------------------------------------
@@ -132,14 +132,7 @@
 
         ReflectionUtils.invokeSetterMethod( schemaService.getSchema( getEntityClass() ).getPlural(), metaData, entityList );
 
-        if ( viewClass.equals( "basic" ) )
-        {
-            handleLinksAndAccess( options, metaData, entityList, false );
-        }
-        else
-        {
-            handleLinksAndAccess( options, metaData, entityList, true );
-        }
+        handleLinksAndAccess( options, metaData, entityList );
 
         model.addAttribute( "model", metaData );
         model.addAttribute( "viewClass", viewClass );
@@ -157,7 +150,10 @@
         WebOptions options = new WebOptions( parameters );
         WebMetaData metaData = new WebMetaData();
 
-        Schema schema = schemaService.getSchema( getEntityClass() );
+        if ( include == null && exclude == null )
+        {
+            include = DEFAULT_LIST_INCLUDE;
+        }
 
         boolean hasPaging = options.hasPaging();
 
@@ -200,40 +196,25 @@
             options.getOptions().put( "viewClass", "sharing" );
         }
 
-        if ( options.getViewClass( "basic" ).equals( "basic" ) )
-        {
-            handleLinksAndAccess( options, metaData, entityList, false );
-        }
-        else
-        {
-            handleLinksAndAccess( options, metaData, entityList, true );
-        }
-
-        // enable property filter
-        if ( include != null || exclude != null )
-        {
-            RootNode rootNode = new RootNode( "metadata" );
-
-            if ( hasPaging )
-            {
-                ComplexNode pagerNode = rootNode.addNode( new ComplexNode( "pager" ) );
-                pagerNode.addNode( new SimpleNode( "page", metaData.getPager().getPage() ) );
-                pagerNode.addNode( new SimpleNode( "pageCount", metaData.getPager().getPageCount() ) );
-                pagerNode.addNode( new SimpleNode( "total", metaData.getPager().getTotal() ) );
-                pagerNode.addNode( new SimpleNode( "nextPage", metaData.getPager().getNextPage() ) );
-                pagerNode.addNode( new SimpleNode( "prevPage", metaData.getPager().getPrevPage() ) );
-            }
-
-            rootNode.addNode( filterService.filterProperties( getEntityClass(), entityList, include, exclude ) );
-
-            // response.setContentType( MediaType.APPLICATION_XML_VALUE );
-            // nodeService.serialize( rootNode, MediaType.APPLICATION_XML_VALUE, response.getOutputStream() );
-            nodeService.serialize( rootNode, MediaType.APPLICATION_JSON_VALUE, response.getOutputStream() );
-        }
-        else
-        {
-            renderService.toJson( response.getOutputStream(), metaData, JacksonUtils.getViewClass( options.getViewClass( "basic" ) ) );
-        }
+        handleLinksAndAccess( options, metaData, entityList );
+
+        RootNode rootNode = new RootNode( "metadata" );
+
+        if ( hasPaging )
+        {
+            ComplexNode pagerNode = rootNode.addNode( new ComplexNode( "pager" ) );
+            pagerNode.addNode( new SimpleNode( "page", metaData.getPager().getPage() ) );
+            pagerNode.addNode( new SimpleNode( "pageCount", metaData.getPager().getPageCount() ) );
+            pagerNode.addNode( new SimpleNode( "total", metaData.getPager().getTotal() ) );
+            pagerNode.addNode( new SimpleNode( "nextPage", metaData.getPager().getNextPage() ) );
+            pagerNode.addNode( new SimpleNode( "prevPage", metaData.getPager().getPrevPage() ) );
+        }
+
+        rootNode.addNode( filterService.filterProperties( getEntityClass(), entityList, include, exclude ) );
+
+        // response.setContentType( MediaType.APPLICATION_XML_VALUE );
+        // nodeService.serialize( rootNode, MediaType.APPLICATION_XML_VALUE, response.getOutputStream() );
+        nodeService.serialize( rootNode, MediaType.APPLICATION_JSON_VALUE, response.getOutputStream() );
     }
 
 
@@ -458,7 +439,7 @@
         ((BaseIdentifiableObject) object).setAccess( access );
     }
 
-    protected void handleLinksAndAccess( WebOptions options, WebMetaData metaData, List<T> entityList, boolean deep )
+    protected void handleLinksAndAccess( WebOptions options, WebMetaData metaData, List<T> entityList )
     {
         if ( options != null && options.hasLinks() )
         {