dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #04037
Re: [Branch ~dhis2-devs-core/dhis2/trunk] Rev 1335: A few improvements to zero value storage settings.
+ 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@xxxxxxxxxxxxx> wrote:
> ------------------------------------------------------------
> revno: 1335
> committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
> 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 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
>
> === 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'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<Integer> 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<Integer> 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( "zeroIsSignificant", zeroIsSignificant );
> -
> query.setParameterList( "ids", dataElementIds );
>
> query.executeUpdate();
> -
> }
>
> @SuppressWarnings( "unchecked" )
>
> === 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=">" 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="moveAllLeftToRight()" style="width:50px"><br>
> + <input type="button" value="<<" title="$i18n.getString('move_all')" onclick="moveAllRightToLeft()" style="width:50px">
> </td>
>
> <td>
> @@ -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: https://launchpad.net/~dhis2-devs
> Post to : dhis2-devs@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-devs
> More help : https://help.launchpad.net/ListHelp
>
>
Follow ups
References