------------------------------------------------------------ revno: 13470 committer: Lars Helge Ă˜verland <[email protected]> branch nick: dhis2 timestamp: Sun 2013-12-29 22:18:19 +0100 message: DefaultInputValidationService, using ValidationUtils modified: dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.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-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java 2013-10-15 07:40:07 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java 2013-12-29 21:18:19 +0000 @@ -29,17 +29,15 @@ */ import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.i18n.I18nFormat; -import org.hisp.dhis.i18n.I18nManager; -import org.hisp.dhis.i18n.I18nManagerException; -import org.hisp.dhis.system.util.MathUtils; +import org.hisp.dhis.system.util.ValidationUtils; import org.hisp.dhis.user.UserService; import org.springframework.beans.factory.annotation.Autowired; /** * @author Morten Olav Hansen <[email protected]> */ -public class DefaultInputValidationService implements InputValidationService +public class DefaultInputValidationService + implements InputValidationService { // ------------------------------------------------------------------------- // Dependencies @@ -48,35 +46,6 @@ @Autowired private UserService userService; - @Autowired - private I18nManager i18nManager; - - private I18nFormat _format; - - @Override - public void setFormat( I18nFormat format ) - { - this._format = format; - } - - I18nFormat getFormat() - { - if ( _format != null ) - { - return _format; - } - - try - { - _format = i18nManager.getI18nFormat(); - } - catch ( I18nManagerException ignored ) - { - } - - return _format; - } - // ------------------------------------------------------------------------- // InputValidationService Implementation // ------------------------------------------------------------------------- @@ -84,109 +53,13 @@ @Override public Status validateDataElement( DataElement dataElement, String value ) { - return validateDataElement( dataElement, value, getFormat() ); - } - - @Override - public Status validateDataElement( DataElement dataElement, String value, I18nFormat format ) - { - value = value.trim(); - - if ( value.length() >= 255 ) - { - return new Status( false, value + " is more than 255 characters." ); - } - - if ( dataElement.getType().equals( DataElement.VALUE_TYPE_BOOL ) ) - { - if ( !(value.equalsIgnoreCase( "true" ) || value.equalsIgnoreCase( "false" )) ) - { - return new Status( false, value + " is not a valid boolean expression." ); - } - } - else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_TRUE_ONLY ) ) - { - if ( !value.equalsIgnoreCase( "true" ) ) - { - return new Status( false, value + " can only be true." ); - } - } - else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_DATE ) ) - { - boolean dateIsValidated = getFormat().parseDate( value ) != null; - - if ( !dateIsValidated ) - { - return new Status( false, value + " is not a valid date expression." ); - } - } - else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_USER_NAME ) ) - { - if ( userService.getUserCredentialsByUsername( value ) == null ) - { - return new Status( false, value + " is not a valid username." ); - } - } - else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_STRING ) ) - { - if ( dataElement.getOptionSet() != null ) - { - if ( !dataElement.getOptionSet().getOptions().contains( value ) ) - { - return new Status( false, value + " is not a valid option for this optionSet." ); - } - } - else if ( dataElement.getTextType().equals( DataElement.VALUE_TYPE_TEXT ) || - dataElement.getTextType().equals( DataElement.VALUE_TYPE_LONG_TEXT ) ) - { - // no validation for this right now, we already have length validation - } - } - else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_NUMBER ) ) - { - if ( !MathUtils.isNumeric( value ) ) - { - return new Status( false, value + " is not a valid number." ); - } - - if ( dataElement.getOptionSet() != null ) - { - if ( !dataElement.getOptionSet().getOptions().contains( value ) ) - { - return new Status( false, value + " is not a valid option for this optionSet." ); - } - } - - if ( dataElement.getNumberType().equals( DataElement.VALUE_TYPE_INT ) ) - { - if ( !MathUtils.isInteger( value ) ) - { - return new Status( false, value + " is not a valid integer." ); - } - } - else if ( dataElement.getNumberType().equals( DataElement.VALUE_TYPE_POSITIVE_INT ) ) - { - if ( !MathUtils.isPositiveInteger( value ) ) - { - return new Status( false, value + " is not a valid positive integer." ); - } - } - else if ( dataElement.getNumberType().equals( DataElement.VALUE_TYPE_NEGATIVE_INT ) ) - { - if ( !MathUtils.isNegativeInteger( value ) ) - { - return new Status( false, value + " is not a valid negative integer." ); - } - } - else if ( dataElement.getNumberType().equals( DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT) ) - { - if ( !MathUtils.isZeroOrPositiveInteger( value ) ) - { - return new Status( false, value + " is not a valid zero or positive integer." ); - } - } - } - + String valid = ValidationUtils.dataValueIsValid( value, dataElement ); + + if ( valid != null ) + { + return new Status( false, valid ); + } + return new Status(); } } === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java 2013-09-23 07:28:36 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java 2013-12-29 21:18:19 +0000 @@ -29,15 +29,12 @@ */ import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.i18n.I18nFormat; /** * @author Morten Olav Hansen <[email protected]> */ public interface InputValidationService { - public void setFormat( I18nFormat format ); - final class Status { private boolean success = true; @@ -66,6 +63,4 @@ } Status validateDataElement( DataElement dataElement, String value ); - - Status validateDataElement( DataElement dataElement, String value, I18nFormat format ); } === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-12-29 21:15:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-12-29 21:18:19 +0000 @@ -627,8 +627,7 @@ private boolean validateDataElement( DataElement dataElement, String value, ImportSummary importSummary ) { - InputValidationService.Status status = inputValidationService.validateDataElement( dataElement, value, - getFormat() ); + InputValidationService.Status status = inputValidationService.validateDataElement( dataElement, value ); if ( !status.isSuccess() ) {
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

