dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #00492
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 142: Made the DHIS 1.4 file import more robust against missing identifiers in formulas.
------------------------------------------------------------
revno: 142
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Thu 2009-04-02 09:50:49 +0200
message:
Made the DHIS 1.4 file import more robust against missing identifiers in formulas.
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/file/rowhandler/CalculatedDataElementRowHandler.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/util/Dhis14ExpressionConverter.java
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2009-04-02 07:50:49 +0000
@@ -38,6 +38,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dataelement.CalculatedDataElement;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -58,6 +60,8 @@
public class DefaultExpressionService
implements ExpressionService
{
+ private static final Log log = LogFactory.getLog( DefaultExpressionService.class );
+
private static final String NULL_REPLACEMENT = "0";
// -------------------------------------------------------------------------
@@ -178,16 +182,28 @@
match = match.replaceAll( "[\\[\\]]", "" );
- String dataElementIdString = match.substring( 0, match.indexOf( SEPARATOR ) );
- String categoryOptionComboIdString = match.substring( match.indexOf( SEPARATOR ) + 1, match.length() );
-
- int dataElementId = Integer.parseInt( dataElementIdString );
- int categoryOptionComboId = Integer.parseInt( categoryOptionComboIdString );
-
- dataElementId = dataElementMapping.get( dataElementId );
- categoryOptionComboId = categoryOptionComboMapping.get( categoryOptionComboId );
-
- match = "[" + dataElementId + SEPARATOR + categoryOptionComboId + "]";
+ final int dataElementId = Integer.parseInt( match.substring( 0, match.indexOf( SEPARATOR ) ) );
+ final int categoryOptionComboId = Integer.parseInt( match.substring( match.indexOf( SEPARATOR ) + 1, match.length() ) );
+
+ final Integer mappedDataElementId = dataElementMapping.get( dataElementId );
+ final Integer mappedCategoryOptionComboId = categoryOptionComboMapping.get( categoryOptionComboId );
+
+ if ( mappedDataElementId == null )
+ {
+ log.info( "Data element identifier refers to non-existing object: " + dataElementId );
+
+ match = NULL_REPLACEMENT;
+ }
+ else if ( mappedCategoryOptionComboId == null )
+ {
+ log.info( "Category option combo identifer refers to non-existing object: " + categoryOptionComboId );
+
+ match = NULL_REPLACEMENT;
+ }
+ else
+ {
+ match = "[" + mappedDataElementId + SEPARATOR + mappedCategoryOptionComboId + "]";
+ }
matcher.appendReplacement( convertedFormula, match );
}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/file/rowhandler/CalculatedDataElementRowHandler.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/file/rowhandler/CalculatedDataElementRowHandler.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/file/rowhandler/CalculatedDataElementRowHandler.java 2009-04-02 07:50:49 +0000
@@ -112,6 +112,7 @@
dataElement.setCategoryCombo( categoryCombo );
String expression = calculatedEntryMap.get( dataElement.getId() );
+
expression = expressionService.convertExpression( expression, dataElementMapping, categoryOptionComboMapping );
dataElement.setExpression( new Expression( expression, null, new HashSet<DataElement>() ) );
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/util/Dhis14ExpressionConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/util/Dhis14ExpressionConverter.java 2009-03-23 19:20:18 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/util/Dhis14ExpressionConverter.java 2009-04-02 07:50:49 +0000
@@ -45,6 +45,8 @@
{
private static final Log log = LogFactory.getLog( Dhis14ExpressionConverter.class );
+ private static final String NULL_REPLACEMENT = "0";
+
/**
* Converts an indicator formula from the DHIS 1.4 format to the DHIS 2 format.
*
@@ -106,14 +108,12 @@
{
log.warn( "'" + name + "' contains a non-existing data element identifier: " + dataElementId );
- convertedDataElementId = -1;
- }
-
- // -------------------------------------------------------------
- // Add default category option combo and put brackets back on
- // -------------------------------------------------------------
-
- replaceString = "[" + convertedDataElementId + SEPARATOR + categoryOptionComboId + "]";
+ replaceString = NULL_REPLACEMENT;
+ }
+ else
+ {
+ replaceString = "[" + convertedDataElementId + SEPARATOR + categoryOptionComboId + "]";
+ }
matcher.appendReplacement( convertedFormula, replaceString );
}
--
Trunk
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.