← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10310: Alphabetical orderd keys in feedback message

 

------------------------------------------------------------
revno: 10310
committer: Magnus Korvald <korvald@xxxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2013-03-19 13:18:08 +0100
message:
  Alphabetical orderd keys in feedback message
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-13 15:23:25 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java	2013-03-19 12:18:08 +0000
@@ -5,9 +5,13 @@
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -259,10 +263,12 @@
     {
         String reportBack = "Thank you! Values entered: ";
         String notInReport = "Missing values for: ";
-        boolean missingElements = false;
 
         Period period = null;
 
+        Map<String, DataValue> codesWithDataValues = new TreeMap<String, DataValue>();
+        List<String> codesWithoutDataValues = new ArrayList<String>();
+
         for ( SMSCode code : command.getCodes() )
         {
 
@@ -275,30 +281,41 @@
 
             if ( dv == null && !StringUtils.isEmpty( code.getCode() ) )
             {
-                notInReport += code.getCode() + ",";
-                missingElements = true;
+                codesWithoutDataValues.add( code.getCode() );
             }
             else if ( dv != null )
             {
-                String value = dv.getValue();
-                if ( StringUtils.equals( dv.getDataElement().getType(), DataElement.VALUE_TYPE_BOOL ) )
-                {
-                    if ( "true".equals( value ) )
-                    {
-                        value = "Yes";
-                    }
-                    else if ( "false".equals( value ) )
-                    {
-                        value = "No";
-                    }
-                }
-                reportBack += code.getCode() + "=" + value + " ";
-            }
-        }
-
+                codesWithDataValues.put( code.getCode(), dv );
+            }
+        }
+
+        for ( String key : codesWithDataValues.keySet() )
+        {
+            DataValue dv = codesWithDataValues.get( key );
+            String value = dv.getValue();
+            if ( StringUtils.equals( dv.getDataElement().getType(), DataElement.VALUE_TYPE_BOOL ) )
+            {
+                if ( "true".equals( value ) )
+                {
+                    value = "Yes";
+                }
+                else if ( "false".equals( value ) )
+                {
+                    value = "No";
+                }
+            }
+            reportBack += key + "=" + value + " ";
+        }
+
+        Collections.sort( codesWithoutDataValues );
+
+        for ( String key : codesWithoutDataValues )
+        {
+            notInReport += key + ",";
+        }
         notInReport = notInReport.substring( 0, notInReport.length() - 1 );
 
-        if ( missingElements )
+        if ( codesWithoutDataValues.size() > 0 )
         {
             sendSMS( reportBack + notInReport, sender );
         }