=== 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 listAllMessage (); List 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 msgList = new ArrayList(); @@ -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 @@ - + - + + + === 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 @@ + + + + ../dhis-web-commons/ajax/jsonResponseSuccess.vm plainTextError + + + ../dhis-web-commons/ajax/jsonResponseSuccess.vm + plainTextError + /main.vm === 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 @@

$i18n.getString( "show_receive_sms_form" )

+
@@ -111,6 +144,6 @@
- + \ No newline at end of file