← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10914: [mobile] new UI for SMS receiving page

 

------------------------------------------------------------
revno: 10914
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Tue 2013-05-21 14:01:29 +0700
message:
  [mobile] new UI for SMS receiving page
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/parse/SMSParserException.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java
  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/IParser.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReceivingSMSAction.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/receiveSMSPage.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/sms/parse/SMSParserException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/parse/SMSParserException.java	2012-08-30 12:47:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/parse/SMSParserException.java	2013-05-21 07:01:29 +0000
@@ -3,11 +3,34 @@
 public class SMSParserException
     extends RuntimeException
 {
+    private String reason;
 
     private static final long serialVersionUID = -8088120989819092567L;
 
-    SMSParserException(String message){
-        super(message);
-    }
-    
+    public static final String NO_VALUE = "no_value";
+
+    public static final String WRONG_FORMAT = "wrong_format";
+
+    public static final String MORE_THAN_ONE_ORGUNIT = "more_than_one_orgunit";
+
+    public SMSParserException( String message )
+    {
+        super( message );
+    }
+
+    public SMSParserException( String message, String reason )
+    {
+        super( message );
+        this.reason = reason;
+    }
+
+    public String getReason()
+    {
+        return reason;
+    }
+
+    public void setReason( String reason )
+    {
+        this.reason = reason;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java	2012-11-20 13:34:03 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java	2013-05-21 07:01:29 +0000
@@ -28,6 +28,7 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import org.hisp.dhis.sms.incoming.IncomingSms;
 import org.hisp.dhis.sms.incoming.IncomingSmsService;
@@ -46,7 +47,7 @@
     // -------------------------------------------------------------------------
 
     private IncomingSmsStore incomingSmsStore;
-    
+
     private MessageQueue incomingSmsQueue;
 
     public void setIncomingSmsQueue( MessageQueue incomingSmsQueue )
@@ -163,7 +164,7 @@
     {
         return incomingSmsStore.get( id );
     }
-    
+
     @Override
     public IncomingSms getNextUnprocessed()
     {
@@ -177,6 +178,12 @@
         incomingSmsStore.update( incomingSms );
     }
 
+    @Override
+    public Collection<IncomingSms> getSmsByStatus( SmsMessageStatus status )
+    {
+        return incomingSmsStore.getSmsByStatus( status );
+    }
+
     // -------------------------------------------------------------------------
     // Support methods
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java	2012-11-20 13:34:03 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java	2013-05-21 07:01:29 +0000
@@ -1,5 +1,6 @@
 package org.hisp.dhis.sms.incoming;
 
+import java.util.Collection;
 import java.util.List;
 
 import org.hisp.dhis.sms.queue.MessageQueue;
@@ -64,4 +65,6 @@
     void save ( IncomingSms sms );
     
     public void setIncomingSmsQueue( MessageQueue incomingSmsQueue );
+    
+    Collection<IncomingSms> getSmsByStatus( SmsMessageStatus status );
 }

=== 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-05-20 09:32:19 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java	2013-05-21 07:01:29 +0000
@@ -40,7 +40,6 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -67,6 +66,8 @@
 import org.hisp.dhis.period.WeeklyPeriodType;
 import org.hisp.dhis.period.YearlyPeriodType;
 import org.hisp.dhis.sms.incoming.IncomingSms;
+import org.hisp.dhis.sms.incoming.IncomingSmsService;
+import org.hisp.dhis.sms.incoming.SmsMessageStatus;
 import org.hisp.dhis.sms.outbound.OutboundSms;
 import org.hisp.dhis.sms.outbound.OutboundSmsService;
 import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
@@ -108,7 +109,7 @@
 
     @Autowired
     private DataSetService dataSetService;
-    
+
     private MessageConversationStore messageConversationStore;
 
     public void setMessageConversationStore( MessageConversationStore messageConversationStore )
@@ -116,15 +117,22 @@
         this.messageConversationStore = messageConversationStore;
     }
 
+    @Autowired
+    private IncomingSmsService incomingSmsService;
+
     @Transactional
     public void parse( IncomingSms sms )
     {
         try
         {
-            parse( sms.getOriginator(), sms.getText() );
+            parse( sms.getOriginator(), sms );
+            sms.setStatus( SmsMessageStatus.PROCESSED );
+            incomingSmsService.update( sms );
         }
         catch ( SMSParserException e )
         {
+            sms.setStatus( SmsMessageStatus.FAILED );
+            incomingSmsService.update( sms );
             sendSMS( e.getMessage(), sms.getOriginator() );
             return;
         }
@@ -140,10 +148,10 @@
     }
 
     @Transactional
-    private void parse( String sender, String message )
+    private void parse( String sender, IncomingSms sms )
         throws SMSParserException
     {
-
+        String message = sms.getText();
         if ( StringUtils.isEmpty( sender ) )
         {
             return;
@@ -305,18 +313,18 @@
             else if ( users != null && users.size() == 1 )
             {
                 User sender = (User) users.iterator().next();
-                
+
                 Set<User> receivers = new HashSet<User>( userGroup.getMembers() );
-                
+
                 if ( sender != null )
                 {
                     receivers.add( sender );
                 }
-                
+
                 MessageConversation conversation = new MessageConversation( command.getName(), sender );
-                
+
                 conversation.addMessage( new Message( message, null, sender ) );
-                
+
                 for ( User receiver : receivers )
                 {
                     boolean read = receiver != null && receiver.equals( sender );
@@ -622,11 +630,8 @@
             registration.setSource( organisationUnit );
             registration.setDate( new Date() );
             registration.setStoredBy( storedBy );
-
             registration.setPeriodName( registration.getPeriod().toString() );
-
-            registrationService.saveCompleteDataSetRegistration( registration, true );
-
+            registrationService.saveCompleteDataSetRegistration( registration, false );
             log.info( "DataSet registered as complete: " + registration );
         }
     }
@@ -968,4 +973,11 @@
     {
         this.registrationService = registrationService;
     }
+
+    @Required
+    public IncomingSmsService getIncomingSmsService()
+    {
+        return incomingSmsService;
+    }
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/IParser.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/IParser.java	2013-05-09 17:21:51 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/IParser.java	2013-05-21 07:01:29 +0000
@@ -7,14 +7,17 @@
 import java.util.Map;
 
 /**
- *
+ * 
  * @author Christian
  */
-public interface IParser 
-{    
-    final String DATA_ENTRY_KEYWORD = "DHISDATAENTRYKEYWORD";
-    
-    public Map<String, String> parse(String sms);
-    
-    public void setSeparator(String separator);    
+
+public interface IParser
+{
+    static final String DATA_ENTRY_KEYWORD = "DHISDATAENTRYKEYWORD";
+
+    static final String J2ME_DATA_ENTRY_KEYWORD = "J2MEDATAENTRYKEYWORD";
+
+    public Map<String, String> parse( String sms );
+
+    public void setSeparator( String separator );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java	2013-05-09 17:21:51 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java	2013-05-21 07:01:29 +0000
@@ -77,7 +77,7 @@
                 }
                 catch ( Exception e )
                 {
-                    // ignore
+//                    e.printStackTrace();
                 }
                 try
                 {
@@ -102,6 +102,7 @@
                 catch ( Exception e )
                 {
                     log.error( e );
+                    e.printStackTrace();
                 }
 
                 messageQueue.remove( message );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReceivingSMSAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReceivingSMSAction.java	2013-05-15 04:10:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReceivingSMSAction.java	2013-05-21 07:01:29 +0000
@@ -29,19 +29,18 @@
 
 import java.util.ArrayList;
 import java.util.List;
-
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.sms.SmsConfigurationManager;
 import org.hisp.dhis.sms.config.ModemGatewayConfig;
 import org.hisp.dhis.sms.incoming.IncomingSms;
 import org.hisp.dhis.sms.incoming.IncomingSmsService;
+import org.hisp.dhis.sms.incoming.SmsMessageStatus;
 import org.springframework.beans.factory.annotation.Autowired;
-
 import com.opensymphony.xwork2.Action;
 
 /**
-* @author Nguyen Kim Lai
-*/
+ * @author Nguyen Kim Lai
+ */
 public class ReceivingSMSAction
     implements Action
 {
@@ -62,7 +61,7 @@
     {
         this.i18n = i18n;
     }
-    
+
     @Autowired
     private SmsConfigurationManager smsConfigurationManager;
 
@@ -83,28 +82,39 @@
     {
         return message;
     }
-    
+
     private Integer pollingInterval;
-    
+
     public Integer getPollingInterval()
     {
         return pollingInterval;
     }
 
+    private String smsStatus;
+
+    public String getSmsStatus()
+    {
+        return smsStatus;
+    }
+
+    public void setSmsStatus( String smsStatus )
+    {
+        this.smsStatus = smsStatus;
+    }
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
-
     @Override
     public String execute()
         throws Exception
     {
         ModemGatewayConfig gatewayConfig = (ModemGatewayConfig) smsConfigurationManager
-        .checkInstanceOfGateway( ModemGatewayConfig.class );
+            .checkInstanceOfGateway( ModemGatewayConfig.class );
 
         if ( gatewayConfig != null )
         {
-            pollingInterval = gatewayConfig.getPollingInterval()*1000;
+            pollingInterval = gatewayConfig.getPollingInterval() * 1000;
         }
         else
         {
@@ -114,19 +124,36 @@
 
         if ( listIncomingSms.size() > 0 )
         {
-            for( IncomingSms each : listIncomingSms )
+            for ( IncomingSms each : listIncomingSms )
             {
                 incomingSmsService.save( each );
             }
-            
+
             message = i18n.getString( "new_message" );
-            
+
             incomingSmsService.deleteAllFromModem();
         }
-        
-        listIncomingSms = incomingSmsService.listAllMessage();
+
+        if ( smsStatus == null || smsStatus.trim().equals( "" ) )
+        {
+            listIncomingSms = incomingSmsService.listAllMessage();
+        }
+        else
+        {
+            SmsMessageStatus[] statusArray = SmsMessageStatus.values();
+
+            for ( int i = 0; i < statusArray.length; i++ )
+            {
+                if ( statusArray[i].toString().equalsIgnoreCase( smsStatus ) )
+                {
+                    listIncomingSms = new ArrayList<IncomingSms>( incomingSmsService.getSmsByStatus( statusArray[i] ) );
+                    System.out.println( "Status: " + statusArray[i].toString() );
+                    break;
+                }
+            }
+
+        }
 
         return SUCCESS;
     }
-
 }

=== 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-05-20 09:32:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties	2013-05-21 07:01:29 +0000
@@ -118,4 +118,6 @@
 selected_dataset=Selected dataset
 code_value_separator=Code and value Separator
 no_codes_message=Reply message if no codes are sent (only the command):
-validation_error_space=*White space not allowed
\ No newline at end of file
+validation_error_space=*White space not allowed
+key_value_parser=Key Value Parser
+j2me_parser=J2ME Parser
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.vm	2013-05-15 04:10:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.vm	2013-05-21 07:01:29 +0000
@@ -3,7 +3,7 @@
 	 jQuery(document).ready(function() {
 		checkNewMsg();
 	});
-
+	
 	function checkNewMsg()
 	{	
 		$.get( 'checkNewMessage.action',
@@ -142,30 +142,51 @@
 			);
 		}
 	};
+	
+	function criteriaChanged(list)
+	{	
+    var status = list.options[list.selectedIndex].value;
+
+    var url = "showReceivingPage.action?smsStatus=" + status;
+
+    window.location.href = url;
+	};
 
 	var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_sms" ) , "'")';
 </script>
 <input id="pollingInterval" name="pollingInterval" type="hidden" value="$pollingInterval"/>
 <h3>$i18n.getString( "show_receive_sms_form" )</h3>
 <form id="receiveSmsPage" name="receiveSmsPage" action="showReceivingPage.action" method="post" >
-	<div style="text-align:right; width:800px">
-		<input type="button" name="btnDelete" value="$i18n.getString( 'delete_checked_option' )" onclick="deleteChecked()"/>	
+	<div style="text-align:right; width:840px">	
+		<div style="float: left">
+			<select style="width: 150px" name="smsStatus" onchange="criteriaChanged(this)">
+				<option value="">$i18n.getString( "all" )</option>
+				<option value="INCOMING" #if($smsStatus == 'INCOMING') selected='selected' #end>$i18n.getString( "incoming" )</option>
+				<option value="PROCESSED" #if($smsStatus == 'PROCESSED') selected='selected' #end>$i18n.getString( "processed" )</option>
+				<option value="FAILED" #if($smsStatus == 'FAILED') selected='selected' #end>$i18n.getString( "failed" )</option>
+				<option value="UNHANDLED" #if($smsStatus == 'UNHANDLED') selected='selected' #end>$i18n.getString( "unhandled" )</option>
+			</select>
+		</div>
+		<div style="float: right">
+			<input type="button" name="btnDelete" value="$i18n.getString( 'delete_checked_option' )" onclick="deleteChecked()"/>
+		</div>	
 	</div>
 	<br/>
-	<table id="detailsSmsList" class="listTable" style="width:800px">
+	<table id="detailsSmsList" class="listTable" style="width:840px">
 		<col width="40px"/>
 		<col width="60px"/>
 		<col width="400px"/>
 		<col width="150px"/>
 		<col width="60px"/>
+		<col width="70px"/>
 		<thead>
 			<th style="text-align:center"><a href="#" onclick="checkAll()" title="$i18n.getString( 'check_all' )"><img src="../images/check.png"/></a></th>
 			<th style="text-align:center">$i18n.getString( "no." )</th>
 			<th>$i18n.getString( "message" )</th>
 			<th>$i18n.getString( "phone_number" )</th>
 			<th>$i18n.getString( "status" )</th>
+			<th style="text-align:center">$i18n.getString( "action" )</th>
 			<th style="text-align:center">$i18n.getString( "delete" )</th>
-			
 		</thead>
 		<tbody>
 			#foreach( $incomingSms in $listIncomingSms )
@@ -176,13 +197,16 @@
 					<a id="$velocityCount" style="display: block" href="#" onclick="makeVisible( $incomingSms.id, $velocityCount )">$incomingSms.text</a>
 					<input type="hidden" id="$incomingSms.id" value="$incomingSms.text" onblur="makeVisible( $incomingSms.id, $velocityCount )"/></td>
 				<td>$incomingSms.originator</td>
-				<td>update</td>
+				<td>$incomingSms.status</td>
+				<td style="text-align:center">#if($incomingSms.status == 'FAILED')<a href="#"> Re-import </a> #else None #end</td>
 				<td style="text-align:center"><a href="javascript:removeSingleItem( '$incomingSms.id', '$incomingSms.getText()' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></td>				
 			</tr>
 			#end
 		</tbody>
 	</table>
 	<br/>
+	#parse( "/dhis-web-commons/paging/paging.vm" )
+	<br/>
 	<div style="text-align:right; width:800px">
 		<input type="button" name="btnShowConfig" value="$i18n.getString( 'config_my_gateway' )" onclick="window.location='showSMSConfigureForm.action'"/>
 	</div>