dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36479
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18658: implemented support for proper partial update (PATCH), multiple properties can now be updated at ...
------------------------------------------------------------
revno: 18658
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-23 13:21:33 +0700
message:
implemented support for proper partial update (PATCH), multiple properties can now be updated at the same time, for now; only owner side can be updated
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2015-03-23 05:42:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2015-03-23 06:21:33 +0000
@@ -91,6 +91,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
@@ -244,7 +245,7 @@
@RequestMapping( value = "/{uid}", method = RequestMethod.PATCH )
public void partialUpdateObject(
@PathVariable( "uid" ) String pvUid, @RequestParam Map<String, String> rpParameters,
- HttpServletRequest request, HttpServletResponse response ) throws IOException
+ HttpServletRequest request, HttpServletResponse response ) throws IOException, InvocationTargetException, IllegalAccessException
{
WebOptions options = new WebOptions( rpParameters );
List<T> entities = getEntity( pvUid, options );
@@ -285,7 +286,20 @@
return;
}
- response.setStatus( HttpServletResponse.SC_NO_CONTENT );
+ Schema schema = getSchema();
+
+ for ( String keyProperty : properties )
+ {
+ Property property = schema.getProperty( keyProperty );
+
+ Object value = property.getGetterMethod().invoke( object );
+ property.getSetterMethod().invoke( persistedObject, value );
+ }
+
+ ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), persistedObject,
+ ImportStrategy.UPDATE, MergeStrategy.MERGE );
+
+ serialize( request, response, summary );
}
private List<String> getJsonProperties( String payload ) throws IOException
@@ -367,7 +381,7 @@
property.getSetterMethod().invoke( persistedObject, value );
ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), persistedObject,
- ImportStrategy.UPDATE, MergeStrategy.MERGE_IF_NOT_NULL );
+ ImportStrategy.UPDATE, MergeStrategy.MERGE );
serialize( request, response, summary );
}