dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24864
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12232: require Event.event for updating repeatable stages, updated tests also
------------------------------------------------------------
revno: 12232
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-25 10:02:58 +0200
message:
require Event.event for updating repeatable stages, updated tests also
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/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.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 2013-09-24 09:10:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-09-25 08:02:58 +0000
@@ -233,9 +233,18 @@
{
programStageInstance = programStageInstanceService.getProgramStageInstance( programInstance, programStage );
}
+
else
{
- return new ImportSummary( ImportStatus.ERROR, "ERROR!" );
+ if ( event.getEvent() != null )
+ {
+ programStageInstance = programStageInstanceService.getProgramStageInstance( event.getEvent() );
+
+ if ( programStageInstance == null )
+ {
+ return new ImportSummary( ImportStatus.ERROR, "Event.event did not point to a valid event" );
+ }
+ }
}
}
}
=== 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 2013-09-24 09:10:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java 2013-09-25 08:02:58 +0000
@@ -51,7 +51,6 @@
import org.hisp.dhis.program.ProgramStageDataElementService;
import org.hisp.dhis.program.ProgramStageInstanceService;
import org.hisp.dhis.user.UserService;
-import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -146,7 +145,6 @@
programStageA = createProgramStage( 'A', 0 );
programStageB = createProgramStage( 'B', 0 );
programStageB.setIrregular( true );
- programStageB.setAutoGenerateEvent( true );
manager.save( programStageA );
manager.save( programStageB );
@@ -170,6 +168,7 @@
programStageB.getProgramStageDataElements().add( programStageDataElement );
programStageB.setProgram( programA );
+ programStageB.setMinDaysFromStart( 2 );
programA.getProgramStages().add( programStageA );
programA.getProgramStages().add( programStageB );
@@ -233,20 +232,58 @@
}
@Test
- @Ignore
- public void testSaveWithEnrollmentShouldNotFail()
- {
- Enrollment enrollment = createEnrollment( programA.getUid(), personMaleA.getPerson() );
- ImportSummary importSummary = enrollmentService.saveEnrollment( enrollment );
- assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
-
- Event event = createEvent( programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementA.getUid() );
- importSummary = eventService.saveEvent( event );
- assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
-
- event = createEvent( programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementB.getUid() );
- importSummary = eventService.saveEvent( event );
- assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ public void testSaveWithoutEventIdShouldCreateNewRepeatableEvent()
+ {
+ Enrollment enrollment = createEnrollment( programA.getUid(), personMaleA.getPerson() );
+ ImportSummary importSummary = enrollmentService.saveEnrollment( enrollment );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ Event event = createEvent( programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementA.getUid() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ event = createEvent( programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementB.getUid() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 2, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+
+ event = createEvent( programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementB.getUid() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 3, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ }
+
+ @Test
+ public void testSaveWithEventIdShouldNotCreateAdditionalRepeatableEvents()
+ {
+ Enrollment enrollment = createEnrollment( programA.getUid(), personMaleA.getPerson() );
+ ImportSummary importSummary = enrollmentService.saveEnrollment( enrollment );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ Event event = createEvent( programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementA.getUid() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ event = createEvent( programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementB.getUid() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 2, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+
+ event = createEvent( programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementB.getUid() );
+ event.setEvent( importSummary.getReference() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 2, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+
+ event = createEvent( programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson(), dataElementA.getUid() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 2, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
}
private Enrollment createEnrollment( String program, String person )