dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26807
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13265: Light, split statis methods out to separate util class
------------------------------------------------------------
revno: 13265
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-12-16 18:25:44 +0100
message:
Light, split statis methods out to separate util class
added:
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/ValueUtils.java
modified:
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/anonymous/action/SearchOrgUnitAction.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.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/java/org/hisp/dhis/light/utils/FormUtils.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/NamebasedUtils.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-web/dhis-web-light/src/main/java/org/hisp/dhis/light/anonymous/action/SearchOrgUnitAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/anonymous/action/SearchOrgUnitAction.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/anonymous/action/SearchOrgUnitAction.java 2013-12-16 17:25:44 +0000
@@ -41,7 +41,6 @@
public class SearchOrgUnitAction
implements Action
{
-
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -111,5 +110,4 @@
return SUCCESS;
}
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java 2013-12-16 17:13:31 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryenrollment/action/SaveMobileProgramEnrollmentAction.java 2013-12-16 17:25:44 +0000
@@ -40,6 +40,7 @@
import org.apache.commons.lang.math.NumberUtils;
import org.apache.struts2.StrutsStatics;
import org.hisp.dhis.light.utils.FormUtils;
+import org.hisp.dhis.light.utils.ValueUtils;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientAttribute;
import org.hisp.dhis.patient.PatientAttributeOption;
@@ -311,12 +312,12 @@
Map<String, String> parameterMap = ContextUtils.getParameterMap( request );
DateTimeFormatter sdf = ISODateTimeFormat.yearMonthDay();
- if ( !FormUtils.isDate( enrollmentDate ) )
+ if ( !ValueUtils.isDate( enrollmentDate ) )
{
validationMap.put( "enrollmentDate", "is_invalid_date" );
}
- if ( !FormUtils.isDate( incidentDate ) )
+ if ( !ValueUtils.isDate( incidentDate ) )
{
validationMap.put( "incidentDate", "is_invalid_date" );
}
@@ -384,7 +385,7 @@
}
else if ( value.trim().length() > 0
&& patientAttribute.getValueType().equals( PatientAttribute.TYPE_DATE )
- && !FormUtils.isDate( value ) )
+ && !ValueUtils.isDate( value ) )
{
this.validationMap.put( key, "is_invalid_date" );
}
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java 2013-12-16 17:13:31 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/beneficiaryregistration/action/SaveBeneficiaryAction.java 2013-12-16 17:25:44 +0000
@@ -38,7 +38,7 @@
import org.apache.commons.lang.math.NumberUtils;
import org.apache.struts2.StrutsStatics;
-import org.hisp.dhis.light.utils.FormUtils;
+import org.hisp.dhis.light.utils.ValueUtils;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientAttribute;
@@ -381,93 +381,90 @@
for ( PatientIdentifierType patientIdentifierType : patientIdentifierTypes )
{
- {
- String key = "IDT" + patientIdentifierType.getId();
- String value = parameterMap.get( key );
-
- PatientIdentifier duplicateId = null;
-
- if ( value != null && !value.isEmpty() )
- {
- duplicateId = patientIdentifierService.get( patientIdentifierType, value );
- }
-
- if ( value != null )
- {
- if ( patientIdentifierType.isMandatory() && value.trim().equals( "" ) )
- {
- this.validationMap.put( key, "is_mandatory" );
- }
- else if ( patientIdentifierType.getType().equals( "number" ) && !MathUtils.isNumeric( value ) )
- {
- this.validationMap.put( key, "is_invalid_number" );
- }
- else if ( duplicateId != null )
- {
- this.validationMap.put( key, "is_duplicate" );
- }
- else
- {
- PatientIdentifier patientIdentifier = new PatientIdentifier();
- patientIdentifier.setIdentifierType( patientIdentifierType );
- patientIdentifier.setPatient( patient );
- patientIdentifier.setIdentifier( value.trim() );
- patientIdentifierSet.add( patientIdentifier );
- }
-
- this.previousValues.put( key, value );
- }
+ String key = "IDT" + patientIdentifierType.getId();
+ String value = parameterMap.get( key );
+
+ PatientIdentifier duplicateId = null;
+
+ if ( value != null && !value.isEmpty() )
+ {
+ duplicateId = patientIdentifierService.get( patientIdentifierType, value );
+ }
+
+ if ( value != null )
+ {
+ if ( patientIdentifierType.isMandatory() && value.trim().equals( "" ) )
+ {
+ this.validationMap.put( key, "is_mandatory" );
+ }
+ else if ( patientIdentifierType.getType().equals( "number" ) && !MathUtils.isNumeric( value ) )
+ {
+ this.validationMap.put( key, "is_invalid_number" );
+ }
+ else if ( duplicateId != null )
+ {
+ this.validationMap.put( key, "is_duplicate" );
+ }
+ else
+ {
+ PatientIdentifier patientIdentifier = new PatientIdentifier();
+ patientIdentifier.setIdentifierType( patientIdentifierType );
+ patientIdentifier.setPatient( patient );
+ patientIdentifier.setIdentifier( value.trim() );
+ patientIdentifierSet.add( patientIdentifier );
+ }
+
+ this.previousValues.put( key, value );
}
}
for ( PatientAttribute patientAttribute : patientAttributes )
{
patientAttributeSet.add( patientAttribute );
+
+ String key = "AT" + patientAttribute.getId();
+ String value = parameterMap.get( key ).trim();
+
+ if ( value != null )
{
- String key = "AT" + patientAttribute.getId();
- String value = parameterMap.get( key ).trim();
-
- if ( value != null )
- {
- if ( patientAttribute.isMandatory() && value.trim().equals( "" ) )
- {
- this.validationMap.put( key, "is_mandatory" );
- }
- else if ( value.trim().length() > 0
- && patientAttribute.getValueType().equals( PatientAttribute.TYPE_INT )
- && !MathUtils.isInteger( value ) )
- {
- this.validationMap.put( key, "is_invalid_number" );
- }
- else if ( value.trim().length() > 0
- && patientAttribute.getValueType().equals( PatientAttribute.TYPE_DATE )
- && !FormUtils.isDate( value ) )
- {
- this.validationMap.put( key, "is_invalid_date" );
- }
- else
- {
- PatientAttributeValue patientAttributeValue = new PatientAttributeValue();
-
- if ( PatientAttribute.TYPE_COMBO.equalsIgnoreCase( patientAttribute.getValueType() ) )
+ if ( patientAttribute.isMandatory() && value.trim().equals( "" ) )
+ {
+ this.validationMap.put( key, "is_mandatory" );
+ }
+ else if ( value.trim().length() > 0
+ && patientAttribute.getValueType().equals( PatientAttribute.TYPE_INT )
+ && !MathUtils.isInteger( value ) )
+ {
+ this.validationMap.put( key, "is_invalid_number" );
+ }
+ else if ( value.trim().length() > 0
+ && patientAttribute.getValueType().equals( PatientAttribute.TYPE_DATE )
+ && !ValueUtils.isDate( value ) )
+ {
+ this.validationMap.put( key, "is_invalid_date" );
+ }
+ else
+ {
+ PatientAttributeValue patientAttributeValue = new PatientAttributeValue();
+
+ if ( PatientAttribute.TYPE_COMBO.equalsIgnoreCase( patientAttribute.getValueType() ) )
+ {
+ PatientAttributeOption option = patientAttributeOptionService.get( NumberUtils.toInt(
+ value, 0 ) );
+
+ if ( option != null )
{
- PatientAttributeOption option = patientAttributeOptionService.get( NumberUtils.toInt(
- value, 0 ) );
-
- if ( option != null )
- {
- patientAttributeValue.setPatientAttributeOption( option );
- }
+ patientAttributeValue.setPatientAttributeOption( option );
}
-
- patientAttributeValue.setPatient( patient );
- patientAttributeValue.setPatientAttribute( patientAttribute );
- patientAttributeValue.setValue( value.trim() );
- patientAttributeValues.add( patientAttributeValue );
}
- this.previousValues.put( key, value );
+ patientAttributeValue.setPatient( patient );
+ patientAttributeValue.setPatientAttribute( patientAttribute );
+ patientAttributeValue.setValue( value.trim() );
+ patientAttributeValues.add( patientAttributeValue );
}
+
+ this.previousValues.put( key, value );
}
}
@@ -490,6 +487,7 @@
{
return "redirect";
}
+
return SUCCESS;
}
}
=== 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 2013-12-16 17:21:39 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java 2013-12-16 17:25:44 +0000
@@ -55,6 +55,7 @@
import org.hisp.dhis.datavalue.DeflatedDataValue;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.light.utils.FormUtils;
+import org.hisp.dhis.light.utils.ValueUtils;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
@@ -329,7 +330,7 @@
}
else if ( type.equals( DataElement.VALUE_TYPE_BOOL ) )
{
- if ( !valueIsEmpty && !FormUtils.isBoolean( value ) )
+ if ( !valueIsEmpty && !ValueUtils.isBoolean( value ) )
{
correctType = false;
typeViolations.put( key, "\"" + value + "\"" + " " + i18n.getString( "is_invalid_boolean" ) );
@@ -337,7 +338,7 @@
}
else if ( type.equals( DataElement.VALUE_TYPE_DATE ) )
{
- if ( !FormUtils.isDate( value ) )
+ if ( !ValueUtils.isDate( value ) )
{
correctType = false;
typeViolations.put( key, "\"" + value + "\"" + " " + i18n.getString( "is_invalid_date" ) );
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java 2013-12-16 17:21:39 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java 2013-12-16 17:25:44 +0000
@@ -1,33 +1,5 @@
package org.hisp.dhis.light.utils;
-/*
- * Copyright (c) 2004-2013, 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.
- */
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -64,8 +36,6 @@
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 Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -294,90 +264,4 @@
return periods;
}
}
-
- // -------------------------------------------------------------------------
- // Static Utils
- // -------------------------------------------------------------------------
-
- public static boolean valueHigher( String value, int max )
- {
- int integerValue;
-
- try
- {
- integerValue = Integer.parseInt( value );
-
- if ( integerValue > max )
- {
- return true;
- }
- }
- catch ( NumberFormatException ignored )
- {
- }
-
- return false;
- }
-
- public static boolean valueHigherOrEqual( String value, int max )
- {
- int integerValue;
-
- try
- {
- integerValue = Integer.parseInt( value );
-
- if ( integerValue >= max )
- {
- return true;
- }
- }
- catch ( NumberFormatException ignored )
- {
- }
-
- return false;
- }
-
- public static boolean valueLower( String value, int min )
- {
- int integerValue;
-
- try
- {
- integerValue = Integer.parseInt( value );
-
- if ( integerValue < min )
- {
- return true;
- }
- }
- catch ( NumberFormatException ignored )
- {
- }
-
- 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 ignored )
- {
- }
-
- return false;
- }
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/NamebasedUtils.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/NamebasedUtils.java 2013-12-16 17:21:39 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/NamebasedUtils.java 2013-12-16 17:25:44 +0000
@@ -91,14 +91,14 @@
}
else if ( type.equals( DataElement.VALUE_TYPE_BOOL ) )
{
- if ( !FormUtils.isBoolean( value ) )
+ if ( !ValueUtils.isBoolean( value ) )
{
return "is_invalid_boolean";
}
}
else if ( type.equals( DataElement.VALUE_TYPE_DATE ) )
{
- if ( !FormUtils.isDate( value ) )
+ if ( !ValueUtils.isDate( value ) )
{
return "is_invalid_date";
}
=== added file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/ValueUtils.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/ValueUtils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/ValueUtils.java 2013-12-16 17:25:44 +0000
@@ -0,0 +1,117 @@
+package org.hisp.dhis.light.utils;
+
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+
+public class ValueUtils
+{
+
+ public static boolean valueHigher( String value, int max )
+ {
+ int integerValue;
+
+ try
+ {
+ integerValue = Integer.parseInt( value );
+
+ if ( integerValue > max )
+ {
+ return true;
+ }
+ }
+ catch ( NumberFormatException ignored )
+ {
+ }
+
+ return false;
+ }
+
+ public static boolean valueHigherOrEqual( String value, int max )
+ {
+ int integerValue;
+
+ try
+ {
+ integerValue = Integer.parseInt( value );
+
+ if ( integerValue >= max )
+ {
+ return true;
+ }
+ }
+ catch ( NumberFormatException ignored )
+ {
+ }
+
+ return false;
+ }
+
+ public static boolean valueLower( String value, int min )
+ {
+ int integerValue;
+
+ try
+ {
+ integerValue = Integer.parseInt( value );
+
+ if ( integerValue < min )
+ {
+ return true;
+ }
+ }
+ catch ( NumberFormatException ignored )
+ {
+ }
+
+ 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 ignored )
+ {
+ }
+
+ return false;
+ }
+}