dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24061
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11741: Event analytics, query operators
------------------------------------------------------------
revno: 11741
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-08-22 09:53:43 +0200
message:
Event analytics, query operators
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/QueryItem.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/EventQueryPlanner.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.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/event/EventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java 2013-08-21 18:09:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java 2013-08-22 07:53:43 +0000
@@ -38,5 +38,5 @@
{
Grid getEvents( EventQueryParams params );
- EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, Set<String> item, Set<String> orgUnits );
+ EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, String ou, Set<String> item );
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/QueryItem.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/QueryItem.java 2013-08-21 18:09:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/QueryItem.java 2013-08-22 07:53:43 +0000
@@ -27,6 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.HashMap;
+import java.util.Map;
+
import org.hisp.dhis.common.IdentifiableObject;
/**
@@ -34,6 +37,17 @@
*/
public class QueryItem
{
+ public static final Map<String, String> OPERATOR_MAP = new HashMap<String, String>() { {
+ put( "like", "like" );
+ put( "in", "in" );
+ put( "eq", "=" );
+ put( "gt", ">" );
+ put( "ge", ">=" );
+ put( "lt", "<" );
+ put( "le", "<=" );
+ put( "ne", "!=" );
+ } };
+
private IdentifiableObject item;
private String operator;
@@ -65,6 +79,17 @@
return operator != null && !operator.isEmpty() && filter != null && !filter.isEmpty();
}
+ public String getSqlOperator()
+ {
+ return OPERATOR_MAP.get( operator );
+ }
+
+ @Override
+ public String toString()
+ {
+ return "[Item: " + item + ", operator: " + operator + ", filter: " + filter + "]";
+ }
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== 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-08-21 18:09:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2013-08-22 07:53:43 +0000
@@ -62,7 +62,7 @@
*/
public class DefaultEventAnalyticsService
implements EventAnalyticsService
-{
+{
@Autowired
private ProgramService programService;
@@ -88,7 +88,6 @@
// EventAnalyticsService implementation
// -------------------------------------------------------------------------
- //TODO table name
//TODO org unit children / descendants
public Grid getEvents( EventQueryParams params )
@@ -97,7 +96,7 @@
grid.addHeader( new GridHeader( "Event", "psi" ) );
grid.addHeader( new GridHeader( "Program stage", "ps" ) );
- grid.addHeader( new GridHeader( "Executiondate", "executiondate" ) );
+ grid.addHeader( new GridHeader( "Execution date", "executiondate" ) );
grid.addHeader( new GridHeader( "Organisation unit", "ou" ) );
for ( QueryItem queryItem : params.getItems() )
@@ -117,7 +116,7 @@
return grid;
}
- public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, Set<String> item, Set<String> orgUnits )
+ public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, String ou, Set<String> item )
{
EventQueryParams params = new EventQueryParams();
@@ -145,7 +144,12 @@
}
catch ( RuntimeException ex )
{
- throw new IllegalQueryException( "Start date or end date is invalid: " + startDate + " " + endDate );
+ throw new IllegalQueryException( "Start date or end date is invalid: " + startDate + " - " + endDate );
+ }
+
+ if ( start == null || end == null )
+ {
+ throw new IllegalQueryException( "Start date or end date is invalid: " + startDate + " - " + endDate );
}
if ( start.after( end ) )
@@ -175,15 +179,17 @@
}
}
- if ( orgUnits != null )
+ if ( ou != null )
{
- for ( String orgUnit : orgUnits )
+ String[] split = ou.split( OPTION_SEP );
+
+ for ( String ouId : split )
{
- OrganisationUnit ou = organisationUnitService.getOrganisationUnit( orgUnit );
+ OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouId );
- if ( ou != null )
+ if ( orgUnit != null )
{
- params.getOrganisationUnits().add( ou );
+ params.getOrganisationUnits().add( orgUnit );
}
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/EventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/EventQueryPlanner.java 2013-08-21 18:09:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/EventQueryPlanner.java 2013-08-22 07:53:43 +0000
@@ -1,5 +1,32 @@
package org.hisp.dhis.analytics.event.data;
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -8,6 +35,9 @@
import org.hisp.dhis.period.Cal;
import org.hisp.dhis.program.Program;
+/**
+ * @author Lars Helge Overland
+ */
public class EventQueryPlanner
{
private static final String TABLE_BASE_NAME = "analytics_event_";
=== 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-08-21 18:09:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2013-08-22 07:53:43 +0000
@@ -37,6 +37,7 @@
import org.hisp.dhis.analytics.event.QueryItem;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.system.util.Timer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
@@ -85,14 +86,18 @@
{
if ( filter.hasFilter() )
{
- sql += "and " + filter.getFilter() + " " + filter.getOperator() + " '" + filter.getFilter() + "' ";
+ sql += "and " + filter.getItem().getUid() + " " + filter.getSqlOperator() + " '" + filter.getFilter() + "' ";
}
}
int rowLength = grid.getHeaders().size();
+
+ Timer t = new Timer().start();
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
+ t.getTime( "Analytics event SQL: " + sql );
+
while ( rowSet.next() )
{
grid.addRow();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java 2013-08-21 18:09:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java 2013-08-22 07:53:43 +0000
@@ -47,7 +47,7 @@
@Controller
public class EventAnalyticsController
{
- private static final String RESOURCE_PATH = "/analytics/events";
+ private static final String RESOURCE_PATH = "/analytics/events/query";
@Autowired
private EventAnalyticsService analyticsService;
@@ -65,12 +65,12 @@
@RequestParam(required=false) String stage,
@RequestParam String startDate,
@RequestParam String endDate,
+ @RequestParam(required=false) String ou,
@RequestParam Set<String> item,
- @RequestParam(required=false) Set<String> orgUnits,
Model model,
HttpServletResponse response ) throws Exception
{
- EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, item, orgUnits );
+ EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, ou, item );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getEvents( params );