=== 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 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java 2015-01-21 09:30:45 +0000 @@ -47,7 +47,7 @@ DashboardSearchResult search( String query, Set maxTypes ); - boolean addItemContent( String dashboardUid, String type, String contentUid ); + DashboardItem addItemContent( String dashboardUid, String type, String contentUid ); void mergeDashboard( Dashboard dashboard ); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorType.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorType.java 2015-01-21 09:30:45 +0000 @@ -28,16 +28,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonView; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; -import org.hisp.dhis.schema.annotation.PropertyRange; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; /** * @author Lars Helge Overland === 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 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java 2015-01-21 09:30:45 +0000 @@ -122,48 +122,44 @@ } @Override - public boolean addItemContent( String dashboardUid, String type, String contentUid ) + public DashboardItem addItemContent( String dashboardUid, String type, String contentUid ) { Dashboard dashboard = getDashboard( dashboardUid ); if ( dashboard == null ) { - return false; + return null; } - + + DashboardItem item = new DashboardItem(); + if ( TYPE_CHART.equals( type ) ) - { - DashboardItem item = new DashboardItem(); + { item.setChart( objectManager.get( Chart.class, contentUid ) ); dashboard.getItems().add( 0, item ); } else if ( TYPE_EVENT_CHART.equals( type ) ) { - DashboardItem item = new DashboardItem(); item.setEventChart( objectManager.get( EventChart.class, contentUid ) ); dashboard.getItems().add( 0, item ); } else if ( TYPE_MAP.equals( type ) ) { - DashboardItem item = new DashboardItem(); item.setMap( objectManager.get( Map.class, contentUid ) ); dashboard.getItems().add( 0, item ); } else if ( TYPE_REPORT_TABLE.equals( type ) ) { - DashboardItem item = new DashboardItem(); item.setReportTable( objectManager.get( ReportTable.class, contentUid ) ); dashboard.getItems().add( 0, item ); } else if ( TYPE_EVENT_REPORT.equals( type ) ) { - DashboardItem item = new DashboardItem(); item.setEventReport( objectManager.get( EventReport.class, contentUid ) ); dashboard.getItems().add( 0, item ); } else if ( TYPE_MESSAGES.equals( type ) ) { - DashboardItem item = new DashboardItem(); item.setMessages( true ); dashboard.getItems().add( 0, item ); } @@ -171,7 +167,7 @@ { DashboardItem availableItem = dashboard.getAvailableItemByType( type ); - DashboardItem item = availableItem == null ? new DashboardItem() : availableItem; + item = availableItem == null ? new DashboardItem() : availableItem; if ( TYPE_USERS.equals( type ) ) { @@ -194,12 +190,12 @@ if ( dashboard.getItemCount() > Dashboard.MAX_ITEMS ) { - return false; + return null; } updateDashboard( dashboard ); - return true; + return item; } @Override === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java' --- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java 2015-01-21 09:30:45 +0000 @@ -58,11 +58,14 @@ private DashboardItem diC; private DashboardItem diD; + private Chart chartA; + private Chart chartB; + @Override public void setUpTest() { - Chart chartA = new Chart( "A" ); - Chart chartB = new Chart( "B" ); + chartA = new Chart( "A" ); + chartB = new Chart( "B" ); chartService.addChart( chartA ); chartService.addChart( chartB ); @@ -146,4 +149,16 @@ assertNull( dashboardService.getDashboard( dAId ) ); assertNull( dashboardService.getDashboard( dBId ) ); } + + @Test + public void testAddItemContent() + { + dashboardService.saveDashboard( dA ); + dashboardService.saveDashboard( dB ); + + DashboardItem itemA = dashboardService.addItemContent( dA.getUid(), DashboardItem.TYPE_CHART, chartA.getUid() ); + + assertNotNull( itemA ); + assertNotNull( itemA.getUid() ); + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java 2015-01-21 09:30:45 +0000 @@ -44,6 +44,7 @@ import org.hisp.dhis.dashboard.DashboardService; import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException; +import org.hisp.dhis.schema.descriptors.DashboardItemSchemaDescriptor; import org.hisp.dhis.schema.descriptors.DashboardSchemaDescriptor; import org.hisp.dhis.webapi.utils.ContextUtils; import org.hisp.dhis.webapi.webdomain.WebOptions; @@ -156,15 +157,15 @@ public void postJsonItemContent( HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @RequestParam String type, @RequestParam( "id" ) String contentUid ) throws Exception { - boolean result = dashboardService.addItemContent( dashboardUid, type, contentUid ); + DashboardItem item = dashboardService.addItemContent( dashboardUid, type, contentUid ); - if ( !result ) + if ( item == null ) { ContextUtils.conflictResponse( response, "Max number of dashboard items reached: " + MAX_ITEMS ); } else { - ContextUtils.okResponse( response, "Dashboard item added" ); + ContextUtils.createdResponse( response, "Dashboard item added", DashboardItemSchemaDescriptor.API_ENDPOINT + "/" + item.getUid() ); } }