dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16726
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6435: Implemented options for import: id scheme, dry run, import strategy
------------------------------------------------------------
revno: 6435
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-03-29 10:52:54 +0200
message:
Implemented options for import: id scheme, dry run, import strategy
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/importexport/ImportStrategy.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValueService.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DefaultDataValueService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.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-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java 2012-03-28 18:27:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java 2012-03-29 08:52:54 +0000
@@ -36,7 +36,7 @@
enum IdentifiableProperty
{
- ID, UID, NAME, CODE, LAST_UPDATED
+ ID, UID, NAME, CODE
}
int getId();
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/importexport/ImportStrategy.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/importexport/ImportStrategy.java 2012-03-29 07:45:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/importexport/ImportStrategy.java 2012-03-29 08:52:54 +0000
@@ -34,6 +34,6 @@
public enum ImportStrategy
{
NEW_AND_UPDATES,
- NEW_NO_UPDATES,
- UPDATES_NO_NEW
+ NEW,
+ UPDATES
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValueService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValueService.java 2012-03-29 07:45:12 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValueService.java 2012-03-29 08:52:54 +0000
@@ -28,8 +28,9 @@
*/
import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
+import org.hisp.dhis.importexport.ImportStrategy;
public interface DataValueService
{
- void saveDataValues( DataValues dataValues, IdentifiableProperty idScheme, boolean dryRun );
+ void saveDataValues( DataValues dataValues, IdentifiableProperty idScheme, boolean dryRun, ImportStrategy strategy );
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DefaultDataValueService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DefaultDataValueService.java 2012-03-29 07:45:12 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DefaultDataValueService.java 2012-03-29 08:52:54 +0000
@@ -28,6 +28,7 @@
*/
import static org.hisp.dhis.system.util.DateUtils.getDefaultDate;
+import static org.hisp.dhis.importexport.ImportStrategy.*;
import java.util.Map;
@@ -39,6 +40,7 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.importexport.ImportStrategy;
import org.hisp.dhis.jdbc.batchhandler.DataValueBatchHandler;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
@@ -63,7 +65,7 @@
private BatchHandlerFactory batchHandlerFactory;
@Transactional
- public void saveDataValues( DataValues dataValues, IdentifiableProperty idScheme, boolean dryRun )
+ public void saveDataValues( DataValues dataValues, IdentifiableProperty idScheme, boolean dryRun, ImportStrategy strategy )
{
Map<String, DataElement> dataElementMap = identifiableObjectManager.getIdMap( DataElement.class, idScheme );
Map<String, OrganisationUnit> orgUnitMap = identifiableObjectManager.getIdMap( OrganisationUnit.class, idScheme );
@@ -101,7 +103,7 @@
{
categoryOptionCombo = fallbackCategoryOptionCombo;
}
-
+
internalValue.setDataElement( dataElement );
internalValue.setPeriod( periodService.reloadPeriod( period ) );
internalValue.setSource( orgUnit );
@@ -114,14 +116,14 @@
if ( batchHandler.objectExists( internalValue ) )
{
- if ( !dryRun )
+ if ( !dryRun && ( NEW_AND_UPDATES.equals( strategy ) || UPDATES.equals( strategy ) ) )
{
batchHandler.updateObject( internalValue );
}
}
else
{
- if ( !dryRun )
+ if ( !dryRun && ( NEW_AND_UPDATES.equals( strategy ) || NEW.equals( strategy ) ) )
{
batchHandler.addObject( internalValue );
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java 2012-03-29 07:45:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java 2012-03-29 08:52:54 +0000
@@ -33,15 +33,18 @@
import javax.servlet.http.HttpServletResponse;
import org.hisp.dhis.api.utils.ContextUtils;
-import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.dxf2.datavalue.DataValueService;
import org.hisp.dhis.dxf2.datavalue.DataValues;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import org.hisp.dhis.importexport.ImportStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import static org.hisp.dhis.common.IdentifiableObject.*;
@Controller
@RequestMapping( value = DataValueController.RESOURCE_PATH )
@@ -54,13 +57,21 @@
@RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml"} )
@PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" )
- public void postDataValues( HttpServletResponse response, InputStream input )
+ public void postDataValues( @RequestParam(required=false, defaultValue="UID") String idScheme,
+ @RequestParam(required=false) boolean dryRun,
+ @RequestParam(required=false, defaultValue="NEW_AND_UPDATES") String strategy,
+ HttpServletResponse response,
+ InputStream input )
throws IOException
{
+ IdentifiableProperty _idScheme = IdentifiableProperty.valueOf( idScheme );
+
+ ImportStrategy _strategy = ImportStrategy.valueOf( strategy );
+
DataValues dataValues = JacksonUtils.fromXml( input, DataValues.class );
- dataValueService.saveDataValues( dataValues, IdentifiableObject.IdentifiableProperty.UID, false );
+ dataValueService.saveDataValues( dataValues, _idScheme, dryRun, _strategy );
- ContextUtils.okResponse( response, "Data values saved successfully" );
+ ContextUtils.okResponse( response, "Data values saved using id scheme: " + _idScheme + ", dry run: " + dryRun + ", strategy: " + _strategy );
}
}