← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14188: [mobile] support the custom response message for sms data reporting

 

------------------------------------------------------------
revno: 14188
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Tue 2014-03-11 15:23:00 +0700
message:
  [mobile] support the custom response message for sms data reporting
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DHISMessageAlertListener.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/J2MEDataValueSMSListener.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/sms/hibernate/SMSCommand.hbm.xml
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm


--
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-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java	2014-01-07 10:08:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java	2014-03-11 08:23:00 +0000
@@ -36,6 +36,12 @@
 
 public class SMSCommand
 {
+    public static final String WRONG_FORMAT_MESSAGE = "Wrong format for command";
+    
+    public static final String MORE_THAN_ONE_ORGUNIT_MESSAGE = "Found more than one org unit for this number. Please specify one organisation unit";
+    
+    public static final String NO_USER_MESSAGE = "No user associated with this phone number. Please contact your supervisor.";
+    
     private int id;
 
     private String name;
@@ -52,15 +58,23 @@
 
     private String codeSeparator;
 
-    private String defaultMessage;
-
-    private String receivedMessage;
-
     private UserGroup userGroup;
 
     private Set<SMSSpecialCharacter> specialCharacters;
 
     private boolean currentPeriodUsedForReporting = false; // default is prev
+    
+    //Messages
+    
+    private String defaultMessage;
+
+    private String receivedMessage;
+    
+    private String wrongFormatMessage;
+    
+    private String noUserMessage;
+    
+    private String moreThanOneOrgUnitMessage;
 
     public SMSCommand( String name, String parser, ParserType parserType, String separator, DataSet dataset,
         Set<SMSCode> codes, String codeSeparator, String defaultMessage, UserGroup userGroup, String receivedMessage, Set<SMSSpecialCharacter> specialCharacters )
@@ -296,4 +310,33 @@
         this.specialCharacters = specialCharacters;
     }
 
+    public String getWrongFormatMessage()
+    {
+        return wrongFormatMessage;
+    }
+
+    public void setWrongFormatMessage( String wrongFormatMessage )
+    {
+        this.wrongFormatMessage = wrongFormatMessage;
+    }
+
+    public String getNoUserMessage()
+    {
+        return noUserMessage;
+    }
+
+    public void setNoUserMessage( String noUserMessage )
+    {
+        this.noUserMessage = noUserMessage;
+    }
+
+    public String getMoreThanOneOrgUnitMessage()
+    {
+        return moreThanOneOrgUnitMessage;
+    }
+
+    public void setMoreThanOneOrgUnitMessage( String moreThanOneOrgUnitMessage )
+    {
+        this.moreThanOneOrgUnitMessage = moreThanOneOrgUnitMessage;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DHISMessageAlertListener.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DHISMessageAlertListener.java	2014-01-01 16:19:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DHISMessageAlertListener.java	2014-03-11 08:23:00 +0000
@@ -117,7 +117,11 @@
 
             if ( users != null && users.size() > 1 )
             {
-                String messageMoreThanOneUser = "System only accepts sender's number assigned for one user, but found more than one user for this number: ";
+                String messageMoreThanOneUser = smsCommand.getMoreThanOneOrgUnitMessage();
+                if ( messageMoreThanOneUser.trim().equals( "" ) )
+                {
+                    messageMoreThanOneUser = SMSCommand.MORE_THAN_ONE_ORGUNIT_MESSAGE;
+                }
                 for ( Iterator<User> i = users.iterator(); i.hasNext(); )
                 {
                     User user = i.next();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java	2014-01-02 13:36:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java	2014-03-11 08:23:00 +0000
@@ -139,10 +139,17 @@
 
         if ( orgUnits == null || orgUnits.size() == 0 )
         {
-            throw new SMSParserException( "No user associated with this phone number. Please contact your supervisor." );
+            if ( StringUtils.isEmpty( smsCommand.getNoUserMessage() ) )
+            {
+                throw new SMSParserException( SMSCommand.NO_USER_MESSAGE );
+            }
+            else
+            {
+                throw new SMSParserException( smsCommand.getNoUserMessage() );
+            }
         }
 
-        OrganisationUnit orgUnit = this.selectOrganisationUnit( orgUnits, parsedMessage );
+        OrganisationUnit orgUnit = this.selectOrganisationUnit( orgUnits, parsedMessage, smsCommand );
         Period period = getPeriod( smsCommand, date );
 
         if ( dataSetService.isLocked( smsCommand.getDataset(), period, orgUnit, null, null ) )
@@ -157,7 +164,6 @@
         {
             if ( parsedMessage.containsKey( code.getCode().toUpperCase() ) )
             {
-                // potential bugs [noted by Lai]
                 valueStored = storeDataValue( senderPhoneNumber, orgUnit, parsedMessage, code, smsCommand, date,
                     smsCommand.getDataset() );
             }
@@ -176,7 +182,14 @@
         }
         else if ( !valueStored )
         {
-            throw new SMSParserException( "Wrong format for command '" + smsCommand.getName() + "'" );
+            if ( StringUtils.isEmpty( smsCommand.getWrongFormatMessage() ) )
+            {
+                throw new SMSParserException( SMSCommand.WRONG_FORMAT_MESSAGE );
+            }
+            else
+            {
+                throw new SMSParserException( smsCommand.getWrongFormatMessage() );
+            }
         }
 
         markCompleteDataSet( senderPhoneNumber, orgUnit, parsedMessage, smsCommand, date );
@@ -264,7 +277,7 @@
     }
 
     private OrganisationUnit selectOrganisationUnit( Collection<OrganisationUnit> orgUnits,
-        Map<String, String> parsedMessage )
+        Map<String, String> parsedMessage, SMSCommand smsCommand )
     {
         OrganisationUnit orgUnit = null;
 
@@ -283,7 +296,7 @@
 
         if ( orgUnit == null && orgUnits.size() > 1 )
         {
-            String messageListingOrgUnits = "Found more than one org unit for this number. Please specify one of the following:";
+            String messageListingOrgUnits = smsCommand.getMoreThanOneOrgUnitMessage();
             for ( Iterator<OrganisationUnit> i = orgUnits.iterator(); i.hasNext(); )
             {
                 OrganisationUnit o = i.next();
@@ -327,7 +340,7 @@
     {
         String upperCaseCode = code.getCode().toUpperCase();
 
-        String storedBy = getUser( sender ).getUsername();
+        String storedBy = getUser( sender, command ).getUsername();
 
         if ( StringUtils.isBlank( storedBy ) )
         {
@@ -409,7 +422,7 @@
         return true;
     }
 
-    private User getUser( String sender )
+    private User getUser( String sender, SMSCommand smsCommand )
     {
         OrganisationUnit orgunit = null;
         User user = null;
@@ -432,8 +445,14 @@
                 }
                 else
                 {
-                    throw new SMSParserException(
-                        "User is associated with more than one orgunit. Please contact your supervisor." );
+                    if ( StringUtils.isEmpty( smsCommand.getMoreThanOneOrgUnitMessage() ) )
+                    {
+                        throw new SMSParserException( SMSCommand.MORE_THAN_ONE_ORGUNIT_MESSAGE );
+                    }
+                    else
+                    {
+                        throw new SMSParserException( smsCommand.getMoreThanOneOrgUnitMessage() );
+                    }
                 }
             }
             user = u;
@@ -468,7 +487,7 @@
             }
         }
 
-        String storedBy = getUser( sender ).getUsername();
+        String storedBy = getUser( sender, command ).getUsername();
 
         if ( StringUtils.isBlank( storedBy ) )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/J2MEDataValueSMSListener.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/J2MEDataValueSMSListener.java	2013-12-19 18:12:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/J2MEDataValueSMSListener.java	2014-03-11 08:23:00 +0000
@@ -125,10 +125,17 @@
 
         if ( orgUnits == null || orgUnits.size() == 0 )
         {
-            throw new SMSParserException( "No user associated with this phone number. Please contact your supervisor." );
+            if ( StringUtils.isEmpty( smsCommand.getNoUserMessage() ) )
+            {
+                throw new SMSParserException( SMSCommand.NO_USER_MESSAGE );
+            }
+            else
+            {
+                throw new SMSParserException( smsCommand.getNoUserMessage() );
+            }
         }
 
-        OrganisationUnit orgUnit = this.selectOrganisationUnit( orgUnits, parsedMessage );
+        OrganisationUnit orgUnit = this.selectOrganisationUnit( orgUnits, parsedMessage, smsCommand );
         Period period = this.getPeriod( token[0].trim(), smsCommand.getDataset().getPeriodType() );
         boolean valueStored = false;
 
@@ -188,7 +195,7 @@
     {
         String upperCaseCode = code.getCode().toUpperCase();
 
-        String storedBy = getUser( sender ).getUsername();
+        String storedBy = getUser( sender, command ).getUsername();
 
         if ( StringUtils.isBlank( storedBy ) )
         {
@@ -249,7 +256,7 @@
     }
 
     private OrganisationUnit selectOrganisationUnit( Collection<OrganisationUnit> orgUnits,
-        Map<String, String> parsedMessage )
+        Map<String, String> parsedMessage, SMSCommand smsCommand )
     {
         OrganisationUnit orgUnit = null;
 
@@ -268,7 +275,7 @@
 
         if ( orgUnit == null && orgUnits.size() > 1 )
         {
-            String messageListingOrgUnits = "Found more than one org unit for this number. Please specify one of the following:";
+            String messageListingOrgUnits = smsCommand.getMoreThanOneOrgUnitMessage();
             for ( Iterator<OrganisationUnit> i = orgUnits.iterator(); i.hasNext(); )
             {
                 OrganisationUnit o = i.next();
@@ -299,7 +306,7 @@
         return orgUnits;
     }
 
-    private User getUser( String sender )
+    private User getUser( String sender, SMSCommand smsCommand )
     {
         OrganisationUnit orgunit = null;
         User user = null;
@@ -319,8 +326,14 @@
             }
             else
             {
-                throw new SMSParserException(
-                    "User is associated with more than one orgunit. Please contact your supervisor." );
+                if ( StringUtils.isEmpty( smsCommand.getMoreThanOneOrgUnitMessage() ) )
+                {
+                    throw new SMSParserException( SMSCommand.MORE_THAN_ONE_ORGUNIT_MESSAGE );
+                }
+                else
+                {
+                    throw new SMSParserException( smsCommand.getMoreThanOneOrgUnitMessage() );
+                }
             }
             user = u;
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/sms/hibernate/SMSCommand.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/sms/hibernate/SMSCommand.hbm.xml	2014-01-07 10:08:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/sms/hibernate/SMSCommand.hbm.xml	2014-03-11 08:23:00 +0000
@@ -25,6 +25,9 @@
     <property name="codeSeparator" type="text" />
     <property name="defaultMessage" type="text" />
     <property name="receivedMessage" type="text" />
+    <property name="wrongFormatMessage" type="text" />
+    <property name="noUserMessage" type="text" />
+    <property name="moreThanOneOrgUnitMessage" type="text" />
     <property name="currentPeriodUsedForReporting" type="boolean" />
 
     <many-to-one name="dataset" class="org.hisp.dhis.dataset.DataSet" column="datasetid" foreign-key="fk_dataset_datasetid" />

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java	2014-02-09 13:16:17 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java	2014-03-11 08:23:00 +0000
@@ -88,6 +88,9 @@
         {
             programs.add( getProgramLWUIT( program.getId() ) );
         }
+        
+        System.out.println("Program by unit size: " + programByUnit.size());
+        System.out.println("Program size: " + programs.size());
 
         return programs;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java	2013-11-22 04:59:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java	2014-03-11 08:23:00 +0000
@@ -103,6 +103,12 @@
     private String defaultMessage;
     
     private String receivedMessage;
+    
+    private String wrongFormatMessage;
+    
+    private String noUserMessage;
+    
+    private String moreThanOneOrgUnitMessage;
 
     private int selectedCommandID = -1;
 
@@ -163,8 +169,14 @@
             smsCommandService.deleteSpecialCharacterSet( toRemoveCharacters );
             
             c.setCodes( codeSet );
+            
+            // message
             c.setDefaultMessage( defaultMessage );
             c.setReceivedMessage( receivedMessage );
+            c.setMoreThanOneOrgUnitMessage( moreThanOneOrgUnitMessage );
+            c.setNoUserMessage( noUserMessage );
+            c.setWrongFormatMessage( wrongFormatMessage );
+            
             if( userGroupID != null && userGroupID > -1 )
             {
                 c.setUserGroup( userGroupService.getUserGroup( userGroupID ) );
@@ -303,5 +315,34 @@
     {
         this.specialCharactersInfo = specialCharactersInfo;
     }
-    
+
+    public String getWrongFormatMessage()
+    {
+        return wrongFormatMessage;
+    }
+
+    public void setWrongFormatMessage( String wrongFormatMessage )
+    {
+        this.wrongFormatMessage = wrongFormatMessage;
+    }
+
+    public String getNoUserMessage()
+    {
+        return noUserMessage;
+    }
+
+    public void setNoUserMessage( String noUserMessage )
+    {
+        this.noUserMessage = noUserMessage;
+    }
+
+    public String getMoreThanOneOrgUnitMessage()
+    {
+        return moreThanOneOrgUnitMessage;
+    }
+
+    public void setMoreThanOneOrgUnitMessage( String moreThanOneOrgUnitMessage )
+    {
+        this.moreThanOneOrgUnitMessage = moreThanOneOrgUnitMessage;
+    }
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties	2013-12-24 08:11:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties	2014-03-11 08:23:00 +0000
@@ -136,3 +136,6 @@
 ALERT_PARSER=Alert Parser
 UNREGISTERED_PARSER=Unregistered Parser
 ANONYMOUS_PROGRAM_PARSER=Anonymous Program Parser
+wrong_format_message=Wrong format message
+no_user_message=No user message
+more_than_one_orgunit_message=User belong to more than one OrgUnit message

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm	2014-01-07 10:08:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm	2014-03-11 08:23:00 +0000
@@ -143,7 +143,26 @@
 			<td>
 				<input type="text"  #if($smsCommand.separator) value="$smsCommand.separator" #end name="separator" style="width:20em" class="validate" />
 			</td>
-		</tr> 
+		</tr>
+		
+		<tr>
+            <td style="width:130px">$i18n.getString( "no_codes_message" )</td>
+            <td><textarea cols="35" type="text" name="defaultMessage">#if($smsCommand.defaultMessage)$smsCommand.defaultMessage#end</textarea></td>
+        </tr>
+        <tr>
+            <td style="width:130px">$i18n.getString( "wrong_format_message" )</td>
+            <td><textarea cols="35" type="text" name="wrongFormatMessage">#if($smsCommand.wrongFormatMessage)$smsCommand.wrongFormatMessage#end</textarea></td>
+        </tr>
+        <tr>
+            <td style="width:130px">$i18n.getString( "no_user_message" )</td>
+            <td><textarea cols="35" type="text" name="noUserMessage">#if($smsCommand.noUserMessage)$smsCommand.noUserMessage#end</textarea></td>
+        </tr>
+        
+		<tr>
+            <td style="width:130px">$i18n.getString( "more_than_one_orgunit_message" )</td>
+            <td><textarea cols="35" type="text" name="moreThanOneOrgUnitMessage">#if($smsCommand.moreThanOneOrgUnitMessage)$smsCommand.moreThanOneOrgUnitMessage#end</textarea></td>
+        </tr>
+		 
 		#elseif( $smsCommand.parserType == 'ALERT_PARSER' || $smsCommand.parserType == 'UNREGISTERED_PARSER' )
 		<tr>
 			<td>$i18n.getString( "userGroup" )</td>
@@ -160,10 +179,6 @@
 			<td><textarea cols="35" type="text" name="receivedMessage">#if($smsCommand.receivedMessage)$smsCommand.receivedMessage#end</textarea></td>
 		</tr>
 		#end
-        <tr>
-            <td style="width:130px">$i18n.getString( "no_codes_message" )</td>
-            <td><textarea cols="35" type="text" name="defaultMessage">#if($smsCommand.defaultMessage)$smsCommand.defaultMessage#end</textarea></td>
-        </tr>
         
 	</table>