dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24284
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11875: expanded EventStore/EventService to have more options (get by programstage, ou, etc). Made it pos...
------------------------------------------------------------
revno: 11875
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-09-03 11:40:41 +0200
message:
expanded EventStore/EventService to have more options (get by programstage, ou, etc). Made it possible to get by programStage in EventController, either program or programStage must be provided.
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventStore.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/event/BaseEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java 2013-09-03 08:42:56 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java 2013-09-03 09:40:41 +0000
@@ -347,15 +347,48 @@
}
@Override
- public Events getEvents( Program program )
- {
- return getEvents( program, null );
- }
-
- @Override
public Events getEvents( Program program, OrganisationUnit organisationUnit )
{
- ProgramStage programStage = program.getProgramStageByStage( 1 );
+ List<Event> eventList = eventStore.getAll( program, organisationUnit );
+ Events events = new Events();
+ events.setEvents( eventList );
+
+ return events;
+ }
+
+ @Override
+ public Events getEvents( Program program, OrganisationUnit organisationUnit, Date startDate, Date endDate )
+ {
+ List<Event> eventList = eventStore.getAll( program, organisationUnit, startDate, endDate );
+ Events events = new Events();
+ events.setEvents( eventList );
+
+ return events;
+ }
+
+ @Override
+ public Events getEvents( ProgramStage programStage, OrganisationUnit organisationUnit )
+ {
+ List<Event> eventList = eventStore.getAll( programStage, organisationUnit );
+ Events events = new Events();
+ events.setEvents( eventList );
+
+ return events;
+ }
+
+ @Override
+ public Events getEvents( ProgramStage programStage, OrganisationUnit organisationUnit, Date startDate, Date endDate )
+ {
+ List<Event> eventList = eventStore.getAll( programStage, organisationUnit, startDate, endDate );
+ Events events = new Events();
+ events.setEvents( eventList );
+
+ return events;
+ }
+
+ @Override
+ public Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit )
+ {
List<Event> eventList = eventStore.getAll( program, programStage, organisationUnit );
Events events = new Events();
events.setEvents( eventList );
@@ -364,10 +397,19 @@
}
@Override
- public Events getEvents( Program program, OrganisationUnit organisationUnit, Date start, Date end )
- {
- ProgramStage programStage = program.getProgramStageByStage( 1 );
- List<Event> eventList = eventStore.getAll( program, programStage, organisationUnit, start, end );
+ public Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, Date startDate, Date endDate )
+ {
+ List<Event> eventList = eventStore.getAll( program, programStage, organisationUnit, startDate, endDate );
+ Events events = new Events();
+ events.setEvents( eventList );
+
+ return events;
+ }
+
+ @Override
+ public Events getEvents( List<Program> programs, List<ProgramStage> programStages, List<OrganisationUnit> organisationUnits, Date startDate, Date endDate )
+ {
+ List<Event> eventList = eventStore.getAll( programs, programStages, organisationUnits, startDate, endDate );
Events events = new Events();
events.setEvents( eventList );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java 2013-09-03 09:40:41 +0000
@@ -40,7 +40,7 @@
private String dataElement;
- private Boolean providedElsewhere = false;
+ private Boolean providedElsewhere;
public DataValue()
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java 2013-09-03 08:42:56 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java 2013-09-03 09:40:41 +0000
@@ -57,6 +57,24 @@
}
@Override
+ public List<Event> getAll( Program program, OrganisationUnit organisationUnit, Date startDate, Date endDate )
+ {
+ return getAll( Arrays.asList( program ), new ArrayList<ProgramStage>(), Arrays.asList( organisationUnit ), startDate, endDate );
+ }
+
+ @Override
+ public List<Event> getAll( ProgramStage programStage, OrganisationUnit organisationUnit )
+ {
+ return getAll( new ArrayList<Program>(), Arrays.asList( programStage ), Arrays.asList( organisationUnit ), null, null );
+ }
+
+ @Override
+ public List<Event> getAll( ProgramStage programStage, OrganisationUnit organisationUnit, Date startDate, Date endDate )
+ {
+ return getAll( new ArrayList<Program>(), Arrays.asList( programStage ), Arrays.asList( organisationUnit ), startDate, endDate );
+ }
+
+ @Override
public List<Event> getAll( Program program, ProgramStage programStage, OrganisationUnit organisationUnit )
{
return getAll( Arrays.asList( program ), Arrays.asList( programStage ), Arrays.asList( organisationUnit ), null, null );
@@ -69,6 +87,18 @@
}
@Override
+ public List<Event> getAll( Program program, List<ProgramStage> programStages, OrganisationUnit organisationUnit )
+ {
+ return getAll( Arrays.asList( program ), programStages, Arrays.asList( organisationUnit ), null, null );
+ }
+
+ @Override
+ public List<Event> getAll( Program program, List<ProgramStage> programStages, OrganisationUnit organisationUnit, Date startDate, Date endDate )
+ {
+ return getAll( Arrays.asList( program ), programStages, Arrays.asList( organisationUnit ), startDate, endDate );
+ }
+
+ @Override
public List<Event> getAll( List<Program> programs, List<ProgramStage> programStages, List<OrganisationUnit> organisationUnits, Date startDate, Date endDate )
{
List<Event> events = new ArrayList<Event>();
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java 2013-09-02 10:37:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java 2013-09-03 09:40:41 +0000
@@ -32,11 +32,13 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageInstance;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
+import java.util.List;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -51,11 +53,19 @@
ImportSummaries saveEventsJson( InputStream inputStream ) throws IOException;
- Events getEvents( Program program );
-
Events getEvents( Program program, OrganisationUnit organisationUnit );
- Events getEvents( Program program, OrganisationUnit organisationUnit, Date start, Date end );
+ Events getEvents( Program program, OrganisationUnit organisationUnit, Date startDate, Date endDate );
+
+ Events getEvents( ProgramStage programStage, OrganisationUnit organisationUnit );
+
+ Events getEvents( ProgramStage programStage, OrganisationUnit organisationUnit, Date startDate, Date endDate );
+
+ Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit );
+
+ Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, Date startDate, Date endDate );
+
+ Events getEvents( List<Program> programs, List<ProgramStage> programStages, List<OrganisationUnit> organisationUnits, Date startDate, Date endDate );
Event getEvent( String uid );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventStore.java 2013-09-03 08:42:56 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventStore.java 2013-09-03 09:40:41 +0000
@@ -42,10 +42,20 @@
{
List<Event> getAll( Program program, OrganisationUnit organisationUnit );
+ List<Event> getAll( Program program, OrganisationUnit organisationUnit, Date startDate, Date endDate );
+
+ List<Event> getAll( ProgramStage programStage, OrganisationUnit organisationUnit );
+
+ List<Event> getAll( ProgramStage programStage, OrganisationUnit organisationUnit, Date startDate, Date endDate );
+
List<Event> getAll( Program program, ProgramStage programStage, OrganisationUnit organisationUnit );
List<Event> getAll( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, Date startDate, Date endDate );
+ List<Event> getAll( Program program, List<ProgramStage> programStages, OrganisationUnit organisationUnit );
+
+ List<Event> getAll( Program program, List<ProgramStage> programStages, OrganisationUnit organisationUnit, Date startDate, Date endDate );
+
List<Event> getAll( List<Program> programs, List<ProgramStage> programStages, List<OrganisationUnit> organisationUnits,
Date startDate, Date endDate );
}
=== 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 2013-09-02 10:37:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2013-09-03 09:40:41 +0000
@@ -40,6 +40,7 @@
import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
@@ -51,7 +52,7 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
-import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -63,7 +64,7 @@
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Controller
-@RequestMapping( value = EventController.RESOURCE_PATH )
+@RequestMapping(value = EventController.RESOURCE_PATH)
public class EventController
{
public static final String RESOURCE_PATH = "/events";
@@ -82,22 +83,25 @@
// Controller
// -------------------------------------------------------------------------
- @RequestMapping( value = "", method = RequestMethod.GET )
+ @RequestMapping(value = "", method = RequestMethod.GET)
public String getEvents(
- @RequestParam( "program" ) String programUid,
- @RequestParam( value = "orgUnit" ) String orgUnitUid,
- @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date startDate,
- @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
+ @RequestParam( value = "program", required = false ) String programUid,
+ @RequestParam(value = "programStage", required = false) String programStageUid,
+ @RequestParam(value = "orgUnit") String orgUnitUid,
+ @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
+ @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
@RequestParam Map<String, String> parameters, Model model, HttpServletRequest request,
HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
Program program = manager.get( Program.class, programUid );
+ ProgramStage programStage = manager.get( ProgramStage.class, programStageUid );
OrganisationUnit organisationUnit;
- if ( program == null )
+ if ( program == null && programStage == null )
{
- throw new NotFoundException( "Program", programUid );
+ throw new HttpServerErrorException( HttpStatus.BAD_REQUEST,
+ "Both program and programStage is invalid or missing, needs at least one." );
}
organisationUnit = manager.get( OrganisationUnit.class, orgUnitUid );
@@ -118,12 +122,20 @@
throw new NotFoundException( "OrganisationUnit", programUid );
}
- if ( program.isRegistration() || !program.isSingleEvent() )
- {
- throw new HttpClientErrorException( HttpStatus.BAD_REQUEST, "Only single event with no registration is currently supported." );
- }
+ Events events;
- Events events = eventService.getEvents( program, organisationUnit, startDate, endDate );
+ if ( program != null && programStage != null )
+ {
+ events = eventService.getEvents( program, programStage, organisationUnit, startDate, endDate );
+ }
+ else if ( program != null )
+ {
+ events = eventService.getEvents( program, organisationUnit, startDate, endDate );
+ }
+ else
+ {
+ events = eventService.getEvents( programStage, organisationUnit, startDate, endDate );
+ }
if ( options.hasLinks() )
{