[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1335: A few improvements to zero value storage settings.

revision-diff.txt (8.99 KB)

+ return dataElement != null && dataElement.getType().equals(
DataElement.VALUE_TYPE_INT )
+ && value != null && ( value.equals( "0" ) ||
value.startsWith( "0." ) );

Sorry for my script-kiddy comments, but I want to be sure I understand
this part, as zeroes are one of my favourite values.

If a number is an integer, is it ever going to start with 0.?

I would think it would be more efficient to have a regular expression
to catch all values that might be zero..

0
0.0
0.00
etc

Is this possible?

Regards,
JPP

···

On Mon, Jan 25, 2010 at 4:10 PM, <noreply@launchpad.net> wrote:

------------------------------------------------------------
revno: 1335
committer: Lars Helge Oeverland <larshelge@gmail.com>
branch nick: trunk
timestamp: Mon 2010-01-25 15:08:24 +0100
message:
A few improvements to zero value storage settings.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/zeroValueStorageManagement.vm

--
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 OpenID transaction in progress.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java 2010-01-25 07:24:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java 2010-01-25 14:08:24 +0000
@@ -50,7 +50,6 @@
{
public static final String TRUE = "true";
public static final String FALSE = "false";
- public static final String ZERO = "0";

/\*\*
 \* Part of the DataValue&#39;s composite ID

@@ -196,6 +195,17 @@
return followup != null && followup;
}

+ public boolean isZero()
+ {
+ return dataElement != null && dataElement.getType().equals( DataElement.VALUE_TYPE_INT )
+ && value != null && ( value.equals( "0" ) || value.startsWith( "0." ) );
+ }
+
+ public boolean isNullValue()
+ {
+ return value == null && comment == null;
+ }
+
// -------------------------------------------------------------------------
// hashCode and equals
// -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2010-01-25 07:24:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2010-01-25 14:08:24 +0000
@@ -176,7 +176,7 @@

public void setZeroIsSignificantForDataElements\( Collection&lt;Integer&gt; dataElementIds, boolean zeroIsSignificant \)
\{

- if ( !dataElementIds.isEmpty() )
+ if ( dataElementIds != null && !dataElementIds.isEmpty() )
{
dataElementStore.setZeroIsSignificantForDataElements( dataElementIds, zeroIsSignificant );
}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-01-25 07:24:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-01-25 14:08:24 +0000
@@ -240,17 +240,14 @@

public void setZeroIsSignificantForDataElements\( Collection&lt;Integer&gt; dataElementIds, boolean zeroIsSignificant \)
\{

-
String sql = "update DataElement d set d.zeroIsSignificant=:zeroIsSignificant where d.id in (:ids)";

    Query query = sessionFactory\.getCurrentSession\(\)\.createQuery\( sql \);

    query\.setParameter\( &quot;zeroIsSignificant&quot;, zeroIsSignificant \);

-
query.setParameterList( "ids", dataElementIds );

    query\.executeUpdate\(\);

-
}

@SuppressWarnings\( &quot;unchecked&quot; \)

=== 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 2010-01-25 07:24:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2010-01-25 14:08:24 +0000
@@ -37,6 +37,8 @@
import org.hisp.dhis.source.Source;
import org.springframework.transaction.annotation.Transactional;

+import static org.hisp.dhis.dataelement.DataElement.*;
+
/**
* @author Kristian Nordal
* @version $Id: DefaultDataValueService.java 5715 2008-09-17 14:05:28Z larshelg
@@ -46,8 +48,8 @@
public class DefaultDataValueService
implements DataValueService
{
- private static final Log LOG = LogFactory.getLog( DefaultDataValueService.class );
-
+ private static final Log log = LogFactory.getLog( DefaultDataValueService.class );
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -65,76 +67,38 @@

public void addDataValue\( DataValue dataValue \)
\{

-
- if ( !(dataValue.getValue() == null && dataValue.getComment() == null) )
+ if ( !dataValue.isNullValue() )
{
- if ( isZero( dataValue ) )
+ if ( dataValue.isZero() && !dataValue.getDataElement().isZeroIsSignificant() &&
+ !dataValue.getDataElement().getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) )
{
- if ( dataValue.getDataElement().isZeroIsSignificant() )
- {
- int value = Integer.parseInt( dataValue.getValue() );
-
- dataValue.setValue( String.valueOf( value ) );
-
- dataValueStore.addDataValue( dataValue );
-
- LOG.info( "Allow save zero value" );
- }
+ log.info( "DataValue was ignored as zero values are insignificant for this data element: " + dataValue.getDataElement() );
}
else
{
dataValueStore.addDataValue( dataValue );
}
-
}
}

public void updateDataValue\( DataValue dataValue \)
\{

-
- if ( dataValue.getValue() == null && dataValue.getComment() == null )
+ if ( dataValue.isNullValue() )
{
dataValueStore.deleteDataValue( dataValue );
}
else
{
- if ( isZero( dataValue ) )
+ if ( dataValue.isZero() && !dataValue.getDataElement().isZeroIsSignificant() &&
+ !dataValue.getDataElement().getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) )
{
- if ( dataValue.getDataElement().isZeroIsSignificant() )
- {
- int value = Integer.parseInt( dataValue.getValue() );
-
- dataValue.setValue( String.valueOf( value ) );
-
- dataValueStore.updateDataValue( dataValue );
-
- LOG.info( "Allow save zero value" );
- }
+ log.info( "DataValue was ignored as zero values are insignificant for this data element: " + dataValue.getDataElement() );
}
else
{
-
dataValueStore.updateDataValue( dataValue );
}
-
- }
- }
-
- private boolean isZero( DataValue dataValue )
- {
- if ( !dataValue.getDataElement().getType().equalsIgnoreCase( DataElement.VALUE_TYPE_INT ) )
- {
- return false;
- }
-
- Double value = Double.parseDouble( dataValue.getValue() );
-
- if ( value.equals( Double.parseDouble( DataValue.ZERO ) ) )
- {
- return true;
- }
-
- return false;
+ }
}

public void deleteDataValue\( DataValue dataValue \)

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/zeroValueStorageManagement.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/zeroValueStorageManagement.vm 2010-01-25 07:24:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/zeroValueStorageManagement.vm 2010-01-25 14:08:24 +0000
@@ -33,11 +33,11 @@
</select>
</td>

- <td style="text-align:center">
- <input type="button" value=">>" title="$i18n.getString('move_all')" onclick="moveAllLeftToRight()" style="width:50px"/><br>
- <input type="button" value=">" title="$i18n.getString('move_selected')" onclick="moveLeftToRight()" style="width:50px"/><br>
- <input type="button" value="<" title="$i18n.getString('move_selected')" onclick="moveRightToLeft()" style="width:50px"/><br>
- <input type="button" value="<<" title="$i18n.getString('move_all')" onclick="moveAllRightToLeft()" style="width:50px"/>
+ <td style="text-align:center">
+ <input type="button" value="&gt;" title="$i18n.getString('move_selected')" onclick="moveLeftToRight()" style="width:50px"><br>
+ <input type="button" value="&lt;" title="$i18n.getString('move_selected')" onclick="moveRightToLeft()" style="width:50px"><br>
+ <input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" onclick="moveAllLeftToRight()" style="width:50px"><br>
+ <input type="button" value="&lt;&lt;" title="$i18n.getString('move_all')" onclick="moveAllRightToLeft()" style="width:50px">
</td>

                   &lt;td&gt;

@@ -48,7 +48,8 @@
</tbody>
</table>
<p>
- <input type="button" value="$i18n.getString( "save" )" onclick="submitForm()" style="width:100px"/>
+ <input type="button" value="$i18n.getString( "save" )" onclick="submitForm()" style="width:100px"><input
+ type="button" value="$i18n.getString( "cancel" )" onclick="window.location.href='index.action'" style="width:100px">
</p>
</form>
<script>

_______________________________________________
Mailing list: DHIS 2 developers in Launchpad
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe : DHIS 2 developers in Launchpad
More help : ListHelp - Launchpad Help

Tri actually pointed that out to me right now. I have committed a fix which hopefully gets it right now.

···

2010/1/25 Jason Pickering jason.p.pickering@gmail.com

  •    return dataElement != null && dataElement.getType().equals(
    

DataElement.VALUE_TYPE_INT )

  •        && value != null && ( value.equals( "0" ) ||
    

value.startsWith( “0.” ) );

Sorry for my script-kiddy comments, but I want to be sure I understand

this part, as zeroes are one of my favourite values.

If a number is an integer, is it ever going to start with 0.?

I would think it would be more efficient to have a regular expression

to catch all values that might be zero…

0

0.0

0.00

etc