dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24988
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12306: Event analytics, improved filtering
------------------------------------------------------------
revno: 12306
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-09-29 23:05:46 +0200
message:
Event analytics, improved filtering
modified:
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/event/EventQueryParams.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.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-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-09-29 15:48:42 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-09-29 21:05:46 +0000
@@ -377,7 +377,7 @@
{
return CollectionUtils.intersection( dimensions, filters );
}
-
+
/**
* Indicates whether periods are present as a dimension or as a filter. If
* not this object is in an illegal state.
@@ -391,6 +391,17 @@
}
/**
+ * Indicates whether organisation units are present as dimensio or filter.
+ */
+ public boolean hasOrganisationUnits()
+ {
+ List<NameableObject> dimOpts = getDimensionOptions( ORGUNIT_DIM_ID );
+ List<NameableObject> filterOpts = getFilterOptions( ORGUNIT_DIM_ID );
+
+ return ( dimOpts != null && !dimOpts.isEmpty() ) || ( filterOpts != null && !filterOpts.isEmpty() );
+ }
+
+ /**
* Returns the period type of the first period specified as filter, or
* null if there is no period filter.
*/
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java 2013-09-29 17:43:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java 2013-09-29 21:05:46 +0000
@@ -136,7 +136,7 @@
{
Set<OrganisationUnit> children = new HashSet<OrganisationUnit>();
- for ( NameableObject object : getOrganisationUnits() )
+ for ( NameableObject object : getDimensionOrFilter( DimensionalObject.ORGUNIT_DIM_ID ) )
{
OrganisationUnit unit = (OrganisationUnit) object;
children.addAll( unit.getChildren() );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2013-09-29 17:43:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2013-09-29 21:05:46 +0000
@@ -309,7 +309,7 @@
}
}
- for ( NameableObject object : params.getOrganisationUnits() )
+ for ( NameableObject object : params.getDimensionOrFilter( ORGUNIT_DIM_ID ) )
{
OrganisationUnit unit = (OrganisationUnit) object;
unit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( unit.getUid() ) );
@@ -330,21 +330,6 @@
params.getDesc().add( getSortItem( sort, pr ) );
}
}
-
- if ( params.getOrganisationUnits().isEmpty() )
- {
- throw new IllegalQueryException( "At least one organisation unit must be specified" );
- }
-
- if ( page != null && page <= 0 )
- {
- throw new IllegalQueryException( "Page number must be positive: " + page );
- }
-
- if ( pageSize != null && pageSize < 0 )
- {
- throw new IllegalQueryException( "Page size must be zero or positive: " + pageSize );
- }
params.setProgram( pr );
params.setProgramStage( ps );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java 2013-09-29 17:20:53 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java 2013-09-29 21:05:46 +0000
@@ -28,6 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.common.DimensionalObject.*;
+
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -67,12 +69,12 @@
throw new IllegalQueryException( "Params cannot be null" );
}
- if ( params.getOrganisationUnits().isEmpty() )
+ if ( !params.hasOrganisationUnits() )
{
violation = "At least one organisation unit must be specified";
}
- if ( params.getPeriods() == null && ( params.getStartDate() == null || params.getEndDate() == null ) )
+ if ( !params.hasPeriods() && ( params.getStartDate() == null || params.getEndDate() == null ) )
{
violation = "Start and end date or at least one period must be specified";
}
@@ -81,10 +83,20 @@
{
if ( params.getStartDate().after( params.getEndDate() ) )
{
- throw new IllegalQueryException( "Start date is after end date: " + params.getStartDate() + " - " + params.getEndDate() );
+ violation = "Start date is after end date: " + params.getStartDate() + " - " + params.getEndDate();
}
}
+ if ( params.getPage() != null && params.getPage() <= 0 )
+ {
+ violation = "Page number must be positive: " + params.getPage();
+ }
+
+ if ( params.getPageSize() != null && params.getPageSize() < 0 )
+ {
+ violation = "Page size must be zero or positive: " + params.getPageSize();
+ }
+
if ( violation != null )
{
log.warn( "Validation failed: " + violation );
@@ -151,7 +163,7 @@
else
{
//TODO implement properly
- Period period = (Period) params.getPeriods().get( 0 );
+ Period period = (Period) params.getDimensionOrFilter( PERIOD_DIM_ID ).get( 0 );
params.setTableName( TABLE_BASE_NAME + year( period.getStartDate() ) + "_" + program.getUid() );
params.setPeriodType( period.getPeriodType().getName() );
list.add( params );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2013-09-29 17:43:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2013-09-29 21:05:46 +0000
@@ -32,6 +32,7 @@
import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
import static org.hisp.dhis.system.util.TextUtils.removeLast;
+import static org.hisp.dhis.common.DimensionalObject.*;
import java.util.Arrays;
@@ -237,12 +238,12 @@
}
else // Periods
{
- sql += "where " + params.getPeriodType() + " in (" + getQuotedCommaDelimitedString( getUids( params.getPeriods() ) ) + ") ";
+ sql += "where " + params.getPeriodType() + " in (" + getQuotedCommaDelimitedString( getUids( params.getDimensionOrFilter( PERIOD_DIM_ID ) ) ) + ") ";
}
if ( params.isOrganisationUnitMode( EventQueryParams.OU_MODE_SELECTED ) )
{
- sql += "and ou in (" + getQuotedCommaDelimitedString( getUids( params.getOrganisationUnits() ) ) + ") ";
+ sql += "and ou in (" + getQuotedCommaDelimitedString( getUids( params.getDimensionOrFilter( ORGUNIT_DIM_ID ) ) ) + ") ";
}
else if ( params.isOrganisationUnitMode( EventQueryParams.OU_MODE_CHILDREN ) )
{
@@ -252,7 +253,7 @@
{
sql += "and (";
- for ( NameableObject object : params.getOrganisationUnits() )
+ for ( NameableObject object : params.getDimensionOrFilter( ORGUNIT_DIM_ID ) )
{
OrganisationUnit unit = (OrganisationUnit) object;
sql += "uidlevel" + unit.getLevel() + " = '" + unit.getUid() + "' or ";