dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28858
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14486: support xml in renderService, extended crudController to support create/update/delete with acl ch...
------------------------------------------------------------
revno: 14486
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-03-27 12:55:28 +0100
message:
support xml in renderService, extended crudController to support create/update/delete with acl checks and writes/update/deletes through idObjectManager
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/RenderService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.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/render/DefaultRenderService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java 2014-03-25 15:38:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java 2014-03-27 11:55:28 +0000
@@ -34,6 +34,8 @@
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import java.io.IOException;
import java.io.InputStream;
@@ -48,9 +50,11 @@
{
private final ObjectMapper jsonMapper = new ObjectMapper();
+ private final XmlMapper xmlMapper = new XmlMapper();
+
public DefaultRenderService()
{
- configureObjectMapper();
+ configureObjectMappers();
}
//--------------------------------------------------------------------------
@@ -75,28 +79,53 @@
return jsonMapper.readValue( input, klass );
}
+ @Override
+ public <T> void toXml( OutputStream output, T value ) throws IOException
+ {
+
+ }
+
+ @Override
+ public <T> void toXml( OutputStream output, T value, Class<?> klass ) throws IOException
+ {
+
+ }
+
+ @Override
+ public <T> T fromXml( InputStream input, Class<T> klass ) throws IOException
+ {
+ return null;
+ }
+
//--------------------------------------------------------------------------
// Helpers
//--------------------------------------------------------------------------
- private void configureObjectMapper()
+ private void configureObjectMappers()
{
- jsonMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );
- jsonMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false );
- jsonMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false );
- jsonMapper.configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false );
- jsonMapper.configure( SerializationFeature.WRAP_EXCEPTIONS, true );
-
- jsonMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
- jsonMapper.configure( DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true );
- jsonMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );
-
- jsonMapper.disable( MapperFeature.AUTO_DETECT_FIELDS );
- jsonMapper.disable( MapperFeature.AUTO_DETECT_CREATORS );
- jsonMapper.disable( MapperFeature.AUTO_DETECT_GETTERS );
- jsonMapper.disable( MapperFeature.AUTO_DETECT_SETTERS );
- jsonMapper.disable( MapperFeature.AUTO_DETECT_IS_GETTERS );
+ ObjectMapper[] objectMappers = new ObjectMapper[]{ jsonMapper, xmlMapper };
+
+ for ( ObjectMapper objectMapper : objectMappers )
+ {
+ // objectMapper.setDateFormat( format );
+ objectMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );
+ objectMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false );
+ objectMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false );
+ objectMapper.configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false );
+ objectMapper.configure( SerializationFeature.WRAP_EXCEPTIONS, true );
+
+ objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
+ objectMapper.configure( DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true );
+ objectMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );
+
+ objectMapper.disable( MapperFeature.AUTO_DETECT_FIELDS );
+ objectMapper.disable( MapperFeature.AUTO_DETECT_CREATORS );
+ objectMapper.disable( MapperFeature.AUTO_DETECT_GETTERS );
+ objectMapper.disable( MapperFeature.AUTO_DETECT_SETTERS );
+ objectMapper.disable( MapperFeature.AUTO_DETECT_IS_GETTERS );
+ }
jsonMapper.getJsonFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES );
+ xmlMapper.configure( ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/RenderService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/RenderService.java 2014-03-25 15:38:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/RenderService.java 2014-03-27 11:55:28 +0000
@@ -42,4 +42,10 @@
<T> void toJson( OutputStream output, T value, Class<?> klass ) throws IOException;
<T> T fromJson( InputStream input, Class<T> klass ) throws IOException;
+
+ <T> void toXml( OutputStream output, T value ) throws IOException;
+
+ <T> void toXml( OutputStream output, T value, Class<?> klass ) throws IOException;
+
+ <T> T fromXml( InputStream input, Class<T> klass ) throws IOException;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2014-03-27 11:19:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2014-03-27 11:55:28 +0000
@@ -260,6 +260,9 @@
{
throw new CreateAccessDeniedException( "You don't have the proper permissions to create this object." );
}
+
+ T parsed = renderService.fromXml( request.getInputStream(), getEntityClass() );
+ manager.save( parsed );
}
@RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
@@ -269,6 +272,9 @@
{
throw new CreateAccessDeniedException( "You don't have the proper permissions to create this object." );
}
+
+ T parsed = renderService.fromJson( request.getInputStream(), getEntityClass() );
+ manager.save( parsed );
}
//--------------------------------------------------------------------------
@@ -286,6 +292,12 @@
{
throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
}
+
+ T parsed = renderService.fromXml( request.getInputStream(), getEntityClass() );
+ ((BaseIdentifiableObject) parsed).setUid( uid );
+
+ object.mergeWith( parsed );
+ manager.update( object );
}
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
@@ -299,6 +311,12 @@
{
throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
}
+
+ T parsed = renderService.fromJson( request.getInputStream(), getEntityClass() );
+ ((BaseIdentifiableObject) parsed).setUid( uid );
+
+ object.mergeWith( parsed );
+ manager.update( object );
}
//--------------------------------------------------------------------------