------------------------------------------------------------ revno: 11503 committer: Lars Helge Ă˜verland <larshe...@gmail.com> branch nick: dhis2 timestamp: Wed 2013-07-24 17:55:13 +0200 message: Impl method for removing dashboard item content 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/test/java/org/hisp/dhis/dashboard/DashboardTest.java dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.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-24 11:48:13 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java 2013-07-24 15:55:13 +0000 @@ -122,6 +122,20 @@ } /** + * Returns the item with the given uid, or null if no item with the given + * uid is present for this dashboard. + * + * @param uid the item identifier. + * @return an item. + */ + public DashboardItem getItemByUid( String uid ) + { + int index = items.indexOf( new DashboardItem( uid ) ); + + return index != -1 ? items.get( index ) : null; + } + + /** * Returns an item from this dashboard of the given type which number of * content is less than max. Returns null if no item matches the criteria. * === 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-24 11:48:13 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java 2013-07-24 15:55:13 +0000 @@ -28,6 +28,7 @@ */ import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import org.hisp.dhis.chart.Chart; @@ -93,6 +94,7 @@ // ------------------------------------------------------------------------- @JsonProperty + @JacksonXmlProperty public String getType() { if ( chart != null ) @@ -122,7 +124,9 @@ return null; } - + + @JsonProperty + @JacksonXmlProperty public int getContentCount() { int count = 0; @@ -133,6 +137,49 @@ return count; } + /** + * Removes the content with the given uid. Returns true if a content with + * the given uid existed and was removed. + * + * @param uid the identifier of the content. + * @return true if a content was removed. + */ + public boolean removeItemContent( String uid ) + { + if ( !users.isEmpty() ) + { + return removeContent( uid, users ); + } + else if ( !reportTables.isEmpty() ) + { + return removeContent( uid, reportTables ); + } + else if ( !reports.isEmpty() ) + { + return removeContent( uid, reports ); + } + else + { + return removeContent( uid, resources ); + } + } + + private boolean removeContent( String uid, List<? extends IdentifiableObject> content ) + { + Iterator<? extends IdentifiableObject> iterator = content.iterator(); + + while ( iterator.hasNext() ) + { + if ( uid.equals( iterator.next().getUid() ) ) + { + iterator.remove(); + return true; + } + } + + return false; + } + // ------------------------------------------------------------------------- // Getters and setters // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dashboard/DashboardTest.java' --- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dashboard/DashboardTest.java 2013-07-24 11:48:13 +0000 +++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dashboard/DashboardTest.java 2013-07-24 15:55:13 +0000 @@ -152,4 +152,25 @@ assertFalse( dashboard.removeItem( "X" ) ); assertEquals( 2, dashboard.getItems().size() ); } + + @Test + public void testGetItem() + { + Dashboard dashboard = new Dashboard(); + + DashboardItem diA = new DashboardItem(); + DashboardItem diB = new DashboardItem(); + DashboardItem diC = new DashboardItem(); + + diA.setUid( "A" ); + diB.setUid( "B" ); + diC.setUid( "C" ); + + dashboard.getItems().add( diA ); + dashboard.getItems().add( diB ); + dashboard.getItems().add( diC ); + + assertEquals( diB, dashboard.getItemByUid( "B" ) ); + assertNull( dashboard.getItemByUid( "X" ) ); + } } === modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java' --- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java 2013-07-24 12:38:12 +0000 +++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java 2013-07-24 15:55:13 +0000 @@ -44,8 +44,8 @@ */ public class Legend { - public static final Font TITLE_FONT = new Font( "title", Font.BOLD, 15 ); - public static final Font PLAIN_FONT = new Font( "plain", Font.PLAIN, 11 ); + public static final Font TITLE_FONT = new Font( "title", Font.BOLD, 14 ); + public static final Font PLAIN_FONT = new Font( "plain", Font.PLAIN, 10 ); private InternalMapLayer mapLayer; === modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java' --- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java 2013-07-24 12:38:12 +0000 +++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java 2013-07-24 15:55:13 +0000 @@ -30,7 +30,6 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; @@ -50,7 +49,7 @@ private Color backgroundColor = null; private static final int LEGEND_WIDTH = 145; - private static final int LEGEND_MARGIN_LEFT = 4; + private static final int LEGEND_MARGIN_LEFT = 3; private static final int LEGEND_MARGIN_BOTTOM = 20; public static final int LEGEND_TOTAL_WIDTH = LEGEND_WIDTH + LEGEND_MARGIN_LEFT; === 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-24 11:48:13 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java 2013-07-24 15:55:13 +0000 @@ -193,4 +193,32 @@ ContextUtils.okResponse( response, "Dashboard item removed" ); } } + + @RequestMapping( value = "/{dashboardUid}/items/{itemUid}/content/{contentUid}", method = RequestMethod.DELETE ) + public void deleteItemContent( HttpServletResponse response, HttpServletRequest request, + @PathVariable String dashboardUid, @PathVariable String itemUid, @PathVariable String contentUid ) + { + Dashboard dashboard = dashboardService.getDashboard( dashboardUid ); + + if ( dashboard == null ) + { + ContextUtils.notFoundResponse( response, "Dashboard does not exist: " + dashboardUid ); + return; + } + + DashboardItem item = dashboard.getItemByUid( itemUid ); + + if ( item == null ) + { + ContextUtils.notFoundResponse( response, "Dashboard item does not exist: " + itemUid ); + return; + } + + if ( item.removeItemContent( contentUid ) ) + { + dashboardService.updateDashboard( dashboard ); + + ContextUtils.okResponse( response, "Dashboard item content removed" ); + } + } }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp