------------------------------------------------------------ revno: 5076 committer: Morten Olav Hansen <morte...@gmail.com> branch nick: dhis2 timestamp: Tue 2011-11-01 19:28:36 +0100 message: (mobile) minor refactor removed: dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/SectionFormUtils.java added: dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/FormUtils.java modified: dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectOrganisationUnit.vm dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectPeriod.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-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java 2011-10-24 12:18:38 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java 2011-11-01 18:28:36 +0000 @@ -31,7 +31,7 @@ import java.util.Collections; import java.util.List; -import org.hisp.dhis.light.dataentry.utils.SectionFormUtils; +import org.hisp.dhis.light.dataentry.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; import org.hisp.dhis.user.CurrentUserService; @@ -56,18 +56,18 @@ this.currentUserService = currentUserService; } - private SectionFormUtils sectionFormUtils; - - public void setSectionFormUtils( SectionFormUtils sectionFormUtils ) - { - this.sectionFormUtils = sectionFormUtils; - } - - public SectionFormUtils getSectionFormUtils() - { - return sectionFormUtils; - } - + private FormUtils formUtils; + + public void setFormUtils( FormUtils formUtils ) + { + this.formUtils = formUtils; + } + + public FormUtils getFormUtils() + { + return formUtils; + } + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java 2011-09-30 11:13:16 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java 2011-11-01 18:28:36 +0000 @@ -37,7 +37,7 @@ import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.datavalue.DeflatedDataValue; -import org.hisp.dhis.light.dataentry.utils.SectionFormUtils; +import org.hisp.dhis.light.dataentry.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; @@ -83,16 +83,16 @@ this.periodService = periodService; } - private SectionFormUtils sectionFormUtils; + private FormUtils formUtils; - public void setSectionFormUtils( SectionFormUtils sectionFormUtils ) + public void setFormUtils( FormUtils formUtils ) { - this.sectionFormUtils = sectionFormUtils; + this.formUtils = formUtils; } - public SectionFormUtils getSectionFormUtils() + public FormUtils getFormUtils() { - return sectionFormUtils; + return formUtils; } // ------------------------------------------------------------------------- @@ -195,11 +195,11 @@ dataSet = dataSetService.getDataSet( dataSetId ); - dataValues = sectionFormUtils.getDataValueMap( organisationUnit, dataSet, period ); - - validationViolations = sectionFormUtils.getValidationViolations( organisationUnit, dataSet, period ); - - validationRuleViolations = sectionFormUtils.getValidationRuleViolations( organisationUnit, dataSet, period ); + dataValues = formUtils.getDataValueMap( organisationUnit, dataSet, period ); + + validationViolations = formUtils.getValidationViolations( organisationUnit, dataSet, period ); + + validationRuleViolations = formUtils.getValidationRuleViolations( organisationUnit, dataSet, period ); CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period, organisationUnit ); === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java 2011-11-01 15:01:22 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java 2011-11-01 18:28:36 +0000 @@ -48,7 +48,7 @@ import org.hisp.dhis.datavalue.DataValueService; import org.hisp.dhis.datavalue.DeflatedDataValue; import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.light.dataentry.utils.SectionFormUtils; +import org.hisp.dhis.light.dataentry.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; @@ -125,16 +125,16 @@ this.periodService = periodService; } - private SectionFormUtils sectionFormUtils; + private FormUtils formUtils; - public void setSectionFormUtils( SectionFormUtils sectionFormUtils ) + public void setFormUtils( FormUtils formUtils ) { - this.sectionFormUtils = sectionFormUtils; + this.formUtils = formUtils; } - public SectionFormUtils getSectionFormUtils() + public FormUtils getFormUtils() { - return sectionFormUtils; + return formUtils; } private I18n i18n; @@ -300,7 +300,7 @@ } else if ( type.equals( DataElement.VALUE_TYPE_BOOL ) ) { - if ( !valueIsEmpty && !SectionFormUtils.isBoolean( value ) ) + if ( !valueIsEmpty && !FormUtils.isBoolean( value ) ) { correctType = false; typeViolations.put( key, value + " " + i18n.getString( "is_invalid_boolean" ) ); @@ -308,7 +308,7 @@ } else if ( type.equals( DataElement.VALUE_TYPE_DATE ) ) { - if ( !SectionFormUtils.isDate( value ) ) + if ( !FormUtils.isDate( value ) ) { correctType = false; typeViolations.put( key, value + " " + i18n.getString( "is_invalid_date" ) ); @@ -317,7 +317,7 @@ else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_NUMBER ) ) { - if ( !SectionFormUtils.isNumber( value ) ) + if ( !FormUtils.isNumber( value ) ) { correctType = false; typeViolations.put( key, value + " " + i18n.getString( "is_invalid_number" ) ); @@ -326,7 +326,7 @@ else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_INT ) ) { - if ( !SectionFormUtils.isInteger( value ) ) + if ( !FormUtils.isInteger( value ) ) { correctType = false; typeViolations.put( key, value + " " + i18n.getString( "is_invalid_integer" ) ); @@ -335,7 +335,7 @@ else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_POSITIVE_INT ) ) { - if ( !SectionFormUtils.isPositiveInteger( value ) ) + if ( !FormUtils.isPositiveInteger( value ) ) { correctType = false; typeViolations.put( key, value + " " + i18n.getString( "is_invalid_positive_integer" ) ); @@ -344,7 +344,7 @@ else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_NEGATIVE_INT ) ) { - if ( !SectionFormUtils.isNegativeInteger( value ) ) + if ( !FormUtils.isNegativeInteger( value ) ) { correctType = false; typeViolations.put( key, value + " " + i18n.getString( "is_invalid_negative_integer" ) ); @@ -411,11 +411,11 @@ needsValidation = true; } - dataValues = sectionFormUtils.getDataValueMap( organisationUnit, dataSet, period ); - - validationViolations = sectionFormUtils.getValidationViolations( organisationUnit, dataSet, period ); - - validationRuleViolations = sectionFormUtils.getValidationRuleViolations( organisationUnit, dataSet, period ); + dataValues = formUtils.getDataValueMap( organisationUnit, dataSet, period ); + + validationViolations = formUtils.getValidationViolations( organisationUnit, dataSet, period ); + + validationRuleViolations = formUtils.getValidationRuleViolations( organisationUnit, dataSet, period ); if ( needsValidation && (!validationViolations.isEmpty() || !validationRuleViolations.isEmpty() || !typeViolations.isEmpty()) ) === added file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/FormUtils.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/FormUtils.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/FormUtils.java 2011-11-01 18:28:36 +0000 @@ -0,0 +1,322 @@ +/* + * Copyright (c) 2004-2010, 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. + */ + +package org.hisp.dhis.light.dataentry.utils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import org.apache.commons.collections.CollectionUtils; +import org.hisp.dhis.dataanalysis.DataAnalysisService; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.datavalue.DeflatedDataValue; +import org.hisp.dhis.expression.ExpressionService; +import org.hisp.dhis.minmax.MinMaxDataElement; +import org.hisp.dhis.minmax.MinMaxDataElementService; +import org.hisp.dhis.minmax.validation.MinMaxValuesGenerationService; +import org.hisp.dhis.options.SystemSettingManager; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.system.filter.OrganisationUnitWithDataSetsFilter; +import org.hisp.dhis.system.util.FilterUtils; +import org.hisp.dhis.system.util.ListUtils; +import org.hisp.dhis.validation.ValidationResult; +import org.hisp.dhis.validation.ValidationRule; +import org.hisp.dhis.validation.ValidationRuleService; +import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; + +/** + * @author mortenoh + */ +public class FormUtils +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataValueService dataValueService; + + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + + private DataAnalysisService stdDevOutlierAnalysisService; + + public void setStdDevOutlierAnalysisService( DataAnalysisService stdDevOutlierAnalysisService ) + { + this.stdDevOutlierAnalysisService = stdDevOutlierAnalysisService; + } + + private DataAnalysisService minMaxOutlierAnalysisService; + + public void setMinMaxOutlierAnalysisService( DataAnalysisService minMaxOutlierAnalysisService ) + { + this.minMaxOutlierAnalysisService = minMaxOutlierAnalysisService; + } + + private SystemSettingManager systemSettingManager; + + public void setSystemSettingManager( SystemSettingManager systemSettingManager ) + { + this.systemSettingManager = systemSettingManager; + } + + private MinMaxValuesGenerationService minMaxValuesGenerationService; + + public void setMinMaxValuesGenerationService( MinMaxValuesGenerationService minMaxValuesGenerationService ) + { + this.minMaxValuesGenerationService = minMaxValuesGenerationService; + } + + private MinMaxDataElementService minMaxDataElementService; + + public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService ) + { + this.minMaxDataElementService = minMaxDataElementService; + } + + private ValidationRuleService validationRuleService; + + public void setValidationRuleService( ValidationRuleService validationRuleService ) + { + this.validationRuleService = validationRuleService; + } + + private ExpressionService expressionService; + + public void setExpressionService( ExpressionService expressionService ) + { + this.expressionService = expressionService; + } + + // ------------------------------------------------------------------------- + // Utils + // ------------------------------------------------------------------------- + + @SuppressWarnings( "unchecked" ) + public Map<String, DeflatedDataValue> getValidationViolations( OrganisationUnit organisationUnit, DataSet dataSet, + Period period ) + { + Map<String, DeflatedDataValue> validationErrorMap = new HashMap<String, DeflatedDataValue>(); + + Collection<MinMaxDataElement> minmaxs = minMaxDataElementService.getMinMaxDataElements( organisationUnit, + dataSet.getDataElements() ); + + Collection<DeflatedDataValue> deflatedDataValues = new HashSet<DeflatedDataValue>(); + + if ( minmaxs == null ) + { + Double factor = (Double) systemSettingManager.getSystemSetting( + SystemSettingManager.KEY_FACTOR_OF_DEVIATION, 2.0 ); + + Collection<DeflatedDataValue> stdDevs = stdDevOutlierAnalysisService.analyse( organisationUnit, + dataSet.getDataElements(), ListUtils.getCollection( period ), factor ); + + Collection<DeflatedDataValue> minMaxs = minMaxOutlierAnalysisService.analyse( organisationUnit, + dataSet.getDataElements(), ListUtils.getCollection( period ), null ); + + deflatedDataValues = CollectionUtils.union( stdDevs, minMaxs ); + } + else + { + deflatedDataValues = minMaxValuesGenerationService.findOutliers( organisationUnit, + ListUtils.getCollection( period ), minmaxs ); + } + + for ( DeflatedDataValue deflatedDataValue : deflatedDataValues ) + { + String key = String.format( "DE%dOC%d", deflatedDataValue.getDataElementId(), + deflatedDataValue.getCategoryOptionComboId() ); + validationErrorMap.put( key, deflatedDataValue ); + } + + return validationErrorMap; + } + + public List<String> getValidationRuleViolations( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) + { + List<ValidationResult> validationRuleResults = new ArrayList<ValidationResult>( validationRuleService.validate( + dataSet, period, organisationUnit ) ); + + List<String> validationRuleViolations = new ArrayList<String>( validationRuleResults.size() ); + + for ( ValidationResult result : validationRuleResults ) + { + ValidationRule rule = result.getValidationRule(); + + StringBuffer sb = new StringBuffer(); + sb.append( expressionService.getExpressionDescription( rule.getLeftSide().getExpression() ) ); + sb.append( " " + rule.getOperator().getMathematicalOperator() + " " ); + sb.append( expressionService.getExpressionDescription( rule.getRightSide().getExpression() ) ); + + validationRuleViolations.add( sb.toString() ); + } + + return validationRuleViolations; + } + + public Map<String, String> getDataValueMap( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) + { + Map<String, String> dataValueMap = new HashMap<String, String>(); + List<DataValue> values = new ArrayList<DataValue>( dataValueService.getDataValues( organisationUnit, period, + dataSet.getDataElements() ) ); + + for ( DataValue dataValue : values ) + { + DataElement dataElement = dataValue.getDataElement(); + DataElementCategoryOptionCombo optionCombo = dataValue.getOptionCombo(); + + String key = String.format( "DE%dOC%d", dataElement.getId(), optionCombo.getId() ); + String value = dataValue.getValue(); + + dataValueMap.put( key, value ); + } + + return dataValueMap; + } + + public List<OrganisationUnit> organisationUnitWithDataSetsFilter( Collection<OrganisationUnit> organisationUnits ) + { + List<OrganisationUnit> ous = new ArrayList<OrganisationUnit>( organisationUnits ); + FilterUtils.filter( ous, new OrganisationUnitWithDataSetsFilter() ); + + return ous; + } + + // ------------------------------------------------------------------------- + // Static Utils + // ------------------------------------------------------------------------- + + public static boolean isNumber( String value ) + { + try + { + Double.parseDouble( value ); + } + catch ( NumberFormatException e ) + { + return false; + } + + return true; + } + + public static boolean isInteger( String value ) + { + try + { + Integer.parseInt( value ); + } + catch ( NumberFormatException e ) + { + return false; + } + + return true; + } + + public static boolean isPositiveInteger( String value ) + { + return valueHigher( value, 0 ); + } + + public static boolean isNegativeInteger( String value ) + { + return valueLower( value, 0 ); + } + + public static boolean valueHigher( String value, int max ) + { + int integerValue; + + try + { + integerValue = Integer.parseInt( value ); + + if ( integerValue > max ) + { + return true; + } + } + catch ( NumberFormatException e ) + { + } + + return false; + } + + public static boolean valueLower( String value, int min ) + { + int integerValue; + + try + { + integerValue = Integer.parseInt( value ); + + if ( integerValue < min ) + { + return true; + } + } + catch ( NumberFormatException e ) + { + } + + return false; + } + + public static boolean isBoolean( String value ) + { + return value.equals( "true" ) || value.equals( "false" ); + } + + public static boolean isDate( String value ) + { + DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay(); + + try + { + sdf.parseDateTime( value ); + return true; + } + catch ( IllegalArgumentException e ) + { + } + + return false; + } +} === removed file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/SectionFormUtils.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/SectionFormUtils.java 2011-10-26 11:49:43 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/SectionFormUtils.java 1970-01-01 00:00:00 +0000 @@ -1,322 +0,0 @@ -/* - * Copyright (c) 2004-2010, 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. - */ - -package org.hisp.dhis.light.dataentry.utils; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - -import org.apache.commons.collections.CollectionUtils; -import org.hisp.dhis.dataanalysis.DataAnalysisService; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.datavalue.DeflatedDataValue; -import org.hisp.dhis.expression.ExpressionService; -import org.hisp.dhis.minmax.MinMaxDataElement; -import org.hisp.dhis.minmax.MinMaxDataElementService; -import org.hisp.dhis.minmax.validation.MinMaxValuesGenerationService; -import org.hisp.dhis.options.SystemSettingManager; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.system.filter.OrganisationUnitWithDataSetsFilter; -import org.hisp.dhis.system.util.FilterUtils; -import org.hisp.dhis.system.util.ListUtils; -import org.hisp.dhis.validation.ValidationResult; -import org.hisp.dhis.validation.ValidationRule; -import org.hisp.dhis.validation.ValidationRuleService; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; - -/** - * @author mortenoh - */ -public class SectionFormUtils -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - private DataAnalysisService stdDevOutlierAnalysisService; - - public void setStdDevOutlierAnalysisService( DataAnalysisService stdDevOutlierAnalysisService ) - { - this.stdDevOutlierAnalysisService = stdDevOutlierAnalysisService; - } - - private DataAnalysisService minMaxOutlierAnalysisService; - - public void setMinMaxOutlierAnalysisService( DataAnalysisService minMaxOutlierAnalysisService ) - { - this.minMaxOutlierAnalysisService = minMaxOutlierAnalysisService; - } - - private SystemSettingManager systemSettingManager; - - public void setSystemSettingManager( SystemSettingManager systemSettingManager ) - { - this.systemSettingManager = systemSettingManager; - } - - private MinMaxValuesGenerationService minMaxValuesGenerationService; - - public void setMinMaxValuesGenerationService( MinMaxValuesGenerationService minMaxValuesGenerationService ) - { - this.minMaxValuesGenerationService = minMaxValuesGenerationService; - } - - private MinMaxDataElementService minMaxDataElementService; - - public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService ) - { - this.minMaxDataElementService = minMaxDataElementService; - } - - private ValidationRuleService validationRuleService; - - public void setValidationRuleService( ValidationRuleService validationRuleService ) - { - this.validationRuleService = validationRuleService; - } - - private ExpressionService expressionService; - - public void setExpressionService( ExpressionService expressionService ) - { - this.expressionService = expressionService; - } - - // ------------------------------------------------------------------------- - // Utils - // ------------------------------------------------------------------------- - - @SuppressWarnings( "unchecked" ) - public Map<String, DeflatedDataValue> getValidationViolations( OrganisationUnit organisationUnit, DataSet dataSet, - Period period ) - { - Map<String, DeflatedDataValue> validationErrorMap = new HashMap<String, DeflatedDataValue>(); - - Collection<MinMaxDataElement> minmaxs = minMaxDataElementService.getMinMaxDataElements( organisationUnit, - dataSet.getDataElements() ); - - Collection<DeflatedDataValue> deflatedDataValues = new HashSet<DeflatedDataValue>(); - - if ( minmaxs == null ) - { - Double factor = (Double) systemSettingManager.getSystemSetting( - SystemSettingManager.KEY_FACTOR_OF_DEVIATION, 2.0 ); - - Collection<DeflatedDataValue> stdDevs = stdDevOutlierAnalysisService.analyse( organisationUnit, - dataSet.getDataElements(), ListUtils.getCollection( period ), factor ); - - Collection<DeflatedDataValue> minMaxs = minMaxOutlierAnalysisService.analyse( organisationUnit, - dataSet.getDataElements(), ListUtils.getCollection( period ), null ); - - deflatedDataValues = CollectionUtils.union( stdDevs, minMaxs ); - } - else - { - deflatedDataValues = minMaxValuesGenerationService.findOutliers( organisationUnit, - ListUtils.getCollection( period ), minmaxs ); - } - - for ( DeflatedDataValue deflatedDataValue : deflatedDataValues ) - { - String key = String.format( "DE%dOC%d", deflatedDataValue.getDataElementId(), - deflatedDataValue.getCategoryOptionComboId() ); - validationErrorMap.put( key, deflatedDataValue ); - } - - return validationErrorMap; - } - - public List<String> getValidationRuleViolations( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) - { - List<ValidationResult> validationRuleResults = new ArrayList<ValidationResult>( validationRuleService.validate( - dataSet, period, organisationUnit ) ); - - List<String> validationRuleViolations = new ArrayList<String>( validationRuleResults.size() ); - - for ( ValidationResult result : validationRuleResults ) - { - ValidationRule rule = result.getValidationRule(); - - StringBuffer sb = new StringBuffer(); - sb.append( expressionService.getExpressionDescription( rule.getLeftSide().getExpression() ) ); - sb.append( " " + rule.getOperator().getMathematicalOperator() + " " ); - sb.append( expressionService.getExpressionDescription( rule.getRightSide().getExpression() ) ); - - validationRuleViolations.add( sb.toString() ); - } - - return validationRuleViolations; - } - - public Map<String, String> getDataValueMap( OrganisationUnit organisationUnit, DataSet dataSet, Period period ) - { - Map<String, String> dataValueMap = new HashMap<String, String>(); - List<DataValue> values = new ArrayList<DataValue>( dataValueService.getDataValues( organisationUnit, period, - dataSet.getDataElements() ) ); - - for ( DataValue dataValue : values ) - { - DataElement dataElement = dataValue.getDataElement(); - DataElementCategoryOptionCombo optionCombo = dataValue.getOptionCombo(); - - String key = String.format( "DE%dOC%d", dataElement.getId(), optionCombo.getId() ); - String value = dataValue.getValue(); - - dataValueMap.put( key, value ); - } - - return dataValueMap; - } - - public List<OrganisationUnit> organisationUnitWithDataSetsFilter( Collection<OrganisationUnit> organisationUnits ) - { - List<OrganisationUnit> ous = new ArrayList<OrganisationUnit>( organisationUnits ); - FilterUtils.filter( ous, new OrganisationUnitWithDataSetsFilter() ); - - return ous; - } - - // ------------------------------------------------------------------------- - // Static Utils - // ------------------------------------------------------------------------- - - public static boolean isNumber( String value ) - { - try - { - Double.parseDouble( value ); - } - catch ( NumberFormatException e ) - { - return false; - } - - return true; - } - - public static boolean isInteger( String value ) - { - try - { - Integer.parseInt( value ); - } - catch ( NumberFormatException e ) - { - return false; - } - - return true; - } - - public static boolean isPositiveInteger( String value ) - { - return valueHigher( value, 0 ); - } - - public static boolean isNegativeInteger( String value ) - { - return valueLower( value, 0 ); - } - - public static boolean valueHigher( String value, int max ) - { - int integerValue; - - try - { - integerValue = Integer.parseInt( value ); - - if ( integerValue > max ) - { - return true; - } - } - catch ( NumberFormatException e ) - { - } - - return false; - } - - public static boolean valueLower( String value, int min ) - { - int integerValue; - - try - { - integerValue = Integer.parseInt( value ); - - if ( integerValue < min ) - { - return true; - } - } - catch ( NumberFormatException e ) - { - } - - return false; - } - - public static boolean isBoolean( String value ) - { - return value.equals( "true" ) || value.equals( "false" ); - } - - public static boolean isDate( String value ) - { - DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay(); - - try - { - sdf.parseDateTime( value ); - return true; - } - catch ( IllegalArgumentException e ) - { - } - - return false; - } -} === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2011-11-01 15:01:22 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2011-11-01 18:28:36 +0000 @@ -7,7 +7,7 @@ <!-- data entry --> - <bean id="org.hisp.dhis.light.dataentry.utils.SectionFormUtils" class="org.hisp.dhis.light.dataentry.utils.SectionFormUtils"> + <bean id="org.hisp.dhis.light.dataentry.utils.FormUtils" class="org.hisp.dhis.light.dataentry.utils.FormUtils"> <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" /> <property name="stdDevOutlierAnalysisService" ref="org.hisp.dhis.dataanalysis.StdDevOutlierAnalysisService" /> <property name="minMaxOutlierAnalysisService" ref="org.hisp.dhis.dataanalysis.MinMaxOutlierAnalysisService" /> @@ -21,7 +21,7 @@ <bean id="org.hisp.dhis.light.dataentry.action.GetOrganisationUnitsAction" class="org.hisp.dhis.light.dataentry.action.GetOrganisationUnitsAction" scope="prototype"> <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" /> - <property name="sectionFormUtils" ref="org.hisp.dhis.light.dataentry.utils.SectionFormUtils" /> + <property name="formUtils" ref="org.hisp.dhis.light.dataentry.utils.FormUtils" /> </bean> <bean id="org.hisp.dhis.light.dataentry.action.GetDataSetsAction" class="org.hisp.dhis.light.dataentry.action.GetDataSetsAction" @@ -36,12 +36,13 @@ <property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" /> </bean> - <bean id="org.hisp.dhis.light.dataentry.action.GetSectionFormAction" class="org.hisp.dhis.light.dataentry.action.GetSectionFormAction"> + <bean id="org.hisp.dhis.light.dataentry.action.GetSectionFormAction" class="org.hisp.dhis.light.dataentry.action.GetSectionFormAction" + scope="prototype"> <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" /> <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" /> <property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" /> <property name="periodService" ref="org.hisp.dhis.period.PeriodService" /> - <property name="sectionFormUtils" ref="org.hisp.dhis.light.dataentry.utils.SectionFormUtils" /> + <property name="formUtils" ref="org.hisp.dhis.light.dataentry.utils.FormUtils" /> </bean> <bean id="org.hisp.dhis.light.dataentry.action.SaveSectionFormAction" class="org.hisp.dhis.light.dataentry.action.SaveSectionFormAction" @@ -54,7 +55,7 @@ <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" /> <property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" /> <property name="periodService" ref="org.hisp.dhis.period.PeriodService" /> - <property name="sectionFormUtils" ref="org.hisp.dhis.light.dataentry.utils.SectionFormUtils" /> + <property name="formUtils" ref="org.hisp.dhis.light.dataentry.utils.FormUtils" /> </bean> <!-- dashboard --> === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectOrganisationUnit.vm' --- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectOrganisationUnit.vm 2011-10-24 12:18:38 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectOrganisationUnit.vm 2011-11-01 18:28:36 +0000 @@ -8,7 +8,7 @@ <li><a href="selectDataSet.action?organisationUnitId=$organisationUnit.id">$!encoder.htmlEncode( ${organisationUnit.name} )</a></li> #else #if( $organisationUnit.children.size() > 0 ) - #set( $children = $sectionFormUtils.organisationUnitWithDataSetsFilter( $organisationUnit.children ) ) + #set( $children = $formUtils.organisationUnitWithDataSetsFilter( $organisationUnit.children ) ) #if( $organisationUnit.dataSets.size() > 0 ) <li><a href="selectDataSet.action?organisationUnitId=$organisationUnit.id">$!encoder.htmlEncode( ${organisationUnit.name} )</a></li> === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectPeriod.vm' --- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectPeriod.vm 2011-11-01 15:01:22 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/selectPeriod.vm 2011-11-01 18:28:36 +0000 @@ -6,9 +6,9 @@ <h3 style="text-align: left;">Successfully Saved</h3> <p style="text-align: left;"> #if( $complete ) - Marked DataSet $dataSet.name as complete <br /> + DataSet $dataSet.name was saved and completed <br /> #else - Saved data set $dataSet.name <br /> + DataSet $dataSet.name was saved<br /> #end </p> </div>
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp