dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16763
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6459: Refactored data value set import to use streaming processing. No change in XML format.
------------------------------------------------------------
revno: 6459
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-04-01 14:17:55 +0200
message:
Refactored data value set import to use streaming processing. No change in XML format.
modified:
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.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-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java 2012-04-01 12:04:14 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java 2012-04-01 12:17:55 +0000
@@ -142,6 +142,11 @@
this.dataValues = dataValues;
}
+ public boolean hasNextDataValue()
+ {
+ return dataValues.iterator().hasNext();
+ }
+
public DataValue getNextDataValue()
{
return dataValues.iterator().next();
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2012-04-01 12:04:14 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2012-04-01 12:17:55 +0000
@@ -27,6 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.InputStream;
import java.io.OutputStream;
import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
@@ -37,7 +38,7 @@
{
void writeDataValueSet( String dataSet, String period, String orgUnit, OutputStream out );
- ImportSummary saveDataValueSet( DataValueSet dataValueSet );
+ ImportSummary saveDataValueSet( InputStream in );
- ImportSummary saveDataValueSet( DataValueSet dataValueSet, IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, boolean dryRun, ImportStrategy strategy );
+ ImportSummary saveDataValueSet( InputStream in, IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, boolean dryRun, ImportStrategy strategy );
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2012-04-01 12:04:14 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2012-04-01 12:17:55 +0000
@@ -33,12 +33,14 @@
import static org.hisp.dhis.system.util.ConversionUtils.wrap;
import static org.hisp.dhis.system.util.DateUtils.getDefaultDate;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Map;
import org.amplecode.quick.BatchHandler;
import org.amplecode.quick.BatchHandlerFactory;
+import org.amplecode.staxwax.factory.XMLFactory;
import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dataelement.DataElement;
@@ -129,15 +131,17 @@
dataValueSetStore.writeDataValueSet( dataSet_, completeDate, orgUnit_, period_, dataSet_.getDataElements(), wrap( period_ ), wrap( orgUnit_ ), out );
}
- public ImportSummary saveDataValueSet( DataValueSet dataValueSet )
+ public ImportSummary saveDataValueSet( InputStream in )
{
- return saveDataValueSet( dataValueSet, IdentifiableProperty.UID, IdentifiableProperty.UID, false, ImportStrategy.NEW_AND_UPDATES );
+ return saveDataValueSet( in, IdentifiableProperty.UID, IdentifiableProperty.UID, false, ImportStrategy.NEW_AND_UPDATES );
}
- public ImportSummary saveDataValueSet( DataValueSet dataValueSet, IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, boolean dryRun, ImportStrategy strategy )
+ public ImportSummary saveDataValueSet( InputStream in, IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, boolean dryRun, ImportStrategy strategy )
{
ImportSummary summary = new ImportSummary();
+ DataValueSet dataValueSet = new StreamingDataValueSet( XMLFactory.getXMLReader( in ) );
+
dataElementIdScheme = dataValueSet.getDataElementIdScheme() != null ? IdentifiableProperty.valueOf( dataValueSet.getDataElementIdScheme().toUpperCase() ) : dataElementIdScheme;
orgUnitIdScheme = dataValueSet.getOrgUnitIdScheme() != null ? IdentifiableProperty.valueOf( dataValueSet.getOrgUnitIdScheme().toUpperCase() ) : orgUnitIdScheme;
@@ -168,8 +172,10 @@
int updateCount = 0;
int totalCount = 0;
- for ( org.hisp.dhis.dxf2.datavalue.DataValue dataValue : dataValueSet.getDataValues() )
+ while ( dataValueSet.hasNextDataValue() )
{
+ org.hisp.dhis.dxf2.datavalue.DataValue dataValue = dataValueSet.getNextDataValue();
+
DataValue internalValue = new DataValue();
totalCount++;
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java 2012-04-01 12:04:14 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java 2012-04-01 12:17:55 +0000
@@ -113,13 +113,17 @@
}
@Override
+ public boolean hasNextDataValue()
+ {
+ return reader.moveToStartElement( FIELD_DATAVALUE, FIELD_DATAVALUESET );
+ }
+
+ @Override
public DataValue getNextDataValue()
{
- boolean hasNext = reader.moveToStartElement( FIELD_DATAVALUE, FIELD_DATAVALUESET );
-
- return hasNext ? new StreamingDataValue( reader ) : null;
+ return new StreamingDataValue( reader );
}
-
+
//--------------------------------------------------------------------------
// Setters
//--------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java 2012-04-01 12:04:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java 2012-04-01 12:17:55 +0000
@@ -41,7 +41,6 @@
import org.hisp.dhis.dxf2.datavalueset.DataValueSet;
import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
-import org.hisp.dhis.dxf2.utils.DataValueSetMapper;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.hisp.dhis.importexport.ImportStrategy;
import org.springframework.beans.factory.annotation.Autowired;
@@ -94,18 +93,16 @@
@RequestParam(required=false) boolean dryRun,
@RequestParam(required=false, defaultValue="NEW_AND_UPDATES") String strategy,
HttpServletResponse response,
- InputStream input,
+ InputStream in,
Model model ) throws IOException
{
IdentifiableProperty _dataElementidScheme = IdentifiableProperty.valueOf( dataElementIdScheme.toUpperCase() );
IdentifiableProperty _orgUnitIdScheme = IdentifiableProperty.valueOf( orgUnitIdScheme.toUpperCase() );
ImportStrategy _strategy = ImportStrategy.valueOf( strategy.toUpperCase() );
- DataValueSet dataValueSet = DataValueSetMapper.fromXml( input );
-
- ImportSummary summary = dataValueSetService.saveDataValueSet( dataValueSet, _dataElementidScheme, _orgUnitIdScheme, dryRun, _strategy );
+ ImportSummary summary = dataValueSetService.saveDataValueSet( in, _dataElementidScheme, _orgUnitIdScheme, dryRun, _strategy );
- log.info( "Data values " + dataValueSet + " saved, data element id scheme: " + _dataElementidScheme + ", org unit id scheme: " + _orgUnitIdScheme + ", dry run: " + dryRun + ", strategy: " + _strategy );
+ log.info( "Data values set saved, data element id scheme: " + _dataElementidScheme + ", org unit id scheme: " + _orgUnitIdScheme + ", dry run: " + dryRun + ", strategy: " + _strategy );
response.setContentType( CONTENT_TYPE_XML );
JacksonUtils.toXml( response.getOutputStream(), summary );