dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25143
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12400: Event analytics, implemented support for sort order
------------------------------------------------------------
revno: 12400
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-10-02 16:40:51 +0200
message:
Event analytics, implemented support for sort order
added:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/SortOrder.java
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/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/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
=== added file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/SortOrder.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/SortOrder.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/SortOrder.java 2013-10-02 14:40:51 +0000
@@ -0,0 +1,38 @@
+package org.hisp.dhis.analytics;
+
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
+public enum SortOrder
+{
+ ASC,
+ DESC
+}
=== 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-10-02 14:21:56 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java 2013-10-02 14:40:51 +0000
@@ -30,6 +30,7 @@
import java.util.Set;
+import org.hisp.dhis.analytics.SortOrder;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.i18n.I18nFormat;
@@ -43,7 +44,7 @@
Grid getEvents( EventQueryParams params );
EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate,
- Set<String> dimension, Set<String> filter, Integer limit, I18nFormat format );
+ Set<String> dimension, Set<String> filter, SortOrder sortOrder, Integer limit, I18nFormat format );
EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate,
Set<String> dimension, Set<String> filter, String ouMode, Set<String> asc, Set<String> desc, Integer page, Integer pageSize, I18nFormat format );
=== 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-10-02 14:21:56 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java 2013-10-02 14:40:51 +0000
@@ -35,6 +35,7 @@
import java.util.Set;
import org.hisp.dhis.analytics.DataQueryParams;
+import org.hisp.dhis.analytics.SortOrder;
import org.hisp.dhis.common.DimensionalObject;
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -75,6 +76,8 @@
private Integer pageSize;
+ private SortOrder sortOrder;
+
private Integer limit;
// -------------------------------------------------------------------------
@@ -115,6 +118,7 @@
params.tableName = this.tableName;
params.page = this.page;
params.pageSize = this.pageSize;
+ params.sortOrder = this.sortOrder;
params.limit = this.limit;
params.periodType = this.periodType;
@@ -173,6 +177,11 @@
return ( getPageWithDefault() - 1 ) * getPageSizeWithDefault();
}
+ public boolean hasSortOrder()
+ {
+ return sortOrder != null;
+ }
+
public boolean hasLimit()
{
return limit != null && limit > 0;
@@ -324,6 +333,16 @@
this.pageSize = pageSize;
}
+ public SortOrder getSortOrder()
+ {
+ return sortOrder;
+ }
+
+ public void setSortOrder( SortOrder sortOrder )
+ {
+ this.sortOrder = sortOrder;
+ }
+
public Integer getLimit()
{
return limit;
=== 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-10-02 14:21:56 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2013-10-02 14:40:51 +0000
@@ -42,6 +42,7 @@
import org.hisp.dhis.analytics.AnalyticsService;
import org.hisp.dhis.analytics.DataQueryParams;
import org.hisp.dhis.analytics.IllegalQueryException;
+import org.hisp.dhis.analytics.SortOrder;
import org.hisp.dhis.analytics.event.EventAnalyticsManager;
import org.hisp.dhis.analytics.event.EventAnalyticsService;
import org.hisp.dhis.analytics.event.EventQueryParams;
@@ -146,8 +147,6 @@
// ---------------------------------------------------------------------
// Data
// ---------------------------------------------------------------------
-
- //TODO relative periods
List<EventQueryParams> queries = queryPlanner.planQuery( params );
@@ -234,9 +233,10 @@
}
public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate,
- Set<String> dimension, Set<String> filter, Integer limit, I18nFormat format )
+ Set<String> dimension, Set<String> filter, SortOrder sortOrder, Integer limit, I18nFormat format )
{
EventQueryParams params = getFromUrl( program, stage, startDate, endDate, dimension, filter, null, null, null, null, null, format );
+ params.setSortOrder( sortOrder );
params.setLimit( limit );
return 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-10-02 14:21:56 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2013-10-02 14:40:51 +0000
@@ -79,7 +79,7 @@
// ---------------------------------------------------------------------
sql += getFromWhereClause( params );
-
+
// ---------------------------------------------------------------------
// Group by
// ---------------------------------------------------------------------
@@ -87,6 +87,15 @@
sql += "group by " + getSelectColumns( params ) + " ";
// ---------------------------------------------------------------------
+ // Sort order
+ // ---------------------------------------------------------------------
+
+ if ( params.hasSortOrder() )
+ {
+ sql += "order by value " + params.getSortOrder().toString().toLowerCase() + " ";
+ }
+
+ // ---------------------------------------------------------------------
// Limit
// ---------------------------------------------------------------------
=== 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-10-02 14:21:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java 2013-10-02 14:40:51 +0000
@@ -33,6 +33,7 @@
import javax.servlet.http.HttpServletResponse;
import org.hisp.dhis.analytics.IllegalQueryException;
+import org.hisp.dhis.analytics.SortOrder;
import org.hisp.dhis.analytics.event.EventAnalyticsService;
import org.hisp.dhis.analytics.event.EventQueryParams;
import org.hisp.dhis.api.utils.ContextUtils;
@@ -79,10 +80,11 @@
@RequestParam Set<String> dimension,
@RequestParam(required=false) Set<String> filter,
@RequestParam(required=false) Integer limit,
+ @RequestParam(required=false) SortOrder sortOrder,
Model model,
HttpServletResponse response ) throws Exception
{
- EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, limit, i18nManager.getI18nFormat() );
+ EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, sortOrder, limit, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getAggregatedEventData( params );
@@ -100,10 +102,11 @@
@RequestParam Set<String> dimension,
@RequestParam(required=false) Set<String> filter,
@RequestParam(required=false) Integer limit,
+ @RequestParam(required=false) SortOrder sortOrder,
Model model,
HttpServletResponse response ) throws Exception
{
- EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, limit, i18nManager.getI18nFormat() );
+ EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, sortOrder, limit, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xls", true );
Grid grid = analyticsService.getAggregatedEventData( params );