dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34816
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17862: factor out event/enrollment import from deserialization, makes sure that exceptions are not swall...
------------------------------------------------------------
revno: 17862
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-02 15:37:39 +0100
message:
factor out event/enrollment import from deserialization, makes sure that exceptions are not swallowed by deserialization exceptions
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.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/enrollment/JacksonEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java 2014-11-06 13:26:50 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java 2015-01-02 14:37:39 +0000
@@ -54,25 +54,25 @@
private final static ObjectMapper jsonMapper = new ObjectMapper();
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromXml( InputStream inputStream, Class<?> clazz ) throws IOException
{
return (T) xmlMapper.readValue( inputStream, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromXml( String input, Class<?> clazz ) throws IOException
{
return (T) xmlMapper.readValue( input, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromJson( InputStream inputStream, Class<?> clazz ) throws IOException
{
return (T) jsonMapper.readValue( inputStream, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromJson( String input, Class<?> clazz ) throws IOException
{
return (T) jsonMapper.readValue( input, clazz );
@@ -97,19 +97,21 @@
{
ImportSummaries importSummaries = new ImportSummaries();
String input = StreamUtils.copyToString( inputStream, Charset.forName( "UTF-8" ) );
+ Enrollments enrollments = new Enrollments();
try
{
- Enrollments enrollments = fromJson( input, Enrollments.class );
-
- for ( Enrollment enrollment : enrollments.getEnrollments() )
- {
- importSummaries.addImportSummary( addEnrollment( enrollment ) );
- }
+ Enrollments fromJson = fromJson( input, Enrollments.class );
+ enrollments.getEnrollments().addAll( fromJson.getEnrollments() );
}
catch ( Exception ex )
{
Enrollment enrollment = fromJson( input, Enrollment.class );
+ enrollments.getEnrollments().add( enrollment );
+ }
+
+ for ( Enrollment enrollment : enrollments.getEnrollments() )
+ {
importSummaries.addImportSummary( addEnrollment( enrollment ) );
}
@@ -121,19 +123,21 @@
{
ImportSummaries importSummaries = new ImportSummaries();
String input = StreamUtils.copyToString( inputStream, Charset.forName( "UTF-8" ) );
+ Enrollments enrollments = new Enrollments();
try
{
- Enrollments enrollments = fromXml( input, Enrollments.class );
-
- for ( Enrollment enrollment : enrollments.getEnrollments() )
- {
- importSummaries.addImportSummary( addEnrollment( enrollment ) );
- }
+ Enrollments fromJson = fromXml( input, Enrollments.class );
+ enrollments.getEnrollments().addAll( fromJson.getEnrollments() );
}
catch ( Exception ex )
{
Enrollment enrollment = fromXml( input, Enrollment.class );
+ enrollments.getEnrollments().add( enrollment );
+ }
+
+ for ( Enrollment enrollment : enrollments.getEnrollments() )
+ {
importSummaries.addImportSummary( addEnrollment( enrollment ) );
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java 2014-11-20 13:34:47 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java 2015-01-02 14:37:39 +0000
@@ -28,10 +28,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
@@ -44,9 +43,9 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StreamUtils;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
/**
* Implementation of EventService that uses Jackson for serialization and deserialization.
@@ -66,25 +65,25 @@
private final static ObjectMapper jsonMapper = new ObjectMapper();
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromXml( InputStream inputStream, Class<?> clazz ) throws IOException
{
return (T) xmlMapper.readValue( inputStream, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromXml( String input, Class<?> clazz ) throws IOException
{
return (T) xmlMapper.readValue( input, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromJson( InputStream inputStream, Class<?> clazz ) throws IOException
{
return (T) jsonMapper.readValue( inputStream, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromJson( String input, Class<?> clazz ) throws IOException
{
return (T) jsonMapper.readValue( input, clazz );
@@ -122,18 +121,21 @@
notifier.clear( taskId ).notify( taskId, "Importing events" );
Timer timer = new SystemTimer().start();
+ Events events = new Events();
try
{
- Events events = fromXml( input, Events.class );
- importSummaries = addEvents( events.getEvents(), importOptions );
+ Events fromXml = fromXml( input, Events.class );
+ events.getEvents().addAll( fromXml.getEvents() );
}
catch ( Exception ex )
{
Event event = fromXml( input, Event.class );
- importSummaries.addImportSummary( addEvent( event, importOptions ) );
+ events.getEvents().add( event );
}
+ importSummaries = addEvents( events.getEvents(), importOptions );
+
timer.stop();
if ( taskId != null )
@@ -184,20 +186,21 @@
notifier.clear( taskId ).notify( taskId, "Importing events" );
Timer timer = new SystemTimer().start();
+ Events events = new Events();
try
{
- Events events = fromJson( input, Events.class );
- importSummaries = addEvents( events.getEvents(), importOptions );
+ Events fromXml = fromXml( input, Events.class );
+ events.getEvents().addAll( fromXml.getEvents() );
}
catch ( Exception ex )
{
- log.debug( ex );
-
- Event event = fromJson( input, Event.class );
- importSummaries.addImportSummary( addEvent( event, importOptions ) );
+ Event event = fromXml( input, Event.class );
+ events.getEvents().add( event );
}
+ importSummaries = addEvents( events.getEvents(), importOptions );
+
timer.stop();
if ( taskId != null )