dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36299
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18593: Event search. Added support for page and pageSize. Sorting events by lastupdated desc.
------------------------------------------------------------
revno: 18593
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-03-12 12:27:20 +0100
message:
Event search. Added support for page and pageSize. Sorting events by lastupdated desc.
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventSearchParams.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.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/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java 2015-03-12 10:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java 2015-03-12 11:27:20 +0000
@@ -76,7 +76,7 @@
private List<String> desc = new ArrayList<>();
private String organisationUnitMode;
-
+
private Integer page;
private Integer pageSize;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-03-12 11:03:32 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-03-12 11:27:20 +0000
@@ -430,9 +430,10 @@
return events;
}
+ @Override
public EventSearchParams getFromUrl( String program, String programStage, ProgramStatus programStatus, Boolean followUp, String orgUnit,
OrganisationUnitSelectionMode orgUnitSelectionMode, String trackedEntityInstance, Date startDate, Date endDate,
- EventStatus status, Date lastUpdated, IdSchemes idSchemes )
+ EventStatus status, Date lastUpdated, IdSchemes idSchemes, Integer page, Integer pageSize )
{
EventSearchParams params = new EventSearchParams();
@@ -472,6 +473,8 @@
params.setEventStatus( status );
params.setLastUpdated( lastUpdated );
params.setIdSchemes( idSchemes );
+ params.setPage( page );
+ params.setPageSize( pageSize );
return params;
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventSearchParams.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventSearchParams.java 2015-03-12 11:03:32 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventSearchParams.java 2015-03-12 11:27:20 +0000
@@ -68,6 +68,10 @@
private IdSchemes idSchemes;
+ private Integer page;
+
+ private Integer pageSize;
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -77,6 +81,30 @@
}
// -------------------------------------------------------------------------
+ // Logic
+ // -------------------------------------------------------------------------
+
+ public boolean isPaging()
+ {
+ return page != null || pageSize != null;
+ }
+
+ public int getPageWithDefault()
+ {
+ return page != null && page > 0 ? page : 1;
+ }
+
+ public int getPageSizeWithDefault()
+ {
+ return pageSize != null && pageSize >= 0 ? pageSize : 100;
+ }
+
+ public int getOffset()
+ {
+ return ( getPageWithDefault() - 1 ) * getPageSizeWithDefault();
+ }
+
+ // -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
@@ -199,4 +227,24 @@
{
this.idSchemes = idSchemes;
}
+
+ public Integer getPage()
+ {
+ return page;
+ }
+
+ public void setPage( Integer page )
+ {
+ this.page = page;
+ }
+
+ public Integer getPageSize()
+ {
+ return pageSize;
+ }
+
+ public void setPageSize( Integer pageSize )
+ {
+ this.pageSize = pageSize;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2015-03-12 11:03:32 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2015-03-12 11:27:20 +0000
@@ -56,7 +56,7 @@
EventSearchParams getFromUrl( String program, String programStage, ProgramStatus programStatus, Boolean followUp, String orgUnit,
OrganisationUnitSelectionMode orgUnitSelectionMode, String trackedEntityInstance, Date startDate, Date endDate,
- EventStatus status, Date lastUpdated, IdSchemes idSchemes );
+ EventStatus status, Date lastUpdated, IdSchemes idSchemes, Integer page, Integer pageSize );
Event getEvent( String uid );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2015-03-12 11:03:32 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2015-03-12 11:27:20 +0000
@@ -323,7 +323,16 @@
}
}
- sql += " order by psi_uid;";
+ sql += " order by psi.lastupdated desc ";
+
+ // ---------------------------------------------------------------------
+ // Paging
+ // ---------------------------------------------------------------------
+
+ if ( params.isPaging() )
+ {
+ sql += "limit " + params.getPageSizeWithDefault() + " offset " + params.getOffset();
+ }
return sql;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-03-12 11:03:32 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-03-12 11:27:20 +0000
@@ -145,6 +145,8 @@
@RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
@RequestParam( required = false ) EventStatus status,
@RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date lastUpdated,
+ @RequestParam( required = false ) Integer page,
+ @RequestParam( required = false ) Integer pageSize,
@RequestParam( required = false ) String attachment,
@RequestParam( required = false, defaultValue = "false" ) boolean skipHeader,
@RequestParam Map<String, String> parameters,
@@ -153,7 +155,7 @@
WebOptions options = new WebOptions( parameters );
EventSearchParams params = eventService.getFromUrl( program, programStage, programStatus, followUp, orgUnit, ouMode,
- trackedEntityInstance, startDate, endDate, status, lastUpdated, idSchemes );
+ trackedEntityInstance, startDate, endDate, status, lastUpdated, idSchemes, page, pageSize );
Events events = eventService.getEvents( params );
@@ -198,6 +200,8 @@
@RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
@RequestParam( required = false ) EventStatus status,
@RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date lastUpdated,
+ @RequestParam( required = false ) Integer page,
+ @RequestParam( required = false ) Integer pageSize,
@RequestParam( required = false ) boolean skipMeta,
@RequestParam( required = false ) String attachment,
@RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request )
@@ -205,7 +209,7 @@
WebOptions options = new WebOptions( parameters );
EventSearchParams params = eventService.getFromUrl( program, programStage, programStatus, followUp, orgUnit, ouMode,
- trackedEntityInstance, startDate, endDate, status, lastUpdated, idSchemes );
+ trackedEntityInstance, startDate, endDate, status, lastUpdated, idSchemes, page, pageSize );
Events events = eventService.getEvents( params );
@@ -254,7 +258,8 @@
{
WebOptions options = new WebOptions( parameters );
- EventSearchParams params = eventService.getFromUrl( program, null, programStatus, false, orgUnit, ouMode, null, startDate, endDate, null, null, null );
+ EventSearchParams params = eventService.getFromUrl( program, null, programStatus, false,
+ orgUnit, ouMode, null, startDate, endDate, null, null, null, null, null );
EventRows eventRows = eventRowService.getEventRows( params );