dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40370
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20459: Removed constant interface, moved constants to ADXService
------------------------------------------------------------
revno: 20459
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-02 10:02:51 +0200
message:
Removed constant interface, moved constants to ADXService
removed:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/ADXConstants.java
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/ADXDataService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultADXDataService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/csv/DefaultCsvEventService.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
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/ADXConstants.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/ADXConstants.java 2015-09-13 21:54:23 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/ADXConstants.java 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
-package org.hisp.dhis.dxf2.adx;
-
-/*
- * Copyright (c) 2004-2015, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- *
- * @author bobj
- */
-public interface ADXConstants
-{
- //--------------------------------------------------------------------------
- // These are defined in the ADX standard
- //--------------------------------------------------------------------------
-
- String NAMESPACE = "urn:ihe:qrph:adx:2015";
-
- String ROOT = "adx";
-
- String GROUP = "group";
-
- String DATASET = "dataSet";
-
- String PERIOD = "period";
-
- String ORGUNIT = "orgUnit";
-
- String DATAELEMENT = "dataElement";
-
- String DATAVALUE = "dataValue";
-
- String VALUE = "value";
-
- String ANNOTATION = "annotation";
-
- //--------------------------------------------------------------------------
- // DHIS 2 specific
- //--------------------------------------------------------------------------
-
- String CATOPTCOMBO = "categoryOptionCombo";
-
- String ATTOPTCOMBO = "attributeOptionCombo";
-}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/ADXDataService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/ADXDataService.java 2015-06-18 12:42:19 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/ADXDataService.java 2015-10-02 08:02:51 +0000
@@ -31,23 +31,48 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+
import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.datavalueset.DataExportParams;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
/**
- *
* @author bobj
*/
public interface ADXDataService
{
+ //--------------------------------------------------------------------------
+ // ADX standard constants
+ //--------------------------------------------------------------------------
+
+ String NAMESPACE = "urn:ihe:qrph:adx:2015";
+ String ROOT = "adx";
+ String GROUP = "group";
+ String DATASET = "dataSet";
+ String PERIOD = "period";
+ String ORGUNIT = "orgUnit";
+ String DATAELEMENT = "dataElement";
+ String DATAVALUE = "dataValue";
+ String VALUE = "value";
+ String ANNOTATION = "annotation";
+
+ //--------------------------------------------------------------------------
+ // DHIS 2 specific constants
+ //--------------------------------------------------------------------------
+
+ String CATOPTCOMBO = "categoryOptionCombo";
+ String ATTOPTCOMBO = "attributeOptionCombo";
+
+ //--------------------------------------------------------------------------
+ // Methods
+ //--------------------------------------------------------------------------
/**
- * postData
+ * Post data.
*
* Takes ADX Data from input stream and saves a series of DXF2 DataValueSets
*
- * @param in The InputStream - typically from servlet http response
+ * @param in The InputStream - typically from servlet HTTP response
* @param importOptions The importOptions - typically from the servlet request
* @return an ImportSummaries collection of ImportSummary for each DataValueSet
* @throws IOException
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultADXDataService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultADXDataService.java 2015-09-23 12:27:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultADXDataService.java 2015-10-02 08:02:51 +0000
@@ -91,8 +91,7 @@
// Constants
// -------------------------------------------------------------------------
- public static final int PIPE_BUFFER_SIZE = 4096;
- public static final int TOTAL_MINUTES_TO_WAIT = 5;
+ private static final int TOTAL_MINUTES_TO_WAIT = 5;
// -------------------------------------------------------------------------
// Dependencies
@@ -130,13 +129,14 @@
ImportSummaries importSummaries = new ImportSummaries();
- adxReader.moveToStartElement( ADXConstants.ROOT, ADXConstants.NAMESPACE );
+ adxReader.moveToStartElement( ADXDataService.ROOT, ADXDataService.NAMESPACE );
ExecutorService executor = Executors.newSingleThreadExecutor();
int count = 0;
+
// submit each ADX group to DXF importer as a datavalueSet
- while ( adxReader.moveToStartElement( ADXConstants.GROUP, ADXConstants.NAMESPACE ) )
+ while ( adxReader.moveToStartElement( ADXDataService.GROUP, ADXDataService.NAMESPACE ) )
{
try ( PipedOutputStream pipeOut = new PipedOutputStream() )
{
@@ -145,14 +145,14 @@
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter dxfWriter = factory.createXMLStreamWriter( pipeOut );
- // note theis returns conflicts which are detected at adx level
+ // note this returns conflicts which are detected at ADX level
List<ImportConflict> adxConflicts = parseADXGroupToDxf( adxReader, dxfWriter, importOptions );
pipeOut.flush();
ImportSummary summary = futureImportSummary.get( TOTAL_MINUTES_TO_WAIT, TimeUnit.MINUTES );
- // add adx conflicts to the import summary
+ // add ADX conflicts to the import summary
for ( ImportConflict conflict : adxConflicts)
{
summary.getConflicts().add( conflict );
@@ -202,48 +202,48 @@
Map<String, String> groupAttributes = readAttributes( adxReader );
- if ( !groupAttributes.containsKey( ADXConstants.PERIOD ) )
+ if ( !groupAttributes.containsKey( ADXDataService.PERIOD ) )
{
- throw new ADXException( ADXConstants.PERIOD + " attribute is required on 'group'" );
+ throw new ADXException( ADXDataService.PERIOD + " attribute is required on 'group'" );
}
- if ( !groupAttributes.containsKey( ADXConstants.ORGUNIT ) )
+ if ( !groupAttributes.containsKey( ADXDataService.ORGUNIT ) )
{
- throw new ADXException( ADXConstants.ORGUNIT + " attribute is required on 'group'" );
+ throw new ADXException( ADXDataService.ORGUNIT + " attribute is required on 'group'" );
}
// translate adx period to dxf2
- String periodStr = groupAttributes.get( ADXConstants.PERIOD );
- groupAttributes.remove( ADXConstants.PERIOD );
+ String periodStr = groupAttributes.get( ADXDataService.PERIOD );
+ groupAttributes.remove( ADXDataService.PERIOD );
Period period = ADXPeriod.parse( periodStr );
- groupAttributes.put( ADXConstants.PERIOD, period.getIsoDate());
+ groupAttributes.put( ADXDataService.PERIOD, period.getIsoDate());
// process adx group attributes
- if ( !groupAttributes.containsKey( ADXConstants.ATTOPTCOMBO )
- && groupAttributes.containsKey( ADXConstants.DATASET ) )
+ if ( !groupAttributes.containsKey( ADXDataService.ATTOPTCOMBO )
+ && groupAttributes.containsKey( ADXDataService.DATASET ) )
{
log.debug( "No attributeOptionCombo present. Check dataSet for attribute categorycombo" );
DataSet dataSet = identifiableObjectManager.getObject( DataSet.class, dataElementIdScheme,
- groupAttributes.get( ADXConstants.DATASET ) );
+ groupAttributes.get( ADXDataService.DATASET ) );
if (dataSet == null)
{
- throw new ADXException("No dataSet matching identifier: " + groupAttributes.get( ADXConstants.DATASET ));
+ throw new ADXException("No dataSet matching identifier: " + groupAttributes.get( ADXDataService.DATASET ));
}
- groupAttributes.put( ADXConstants.DATASET, dataSet.getUid() );
+ groupAttributes.put( ADXDataService.DATASET, dataSet.getUid() );
DataElementCategoryCombo attributeCombo = dataSet.getCategoryCombo();
- attributesToDXF( ADXConstants.ATTOPTCOMBO, attributeCombo, groupAttributes, dataElementIdScheme );
+ attributesToDXF( ADXDataService.ATTOPTCOMBO, attributeCombo, groupAttributes, dataElementIdScheme );
}
- // write the remaining attributes through to dxf stream
+ // write the remaining attributes through to DXF stream
for ( String attribute : groupAttributes.keySet() )
{
dxfWriter.writeAttribute( attribute, groupAttributes.get( attribute ) );
}
// process the dataValues
- while ( adxReader.moveToStartElement( ADXConstants.DATAVALUE, ADXConstants.GROUP ) )
+ while ( adxReader.moveToStartElement( ADXDataService.DATAVALUE, ADXDataService.GROUP ) )
{
try
{
@@ -269,51 +269,54 @@
log.debug("Processing datavalue: " + dvAttributes );
- if ( !dvAttributes.containsKey( ADXConstants.DATAELEMENT ) )
+ if ( !dvAttributes.containsKey( ADXDataService.DATAELEMENT ) )
{
- throw new ADXException( ADXConstants.DATAELEMENT + " attribute is required on 'dataValue'" );
+ throw new ADXException( ADXDataService.DATAELEMENT + " attribute is required on 'dataValue'" );
}
- if ( !dvAttributes.containsKey( ADXConstants.VALUE ) )
+ if ( !dvAttributes.containsKey( ADXDataService.VALUE ) )
{
- throw new ADXException( ADXConstants.VALUE + " attribute is required on 'dataValue'" );
+ throw new ADXException( ADXDataService.VALUE + " attribute is required on 'dataValue'" );
}
IdentifiableProperty dataElementIdScheme = importOptions.getDataElementIdScheme();
- DataElement dataElement = identifiableObjectManager.getObject( DataElement.class, dataElementIdScheme,dvAttributes.get( ADXConstants.DATAELEMENT));
+ DataElement dataElement = identifiableObjectManager.getObject( DataElement.class, dataElementIdScheme,dvAttributes.get( ADXDataService.DATAELEMENT));
if ( dataElement == null )
{
- throw new ADXException(dvAttributes.get( ADXConstants.DATAELEMENT), "No matching dataelement");
+ throw new ADXException(dvAttributes.get( ADXDataService.DATAELEMENT), "No matching dataelement");
}
- // process adx datavalue attributes
- if ( !dvAttributes.containsKey( ADXConstants.CATOPTCOMBO ) )
+
+ // process ADX datavalue attributes
+ if ( !dvAttributes.containsKey( ADXDataService.CATOPTCOMBO ) )
{
log.debug( "No categoryOptionCombo present." );
DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo();
- attributesToDXF( ADXConstants.CATOPTCOMBO, categoryCombo, dvAttributes, dataElementIdScheme );
+ attributesToDXF( ADXDataService.CATOPTCOMBO, categoryCombo, dvAttributes, dataElementIdScheme );
}
- // if dataelement type is string we need to pick out the 'annotation' element
+
+ // if data element type is string we need to pick out the 'annotation' element
if ( dataElement.getValueType().isText() )
{
- adxReader.moveToStartElement( ADXConstants.ANNOTATION, ADXConstants.DATAVALUE );
- if ( adxReader.isStartElement( ADXConstants.ANNOTATION ) )
+ adxReader.moveToStartElement( ADXDataService.ANNOTATION, ADXDataService.DATAVALUE );
+ if ( adxReader.isStartElement( ADXDataService.ANNOTATION ) )
{
String textValue = adxReader.getElementValue();
- dvAttributes.put( ADXConstants.VALUE, textValue );
+ dvAttributes.put( ADXDataService.VALUE, textValue );
}
else
{
- throw new ADXException( dvAttributes.get( ADXConstants.DATAELEMENT),"Dataelement expects text annotation" );
+ throw new ADXException( dvAttributes.get( ADXDataService.DATAELEMENT),"Dataelement expects text annotation" );
}
}
log.debug("Processing datavalue as DXF2: " + dvAttributes );
dxfWriter.writeStartElement( "dataValue" );
- // pass through the remaining attributes to dxf
+
+ // pass through the remaining attributes to DXF
for ( String attribute : dvAttributes.keySet() )
{
dxfWriter.writeAttribute( attribute, dvAttributes.get( attribute ) );
@@ -401,7 +404,6 @@
if ( catCombo.isDefault() )
{
- // nothing to do
return;
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/csv/DefaultCsvEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/csv/DefaultCsvEventService.java 2015-10-02 03:59:43 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/csv/DefaultCsvEventService.java 2015-10-02 08:02:51 +0000
@@ -52,9 +52,9 @@
*/
public class DefaultCsvEventService implements CsvEventService
{
- private static CsvMapper CSV_MAPPER = new CsvMapper().enable( CsvParser.Feature.WRAP_AS_ARRAY );
+ private static final CsvMapper CSV_MAPPER = new CsvMapper().enable( CsvParser.Feature.WRAP_AS_ARRAY );
- private static CsvSchema CSV_SCHEMA = CSV_MAPPER.schemaFor( CsvEventDataValue.class ).withLineSeparator( "\n" );
+ private static final CsvSchema CSV_SCHEMA = CSV_MAPPER.schemaFor( CsvEventDataValue.class ).withLineSeparator( "\n" );
@Override
public void writeEvents( OutputStream outputStream, Events events, boolean withHeader ) throws IOException