dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34261
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17592: Fix for parent graph map and data view org units
------------------------------------------------------------
revno: 17592
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-11-26 13:20:00 +0100
message:
Fix for parent graph map and data view org units
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChartController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportTableController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventChartController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventReportController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/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/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2014-11-10 11:43:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2014-11-26 12:20:00 +0000
@@ -53,6 +53,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
@@ -556,6 +557,10 @@
return builder.toString();
}
+ /**
+ * Returns the list of ancestor organisation units for this organisation unit.
+ * Does not include itself. The list is ordered by root first.
+ */
public List<OrganisationUnit> getAncestors()
{
List<OrganisationUnit> units = new ArrayList<>();
@@ -571,6 +576,35 @@
Collections.reverse( units );
return units;
}
+
+ /**
+ * Returns the list of ancestor organisation units up the any of the given roots
+ * for this organisation unit. Does not include itself. The list is ordered
+ * by root first.
+ *
+ * @param roots the root organisation units, if null using real roots.
+ */
+ public List<OrganisationUnit> getAncestors( Collection<OrganisationUnit> roots )
+ {
+ List<OrganisationUnit> units = new ArrayList<>();
+
+ OrganisationUnit unit = parent;
+
+ while ( unit != null )
+ {
+ units.add( unit );
+
+ if ( roots != null && roots.contains( unit ) )
+ {
+ break;
+ }
+
+ unit = unit.getParent();
+ }
+
+ Collections.reverse( units );
+ return units;
+ }
public Set<DataElement> getDataElementsInDataSets()
{
@@ -662,11 +696,17 @@
return featureType.equals( FEATURETYPE_POINT );
}
- public String getParentGraph()
+ /**
+ * Returns a string representing the graph of ancestors. The string is delimited
+ * by "/". The ancestors are ordered by root first and represented by UIDs.
+ *
+ * @param roots the root organisation units, if null using real roots.
+ */
+ public String getParentGraph( Collection<OrganisationUnit> roots )
{
StringBuilder builder = new StringBuilder();
- List<OrganisationUnit> ancestors = getAncestors();
+ List<OrganisationUnit> ancestors = getAncestors( roots );
for ( OrganisationUnit unit : ancestors )
{
@@ -707,7 +747,7 @@
{
for ( OrganisationUnit unit : organisationUnits )
{
- map.put( unit.getUid(), unit.getParentGraph() );
+ map.put( unit.getUid(), unit.getParentGraph( organisationUnits ) );
}
}
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java 2014-10-10 14:45:25 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitTest.java 2014-11-26 12:20:00 +0000
@@ -31,6 +31,7 @@
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.junit.Before;
@@ -52,6 +53,11 @@
private CoordinatesTuple tupleC;
private CoordinatesTuple tupleD;
+ private OrganisationUnit unitA;
+ private OrganisationUnit unitB;
+ private OrganisationUnit unitC;
+ private OrganisationUnit unitD;
+
@Before
public void before()
{
@@ -77,8 +83,62 @@
multiPolygonCoordinatesList.add( tupleB );
multiPolygonCoordinatesList.add( tupleC );
pointCoordinatesList.add( tupleD );
- }
-
+
+ unitA = new OrganisationUnit( "OrgUnitA" );
+ unitB = new OrganisationUnit( "OrgUnitB" );
+ unitC = new OrganisationUnit( "OrgUnitC" );
+ unitD = new OrganisationUnit( "OrgUnitD" );
+
+ unitA.setUid( "uidA" );
+ unitB.setUid( "uidB" );
+ unitC.setUid( "uidC" );
+ unitD.setUid( "uidD" );
+ }
+
+ @Test
+ public void testGetAncestors()
+ {
+ unitD.setParent( unitC );
+ unitC.setParent( unitB );
+ unitB.setParent( unitA );
+
+ List<OrganisationUnit> expected = new ArrayList<>( Arrays.asList( unitA, unitB, unitC ) );
+
+ assertEquals( expected, unitD.getAncestors() );
+ }
+
+ @Test
+ public void testGetAncestorsWithRoots()
+ {
+ unitD.setParent( unitC );
+ unitC.setParent( unitB );
+ unitB.setParent( unitA );
+
+ List<OrganisationUnit> roots = new ArrayList<>( Arrays.asList( unitB ) );
+
+ List<OrganisationUnit> expected = new ArrayList<>( Arrays.asList( unitB, unitC ) );
+
+ assertEquals( expected, unitD.getAncestors( roots ) );
+ }
+
+ @Test
+ public void testGetParentGraph()
+ {
+ unitD.setParent( unitC );
+ unitC.setParent( unitB );
+ unitB.setParent( unitA );
+
+ List<OrganisationUnit> roots = new ArrayList<>( Arrays.asList( unitB ) );
+
+ String expected = "/uidB/uidC";
+
+ assertEquals( expected, unitD.getParentGraph( roots ) );
+
+ expected = "/uidA/uidB/uidC";
+
+ assertEquals( expected, unitD.getParentGraph( null ) );
+ }
+
@Test
public void testSetMultiPolygonCoordinatesFromCollection()
{
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChartController.java 2014-11-11 12:51:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChartController.java 2014-11-26 12:20:00 +0000
@@ -46,6 +46,7 @@
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.schema.descriptors.ChartSchemaDescriptor;
import org.hisp.dhis.system.util.CodecUtils;
+import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
import org.jfree.chart.ChartUtilities;
@@ -60,9 +61,11 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
+import java.util.Set;
import static org.hisp.dhis.common.DimensionalObjectUtils.getUniqueDimensions;
import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
@@ -94,6 +97,9 @@
@Autowired
private DimensionService dimensionService;
+
+ @Autowired
+ private CurrentUserService currentUserService;
@Autowired
private I18nManager i18nManager;
@@ -273,9 +279,11 @@
{
chart.populateAnalyticalProperties();
+ Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnits();
+
for ( OrganisationUnit organisationUnit : chart.getOrganisationUnits() )
{
- chart.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph() );
+ chart.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph( roots ) );
}
if ( chart.getPeriods() != null && !chart.getPeriods().isEmpty() )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportTableController.java 2014-10-23 10:07:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportTableController.java 2014-11-26 12:20:00 +0000
@@ -34,6 +34,7 @@
import java.io.InputStream;
import java.util.Date;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -267,9 +268,11 @@
{
reportTable.populateAnalyticalProperties();
+ Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnits();
+
for ( OrganisationUnit organisationUnit : reportTable.getOrganisationUnits() )
{
- reportTable.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph() );
+ reportTable.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph( roots ) );
}
I18nFormat format = i18nManager.getI18nFormat();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventChartController.java 2014-10-23 10:07:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventChartController.java 2014-11-26 12:20:00 +0000
@@ -34,6 +34,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -192,9 +193,11 @@
{
eventChart.populateAnalyticalProperties();
+ Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnits();
+
for ( OrganisationUnit organisationUnit : eventChart.getOrganisationUnits() )
{
- eventChart.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph() );
+ eventChart.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph( roots ) );
}
I18nFormat format = i18nManager.getI18nFormat();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventReportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventReportController.java 2014-10-23 10:07:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventReportController.java 2014-11-26 12:20:00 +0000
@@ -31,6 +31,7 @@
import static org.hisp.dhis.common.DimensionalObjectUtils.getDimensions;
import java.io.InputStream;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -140,9 +141,11 @@
{
report.populateAnalyticalProperties();
+ Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnits();
+
for ( OrganisationUnit organisationUnit : report.getOrganisationUnits() )
{
- report.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph() );
+ report.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph( roots ) );
}
I18nFormat format = i18nManager.getI18nFormat();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java 2014-11-11 12:24:42 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java 2014-11-26 12:20:00 +0000
@@ -41,6 +41,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
import org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter;
import org.hisp.dhis.system.util.FilterUtils;
+import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.webdomain.GeoFeature;
import org.hisp.dhis.webapi.webdomain.WebOptions;
@@ -53,6 +54,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -91,6 +93,9 @@
@Autowired
private RenderService renderService;
+
+ @Autowired
+ private CurrentUserService currentUserService;
@RequestMapping( method = RequestMethod.GET, produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_HTML } )
public void getGeoFeaturesJson(
@@ -151,6 +156,8 @@
List<GeoFeature> features = new ArrayList<>();
+ Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnits();
+
for ( OrganisationUnit organisationUnit : organisationUnits )
{
GeoFeature feature = new GeoFeature();
@@ -159,7 +166,7 @@
feature.setHcd( organisationUnit.hasChildrenWithCoordinates() );
feature.setHcu( organisationUnit.hasCoordinatesUp() );
feature.setLe( organisationUnit.getLevel() );
- feature.setPg( organisationUnit.getParentGraph() );
+ feature.setPg( organisationUnit.getParentGraph( roots ) );
feature.setPi( organisationUnit.getParent() != null ? organisationUnit.getParent().getUid() : null );
feature.setPn( organisationUnit.getParent() != null ? organisationUnit.getParent().getDisplayName() : null );
feature.setTy( FEATURE_TYPE_MAP.get( organisationUnit.getFeatureType() ) );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java 2014-11-11 12:36:27 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java 2014-11-26 12:20:00 +0000
@@ -57,10 +57,12 @@
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.Date;
import java.util.Iterator;
+import java.util.Set;
import static org.hisp.dhis.webapi.utils.ContextUtils.DATE_PATTERN;
@@ -230,13 +232,15 @@
{
I18nFormat format = i18nManager.getI18nFormat();
+ Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnits();
+
for ( MapView view : map.getMapViews() )
{
view.populateAnalyticalProperties();
for ( OrganisationUnit organisationUnit : view.getOrganisationUnits() )
{
- view.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph() );
+ view.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph( roots ) );
}
if ( view.getPeriods() != null && !view.getPeriods().isEmpty() )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java 2014-11-24 06:33:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java 2014-11-26 12:20:00 +0000
@@ -31,6 +31,7 @@
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.google.common.collect.Lists;
+
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -52,11 +53,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -312,11 +315,13 @@
if ( includeProperties )
{
+ Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnits();
+
generator.writeStringField( "code", organisationUnit.getCode() );
generator.writeStringField( "name", organisationUnit.getName() );
generator.writeStringField( "level", String.valueOf( organisationUnit.getLevel() ) );
generator.writeStringField( "parent", organisationUnit.getParent().getUid() );
- generator.writeStringField( "parentGraph", organisationUnit.getParentGraph() );
+ generator.writeStringField( "parentGraph", organisationUnit.getParentGraph( roots ) );
}
generator.writeEndObject();