dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35931
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18401: support mergeStragy in post/put of object in AbstractCrudController
------------------------------------------------------------
revno: 18401
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-02-25 13:11:43 +0700
message:
support mergeStragy in post/put of object in AbstractCrudController
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java
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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java 2015-02-20 11:17:31 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java 2015-02-25 06:11:43 +0000
@@ -148,6 +148,11 @@
return mergeStrategy;
}
+ public void setMergeStrategy( MergeStrategy mergeStrategy )
+ {
+ this.mergeStrategy = mergeStrategy;
+ }
+
public boolean isSkipExistingCheck()
{
return skipExistingCheck;
@@ -221,7 +226,7 @@
public String toString()
{
return "[Id scheme: " + idScheme + ", data element id scheme: " + dataElementIdScheme + ", org unit id scheme: " +
- orgUnitIdScheme + ", dry run: " + dryRun + ", preheat cache: " + preheatCache + ", async: " +
+ orgUnitIdScheme + ", dry run: " + dryRun + ", preheat cache: " + preheatCache + ", async: " +
async + ", strategy: " + importStrategy + ", skip check: " + skipExistingCheck + "]";
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2015-02-17 06:00:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2015-02-25 06:11:43 +0000
@@ -33,6 +33,7 @@
import org.hibernate.SessionFactory;
import org.hisp.dhis.cache.HibernateCacheManager;
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.MergeStrategy;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.system.timer.SystemTimer;
import org.hisp.dhis.system.timer.Timer;
@@ -97,7 +98,7 @@
//-------------------------------------------------------------------------------------------------------
@Override
- public <T extends IdentifiableObject> ImportTypeSummary importObject( String userUid, T object, ImportStrategy importStrategy )
+ public <T extends IdentifiableObject> ImportTypeSummary importObject( String userUid, T object, ImportStrategy importStrategy, MergeStrategy mergeStrategy )
{
User user = userService.getUser( userUid );
@@ -105,6 +106,7 @@
importOptions.setDryRun( false );
importOptions.setPreheatCache( false );
importOptions.setImportStrategy( importStrategy.toString() );
+ importOptions.setMergeStrategy( mergeStrategy );
objectBridge.setWriteEnabled( !importOptions.isDryRun() );
objectBridge.setPreheatCache( importOptions.isPreheatCache() );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java 2015-02-17 06:00:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportService.java 2015-02-25 06:11:43 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.MergeStrategy;
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.importexport.ImportStrategy;
import org.hisp.dhis.scheduling.TaskId;
@@ -40,7 +41,7 @@
@Service
public interface ImportService
{
- <T extends IdentifiableObject> ImportTypeSummary importObject( String userUid, T object, ImportStrategy importStrategy );
+ <T extends IdentifiableObject> ImportTypeSummary importObject( String userUid, T object, ImportStrategy importStrategy, MergeStrategy mergeStrategy );
ImportSummary importMetaData( String userUid, MetaData metaData );
=== 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-02-20 09:14:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2015-02-25 06:11:43 +0000
@@ -36,8 +36,10 @@
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.MergeStrategy;
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.common.PagerUtils;
+import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.common.OrderOptions;
import org.hisp.dhis.dxf2.common.TranslateOptions;
import org.hisp.dhis.dxf2.fieldfilter.FieldFilterService;
@@ -278,7 +280,9 @@
property.getSetterMethod().invoke( persistedObject, value );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), persistedObject, ImportStrategy.UPDATE );
+ ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), persistedObject,
+ ImportStrategy.UPDATE, MergeStrategy.MERGE_IF_NOT_NULL );
+
serialize( request, response, summary );
}
@@ -354,7 +358,7 @@
//--------------------------------------------------------------------------
@RequestMapping( method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } )
- public void postXmlObject( HttpServletRequest request, HttpServletResponse response )
+ public void postXmlObject( ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response )
throws Exception
{
if ( !aclService.canCreate( currentUserService.getCurrentUser(), getEntityClass() ) )
@@ -366,7 +370,8 @@
preCreateEntity( parsed );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.CREATE );
+ ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportStrategy.CREATE, importOptions.getMergeStrategy() );
if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
{
@@ -383,7 +388,7 @@
}
@RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
- public void postJsonObject( HttpServletRequest request, HttpServletResponse response )
+ public void postJsonObject( ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response )
throws Exception
{
if ( !aclService.canCreate( currentUserService.getCurrentUser(), getEntityClass() ) )
@@ -395,7 +400,8 @@
preCreateEntity( parsed );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.CREATE );
+ ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportStrategy.CREATE, importOptions.getMergeStrategy() );
if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
{
@@ -416,7 +422,7 @@
//--------------------------------------------------------------------------
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE } )
- public void putXmlObject( @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ public void putXmlObject( ImportOptions importOptions, @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
List<T> objects = getEntity( pvUid );
@@ -436,7 +442,8 @@
preUpdateEntity( parsed );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.UPDATE );
+ ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportStrategy.UPDATE, importOptions.getMergeStrategy() );
if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
{
@@ -447,7 +454,7 @@
}
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
- public void putJsonObject( @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ public void putJsonObject( ImportOptions importOptions, @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
List<T> objects = getEntity( pvUid );
@@ -467,7 +474,8 @@
preUpdateEntity( parsed );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.UPDATE );
+ ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportStrategy.UPDATE, importOptions.getMergeStrategy() );
if ( ImportStatus.SUCCESS.equals( summary.getStatus() ) )
{