dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23860
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11624: Analytics API: Impl support for selecting organisation units as groups in query string. Syntax is...
------------------------------------------------------------
revno: 11624
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-08-09 16:10:43 +0200
message:
Analytics API: Impl support for selecting organisation units as groups in query string. Syntax is dimension=ou:OU_GROUP-<group-uid>. Added item organisation units groups as persistent properties for ReportTable and Chart.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml
dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml
--
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/common/BaseAnalyticalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java 2013-07-04 15:41:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java 2013-08-09 14:10:43 +0000
@@ -39,6 +39,7 @@
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT;
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT_CHILDREN;
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_LEVEL;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_ORGUNIT_GROUP;
import java.util.ArrayList;
import java.util.Arrays;
@@ -46,8 +47,10 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.common.adapter.JacksonPeriodDeserializer;
@@ -131,8 +134,16 @@
protected boolean userOrganisationUnitChildren;
+ /**
+ * Level of dimension item organisation units.
+ */
protected Integer organisationUnitLevel;
+ /**
+ * Groups containing dimension item organisation units.
+ */
+ protected List<OrganisationUnitGroup> itemOrganisationUnitGroups = new ArrayList<OrganisationUnitGroup>();
+
protected boolean rewindRelativePeriods;
// -------------------------------------------------------------------------
@@ -193,6 +204,18 @@
}
}
+ protected Set<OrganisationUnit> getOrganisationUnitsInItemGroups()
+ {
+ Set<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+
+ for ( OrganisationUnitGroup group : itemOrganisationUnitGroups )
+ {
+ units.addAll( group.getMembers() );
+ }
+
+ return units;
+ }
+
/**
* Assembles a DimensionalObject. Collapses indicators, data elements, data
* element operands and data sets into the dx dimension.
@@ -264,6 +287,11 @@
items.addAll( organisationUnitsAtLevel );
}
+ if ( itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty() )
+ {
+ items.addAll( getOrganisationUnitsInItemGroups() );
+ }
+
type = DimensionType.ORGANISATIONUNIT;
}
else if ( CATEGORYOPTIONCOMBO_DIM_ID.equals( dimension ) )
@@ -407,6 +435,16 @@
}
}
+ if ( itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty() )
+ {
+ for ( OrganisationUnitGroup group : itemOrganisationUnitGroups )
+ {
+ String id = KEY_ORGUNIT_GROUP + group.getUid();
+
+ ouList.add( new BaseNameableObject( id, id, id ) );
+ }
+ }
+
objects.add( new BaseDimensionalObject( dimension, DimensionType.ORGANISATIONUNIT, ouList ) );
}
else if ( CATEGORYOPTIONCOMBO_DIM_ID.equals( dimension ) )
@@ -762,6 +800,20 @@
@JsonProperty
@JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlElementWrapper( localName = "itemOrganisationUnitGroups", namespace = DxfNamespaces.DXF_2_0)
+ @JacksonXmlProperty( localName = "itemOrganisationUnitGroup", namespace = DxfNamespaces.DXF_2_0)
+ public List<OrganisationUnitGroup> getItemOrganisationUnitGroups()
+ {
+ return itemOrganisationUnitGroups;
+ }
+
+ public void setItemOrganisationUnitGroups( List<OrganisationUnitGroup> itemOrganisationUnitGroups )
+ {
+ this.itemOrganisationUnitGroups = itemOrganisationUnitGroups;
+ }
+
+ @JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
public boolean isRewindRelativePeriods()
{
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java 2013-07-04 15:41:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java 2013-08-09 14:10:43 +0000
@@ -166,4 +166,25 @@
return null;
}
+
+ /**
+ * Retrieves the uid from an org unit group parameter string, which is on
+ * the format OU_GROUP-<uid> .
+ */
+ public static String getUidFromOrgUnitGroupParam( String param )
+ {
+ if ( param == null )
+ {
+ return null;
+ }
+
+ String[] split = param.split( "-" );
+
+ if ( split.length > 1 && split[1] != null )
+ {
+ return String.valueOf( split[1] );
+ }
+
+ return null;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-06-24 13:38:28 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-08-09 14:10:43 +0000
@@ -793,6 +793,8 @@
return new ArrayList<String>();
}
+ // TODO move these to DimensionalObjectUtils or API, duplication of code
+
/**
* Retrieves the level from a level parameter string, which is on the format
* LEVEL-<level>-<item> .
@@ -834,6 +836,27 @@
return null;
}
+
+ /**
+ * Retrieves the uid from an org unit group parameter string, which is on
+ * the format OU_GROUP-<uid> .
+ */
+ public static String getUidFromOrgUnitGroupParam( String param )
+ {
+ if ( param == null )
+ {
+ return null;
+ }
+
+ String[] split = param.split( ITEM_SEP );
+
+ if ( split.length > 1 && split[1] != null )
+ {
+ return String.valueOf( split[1] );
+ }
+
+ return null;
+ }
/**
* Splits the given string on the ; character and returns the items in a
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-07-17 19:40:31 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-08-09 14:10:43 +0000
@@ -50,6 +50,7 @@
import static org.hisp.dhis.common.NameableObjectUtils.asList;
import static org.hisp.dhis.common.NameableObjectUtils.asTypedList;
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_LEVEL;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_ORGUNIT_GROUP;
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT;
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT_CHILDREN;
import static org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString;
@@ -105,6 +106,7 @@
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -823,6 +825,17 @@
ous.addAll( organisationUnitService.getOrganisationUnitsAtLevel( level, boundary ) );
}
}
+ else if ( ou != null && ou.startsWith( KEY_ORGUNIT_GROUP ) )
+ {
+ String uid = DataQueryParams.getUidFromOrgUnitGroupParam( ou );
+
+ OrganisationUnitGroup group = null;
+
+ if ( uid != null && ( group = organisationUnitGroupService.getOrganisationUnitGroup( uid ) ) != null )
+ {
+ ous.addAll( group.getMembers() );
+ }
+ }
else
{
OrganisationUnit unit = organisationUnitService.getOrganisationUnit( ou );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java 2013-07-17 12:38:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java 2013-08-09 14:10:43 +0000
@@ -38,6 +38,7 @@
import static org.hisp.dhis.common.DimensionType.PERIOD;
import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_LEVEL;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_ORGUNIT_GROUP;
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT;
import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT_CHILDREN;
@@ -292,14 +293,25 @@
String boundary = DimensionalObjectUtils.getBoundaryFromLevelParam( ou );
- OrganisationUnit unit = identifiableObjectManager.get( OrganisationUnit.class, boundary );
+ OrganisationUnit unit = null;
- if ( level > 0 && unit != null )
+ if ( level > 0 && boundary != null && ( unit = identifiableObjectManager.get( OrganisationUnit.class, boundary ) ) != null )
{
object.setOrganisationUnitLevel( level );
ous.add( unit );
}
}
+ else if ( ou != null && ou.startsWith( KEY_ORGUNIT_GROUP ) )
+ {
+ String uid = DimensionalObjectUtils.getUidFromOrgUnitGroupParam( ou );
+
+ OrganisationUnitGroup group = null;
+
+ if ( uid != null && ( group = identifiableObjectManager.get( OrganisationUnitGroup.class, uid ) ) != null )
+ {
+ ous.addAll( group.getMembers() );
+ }
+ }
else
{
OrganisationUnit unit = identifiableObjectManager.get( OrganisationUnit.class, ou );
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml 2013-08-08 15:14:50 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml 2013-08-09 14:10:43 +0000
@@ -127,6 +127,14 @@
foreign-key="fk_chart_orgunitgroups_orgunitgroupid" />
</list>
+ <list name="itemOrganisationUnitGroups" table="chart_itemorgunitgroups">
+ <cache usage="read-write" />
+ <key column="chartid" foreign-key="fk_chart_itemorgunitunitgroups_chartid" />
+ <list-index column="sort_order" base="0" />
+ <many-to-many column="orgunitgroupid" class="org.hisp.dhis.organisationunit.OrganisationUnitGroup"
+ foreign-key="fk_chart_itemorgunitgroups_orgunitgroupid" />
+ </list>
+
<property name="userOrganisationUnit" />
<property name="userOrganisationUnitChildren" />
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml 2013-07-04 15:41:57 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml 2013-08-09 14:10:43 +0000
@@ -96,6 +96,14 @@
foreign-key="fk_reporttable_orgunitgroups_orgunitgroupid" />
</list>
+ <list name="itemOrganisationUnitGroups" table="reporttable_itemorgunitgroups">
+ <cache usage="read-write" />
+ <key column="reporttableid" foreign-key="fk_reporttable_itemorgunitunitgroups_reporttableid" />
+ <list-index column="sort_order" base="0" />
+ <many-to-many column="orgunitgroupid" class="org.hisp.dhis.organisationunit.OrganisationUnitGroup"
+ foreign-key="fk_reporttable_itemorgunitgroups_orgunitgroupid" />
+ </list>
+
<list name="columnDimensions" table="reporttable_columns">
<cache usage="read-write" />
<key column="reporttableid" foreign-key="fk_reporttable_columns_reporttableid" />
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2013-05-27 08:39:36 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2013-08-09 14:10:43 +0000
@@ -180,6 +180,8 @@
<cache name="org.hisp.dhis.reporttable.ReportTable.organisationUnitGroups" maxElementsInMemory="500" />
+ <cache name="org.hisp.dhis.reporttable.ReportTable.itemOrganisationUnitGroups" maxElementsInMemory="500" />
+
<cache name="org.hisp.dhis.reporttable.ReportTable.categoryDimensions" maxElementsInMemory="500" />
<cache name="org.hisp.dhis.reporttable.ReportTable.columnDimensions" maxElementsInMemory="500" />
@@ -204,6 +206,8 @@
<cache name="org.hisp.dhis.chart.Chart.organisationUnitGroups" maxElementsInMemory="500" />
+ <cache name="org.hisp.dhis.chart.Chart.itemOrganisationUnitGroups" maxElementsInMemory="500" />
+
<cache name="org.hisp.dhis.chart.Chart.categoryDimensions" maxElementsInMemory="500" />
<cache name="org.hisp.dhis.chart.Chart.filterDimensions" maxElementsInMemory="500" />