dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36256
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18569: Event service, moved org unit selection logic to service layer from controller
------------------------------------------------------------
revno: 18569
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-03-10 15:44:53 +0100
message:
Event service, moved org unit selection logic to service layer from controller
modified:
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/EventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.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-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-10 14:29:40 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-03-10 14:44:53 +0000
@@ -28,14 +28,25 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import static org.hisp.dhis.system.notification.NotificationLevel.ERROR;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.hisp.dhis.common.CodeGenerator;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.IdentifiableProperty;
+import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dxf2.common.IdSchemes;
@@ -78,18 +89,8 @@
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.hisp.dhis.system.notification.NotificationLevel.ERROR;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -393,15 +394,35 @@
// -------------------------------------------------------------------------
@Override
- public Events getEvents( Program program, OrganisationUnit organisationUnit )
+ public Events getEvents( Program program, OrganisationUnit organisationUnit, OrganisationUnitSelectionMode orgUnitSelectionMode )
{
- return getEvents( program, null, null, null, Arrays.asList( organisationUnit ), null, null, null, null, null );
+ return getEvents( program, null, null, null, organisationUnit, orgUnitSelectionMode, null, null, null, null, null );
}
@Override
- public Events getEvents( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp,
- List<OrganisationUnit> organisationUnits, TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status, IdSchemes idSchemes )
+ public Events getEvents( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp, OrganisationUnit orgUnit,
+ OrganisationUnitSelectionMode orgUnitSelectionMode, TrackedEntityInstance trackedEntityInstance,
+ Date startDate, Date endDate, EventStatus status, IdSchemes idSchemes )
{
+ List<OrganisationUnit> organisationUnits = new ArrayList<>();
+
+ if ( orgUnit != null )
+ {
+ if ( OrganisationUnitSelectionMode.DESCENDANTS.equals( orgUnitSelectionMode ) )
+ {
+ organisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( orgUnit.getUid() ) );
+ }
+ else if ( OrganisationUnitSelectionMode.CHILDREN.equals( orgUnitSelectionMode ) )
+ {
+ organisationUnits.add( orgUnit );
+ organisationUnits.addAll( orgUnit.getChildren() );
+ }
+ else // SELECTED
+ {
+ organisationUnits.add( orgUnit );
+ }
+ }
+
List<Event> eventList = eventStore.getEvents( program, programStage, programStatus, followUp, organisationUnits,
trackedEntityInstance, startDate, endDate, status, idSchemes );
=== 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-10 14:29:40 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2015-03-10 14:44:53 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
@@ -55,10 +56,11 @@
// READ
// -------------------------------------------------------------------------
- Events getEvents( Program program, OrganisationUnit organisationUnit );
+ Events getEvents( Program program, OrganisationUnit organisationUnit, OrganisationUnitSelectionMode orgUnitSelectionMode );
- Events getEvents( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp, List<OrganisationUnit> organisationUnit,
- TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status, IdSchemes idSchemes );
+ Events getEvents( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp, OrganisationUnit orgUnit,
+ OrganisationUnitSelectionMode orgUnitSelectionMode, TrackedEntityInstance trackedEntityInstance,
+ Date startDate, Date endDate, EventStatus status, IdSchemes idSchemes );
Event getEvent( String uid );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java 2015-03-10 14:29:40 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java 2015-03-10 14:44:53 +0000
@@ -33,6 +33,7 @@
import java.util.List;
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.dxf2.events.event.Event;
import org.hisp.dhis.dxf2.events.event.EventService;
import org.hisp.dhis.dxf2.events.event.Events;
@@ -51,7 +52,6 @@
public class AbstractEventRowService
implements EventRowService
{
-
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -66,14 +66,14 @@
private TrackedEntityInstanceService trackedEntityInstanceService;
@Override
- public EventRows getEventRows( Program program, List<OrganisationUnit> organisationUnits,
+ public EventRows getEventRows( Program program, OrganisationUnit orgUnit, OrganisationUnitSelectionMode orgUnitSelectionMode,
ProgramStatus programStatus, EventStatus eventStatus, Date startDate, Date endDate )
{
List<EventRow> eventRowList = new ArrayList<EventRow>();
EventRows eventRows = new EventRows();
- Events events = eventService.getEvents( program, null, programStatus, null, organisationUnits, null, startDate,
- endDate, eventStatus, null );
+ Events events = eventService.getEvents( program, null, programStatus, null, orgUnit, orgUnitSelectionMode,
+ null, startDate, endDate, eventStatus, null );
for ( Event event : events.getEvents() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java 2015-03-10 14:44:53 +0000
@@ -29,8 +29,8 @@
*/
import java.util.Date;
-import java.util.List;
+import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
@@ -38,16 +38,9 @@
/**
* @author Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
- *
*/
public interface EventRowService
{
-
- // -------------------------------------------------------------------------
- // READ
- // -------------------------------------------------------------------------
-
- EventRows getEventRows( Program program, List<OrganisationUnit> organisationUnits, ProgramStatus programStatus,
- EventStatus eventStatus, Date startDate, Date endDate );
-
+ EventRows getEventRows( Program program, OrganisationUnit orgUnit, OrganisationUnitSelectionMode orgUnitSelectionMode,
+ ProgramStatus programStatus, EventStatus eventStatus, Date startDate, Date endDate );
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java 2015-03-10 14:29:40 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java 2015-03-10 14:44:53 +0000
@@ -31,13 +31,13 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import java.util.Arrays;
import java.util.HashSet;
import org.hamcrest.CoreMatchers;
import org.hibernate.SessionFactory;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dxf2.events.enrollment.Enrollment;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentService;
@@ -234,7 +234,7 @@
importSummary = eventService.addEvent( event );
assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
- assertEquals( 1, eventService.getEvents( programA, programStageA, null, null, Arrays.asList( organisationUnitA ), null, null, null, null, null ).getEvents().size() );
+ assertEquals( 1, eventService.getEvents( programA, programStageA, null, null, organisationUnitA, OrganisationUnitSelectionMode.SELECTED, null, null, null, null, null ).getEvents().size() );
}
@Test
@@ -255,14 +255,14 @@
assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
sessionFactory.getCurrentSession().flush();
- assertEquals( 2, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ assertEquals( 2, eventService.getEvents( programA, organisationUnitA, OrganisationUnitSelectionMode.SELECTED ).getEvents().size() );
event = createEvent( programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(),
trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid() );
importSummary = eventService.addEvent( event );
assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
- assertEquals( 3, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ assertEquals( 3, eventService.getEvents( programA, organisationUnitA, OrganisationUnitSelectionMode.SELECTED ).getEvents().size() );
}
@Test
@@ -283,7 +283,7 @@
assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
sessionFactory.getCurrentSession().flush();
- assertEquals( 2, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ assertEquals( 2, eventService.getEvents( programA, organisationUnitA, OrganisationUnitSelectionMode.SELECTED ).getEvents().size() );
event = createEvent( programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(),
trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid() );
@@ -291,14 +291,14 @@
importSummary = eventService.addEvent( event );
assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
- assertEquals( 2, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ assertEquals( 2, eventService.getEvents( programA, organisationUnitA, OrganisationUnitSelectionMode.SELECTED ).getEvents().size() );
event = createEvent( programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(),
trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid() );
importSummary = eventService.addEvent( event );
assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
- assertEquals( 2, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ assertEquals( 2, eventService.getEvents( programA, organisationUnitA, OrganisationUnitSelectionMode.SELECTED ).getEvents().size() );
}
private Enrollment createEnrollment( String program, String person )
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java 2015-03-10 14:44:53 +0000
@@ -37,6 +37,7 @@
import org.hamcrest.CoreMatchers;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dxf2.events.enrollment.Enrollment;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentService;
@@ -188,19 +189,19 @@
importSummary = eventService.addEvent( event );
assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
- assertEquals( 1, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
-
- event = createEvent( programA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance() );
- importSummary = eventService.addEvent( event );
- assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
-
- assertEquals( 1, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
-
- event = createEvent( programA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance() );
- importSummary = eventService.addEvent( event );
- assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
-
- assertEquals( 1, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ assertEquals( 1, eventService.getEvents( programA, organisationUnitA, OrganisationUnitSelectionMode.SELECTED ).getEvents().size() );
+
+ event = createEvent( programA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance() );
+ importSummary = eventService.addEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 1, eventService.getEvents( programA, organisationUnitA, OrganisationUnitSelectionMode.SELECTED ).getEvents().size() );
+
+ event = createEvent( programA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance() );
+ importSummary = eventService.addEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 1, eventService.getEvents( programA, organisationUnitA, OrganisationUnitSelectionMode.SELECTED ).getEvents().size() );
}
@Test
=== 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-10 14:29:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-03-10 14:44:53 +0000
@@ -31,10 +31,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@@ -157,7 +155,6 @@
Program pr = manager.get( Program.class, program );
ProgramStage prs = manager.get( ProgramStage.class, programStage );
- List<OrganisationUnit> organisationUnits = new ArrayList<>();
TrackedEntityInstance tei = null;
OrganisationUnit ou = null;
@@ -183,24 +180,7 @@
}
}
- if ( ou != null )
- {
- if ( OrganisationUnitSelectionMode.DESCENDANTS.equals( ouMode ) )
- {
- organisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( ou.getUid() ) );
- }
- else if ( OrganisationUnitSelectionMode.CHILDREN.equals( ouMode ) )
- {
- organisationUnits.add( ou );
- organisationUnits.addAll( ou.getChildren() );
- }
- else // SELECTED
- {
- organisationUnits.add( ou );
- }
- }
-
- Events events = eventService.getEvents( pr, prs, programStatus, followUp, organisationUnits, tei, startDate, endDate, status, idSchemes );
+ Events events = eventService.getEvents( pr, prs, programStatus, followUp, ou, ouMode, tei, startDate, endDate, status, idSchemes );
if ( options.hasPaging() )
{
@@ -250,7 +230,6 @@
Program pr = manager.get( Program.class, program );
ProgramStage prs = manager.get( ProgramStage.class, programStage );
- List<OrganisationUnit> organisationUnits = new ArrayList<>();
TrackedEntityInstance tei = null;
OrganisationUnit ou = null;
@@ -276,24 +255,7 @@
}
}
- if ( ou != null )
- {
- if ( OrganisationUnitSelectionMode.DESCENDANTS.equals( ouMode ) )
- {
- organisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( ou.getUid() ) );
- }
- else if ( OrganisationUnitSelectionMode.CHILDREN.equals( ouMode ) )
- {
- organisationUnits.add( ou );
- organisationUnits.addAll( ou.getChildren() );
- }
- else // SELECTED
- {
- organisationUnits.add( ou );
- }
- }
-
- Events events = eventService.getEvents( pr, prs, programStatus, followUp, organisationUnits, tei, startDate, endDate, status, idSchemes );
+ Events events = eventService.getEvents( pr, prs, programStatus, followUp, ou, ouMode, tei, startDate, endDate, status, idSchemes );
if ( options.hasLinks() )
{
@@ -341,7 +303,6 @@
WebOptions options = new WebOptions( parameters );
Program pr = manager.get( Program.class, program );
- List<OrganisationUnit> organisationUnits = new ArrayList<>();
OrganisationUnit ou = null;
if ( orgUnit != null )
@@ -349,24 +310,7 @@
ou = manager.get( OrganisationUnit.class, orgUnit );
}
- if ( ou != null )
- {
- if ( OrganisationUnitSelectionMode.DESCENDANTS.equals( ouMode ) )
- {
- organisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( ou.getUid() ) );
- }
- else if ( OrganisationUnitSelectionMode.CHILDREN.equals( ouMode ) )
- {
- organisationUnits.add( ou );
- organisationUnits.addAll( ou.getChildren() );
- }
- else // SELECTED
- {
- organisationUnits.add( ou );
- }
- }
-
- EventRows eventRows = eventRowService.getEventRows( pr, organisationUnits, programStatus, eventStatus, startDate, endDate );
+ EventRows eventRows = eventRowService.getEventRows( pr, ou, ouMode, programStatus, eventStatus, startDate, endDate );
if ( options.hasPaging() )
{