dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28572
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14279: paging for events
------------------------------------------------------------
revno: 14279
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Tue 2014-03-18 15:20:02 +0100
message:
paging for events
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2014-03-18 14:20:02 +0000
@@ -33,6 +33,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.google.common.collect.Lists;
+
import org.hisp.dhis.attribute.Attribute;
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.common.DimensionalObject;
@@ -55,6 +56,7 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.Section;
import org.hisp.dhis.document.Document;
+import org.hisp.dhis.dxf2.events.event.Event;
import org.hisp.dhis.dxf2.schema.Schema;
import org.hisp.dhis.filter.MetaDataFilter;
import org.hisp.dhis.indicator.Indicator;
@@ -199,6 +201,8 @@
private List<RelationshipType> relationshipTypes = new ArrayList<RelationshipType>();
private List<MetaDataFilter> metaDataFilters = new ArrayList<MetaDataFilter>();
+
+ private List<Event> events = new ArrayList<Event>();
private List<TrackedEntity> trackedEntities = new ArrayList<TrackedEntity>();
@@ -845,6 +849,19 @@
{
this.relationshipTypes = relationshipTypes;
}
+
+ @JsonProperty
+ @JacksonXmlElementWrapper( localName = "events", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "event", namespace = DxfNamespaces.DXF_2_0 )
+ public List<Event> getEvents()
+ {
+ return events;
+ }
+
+ public void setEvents( List<Event> events )
+ {
+ this.events = events;
+ }
@JsonProperty
@JacksonXmlElementWrapper( localName = "trackedEntities", namespace = DxfNamespaces.DXF_2_0 )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2014-03-18 14:20:02 +0000
@@ -28,10 +28,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.api.controller.WebMetaData;
import org.hisp.dhis.api.controller.WebOptions;
import org.hisp.dhis.api.controller.exception.NotFoundException;
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.common.PagerUtils;
import org.hisp.dhis.dxf2.events.event.Event;
import org.hisp.dhis.dxf2.events.event.EventService;
import org.hisp.dhis.dxf2.events.event.Events;
@@ -66,6 +69,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -73,6 +77,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
+
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
@@ -127,7 +132,9 @@
@RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
@RequestParam Map<String, String> parameters, Model model, HttpServletRequest request ) throws NotFoundException
{
- WebOptions options = new WebOptions( parameters );
+ WebOptions options = new WebOptions( parameters );
+ WebMetaData metaData = new WebMetaData();
+
Program program = manager.get( Program.class, programUid );
ProgramStage programStage = manager.get( ProgramStage.class, programStageUid );
List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
@@ -164,8 +171,9 @@
model.addAttribute( "model", events );
model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
- return "events";
- }
+ return "events";
+ }
+
if ( rootOrganisationUnit == null )
{
@@ -187,19 +195,31 @@
}
Events events = eventService.getEvents( Arrays.asList( program ), Arrays.asList( programStage ), organisationUnits, trackedEntityInstance, startDate, endDate );
+
+ List<Event> eventList = new ArrayList<Event>( events.getEvents() );
if ( options.hasLinks() )
{
- for ( Event event : events.getEvents() )
+ for ( Event event : eventList )
{
event.setHref( ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + event.getEvent() );
}
}
+
+ if( options.hasPaging() )
+ {
+ Pager pager = new Pager( options.getPage(), eventList.size(), options.getPageSize() );
+ metaData.setPager( pager );
+ eventList = PagerUtils.pageCollection( eventList, pager );
+ }
+
+ metaData.setEvents( eventList );
- model.addAttribute( "model", events );
+ model.addAttribute( "model", metaData );
model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
- return "events";
+ return "events";
+
}
@RequestMapping( value = "/{uid}", method = RequestMethod.GET )