dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22179
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10641: Centralized logic for ignoring zero values
------------------------------------------------------------
revno: 10641
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-04-19 17:58:28 +0200
message:
Centralized logic for ignoring zero values
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.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-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2012-07-25 14:44:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2013-04-19 15:58:28 +0000
@@ -27,14 +27,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
+import static org.hisp.dhis.system.util.ValidationUtils.dataValueIsValid;
import java.util.Calendar;
import java.util.Collection;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementOperand;
@@ -52,8 +50,6 @@
public class DefaultDataValueService
implements DataValueService
{
- private static final Log log = LogFactory.getLog( DefaultDataValueService.class );
-
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -71,7 +67,7 @@
public void addDataValue( DataValue dataValue )
{
- if ( !dataValue.isNullValue() && isSignificant( dataValue ) )
+ if ( !dataValue.isNullValue() && dataValueIsValid( dataValue.getValue(), dataValue.getDataElement() ) == null )
{
dataValueStore.addDataValue( dataValue );
}
@@ -81,9 +77,9 @@
{
if ( dataValue.isNullValue() )
{
- this.deleteDataValue( dataValue );
+ deleteDataValue( dataValue );
}
- else if ( isSignificant( dataValue ) )
+ else if ( dataValueIsValid( dataValue.getValue(), dataValue.getDataElement() ) == null )
{
dataValueStore.updateDataValue( dataValue );
}
@@ -176,25 +172,12 @@
return dataValueStore.getDataValues( dataElement );
}
- @Override
public DataValue getLatestDataValues( DataElement dataElement, PeriodType periodType,
OrganisationUnit organisationUnit )
{
return dataValueStore.getLatestDataValues( dataElement, periodType, organisationUnit );
}
- private boolean isSignificant( DataValue dataValue )
- {
- if ( dataValue.isZero() && !dataValue.getDataElement().isZeroIsSignificant()
- && !dataValue.getDataElement().getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) )
- {
- log.debug( "DataValue was ignored as zero values are insignificant for this data element: "
- + dataValue.getDataElement() );
- return false;
- }
- return true;
- }
-
public int getDataValueCount( int days )
{
Calendar cal = PeriodType.createCalendarInstance();
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2013-04-19 15:02:38 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2013-04-19 15:58:28 +0000
@@ -212,7 +212,8 @@
/**
* Checks if the given data value is valid according to the value type of the
- * given data element. Returns a string if the valid is invalid, possible
+ * given data element. Considers the value to be valid if null or empty.
+ * Returns a string if the valid is invalid, possible
* values are:
*
* <ul>
@@ -223,6 +224,7 @@
* <li>value_not_integer</li>
* <li>value_not_positive_integer</li>
* <li>value_not_negative_integer</li>
+ * <li>value_is_zero_and_not_zero_significant</li>
* </ul>
*
* @param value the data value.
@@ -233,7 +235,7 @@
{
if ( value == null || value.trim().isEmpty() )
{
- return "value_null_or_empty";
+ return null;
}
if ( dataElement == null || dataElement.getType() == null || dataElement.getType().isEmpty() )
@@ -270,6 +272,12 @@
return "value_not_negative_integer";
}
+ if ( VALUE_TYPE_INT.equals( dataElement.getType() ) && MathUtils.isZero( value ) &&
+ !dataElement.isZeroIsSignificant() && !AGGREGATION_OPERATOR_AVERAGE.equals( dataElement.getAggregationOperator() ) )
+ {
+ return "value_is_zero_and_not_zero_significant";
+ }
+
return null;
}
}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java 2013-04-19 15:15:46 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java 2013-04-19 15:58:28 +0000
@@ -27,17 +27,17 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.system.util.ValidationUtils.coordinateIsValid;
+import static org.hisp.dhis.system.util.ValidationUtils.dataValueIsValid;
+import static org.hisp.dhis.system.util.ValidationUtils.emailIsValid;
+import static org.hisp.dhis.system.util.ValidationUtils.getLatitude;
+import static org.hisp.dhis.system.util.ValidationUtils.getLongitude;
+import static org.hisp.dhis.system.util.ValidationUtils.passwordIsValid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-import static org.hisp.dhis.system.util.ValidationUtils.coordinateIsValid;
-import static org.hisp.dhis.system.util.ValidationUtils.getLatitude;
-import static org.hisp.dhis.system.util.ValidationUtils.getLongitude;
-import static org.hisp.dhis.system.util.ValidationUtils.passwordIsValid;
-import static org.hisp.dhis.system.util.ValidationUtils.emailIsValid;
-import static org.hisp.dhis.system.util.ValidationUtils.dataValueIsValid;
import org.hisp.dhis.dataelement.DataElement;
import org.junit.Test;
@@ -114,8 +114,8 @@
DataElement de = new DataElement( "DEA" );
de.setType( DataElement.VALUE_TYPE_INT );
- assertNotNull( dataValueIsValid( null, de ) );
- assertNotNull( dataValueIsValid( "", de ) );
+ assertNull( dataValueIsValid( null, de ) );
+ assertNull( dataValueIsValid( "", de ) );
assertNull( dataValueIsValid( "34", de ) );
assertNotNull( dataValueIsValid( "Yes", de ) );
@@ -133,6 +133,19 @@
de.setNumberType( DataElement.VALUE_TYPE_NEGATIVE_INT );
assertNull( dataValueIsValid( "-3", de ) );
- assertNotNull( dataValueIsValid( "4", de ) );
+ assertNotNull( dataValueIsValid( "4", de ) );
+
+ de.setNumberType( DataElement.VALUE_TYPE_INT );
+
+ assertNotNull( dataValueIsValid( "0", de ) );
+
+ de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE );
+
+ assertNull( dataValueIsValid( "0", de ) );
+
+ de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
+ de.setType( DataElement.VALUE_TYPE_TEXT );
+
+ assertNull( dataValueIsValid( "0", de ) );
}
}