← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10872: rename ValidationService => InputValidationService (since it only deals with data).

 

------------------------------------------------------------
revno: 10872
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-17 17:26:46 +0700
message:
  rename ValidationService => InputValidationService (since it only deals with data).
removed:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultValidationService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/ValidationService.java
added:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java
  dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml


--
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
=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java	2013-05-17 10:26:46 +0000
@@ -0,0 +1,163 @@
+package org.hisp.dhis.dxf2;
+
+/*
+ * 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.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.user.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class DefaultInputValidationService implements InputValidationService
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private I18nManager i18nManager;
+
+    @Autowired
+    private UserService userService;
+
+    // -------------------------------------------------------------------------
+    // InputValidationService Implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public Status validateDataElement( DataElement dataElement, String value )
+    {
+        I18nFormat format;
+
+        try
+        {
+            format = i18nManager.getI18nFormat();
+        }
+        catch ( I18nManagerException ex )
+        {
+            return new Status( false, ex.getMessage() );
+        }
+
+        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 = format.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 to 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." );
+                }
+            }
+        }
+
+        return new Status();
+    }
+}

=== removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultValidationService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultValidationService.java	2013-05-17 06:44:41 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultValidationService.java	1970-01-01 00:00:00 +0000
@@ -1,164 +0,0 @@
-package org.hisp.dhis.dxf2;
-
-/*
- * 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.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.i18n.locale.LocaleManager;
-import org.hisp.dhis.system.util.MathUtils;
-import org.hisp.dhis.user.UserService;
-import org.springframework.beans.factory.annotation.Autowired;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class DefaultValidationService implements ValidationService
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    @Autowired
-    private I18nManager i18nManager;
-
-    @Autowired
-    private UserService userService;
-
-    // -------------------------------------------------------------------------
-    // ValidationService Implementation
-    // -------------------------------------------------------------------------
-
-    @Override
-    public ValidationStatus validateDataElement( DataElement dataElement, String value )
-    {
-        I18nFormat format;
-
-        try
-        {
-            format = i18nManager.getI18nFormat();
-        }
-        catch ( I18nManagerException ex )
-        {
-            return new ValidationStatus( false, ex.getMessage() );
-        }
-
-        value = value.trim();
-
-        if ( value.length() >= 255 )
-        {
-            return new ValidationStatus( false, value + " is more than 255 characters." );
-        }
-
-        if ( dataElement.getType().equals( DataElement.VALUE_TYPE_BOOL ) )
-        {
-            if ( !(value.equalsIgnoreCase( "true" ) || value.equalsIgnoreCase( "false" )) )
-            {
-                return new ValidationStatus( false, value + " is not a valid boolean expression." );
-            }
-        }
-        else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_TRUE_ONLY ) )
-        {
-            if ( !value.equalsIgnoreCase( "true" ) )
-            {
-                return new ValidationStatus( false, value + " can only be true." );
-            }
-        }
-        else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_DATE ) )
-        {
-            boolean dateIsValidated = format.parseDate( value ) != null;
-
-            if ( !dateIsValidated )
-            {
-                return new ValidationStatus( 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 ValidationStatus( 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 ValidationStatus( 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 to length validation
-            }
-        }
-        else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_NUMBER ) )
-        {
-            if ( !MathUtils.isNumeric( value ) )
-            {
-                return new ValidationStatus( false, value + " is not a valid number." );
-            }
-
-            if ( dataElement.getOptionSet() != null )
-            {
-                if ( !dataElement.getOptionSet().getOptions().contains( value ) )
-                {
-                    return new ValidationStatus( false, value + " is not a valid option for this optionSet." );
-                }
-            }
-
-            if ( dataElement.getNumberType().equals( DataElement.VALUE_TYPE_INT ) )
-            {
-                if ( !MathUtils.isInteger( value ) )
-                {
-                    return new ValidationStatus( false, value + " is not a valid integer." );
-                }
-            }
-            else if ( dataElement.getNumberType().equals( DataElement.VALUE_TYPE_POSITIVE_INT ) )
-            {
-                if ( !MathUtils.isPositiveInteger( value ) )
-                {
-                    return new ValidationStatus( false, value + " is not a valid positive integer." );
-                }
-            }
-            else if ( dataElement.getNumberType().equals( DataElement.VALUE_TYPE_NEGATIVE_INT ) )
-            {
-                if ( !MathUtils.isNegativeInteger( value ) )
-                {
-                    return new ValidationStatus( false, value + " is not a valid negative integer." );
-                }
-            }
-        }
-
-        return new ValidationStatus( true );
-    }
-}

=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java	2013-05-17 10:26:46 +0000
@@ -0,0 +1,65 @@
+package org.hisp.dhis.dxf2;
+
+/*
+ * 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.hisp.dhis.dataelement.DataElement;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface InputValidationService
+{
+    final class Status
+    {
+        private boolean success = true;
+
+        private String message;
+
+        public Status()
+        {
+        }
+
+        public Status( boolean success, String message )
+        {
+            this.success = success;
+            this.message = message;
+        }
+
+        public boolean isSuccess()
+        {
+            return success;
+        }
+
+        public String getMessage()
+        {
+            return message;
+        }
+    }
+
+    Status validateDataElement( DataElement dataElement, String value );
+}

=== removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/ValidationService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/ValidationService.java	2013-05-17 06:44:41 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/ValidationService.java	1970-01-01 00:00:00 +0000
@@ -1,66 +0,0 @@
-package org.hisp.dhis.dxf2;
-
-/*
- * 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.hisp.dhis.dataelement.DataElement;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface ValidationService
-{
-    class ValidationStatus
-    {
-        private boolean success;
-
-        private String message;
-
-        public ValidationStatus( boolean success )
-        {
-            this.success = success;
-        }
-
-        public ValidationStatus( boolean success, String message )
-        {
-            this.success = success;
-            this.message = message;
-        }
-
-        public boolean isSuccess()
-        {
-            return success;
-        }
-
-        public String getMessage()
-        {
-            return message;
-        }
-    }
-
-    ValidationStatus validateDataElement( DataElement dataElement, String value );
-}

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java	2013-05-17 10:10:55 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java	2013-05-17 10:26:46 +0000
@@ -29,7 +29,7 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.dxf2.ValidationService;
+import org.hisp.dhis.dxf2.InputValidationService;
 import org.hisp.dhis.dxf2.importsummary.ImportConflict;
 import org.hisp.dhis.dxf2.importsummary.ImportStatus;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
@@ -85,7 +85,7 @@
     private PatientDataValueService patientDataValueService;
 
     @Autowired
-    private ValidationService validationService;
+    private InputValidationService inputValidationService;
 
     @Autowired
     private I18nManager i18nManager;
@@ -216,7 +216,7 @@
 
     private boolean validateDataElement( DataElement dataElement, String value, ImportSummary importSummary )
     {
-        ValidationService.ValidationStatus status = validationService.validateDataElement( dataElement, value );
+        InputValidationService.Status status = inputValidationService.validateDataElement( dataElement, value );
 
         if ( !status.isSuccess() )
         {

=== modified file 'dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml	2013-05-17 06:44:41 +0000
+++ dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml	2013-05-17 10:26:46 +0000
@@ -16,7 +16,7 @@
 
   <bean id="org.hisp.dhis.dxf2.event.EventService" class="org.hisp.dhis.dxf2.event.JacksonEventService" />
 
-  <bean id="org.hisp.dhis.dxf2.ValidationService" class="org.hisp.dhis.dxf2.DefaultValidationService" />
+  <bean id="org.hisp.dhis.dxf2.InputValidationService" class="org.hisp.dhis.dxf2.DefaultInputValidationService" />
 
   <!-- register idObject handlers -->