dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22839
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11113: forward SMS to usergroup from outside SMS, integrate message to confirm an SMS was received and f...
------------------------------------------------------------
revno: 11113
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-05-30 16:49:45 +0700
message:
forward SMS to usergroup from outside SMS, integrate message to confirm an SMS was received and forwarded ok, split long SMS
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/smscommand/SMSCommand.hbm.xml
dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsSender.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/smslib/SmsLibService.java
dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateBulkGateWayConfigAction.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/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 2013-05-20 09:32:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java 2013-05-30 09:49:45 +0000
@@ -53,12 +53,14 @@
private String defaultMessage;
+ private String receivedMessage;
+
private UserGroup userGroup;
private boolean currentPeriodUsedForReporting = false; // default is prev
public SMSCommand( String name, String parser, ParserType parserType, String separator, DataSet dataset,
- Set<SMSCode> codes, String codeSeparator, String defaultMessage, UserGroup userGroup )
+ Set<SMSCode> codes, String codeSeparator, String defaultMessage, UserGroup userGroup, String receivedMessage )
{
super();
this.name = name;
@@ -70,6 +72,7 @@
this.codeSeparator = codeSeparator;
this.defaultMessage = defaultMessage;
this.userGroup = userGroup;
+ this.receivedMessage = receivedMessage;
}
public SMSCommand( String name, String parser, ParserType parserType, String separator, DataSet dataset,
@@ -252,4 +255,14 @@
{
this.userGroup = userGroup;
}
+
+ public String getReceivedMessage()
+ {
+ return receivedMessage;
+ }
+
+ public void setReceivedMessage( String receivedMessage )
+ {
+ this.receivedMessage = receivedMessage;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/smscommand/SMSCommand.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/smscommand/SMSCommand.hbm.xml 2013-05-20 09:32:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/smscommand/SMSCommand.hbm.xml 2013-05-30 09:49:45 +0000
@@ -25,6 +25,7 @@
<property name="separator" type="text" column="separatorkey" />
<property name="codeSeparator" type="text" />
<property name="defaultMessage" type="text" />
+ <property name="receivedMessage" type="text" />
<property name="currentPeriodUsedForReporting" type="boolean" />
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsSender.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsSender.java 2013-05-22 07:06:36 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsSender.java 2013-05-30 09:49:45 +0000
@@ -28,12 +28,14 @@
package org.hisp.dhis.sms.outbound;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.message.MessageSender;
import org.hisp.dhis.sms.SmsServiceException;
+import org.hisp.dhis.sms.smslib.SmsLibService;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserService;
@@ -51,6 +53,10 @@
{
private static final Log log = LogFactory.getLog( SmsSender.class );
+ private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
+
+ private static final int MAX_HEX_CHAR = 280;
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -82,43 +88,42 @@
/**
* Note this methods is invoked asynchronously.
*/
- //@Async
+ // @Async
@Override
public String sendMessage( String subject, String text, User sender, Set<User> users, boolean forceSend )
{
String message = null;
- Set<User> toSendUserList = new HashSet<User>();
+ Set<User> toSendList = new HashSet<User>();
String gatewayId = transportService.getDefaultGateway();
+
+ if ( SmsLibService.gatewayMap.get( "bulk_gw" ).equals( gatewayId ) )
+ {
+ //bulk is limited in sending long SMS. to be continue....
+ }
if ( gatewayId != null && !gatewayId.trim().isEmpty() )
{
- boolean sendSMSNotification = false;
for ( User user : users )
{
- if ( !currentUserService.getCurrentUser().equals( user ) )
+ if ( currentUserService.getCurrentUser() != null )
{
- // check if receiver is raw number or not
- if ( user.getFirstName() == null )
- {
- toSendUserList.add( user );
- }
- else
- {
- UserSetting userSetting = userService.getUserSetting( user,
- UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION );
- if ( userSetting != null )
+ if ( !currentUserService.getCurrentUser().equals( user ) )
+ {
+ if ( isQualifiedReceiver( user ) )
{
- sendSMSNotification = (Boolean) userSetting.getValue();
- if ( sendSMSNotification == true )
- {
- toSendUserList.add( user );
- sendSMSNotification = false;
- }
+ toSendList.add( user );
}
}
}
+ else if ( currentUserService.getCurrentUser() == null )
+ {
+ if ( isQualifiedReceiver( user ) )
+ {
+ toSendList.add( user );
+ }
+ }
}
Set<String> phoneNumbers = null;
@@ -127,7 +132,7 @@
{
text = createMessage( subject, text, sender );
- phoneNumbers = getRecipientsPhoneNumber( toSendUserList );
+ phoneNumbers = getRecipientsPhoneNumber( toSendList );
if ( !phoneNumbers.isEmpty() && phoneNumbers.size() > 0 )
{
@@ -143,10 +148,40 @@
// Supportive methods
// -------------------------------------------------------------------------
+ private boolean isQualifiedReceiver( User user )
+ {
+ // if receiver is raw number
+ if ( user.getFirstName() == null )
+ {
+ return true;
+ }
+ // if receiver is user
+ else
+ {
+ UserSetting userSetting = userService
+ .getUserSetting( user, UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION );
+ if ( userSetting != null )
+ {
+ boolean sendSMSNotification = (Boolean) userSetting.getValue();
+ if ( sendSMSNotification == true )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
private String createMessage( String subject, String text, User sender )
- //private String createMessage( String subject, String text, User sender, boolean isUnicode )
{
- String name = "unknown";
+ String name = "DHIS";
if ( sender != null )
{
@@ -162,7 +197,7 @@
subject = " - " + subject;
}
- text = "From " + name + subject + ": " + text;
+ text = name + subject + ": " + text;
// Simplistic cut off 160 characters
int length = text.length();
@@ -188,7 +223,8 @@
}
private String sendMessage( String text, Set<String> recipients, String gateWayId )
- //private String sendMessage( String text, Set<String> recipients, String gateWayId, boolean isUnicode )
+ // private String sendMessage( String text, Set<String> recipients, String
+ // gateWayId, boolean isUnicode )
{
String message = null;
OutboundSms sms = new OutboundSms();
@@ -205,7 +241,49 @@
log.warn( "Unable to send message through sms: " + sms, e );
}
-
+
return message;
}
+
+ public static String toHex( byte[] buf )
+ {
+ char[] chars = new char[2 * buf.length];
+ for ( int i = 0; i < buf.length; ++i )
+ {
+ chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
+ chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
+ }
+ return new String( chars );
+ }
+
+ public static List<String> spitLongHexString( String hexString, String message, List<String> result )
+ {
+
+ String firstTempHex = null;
+ String secondTempHex = null;
+ String firstTempString = null;
+ String secondTempString = null;
+ int indexToCut;
+
+ firstTempHex = hexString.substring( 0, MAX_HEX_CHAR );
+
+ int lastSpaceIndex = firstTempHex.lastIndexOf( "0020" );
+
+ firstTempHex = firstTempHex.substring( 0, lastSpaceIndex );
+ indexToCut = (firstTempHex.length() - 4) / 4;
+ firstTempString = message.substring( 0, indexToCut );
+ result.add( firstTempString );
+
+ secondTempHex = "feff" + hexString.substring( firstTempHex.length() + 4, hexString.length() );
+ secondTempString = message.substring( indexToCut + 1, message.length() );
+ if ( secondTempHex.length() <= MAX_HEX_CHAR )
+ {
+ result.add( secondTempString );
+ return result;
+ }
+ else
+ {
+ return spitLongHexString( secondTempHex, secondTempString, result );
+ }
+ }
}
=== 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-24 09:21:22 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java 2013-05-30 09:49:45 +0000
@@ -40,6 +40,7 @@
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;
@@ -55,6 +56,7 @@
import org.hisp.dhis.message.Message;
import org.hisp.dhis.message.MessageConversation;
import org.hisp.dhis.message.MessageConversationStore;
+import org.hisp.dhis.message.MessageSender;
import org.hisp.dhis.message.UserMessage;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.CalendarPeriodType;
@@ -116,6 +118,13 @@
{
this.messageConversationStore = messageConversationStore;
}
+
+ private MessageSender messageSender;
+
+ public void setMessageSender( MessageSender messageSender )
+ {
+ this.messageSender = messageSender;
+ }
@Autowired
private IncomingSmsService incomingSmsService;
@@ -282,17 +291,6 @@
private void runDhisMessageAlertParser( String senderNumber, String message, SMSCommand command )
{
- /*
- * IParser parser = new DhisMessageAlertParser();
- *
- * if ( !StringUtils.isBlank( command.getSeparator() ) ) {
- * parser.setSeparator( command.getSeparator() ); }
- *
- * message = message.trim();
- *
- * Map<String, String> parsedMessage = parser.parse( message );
- */
-
UserGroup userGroup = command.getUserGroup();
if ( userGroup != null )
@@ -318,6 +316,10 @@
Set<User> receivers = new HashSet<User>( userGroup.getMembers() );
+ //forward to user group by SMS
+ messageSender.sendMessage( command.getName(), message, sender, receivers, true );
+
+ //forward to user group by dhis message
if ( sender != null )
{
receivers.add( sender );
@@ -334,6 +336,10 @@
conversation.addUserMessage( new UserMessage( receiver, read ) );
}
messageConversationStore.save( conversation );
+ //confirm SMS was received and forwarded completely
+ Set<User> feedbackList = new HashSet<User>();
+ feedbackList.add( sender );
+ messageSender.sendMessage( command.getName(), command.getReceivedMessage(), null, feedbackList, true );
}
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java 2013-05-22 07:06:36 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java 2013-05-30 09:49:45 +0000
@@ -72,7 +72,7 @@
private final String SMPP_GATEWAY = "smpp_gw";
- private Map<String, String> gatewayMap = new HashMap<String, String>();
+ public static Map<String, String> gatewayMap = new HashMap<String, String>();
private GateWayFactory gatewayFactory = new GateWayFactory();
@@ -148,6 +148,8 @@
OutboundMessage outboundMessage = new OutboundMessage( recipient, sms.getMessage() );
outboundMessage.setEncoding( MessageEncodings.ENCUCS2 );
+
+ outboundMessage.setStatusReport( true );
String longNumber = config.getLongNumber();
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2013-05-20 09:32:19 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2013-05-30 09:49:45 +0000
@@ -61,6 +61,7 @@
<property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
<property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" />
<property name="messageConversationStore" ref="org.hisp.dhis.message.MessageConversationStore" />
+ <property name="messageSender" ref="org.hisp.dhis.sms.outbound.SmsSender" />
</bean>
</beans>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateBulkGateWayConfigAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateBulkGateWayConfigAction.java 2013-03-13 10:11:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateBulkGateWayConfigAction.java 2013-05-30 09:49:45 +0000
@@ -100,44 +100,44 @@
{
if ( gatewayType != null && gatewayType.equals( "bulksms" ) )
{
- SmsConfiguration config = smsConfigurationManager.getSmsConfiguration();
+ SmsConfiguration smsConfig = smsConfigurationManager.getSmsConfiguration();
- if ( config != null )
+ if ( smsConfig != null )
{
- BulkSmsGatewayConfig gatewayConfig = (BulkSmsGatewayConfig) smsConfigurationManager
+ BulkSmsGatewayConfig bulkGatewayConfig = (BulkSmsGatewayConfig) smsConfigurationManager
.checkInstanceOfGateway( BulkSmsGatewayConfig.class );
int index = -1;
- if ( gatewayConfig == null )
+ if ( bulkGatewayConfig == null )
{
- gatewayConfig = new BulkSmsGatewayConfig();
+ bulkGatewayConfig = new BulkSmsGatewayConfig();
}
else
{
- index = config.getGateways().indexOf( gatewayConfig );
+ index = smsConfig.getGateways().indexOf( bulkGatewayConfig );
}
- gatewayConfig.setName( name );
- gatewayConfig.setPassword( password );
- gatewayConfig.setUsername( username );
- gatewayConfig.setRegion( region );
+ bulkGatewayConfig.setName( name );
+ bulkGatewayConfig.setPassword( password );
+ bulkGatewayConfig.setUsername( username );
+ bulkGatewayConfig.setRegion( region );
- if ( config.getGateways() == null || config.getGateways().isEmpty() )
+ if ( smsConfig.getGateways() == null || smsConfig.getGateways().isEmpty() )
{
- gatewayConfig.setDefault( true );
+ bulkGatewayConfig.setDefault( true );
}
if ( index >= 0 )
{
- config.getGateways().set( index, gatewayConfig );
+ smsConfig.getGateways().set( index, bulkGatewayConfig );
}
else
{
- config.getGateways().add( gatewayConfig );
+ smsConfig.getGateways().add( bulkGatewayConfig );
}
- smsConfigurationManager.updateSmsConfiguration( config );
+ smsConfigurationManager.updateSmsConfiguration( smsConfig );
}
}
=== 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-05-22 07:06:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java 2013-05-30 09:49:45 +0000
@@ -97,6 +97,8 @@
private String codeSeparator;
private String defaultMessage;
+
+ private String receivedMessage;
private int selectedCommandID = -1;
@@ -136,6 +138,7 @@
c.setSeparator( separator );
c.setCodes( codeSet );
c.setDefaultMessage( defaultMessage );
+ c.setReceivedMessage( receivedMessage );
if( userGroupID != null && userGroupID > -1 )
{
c.setUserGroup( userGroupService.getUserGroup( userGroupID ) );
@@ -254,8 +257,13 @@
}
}
- public Integer getUserGroupID()
- {
- return userGroupID;
+ public void setUserGroupID( Integer userGroupID )
+ {
+ this.userGroupID = userGroupID;
+ }
+
+ public void setReceivedMessage( String receivedMessage )
+ {
+ this.receivedMessage = receivedMessage;
}
}
\ 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/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 2013-05-22 07:06:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm 2013-05-30 09:49:45 +0000
@@ -77,8 +77,11 @@
</select>
</td>
</tr>
+ <tr>
+ <td style="width:150px">Confirm Message: </td>
+ <td><textarea cols="35" type="text" name="receivedMessage">#if($smsCommand.receivedMessage)$smsCommand.receivedMessage#end</textarea></td>
+ </tr>
#end
-
<tr>
<td style="width:150px">$i18n.getString( "no_codes_message" )</td>
<td><textarea cols="35" type="text" name="defaultMessage">#if($smsCommand.defaultMessage)$smsCommand.defaultMessage#end</textarea></td>