← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12007: Web API: Made the hooks in AbstractCrudController a bit more flexible by providing the WebOptions...

 

------------------------------------------------------------
revno: 12007
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-09-10 13:03:08 +0200
message:
  Web API: Made the hooks in AbstractCrudController a bit more flexible by providing the WebOptions object. DashboardController: Nulling the links to the dashboard items themselves as they are not relevant. Setting links on the item objects.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.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/DashboardController.java
  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/organisationunit/OrganisationUnitController.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-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2013-09-09 18:40:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2013-09-10 11:03:08 +0000
@@ -49,6 +49,9 @@
 import java.util.List;
 
 /**
+ * Represents an item in the dashboard. An item can represent an embedded object
+ * or represent links to other objects.
+ * 
  * @author Lars Helge Overland
  */
 @JacksonXmlRootElement( localName = "dashboardItem", namespace = DxfNamespaces.DXF_2_0 )
@@ -136,6 +139,59 @@
         {
             return TYPE_PATIENT_TABULAR_REPORTS;
         }
+        
+        return null;
+    }
+    
+    /**
+     * Returns the actual item object if this dashboard item represents an 
+     * embedded item and not links to items.
+     */
+    public IdentifiableObject getEmbeddedItem()
+    {
+        if ( chart != null )
+        {
+            return chart;
+        }
+        else if ( map != null )
+        {
+            return map;
+        }
+        else if ( reportTable != null )
+        {
+            return reportTable;
+        }
+        
+        return null;
+    }
+    
+    /**
+     * Returns a list of the actual item objects if this dashboard item 
+     * represents a list of objects and not an embedded item.
+     */
+    public List<? extends IdentifiableObject> getLinkItems()
+    {
+        if ( !users.isEmpty() )
+        {
+            return users;
+        }
+        else if ( !reportTables.isEmpty() )
+        {
+            return reportTables;
+        }
+        else if ( !reports.isEmpty() )
+        {
+            return reports;
+        }
+        else if ( !resources.isEmpty() )
+        {
+            return resources;
+        }
+        else if ( !patientTabularReports.isEmpty() )
+        {
+            return patientTabularReports;
+        }
+        
         return null;
     }
 
@@ -314,7 +370,6 @@
     // Merge with
     // -------------------------------------------------------------------------
 
-
     @Override
     public void mergeWith( IdentifiableObject other )
     {

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2013-09-10 09:00:47 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2013-09-10 11:03:08 +0000
@@ -28,7 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.EOFException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;

=== 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	2013-08-27 11:53:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2013-09-10 11:03:08 +0000
@@ -93,7 +93,7 @@
         handleLinksAndAccess( options, metaData, entityList );
 
         postProcessEntities( entityList );
-        postProcessEntities( entityList, parameters );
+        postProcessEntities( entityList, options, parameters );
 
         model.addAttribute( "model", metaData );
         model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
@@ -113,7 +113,7 @@
         handleLinksAndAccess( options, metaData, entityList );
 
         postProcessEntities( entityList );
-        postProcessEntities( entityList, parameters );
+        postProcessEntities( entityList, options, parameters );
 
         model.addAttribute( "model", metaData );
         model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
@@ -144,7 +144,7 @@
         }
 
         postProcessEntity( entity );
-        postProcessEntity( entity, parameters );
+        postProcessEntity( entity, options, parameters );
 
         model.addAttribute( "model", entity );
         model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
@@ -170,7 +170,7 @@
         }
 
         postProcessEntity( entity );
-        postProcessEntity( entity, parameters );
+        postProcessEntity( entity, options, parameters );
 
         model.addAttribute( "model", entity );
         model.addAttribute( "viewClass", "detailed" );
@@ -232,7 +232,7 @@
      * Override to process entities after it has been retrieved from
      * storage and before it is returned to the view. Entities is null-safe.
      */
-    protected void postProcessEntities( List<T> entityList, Map<String, String> parameters )
+    protected void postProcessEntities( List<T> entityList, WebOptions options, Map<String, String> parameters )
     {
 
     }
@@ -258,7 +258,7 @@
      * Override to process a single entity after it has been retrieved from
      * storage and before it is returned to the view. Entity is null-safe.
      */
-    protected void postProcessEntity( T entity, Map<String, String> parameters ) throws Exception
+    protected void postProcessEntity( T entity, WebOptions options, Map<String, String> parameters ) throws Exception
     {
     }
 
@@ -348,7 +348,7 @@
             }
         }
     }
-
+    
     //--------------------------------------------------------------------------
     // Reflection helpers
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java	2013-09-04 15:50:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java	2013-09-10 11:03:08 +0000
@@ -29,12 +29,15 @@
  */
 
 import java.io.InputStream;
+import java.util.Map;
 import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.api.utils.WebUtils;
+import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dashboard.Dashboard;
 import org.hisp.dhis.dashboard.DashboardItem;
 import org.hisp.dhis.dashboard.DashboardSearchResult;
@@ -224,4 +227,32 @@
             ContextUtils.okResponse( response, "Dashboard item content removed" );
         }        
     }
+
+    // -------------------------------------------------------------------------
+    // Hooks
+    // -------------------------------------------------------------------------
+
+    @Override
+    protected void postProcessEntity( Dashboard entity, WebOptions options, Map<String, String> parameters ) throws Exception
+    {
+        for ( DashboardItem item : entity.getItems() )
+        {
+            if ( item != null )
+            {                
+                item.setHref( null ); // Null item link, not relevant
+            
+                if ( item.getEmbeddedItem() != null )
+                {
+                    WebUtils.generateLinks( item.getEmbeddedItem() );
+                }
+                else if ( item.getLinkItems() != null )
+                {
+                    for ( IdentifiableObject link : item.getLinkItems() )
+                    {
+                        WebUtils.generateLinks( link );
+                    }
+                }
+            }
+        }
+    }
 }

=== 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	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java	2013-09-10 11:03:08 +0000
@@ -76,7 +76,7 @@
     private CurrentUserService currentUserService;
 
     @Override
-    public void postProcessEntity( MessageConversation entity, Map<String, String> parameters ) throws Exception
+    public void postProcessEntity( MessageConversation entity, WebOptions options, Map<String, String> parameters ) throws Exception
     {
         Boolean markRead = Boolean.parseBoolean( parameters.get( "markRead" ) );
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitController.java	2013-09-04 07:20:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/organisationunit/OrganisationUnitController.java	2013-09-10 11:03:08 +0000
@@ -206,7 +206,7 @@
         }
 
         postProcessEntity( entity );
-        postProcessEntity( entity, parameters );
+        postProcessEntity( entity, options, parameters );
 
         model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );