← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10596: [mobile] check the data type before import value from sms

 

------------------------------------------------------------
revno: 10596
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Wed 2013-04-17 15:40:27 +0700
message:
  [mobile] check the data type before import value from sms
modified:
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.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-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java	2013-03-19 12:18:08 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java	2013-04-17 08:40:27 +0000
@@ -199,13 +199,12 @@
         {
             if ( parsedMessage.containsKey( code.getCode().toUpperCase() ) )
             {
-                storeDataValue( sender, orgUnit, parsedMessage, code, command, date, command.getDataset(),
-                    formIsComplete( command, parsedMessage ) );
-                valueStored = true;
+                valueStored = storeDataValue( sender, orgUnit, parsedMessage, code, command, date,
+                    command.getDataset(), formIsComplete( command, parsedMessage ) );
             }
         }
 
-        if ( parsedMessage.isEmpty() || !valueStored )
+        if ( parsedMessage.isEmpty() )
         {
             if ( StringUtils.isEmpty( command.getDefaultMessage() ) )
             {
@@ -216,9 +215,12 @@
                 throw new SMSParserException( command.getDefaultMessage() );
             }
         }
+        else if ( !valueStored )
+        {
+            throw new SMSParserException( "Wrong format for command '" + command.getName() + "'" );
+        }
 
         markCompleteDataSet( sender, orgUnit, parsedMessage, command, date );
-
         sendSuccessFeedback( sender, command, parsedMessage, date, orgUnit );
 
     }
@@ -382,7 +384,7 @@
         return date;
     }
 
-    private void storeDataValue( String sender, OrganisationUnit orgunit, Map<String, String> parsedMessage,
+    private boolean storeDataValue( String sender, OrganisationUnit orgunit, Map<String, String> parsedMessage,
         SMSCode code, SMSCommand command, Date date, DataSet dataSet, boolean completeForm )
     {
         String upperCaseCode = code.getCode().toUpperCase();
@@ -427,6 +429,18 @@
                     value = "false";
                 }
             }
+            else if ( StringUtils.equals( dv.getDataElement().getType(), DataElement.VALUE_TYPE_INT ) )
+            {
+                try
+                {
+                    Integer.parseInt( value );
+                }
+                catch ( NumberFormatException e )
+                {
+                    return false;
+                }
+
+            }
 
             dv.setValue( value );
             dv.setTimestamp( new java.util.Date() );
@@ -442,6 +456,7 @@
             }
         }
 
+        return true;
     }
 
     /* Checks if all defined data codes have values in the database */