dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17668
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7116: Add Save IncomingSMS feature from the modem gateway
------------------------------------------------------------
revno: 7116
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-05-31 16:58:44 +0700
message:
Add Save IncomingSMS feature from the modem gateway
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ImportReceiveSMSAction.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.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/inbound/HibernateIncomingSmsStore.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/incoming/ReceivingSMSAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml
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/struts.xml
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/incoming/IncomingSmsService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java 2012-05-29 07:58:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java 2012-05-31 09:58:44 +0000
@@ -54,4 +54,6 @@
List<IncomingSms> listAllMessage ();
List<InboundMessage> getMsgList();
+
+ void save ( IncomingSms sms );
}
=== 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-05-29 07:58:51 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java 2012-05-31 09:58:44 +0000
@@ -1,10 +1,39 @@
package org.hisp.dhis.sms.inbound;
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
import java.util.ArrayList;
import java.util.List;
-
import org.hisp.dhis.sms.incoming.IncomingSms;
import org.hisp.dhis.sms.incoming.IncomingSmsService;
+import org.hisp.dhis.sms.incoming.IncomingSmsStore;
+import org.hisp.dhis.sms.incoming.SmsMessageEncoding;
+import org.hisp.dhis.sms.incoming.SmsMessageStatus;
import org.smslib.InboundMessage;
import org.smslib.Service;
@@ -14,6 +43,17 @@
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
+
+ private IncomingSmsStore incomingSmsStore;
+
+ public void setIncomingSmsStore( IncomingSmsStore incomingSmsStore )
+ {
+ this.incomingSmsStore = incomingSmsStore;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input & Output
+ // -------------------------------------------------------------------------
private List<InboundMessage> msgList = new ArrayList<InboundMessage>();
@@ -46,11 +86,21 @@
{
IncomingSms incomingSms = new IncomingSms();
- incomingSms.setGatewayId( each.getGatewayId() );
-
incomingSms.setOriginator( each.getOriginator() );
-
+
+ incomingSms.setEncoding( SmsMessageEncoding.ENC7BIT );
+
+ incomingSms.setSentDate( each.getDate() );
+
+ incomingSms.setReceivedDate( each.getDate() );
+
incomingSms.setText( each.getText() );
+
+ incomingSms.setGatewayId( each.getGatewayId() );
+
+ incomingSms.setStatus( SmsMessageStatus.PROCESSED );
+
+ incomingSms.setStatusMessage( "imported" );
result.add( incomingSms );
}
@@ -74,6 +124,49 @@
}
return msgList;
}
+
+ @Override
+ public IncomingSms get( int index )
+ {
+ try
+ {
+ Service.getInstance().readMessages( msgList, InboundMessage.MessageClasses.ALL );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ InboundMessage specifiedMsg = msgList.get( index - 1 );
+
+ IncomingSms incomingSms = new IncomingSms();
+
+ incomingSms.setOriginator( specifiedMsg.getOriginator() );
+
+ incomingSms.setEncoding( SmsMessageEncoding.ENC7BIT );
+
+ incomingSms.setSentDate( specifiedMsg.getDate() );
+
+ incomingSms.setReceivedDate( specifiedMsg.getDate() );
+
+ incomingSms.setText( specifiedMsg.getText() );
+
+ incomingSms.setGatewayId( specifiedMsg.getGatewayId() );
+
+ incomingSms.setStatus( SmsMessageStatus.PROCESSED );
+
+ incomingSms.setStatusMessage( "imported" );
+
+ msgList.clear();
+
+ return incomingSms;
+ }
+
+ @Override
+ public void save( IncomingSms incomingSms )
+ {
+ incomingSmsStore.save( incomingSms );
+ }
@Override
public IncomingSms getNextUnprocessed()
@@ -83,17 +176,11 @@
}
@Override
- public IncomingSms get( int id )
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
public void update( IncomingSms sms )
{
// TODO Auto-generated method stub
}
+
}
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/HibernateIncomingSmsStore.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/HibernateIncomingSmsStore.java 2012-05-29 07:58:51 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/HibernateIncomingSmsStore.java 2012-05-31 09:58:44 +0000
@@ -37,8 +37,9 @@
import org.hisp.dhis.sms.incoming.IncomingSms;
import org.hisp.dhis.sms.incoming.IncomingSmsStore;
import org.hisp.dhis.sms.incoming.SmsMessageStatus;
+import org.springframework.transaction.annotation.Transactional;
-@SuppressWarnings( "unchecked" )
+@Transactional
public class HibernateIncomingSmsStore
implements IncomingSmsStore
{
=== 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 2012-05-29 09:39:45 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2012-05-31 09:58:44 +0000
@@ -28,10 +28,12 @@
<!-- Inbound SMS service -->
- <bean id="inboundSmsStore" class="org.hisp.dhis.sms.inbound.HibernateIncomingSmsStore">
+ <bean id="org.hisp.dhis.sms.incoming.IncomingSmsStore" class="org.hisp.dhis.sms.inbound.HibernateIncomingSmsStore">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
- <bean id="org.hisp.dhis.sms.incoming.IncomingSmsService" class="org.hisp.dhis.sms.inbound.DefaultInboundSmsService"/>
+ <bean id="org.hisp.dhis.sms.incoming.IncomingSmsService" class="org.hisp.dhis.sms.inbound.DefaultInboundSmsService">
+ <property name="incomingSmsStore" ref="org.hisp.dhis.sms.incoming.IncomingSmsStore"/>
+ </bean>
</beans>
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ImportReceiveSMSAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ImportReceiveSMSAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ImportReceiveSMSAction.java 2012-05-31 09:58:44 +0000
@@ -0,0 +1,89 @@
+package org.hisp.dhis.mobile.action.incoming;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.sms.incoming.IncomingSms;
+import org.hisp.dhis.sms.incoming.IncomingSmsService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+* @author Nguyen Kim Lai
+* @version $Id$
+*/
+
+public class ImportReceiveSMSAction
+ implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private IncomingSmsService incomingSmsService;
+
+ public void setIncomingSmsService( IncomingSmsService incomingSmsService )
+ {
+ this.incomingSmsService = incomingSmsService;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input & Output
+ // -------------------------------------------------------------------------
+
+ private Integer[] ids;
+
+ public void setIds( Integer[] ids )
+ {
+ this.ids = ids;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action Implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String execute()
+ throws Exception
+ {
+ System.out.println("size: "+ ids.length);
+
+ if ( ids != null && ids.length > 0 )
+ {
+ for( Integer index : ids )
+ {
+ System.out.println("index: "+ index);
+
+ IncomingSms incomingSms = incomingSmsService.get( index );
+
+ incomingSmsService.save( incomingSms );
+ }
+ }
+
+ return SUCCESS;
+ }
+}
=== 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 2012-05-29 07:58:51 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReceivingSMSAction.java 2012-05-31 09:58:44 +0000
@@ -1,5 +1,32 @@
package org.hisp.dhis.mobile.action.incoming;
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
import java.util.ArrayList;
import java.util.List;
@@ -10,6 +37,11 @@
import com.opensymphony.xwork2.Action;
+/**
+* @author Nguyen Kim Lai
+* @version $Id$
+*/
+
public class ReceivingSMSAction
implements Action
{
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml 2012-05-29 07:58:51 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml 2012-05-31 09:58:44 +0000
@@ -27,6 +27,11 @@
<bean id="org.hisp.dhis.mobile.action.incoming.DeleteReceiveSMSAction" class="org.hisp.dhis.mobile.action.incoming.DeleteReceiveSMSAction"
scope="prototype" >
<property name="incomingSmsService" ref="org.hisp.dhis.sms.incoming.IncomingSmsService"/>
+ </bean>
+
+ <bean id="org.hisp.dhis.mobile.action.incoming.ImportReceiveSMSAction" class="org.hisp.dhis.mobile.action.incoming.ImportReceiveSMSAction"
+ scope="prototype" >
+ <property name="incomingSmsService" ref="org.hisp.dhis.sms.incoming.IncomingSmsService"/>
</bean>
<bean id="org.hisp.dhis.mobile.action.ShowSendSMSBeneficiaryFormAction" class="org.hisp.dhis.mobile.action.ShowSendSMSBeneficiaryFormAction"
=== 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 2012-05-30 08:49:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties 2012-05-31 09:58:44 +0000
@@ -71,6 +71,7 @@
message=Message
send_sms_to_target=Send SMS to
show_receive_sms_form =Receive SMS
+error_import=Please check before import
phone_number=Phone number
raw_phone_number=Raw phone numbers
assigned_user_number=User assigned to organisation unit
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml 2012-05-29 07:58:51 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml 2012-05-31 09:58:44 +0000
@@ -50,6 +50,11 @@
<result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
<param name="onExceptionReturn">plainTextError</param>
</action>
+
+ <action name="importReceiveSMS" class="org.hisp.dhis.mobile.action.incoming.ImportReceiveSMSAction">
+ <result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+ <param name="onExceptionReturn">plainTextError</param>
+ </action>
<action name="showBeneficiarySMSForm" class="org.hisp.dhis.mobile.action.ShowSendSMSBeneficiaryFormAction">
<result name="success" type="velocity">/main.vm</result>
=== 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 2012-05-29 07:58:51 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.vm 2012-05-31 09:58:44 +0000
@@ -25,7 +25,8 @@
checked = false;
- function checkAll(){
+ function checkAll()
+ {
var aa = document.getElementById( 'receiveSmsPage' );
if (checked == false)
{
@@ -69,7 +70,38 @@
else
{
showErrorMessage( "$i18n.getString( 'error_delete' )", 7000 );
- }
+ }
+ };
+
+ function importChecked()
+ {
+ var aa = document.getElementById( 'receiveSmsPage' );
+ var result = "";
+ for (var i = 0; i < aa.elements.length; i++)
+ {
+ if ( aa.elements[i].checked )
+
+ {
+ result += "ids=" + aa.elements[i].value + "&";
+ }
+ }
+ result = result.substring(0 , result.length - 1);
+
+ if ( result != "" )
+ {
+ jQuery.get( 'importReceiveSMS.action?' + result, {},
+ function ( json ) {
+ if ( json.response == "success") {
+ showSuccessMessage( "Import Successfully!" );
+ } else {
+ showErrorMessage( "eggor!" );
+ }
+ })
+ }
+ else
+ {
+ showErrorMessage( "$i18n.getString( 'error_import' )", 7000 );
+ }
};
function removeSingleItem( key, name )
{
@@ -82,6 +114,7 @@
<h3>$i18n.getString( "show_receive_sms_form" )</h3>
<form id="receiveSmsPage" name="receiveSmsPage" action="showReceivingPage.action" method="post" >
+
<input type="hidden" id="currentMessageHidden" value="$currentMessages"/>
<br/>
<table id="detailsSmsList" class="listTable" style="width:800px">
@@ -111,6 +144,6 @@
<br/>
<input type="button" name="btnShowConfig" value="Configurate My Modem" onclick="window.location='showSMSConfigureForm.action'"/>
<input type="button" name="btnDelete" value="Delete Checked Options" onclick="deleteChecked()"/>
- <input type="button" name="btnImport" value="Import"/>
+ <input type="button" name="btnImport" value="Import" onclick="importChecked()"/>
</form>
\ No newline at end of file