dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24346
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11918: support ?dryRun=true/false in EventController
------------------------------------------------------------
revno: 11918
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-04 15:18:44 +0200
message:
support ?dryRun=true/false in EventController
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.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/JacksonEventService.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/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java 2013-09-04 11:58:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java 2013-09-04 13:18:44 +0000
@@ -28,18 +28,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dxf2.InputValidationService;
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
import org.hisp.dhis.dxf2.importsummary.ImportStatus;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.ImportOptions;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.i18n.I18nManagerException;
@@ -60,6 +55,12 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -109,7 +110,7 @@
// Implementation
// -------------------------------------------------------------------------
- protected ImportSummary saveEvent( Event event )
+ protected ImportSummary saveEvent( Event event, ImportOptions importOptions )
{
Program program;
@@ -175,7 +176,7 @@
if ( program.getType() == Program.SINGLE_EVENT_WITHOUT_REGISTRATION )
{
- return saveSingleEventWithoutRegistration( program, organisationUnit, event );
+ return saveSingleEventWithoutRegistration( program, organisationUnit, event, importOptions );
}
else if ( program.getType() == Program.SINGLE_EVENT_WITH_REGISTRATION )
{
@@ -189,7 +190,7 @@
return new ImportSummary();
}
- private ImportSummary saveSingleEventWithoutRegistration( Program program, OrganisationUnit organisationUnit, Event event )
+ private ImportSummary saveSingleEventWithoutRegistration( Program program, OrganisationUnit organisationUnit, Event event, ImportOptions importOptions)
{
try
{
@@ -210,10 +211,15 @@
ImportSummary importSummary = new ImportSummary();
importSummary.setStatus( ImportStatus.SUCCESS );
- ProgramStageInstance programStageInstance = saveEventDate( program, organisationUnit, eventDate,
- event.getCompleted(), event.getCoordinate() );
-
- importSummary.setReference( programStageInstance.getUid() );
+ ProgramStageInstance programStageInstance = null;
+
+ if ( importOptions != null && !importOptions.isDryRun() )
+ {
+ programStageInstance = saveEventDate( program, organisationUnit, eventDate,
+ event.getCompleted(), event.getCoordinate() );
+
+ importSummary.setReference( programStageInstance.getUid() );
+ }
String storedBy = event.getStoredBy();
@@ -240,7 +246,11 @@
{
if ( validateDataElement( dataElement, dataValue.getValue(), importSummary ) )
{
- saveDataValue( programStageInstance, storedBy, dataElement, dataValue.getValue(), dataValue.getProvidedElsewhere() );
+ if ( importOptions != null && !importOptions.isDryRun() )
+ {
+ saveDataValue( programStageInstance, storedBy, dataElement, dataValue.getValue(), dataValue.getProvidedElsewhere() );
+ }
+
importSummary.getDataValueCount().incrementImported();
}
}
=== 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-04 11:58:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java 2013-09-04 13:18:44 +0000
@@ -49,14 +49,22 @@
{
ImportSummary saveEventXml( InputStream inputStream ) throws IOException;
+ ImportSummary saveEventXml( InputStream inputStream, ImportOptions importOptions ) throws IOException;
+
ImportSummaries saveEventsXml( InputStream inputStream ) throws IOException;
+ ImportSummaries saveEventsXml( InputStream inputStream, ImportOptions importOptions ) throws IOException;
+
ImportSummaries saveEventsXml( InputStream inputStream, TaskId taskId, ImportOptions importOptions ) throws IOException;
ImportSummary saveEventJson( InputStream inputStream ) throws IOException;
+ ImportSummary saveEventJson( InputStream inputStream, ImportOptions importOptions ) throws IOException;
+
ImportSummaries saveEventsJson( InputStream inputStream ) throws IOException;
+ ImportSummaries saveEventsJson( InputStream inputStream, ImportOptions importOptions ) throws IOException;
+
ImportSummaries saveEventsJson( InputStream inputStream, TaskId taskId, ImportOptions importOptions ) throws IOException;
Events getEvents( Program program, OrganisationUnit organisationUnit );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/JacksonEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/JacksonEventService.java 2013-09-04 11:58:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/JacksonEventService.java 2013-09-04 13:18:44 +0000
@@ -98,7 +98,13 @@
@Override
public ImportSummaries saveEventsXml( InputStream inputStream ) throws IOException
{
- return saveEventsXml( inputStream, null, ImportOptions.getDefaultImportOptions() );
+ return saveEventsXml( inputStream, null, null );
+ }
+
+ @Override
+ public ImportSummaries saveEventsXml( InputStream inputStream, ImportOptions importOptions ) throws IOException
+ {
+ return saveEventsXml( inputStream, null, importOptions );
}
@Override
@@ -116,13 +122,13 @@
for ( Event event : events.getEvents() )
{
- importSummaries.getImportSummaries().add( saveEvent( event ) );
+ importSummaries.getImportSummaries().add( saveEvent( event, importOptions ) );
}
}
catch ( Exception ex )
{
Event event = fromXml( input, Event.class );
- importSummaries.getImportSummaries().add( saveEvent( event ) );
+ importSummaries.getImportSummaries().add( saveEvent( event, importOptions ) );
}
notifier.notify( taskId, NotificationLevel.INFO, "Import done", true ).
@@ -134,14 +140,26 @@
@Override
public ImportSummary saveEventXml( InputStream inputStream ) throws IOException
{
+ return saveEventXml( inputStream, null );
+ }
+
+ @Override
+ public ImportSummary saveEventXml( InputStream inputStream, ImportOptions importOptions ) throws IOException
+ {
Event event = fromXml( inputStream, Event.class );
- return saveEvent( event );
+ return saveEvent( event, importOptions );
}
@Override
public ImportSummaries saveEventsJson( InputStream inputStream ) throws IOException
{
- return saveEventsJson( inputStream, null, ImportOptions.getDefaultImportOptions() );
+ return saveEventsJson( inputStream, null, null );
+ }
+
+ @Override
+ public ImportSummaries saveEventsJson( InputStream inputStream, ImportOptions importOptions ) throws IOException
+ {
+ return saveEventsJson( inputStream, null, importOptions );
}
@Override
@@ -159,13 +177,13 @@
for ( Event event : events.getEvents() )
{
- importSummaries.getImportSummaries().add( saveEvent( event ) );
+ importSummaries.getImportSummaries().add( saveEvent( event, importOptions ) );
}
}
catch ( Exception ex )
{
Event event = fromJson( input, Event.class );
- importSummaries.getImportSummaries().add( saveEvent( event ) );
+ importSummaries.getImportSummaries().add( saveEvent( event, importOptions ) );
}
notifier.notify( taskId, NotificationLevel.INFO, "Import done", true ).
@@ -177,7 +195,13 @@
@Override
public ImportSummary saveEventJson( InputStream inputStream ) throws IOException
{
+ return saveEventJson( inputStream, null );
+ }
+
+ @Override
+ public ImportSummary saveEventJson( InputStream inputStream, ImportOptions importOptions ) throws IOException
+ {
Event event = fromJson( inputStream, Event.class );
- return saveEvent( event );
+ return saveEvent( event, importOptions );
}
}
=== 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-04 12:31:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2013-09-04 13:18:44 +0000
@@ -201,17 +201,24 @@
if ( !importOptions.isAsync() )
{
- ImportSummaries importSummaries = eventService.saveEventsXml( inputStream );
+ ImportSummaries importSummaries = eventService.saveEventsXml( inputStream, importOptions );
for ( ImportSummary importSummary : importSummaries.getImportSummaries() )
{
- importSummary.setHref( ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+ if ( !importOptions.isDryRun() )
+ {
+ importSummary.setHref( ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+ }
}
if ( importSummaries.getImportSummaries().size() == 1 )
{
ImportSummary importSummary = importSummaries.getImportSummaries().get( 0 );
- response.setHeader( "Location", ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+
+ if ( !importOptions.isDryRun() )
+ {
+ response.setHeader( "Location", ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+ }
}
JacksonUtils.toXml( response.getOutputStream(), importSummaries );
@@ -233,17 +240,24 @@
if ( !importOptions.isAsync() )
{
- ImportSummaries importSummaries = eventService.saveEventsJson( inputStream );
+ ImportSummaries importSummaries = eventService.saveEventsJson( inputStream, importOptions );
for ( ImportSummary importSummary : importSummaries.getImportSummaries() )
{
- importSummary.setHref( ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+ if ( !importOptions.isDryRun() )
+ {
+ importSummary.setHref( ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+ }
}
if ( importSummaries.getImportSummaries().size() == 1 )
{
ImportSummary importSummary = importSummaries.getImportSummaries().get( 0 );
- response.setHeader( "Location", ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+
+ if ( !importOptions.isDryRun() )
+ {
+ response.setHeader( "Location", ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + importSummary.getReference() );
+ }
}
JacksonUtils.toJson( response.getOutputStream(), importSummaries );