← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11485: Impl POST of dashboards in web api

 

------------------------------------------------------------
revno: 11485
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-07-23 09:51:07 +0200
message:
  Impl POST of dashboards in web api
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.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/Dashboard.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java	2013-07-22 21:08:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java	2013-07-23 07:51:07 +0000
@@ -31,7 +31,14 @@
 import java.util.List;
 
 import org.hisp.dhis.common.BaseIdentifiableObject;
-
+import org.hisp.dhis.common.DxfNamespaces;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+@JacksonXmlRootElement( localName = "dashboardItem", namespace = DxfNamespaces.DXF_2_0)
 public class Dashboard
     extends BaseIdentifiableObject
 {
@@ -54,6 +61,9 @@
     // Getters and setters
     // -------------------------------------------------------------------------
 
+    @JsonProperty( value = "items" )
+    @JacksonXmlElementWrapper( localName = "items", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( localName = "item", namespace = DxfNamespaces.DXF_2_0)
     public List<DashboardItem> getItems()
     {
         return items;

=== 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-07-22 21:08:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2013-07-23 07:51:07 +0000
@@ -43,7 +43,9 @@
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 
+@JacksonXmlRootElement( localName = "dashboardItem", namespace = DxfNamespaces.DXF_2_0)
 public class DashboardItem
     extends BaseIdentifiableObject
 {

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2013-07-22 21:08:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2013-07-23 07:51:07 +0000
@@ -41,6 +41,8 @@
 
     DashboardSearchResult search( String query );
     
+    void mergeDashboard( Dashboard dashboard );
+    
     int saveDashboard( Dashboard dashboard );
     
     void updateDashboard( Dashboard dashboard );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java	2013-02-12 15:06:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java	2013-07-23 07:51:07 +0000
@@ -91,5 +91,6 @@
     int getDocumentCount();
 
     int getDocumentCountByName( String name );
-
+    
+    List<Document> getDocumentsByUid( List<String> uids );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java	2013-07-04 09:08:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java	2013-07-23 07:51:07 +0000
@@ -27,14 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.List;
+
 import net.sf.jasperreports.engine.JasperPrint;
+
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.period.Period;
 
-import java.io.OutputStream;
-import java.util.Collection;
-import java.util.List;
-
 /**
  * @author Lars Helge Overland
  */
@@ -164,4 +165,12 @@
      * @return a Collection of Reports.
      */
     Collection<Report> getReports( final Collection<Integer> identifiers );
+
+    /**
+     * Retrieves Reports with the given uids.
+     * 
+     * @param uids the list of uids.
+     * @return a list of ReportTables.
+     */
+    List<Report> getReportsByUid( List<String> uids );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2013-05-20 06:10:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2013-07-23 07:51:07 +0000
@@ -105,6 +105,14 @@
      * @return a Collection of ReportTables.
      */
     Collection<ReportTable> getReportTables( Collection<Integer> reportTables );
+    
+    /**
+     * Retrieves ReportTables with the given uids.
+     * 
+     * @param uids the list of uids.
+     * @return a list of ReportTables.
+     */
+    List<ReportTable> getReportTablesByUid( List<String> uids );
 
     /**
      * Retrieves the ReportTable with the given name.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2013-07-22 15:17:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2013-07-23 07:51:07 +0000
@@ -98,7 +98,7 @@
     
     List<User> getAllUsersBetweenByName( String name, int first, int max );
 
-    Collection<User> getUsersByLastUpdated(Date lastUpdated);
+    Collection<User> getUsersByLastUpdated( Date lastUpdated );
 
     /**
      * Returns a Collection of the Users which are not associated with any
@@ -143,6 +143,8 @@
     int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit );
 
     int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name );
+    
+    List<User> getUsersByUid( List<String> uids );
 
     // -------------------------------------------------------------------------
     // UserCredentials

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2013-07-22 15:17:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2013-07-23 07:51:07 +0000
@@ -228,7 +228,12 @@
                 }
             } );
     }
-
+    
+    public List<User> getUsersByUid( List<String> uids )
+    {
+        return userStore.getByUid( uids );
+    }
+    
     public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit unit, int first, int max )
     {
         return userCredentialsStore.getUsersByOrganisationUnitBetween( unit, first, max );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2013-07-22 21:08:05 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2013-07-23 07:51:07 +0000
@@ -27,11 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
+
 import java.util.List;
 
 import org.hisp.dhis.chart.ChartService;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.dashboard.Dashboard;
+import org.hisp.dhis.dashboard.DashboardItem;
 import org.hisp.dhis.dashboard.DashboardSearchResult;
 import org.hisp.dhis.dashboard.DashboardService;
 import org.hisp.dhis.document.DocumentService;
@@ -124,6 +127,45 @@
         
         return result;
     }
+    
+    public void mergeDashboard( Dashboard dashboard )
+    {
+        if ( dashboard.getItems() != null )
+        {
+            for ( DashboardItem item : dashboard.getItems() )
+            {
+                if ( item.getChart() != null )
+                {
+                    item.setChart( chartService.getChart( item.getChart().getUid() ) );
+                }
+                
+                if ( item.getChart() != null )
+                {
+                    item.setMap( mappingService.getMap( item.getMap().getUid() ) );
+                }
+                
+                if ( item.getUsers() != null )
+                {
+                    item.setUsers( userService.getUsersByUid( getUids( item.getUsers() ) ) );
+                }
+                
+                if ( item.getReportTables() != null )
+                {
+                    item.setReportTables( reportTableService.getReportTablesByUid( getUids( item.getReportTables() ) ) );
+                }
+                
+                if ( item.getReports() != null )
+                {
+                    item.setReports( reportService.getReportsByUid( getUids( item.getReports() ) ) );
+                }
+                
+                if ( item.getResources() != null )
+                {
+                    item.setResources( documentService.getDocumentsByUid( getUids( item.getResources() ) ) );
+                }
+            }
+        }
+    }
 
     @Override
     public int saveDashboard( Dashboard dashboard )

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java	2013-02-21 14:37:09 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java	2013-07-23 07:51:07 +0000
@@ -106,4 +106,9 @@
     {
         return documentStore.getAllLikeNameOrderedName( name, first, max );
     }
+    
+    public List<Document> getDocumentsByUid( List<String> uids )
+    {
+        return documentStore.getByUid( uids );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2013-07-04 09:08:12 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2013-07-23 07:51:07 +0000
@@ -284,4 +284,9 @@
             }
         } );
     }
+    
+    public List<Report> getReportsByUid( List<String> uids )
+    {
+        return reportStore.getByUid( uids );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2013-07-04 15:41:57 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2013-07-23 07:51:07 +0000
@@ -186,6 +186,11 @@
             }
         } );
     }
+    
+    public List<ReportTable> getReportTablesByUid( List<String> uids )
+    {
+        return reportTableStore.getByUid( uids );
+    }
 
     public List<ReportTable> getAllReportTables()
     {

=== 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-07-22 21:08:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java	2013-07-23 07:51:07 +0000
@@ -1,10 +1,15 @@
 package org.hisp.dhis.api.controller;
 
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.dashboard.Dashboard;
 import org.hisp.dhis.dashboard.DashboardSearchResult;
 import org.hisp.dhis.dashboard.DashboardService;
+import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -33,4 +38,17 @@
         
         return "dashboardSearchResult";
     }
+    
+    @Override
+    @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
+    public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
+    {
+        Dashboard dashboard = JacksonUtils.fromJson( input, Dashboard.class );
+        
+        dashboardService.mergeDashboard( dashboard );
+        
+        dashboardService.saveDashboard( dashboard );
+        
+        ContextUtils.createdResponse( response, "Dashboard created", RESOURCE_PATH + "/" + dashboard.getUid() );
+    }
 }