dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24021
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11723: send SMS feedback in un_register command
------------------------------------------------------------
revno: 11723
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-08-21 12:40:49 +0700
message:
send SMS feedback in un_register command
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/UnregisteredSMSListener.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateGenericHTTPGateWayConfigAction.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-core/src/main/java/org/hisp/dhis/sms/UnregisteredSMSListener.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/UnregisteredSMSListener.java 2013-08-12 06:51:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/UnregisteredSMSListener.java 2013-08-21 05:40:49 +0000
@@ -27,8 +27,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.message.Message;
import org.hisp.dhis.message.MessageConversation;
import org.hisp.dhis.message.MessageConversationStore;
@@ -37,6 +41,7 @@
import org.hisp.dhis.sms.incoming.IncomingSms;
import org.hisp.dhis.sms.incoming.IncomingSmsListener;
import org.hisp.dhis.sms.parse.ParserType;
+import org.hisp.dhis.sms.parse.SMSParserException;
import org.hisp.dhis.smscommand.SMSCommand;
import org.hisp.dhis.smscommand.SMSCommandService;
import org.hisp.dhis.user.User;
@@ -53,9 +58,11 @@
private MessageConversationStore messageConversationStore;
private UserService userService;
-
+
private MessageService messageService;
+ private SmsMessageSender smsMessageSender;
+
@Transactional
@Override
public boolean accept( IncomingSms sms )
@@ -95,32 +102,61 @@
UserGroup userGroup = smsCommand.getUserGroup();
+ String senderPhoneNumber = StringUtils.replace( sms.getOriginator(), "+", "" );
+
if ( userGroup != null )
{
- Set<User> receivers = new HashSet<User>( userGroup.getMembers() );
-
- UserCredentials anonymousUser = userService.getUserCredentialsByUsername( "system" );
-
- if ( anonymousUser == null )
- {
- anonymousUser = userService.getUserCredentialsByUsername( "admin" );
- }
-
- MessageConversation conversation = new MessageConversation( smsCommand.getName(), anonymousUser.getUser() );
-
- conversation.addMessage( new Message( message, null, anonymousUser.getUser() ) );
-
- for ( User receiver : receivers )
- {
- boolean read = false;
-
- conversation.addUserMessage( new UserMessage( receiver, read ) );
- }
- // forward to user group by SMS, E-mail, DHIS conversation
-
- messageService.sendMessage( smsCommand.getName(), message, null, receivers, anonymousUser.getUser(), false, false );
-
- // messageConversationStore.save( conversation );
+ Collection<User> users = userService.getUsersByPhoneNumber( senderPhoneNumber );
+
+ if ( users != null && users.size() >= 1 )
+ {
+ String messageError = "This number is already registered for user: ";
+ for ( Iterator<User> iterator = users.iterator(); iterator.hasNext(); )
+ {
+ User user = iterator.next();
+ messageError += user.getName();
+ if ( iterator.hasNext() )
+ {
+ messageError += ", ";
+ }
+ }
+ throw new SMSParserException( messageError );
+ }
+ else
+ {
+ Set<User> receivers = new HashSet<User>( userGroup.getMembers() );
+
+ UserCredentials anonymousUser = userService.getUserCredentialsByUsername( "system" );
+
+ if ( anonymousUser == null )
+ {
+ anonymousUser = userService.getUserCredentialsByUsername( "admin" );
+ }
+
+ MessageConversation conversation = new MessageConversation( smsCommand.getName(),
+ anonymousUser.getUser() );
+
+ conversation.addMessage( new Message( message, null, anonymousUser.getUser() ) );
+
+ for ( User receiver : receivers )
+ {
+ boolean read = false;
+
+ conversation.addUserMessage( new UserMessage( receiver, read ) );
+ }
+ // forward to user group by SMS, E-mail, DHIS conversation
+
+ messageService.sendMessage( smsCommand.getName(), message, null, receivers, anonymousUser.getUser(),
+ false, false );
+
+ // confirm SMS was received and forwarded completely
+ Set<User> feedbackList = new HashSet<User>();
+ User sender = new User();
+ sender.setPhoneNumber( senderPhoneNumber );
+ feedbackList.add( sender );
+ smsMessageSender.sendMessage( smsCommand.getName(), smsCommand.getReceivedMessage(), null,
+ feedbackList, true );
+ }
}
}
@@ -162,5 +198,5 @@
public void setMessageService( MessageService messageService )
{
this.messageService = messageService;
- }
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateGenericHTTPGateWayConfigAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateGenericHTTPGateWayConfigAction.java 2013-08-12 03:29:54 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateGenericHTTPGateWayConfigAction.java 2013-08-21 05:40:49 +0000
@@ -124,6 +124,7 @@
gatewayConfig.setParameters( map );
gatewayConfig.setName( name );
gatewayConfig.setUrlTemplate( urlTemplate );
+ System.out.println("cuc cu: "+urlTemplate);
if ( config.getGateways() == null || config.getGateways().isEmpty() )
{