dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09341
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2451: Services to Receive Queries through SMS
------------------------------------------------------------
revno: 2451
committer: Neeraj <neeraj.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2010-12-30 10:47:07 +0530
message:
Services to Receive Queries through SMS
added:
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMS.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMSService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMSStore.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/impl/DefaultReceiveSMSService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/impl/HibernateReceiveSMSStore.java
dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/ReceiveSMS.hbm.xml
modified:
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportParameters.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java
dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml
--
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-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java 2010-11-24 13:37:22 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java 2010-12-30 05:17:07 +0000
@@ -56,6 +56,7 @@
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.external.location.LocationManager;
import org.hisp.dhis.mobile.SmsService;
+import org.hisp.dhis.mobile.api.ReceiveSMSService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.DailyPeriodType;
@@ -93,6 +94,13 @@
this.sendSMSService = sendSMSService;
}
+ private ReceiveSMSService receiveSMSService;
+
+ public void setReceiveSMSService( ReceiveSMSService receiveSMSService )
+ {
+ this.receiveSMSService = receiveSMSService;
+ }
+
SmsService smsService;
public void setSmsService( SmsService smsService )
@@ -266,6 +274,7 @@
String periodType;
String formType;
String anmName;
+ String anmQuery;
String tempDeid;
String tempDataValue;
@@ -364,6 +373,16 @@
mobileImportParameters.setAnmName( anmName );
}
+ else if( formType.equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMQUERYFORM ) )
+ {
+ // To get ANM Query
+ NodeList anmQueryInfo = doc.getElementsByTagName( "anmquery" );
+ Element anmQueryInfoElement = (Element) anmQueryInfo.item( 0 );
+ NodeList anmQueryInfoNameList = anmQueryInfoElement.getChildNodes();
+ anmQuery = anmQueryInfoNameList.item( 0 ).getNodeValue().trim();
+
+ mobileImportParameters.setAnmQuery( anmQuery );
+ }
}// try block end
catch ( SAXParseException err )
{
@@ -1014,6 +1033,81 @@
return importStatus;
}
+ @Transactional
+ public String importANMQueryData( String importFile, MobileImportParameters mobImportParameters )
+ {
+ String importStatus="";
+
+ try
+ {
+ User curUser = getUserInfo( mobImportParameters.getMobileNumber() );
+
+ if ( curUser != null )
+ {
+ UserCredentials userCredentials = userStore.getUserCredentials( curUser );
+
+ if ( (userCredentials != null)
+ && (mobImportParameters.getMobileNumber().equals( curUser.getPhoneNumber() )) )
+ {
+ }
+ else
+ {
+ LOG.error( " Import File Contains Unrecognised Phone Numbers : "
+ + mobImportParameters.getMobileNumber() );
+ moveFailedFile( importFile );
+ return "Phone number is not registered to any facility. Please contact admin";
+ }
+
+ List<OrganisationUnit> sources = new ArrayList<OrganisationUnit>( curUser.getOrganisationUnits() );
+
+ if ( sources == null || sources.size() <= 0 )
+ {
+ LOG.error( " No User Exists with corresponding Phone Numbers : "
+ + mobImportParameters.getMobileNumber() );
+ moveFailedFile( importFile );
+
+ return "Phone number is not registered to any facility. Please contact admin";
+ }
+
+ String anmQuery = mobImportParameters.getAnmQuery();
+
+ if ( anmQuery == null || anmQuery.trim().equalsIgnoreCase( "" ) )
+ {
+ LOG.error( importFile + " Import File is not Properly Formated" );
+ moveFailedFile( importFile );
+
+ return "Data not Received Properly, Please send again";
+ }
+
+ ReceiveSMS receiveSMS = new ReceiveSMS( importFile, anmQuery );
+ receiveSMSService.addReceiveSMS( receiveSMS );
+
+ moveImportedFile( importFile );
+
+ importStatus = "YOUR Query IS REGISTERD SUCCESSFULLY";
+ }
+ else
+ {
+ LOG.error( importFile + " Phone number not found... Sending to Bounced" );
+ importStatus = "Phone number is not registered to any facility. Please contact admin";
+ moveFailedFile( importFile );
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ LOG.error( e.getMessage() );
+ LOG.error( "Exception caused in importing... Moving to Bounced" );
+
+ importStatus = "Data not Received Properly, Please send again";
+ moveFailedFile( importFile );
+ }
+ finally
+ {
+ }
+
+ return importStatus;
+ }
@Override
@Transactional
public String importXMLFile( String importFile )
@@ -1041,6 +1135,12 @@
return importStatus;
}
+ else if( mobImportParameters.getFormType().equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMQUERYFORM ) )
+ {
+ importStatus = importANMQueryData( importFile, mobImportParameters );
+
+ return importStatus;
+ }
User curUser = getUserInfo( mobImportParameters.getMobileNumber() );
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportParameters.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportParameters.java 2010-11-24 13:37:22 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportParameters.java 2010-12-30 05:17:07 +0000
@@ -35,8 +35,12 @@
{
public static final String FORM_TYPE_ANMREGFORM = "anmregform";
+ public static final String FORM_TYPE_ANMQUERYFORM = "anmqueryform";
public static final String FORM_TYPE_DATAFORM = "dataform";
+
public static final String ANMREG_FORM_ID = "ANMRF";
+ public static final String ANMQUERY_FORM_ID = "ANMQUERY";
+
private String formType;
@@ -52,6 +56,8 @@
private String anmName;
+ private String anmQuery;
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -131,5 +137,17 @@
{
this.anmName = anmName;
}
+
+ public String getAnmQuery()
+ {
+ return anmQuery;
+ }
+
+ public void setAnmQuery( String anmQuery )
+ {
+ this.anmQuery = anmQuery;
+ }
+
+
}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMS.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMS.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMS.java 2010-12-30 05:17:07 +0000
@@ -0,0 +1,91 @@
+package org.hisp.dhis.mobile.api;
+
+import java.io.Serializable;
+
+public class ReceiveSMS implements Serializable
+
+{
+
+ /**
+ * Sender Phone Number with time of Received, Unique and Required.
+ */
+ private String receiverInfo;
+
+ /**
+ * Message to send to sender, Required
+ */
+ private String receiveingMessage;
+
+ // -------------------------------------------------------------------------
+ // Contructors
+ // -------------------------------------------------------------------------
+
+ public ReceiveSMS()
+ {
+
+ }
+
+ public ReceiveSMS( String receiverInfo, String receiveingMessage )
+ {
+ this.receiverInfo = receiverInfo;
+ this.receiveingMessage = receiveingMessage;
+ }
+
+ // -------------------------------------------------------------------------
+ // hashCode and equals
+ // -------------------------------------------------------------------------
+
+ @Override
+ public int hashCode()
+ {
+ return receiverInfo.hashCode();
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+
+ if ( o == null )
+ {
+ return false;
+ }
+
+ if ( !(o instanceof ReceiveSMS) )
+ {
+ return false;
+ }
+
+ final ReceiveSMS other = (ReceiveSMS) o;
+
+ return receiverInfo.equals( other.getReceiverInfo() );
+ }
+
+ // -------------------------------------------------------------------------
+ // Getters and setters
+ // -------------------------------------------------------------------------
+
+ public String getReceiverInfo()
+ {
+ return receiverInfo;
+ }
+
+ public void setReceiverInfo( String receiverInfo )
+ {
+ this.receiverInfo = receiverInfo;
+ }
+
+ public String getReceiveingMessage()
+ {
+ return receiveingMessage;
+ }
+
+ public void setReceiveingMessage( String receiveingMessage )
+ {
+ this.receiveingMessage = receiveingMessage;
+ }
+
+}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMSService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMSService.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMSService.java 2010-12-30 05:17:07 +0000
@@ -0,0 +1,22 @@
+package org.hisp.dhis.mobile.api;
+
+import java.util.Collection;
+
+public interface ReceiveSMSService
+{
+
+ String ID = ReceiveSMSService.class.getName();
+
+ void addReceiveSMS ( ReceiveSMS receiveSMS );
+
+ void updateReceiveSMS ( ReceiveSMS receiveSMS );
+
+ void deleteReceiveSMS ( ReceiveSMS receiveSMS );
+
+ Collection<ReceiveSMS> getReceiveSMS( int start, int end );
+
+ Collection<ReceiveSMS> getAllReceiveSMS();
+
+ long getRowCount();
+
+}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMSStore.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMSStore.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMSStore.java 2010-12-30 05:17:07 +0000
@@ -0,0 +1,22 @@
+package org.hisp.dhis.mobile.api;
+
+import java.util.Collection;
+
+public interface ReceiveSMSStore
+{
+
+ String ID = ReceiveSMSService.class.getName();
+
+ void addReceiveSMS( ReceiveSMS receiveSMS );
+
+ void updateReceiveSMS ( ReceiveSMS receiveSMS );
+
+ void deleteReceiveSMS( ReceiveSMS receiveSMS );
+
+ Collection<ReceiveSMS> getReceiveSMS( int start, int end );
+
+ Collection<ReceiveSMS> getAllReceiveSMS();
+
+ long getRowCount();
+
+}
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java 2010-11-24 13:37:22 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java 2010-12-30 05:17:07 +0000
@@ -93,6 +93,10 @@
{
createXMLFileForANMRegForm();
}
+ else if( formID.equalsIgnoreCase( MobileImportParameters.ANMQUERY_FORM_ID ) )
+ {
+ createXMLFileForANMQueryRegForm();
+ }
else
{
createXMLFileForDataValueForm();
@@ -200,4 +204,52 @@
return;
}
}
+
+ void createXMLFileForANMQueryRegForm()
+ {
+ String dhis2Home = System.getenv( "DHIS2_HOME" );
+ String[] text = info.split( "#" );
+ String msgVersion = text[0];
+ text = text[1].split( "\\*" );
+ String formID = text[0];
+ text = text[1].split( "\\?" );
+ String periodType = text[0];
+ text = text[1].split( "\\$" );
+ String period = text[0];
+ String anmQuery = text[1];
+
+ System.out.println("ANM Query: "+text[1] + " period : " + text[0]);
+
+ try
+ {
+ File file = new File( dhis2Home + File.separator + "mi" + File.separator + "pending" + File.separator + phoneNumber + "_" +sendTime.replace( ":", "-" ) + ".xml" );
+ FileWriter writer = new FileWriter( file );
+ writer.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
+ writer.write( "<mxf version=\"" + msgVersion + "\">\n" );
+ writer.write( "<formtype>" + MobileImportParameters.FORM_TYPE_ANMQUERYFORM + "</formtype>\n" );
+ writer.write( "<source>" + phoneNumber + "</source>\n" );
+ writer.write( "<periodType>" + periodType + "</periodType>\n" );
+ writer.write( "<period>" + period + "</period>\n" );
+ writer.write( "<timeStamp>" + sendTime + "</timeStamp>\n" );
+
+ if( anmQuery != null && !anmQuery.trim().equalsIgnoreCase( "" ) )
+ {
+ writer.write( "<anmquery>" + anmQuery + "</anmquery>\n" );
+ }
+ else
+ {
+ writer.write( "<anmquery> </anmquery>\n" );
+ }
+
+ writer.write( "<info>" + info + "</info>\n" );
+ writer.write( "</mxf>\n" );
+ writer.close();
+ }
+ catch (Exception e)
+ {
+ System.out.println("Exception while creating XML File"+ e.getMessage());
+ return;
+ }
+
+ }
}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/impl/DefaultReceiveSMSService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/impl/DefaultReceiveSMSService.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/impl/DefaultReceiveSMSService.java 2010-12-30 05:17:07 +0000
@@ -0,0 +1,52 @@
+package org.hisp.dhis.mobile.impl;
+
+import java.util.Collection;
+
+import org.hisp.dhis.mobile.api.ReceiveSMS;
+import org.hisp.dhis.mobile.api.ReceiveSMSService;
+import org.hisp.dhis.mobile.api.ReceiveSMSStore;
+
+public class DefaultReceiveSMSService implements ReceiveSMSService
+{
+ private ReceiveSMSStore reveiveSMSStore;
+
+ public void setReveiveSMSStore( ReceiveSMSStore reveiveSMSStore )
+ {
+ this.reveiveSMSStore = reveiveSMSStore;
+ }
+
+ // -------------------------------------------------------------------------
+ // ReceiveSMS
+ // -------------------------------------------------------------------------
+
+ public void addReceiveSMS( ReceiveSMS receiveSMS )
+ {
+ reveiveSMSStore.addReceiveSMS( receiveSMS );
+ }
+
+ public void updateReceiveSMS( ReceiveSMS receiveSMS )
+ {
+ reveiveSMSStore.updateReceiveSMS( receiveSMS );
+ }
+
+ public void deleteReceiveSMS( ReceiveSMS receiveSMS )
+ {
+ reveiveSMSStore.deleteReceiveSMS( receiveSMS );
+ }
+
+ public Collection<ReceiveSMS> getReceiveSMS( int start, int end )
+ {
+ return reveiveSMSStore.getReceiveSMS( start, end );
+ }
+
+ public Collection<ReceiveSMS> getAllReceiveSMS()
+ {
+ return reveiveSMSStore.getAllReceiveSMS();
+ }
+
+ public long getRowCount()
+ {
+ return reveiveSMSStore.getRowCount();
+ }
+
+}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/impl/HibernateReceiveSMSStore.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/impl/HibernateReceiveSMSStore.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/impl/HibernateReceiveSMSStore.java 2010-12-30 05:17:07 +0000
@@ -0,0 +1,76 @@
+package org.hisp.dhis.mobile.impl;
+
+import java.util.Collection;
+
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Projections;
+import org.hisp.dhis.mobile.api.ReceiveSMS;
+import org.hisp.dhis.mobile.api.ReceiveSMSStore;
+
+public class HibernateReceiveSMSStore implements ReceiveSMSStore
+{
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private SessionFactory sessionFactory;
+
+ public void setSessionFactory( SessionFactory sessionFactory )
+ {
+ this.sessionFactory = sessionFactory;
+ }
+
+ // -------------------------------------------------------------------------
+ // SendSMS
+ // -------------------------------------------------------------------------
+
+ public void addReceiveSMS( ReceiveSMS receiveSMS )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ session.save( receiveSMS );
+ }
+
+ public void updateReceiveSMS( ReceiveSMS receiveSMS )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ session.save( receiveSMS );
+ }
+
+ public void deleteReceiveSMS( ReceiveSMS receiveSMS )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ session.delete( receiveSMS );
+ }
+
+ public Collection<ReceiveSMS> getReceiveSMS( int start, int end )
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ return session.createQuery( "from ReceiveSMS" ).list().subList( start, end );
+ }
+
+ public Collection<ReceiveSMS> getAllReceiveSMS()
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ return session.createQuery( "from ReceiveSMS" ).list();
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public long getRowCount()
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria( ReceiveSMS.class );
+ criteria.setProjection( Projections.rowCount() );
+ Long count = (Long) criteria.uniqueResult();
+ return count != null ? count.longValue() : (long) 0;
+ }
+
+}
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml 2010-12-16 17:38:32 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml 2010-12-30 05:17:07 +0000
@@ -20,6 +20,7 @@
<property name="periodService" ref="org.hisp.dhis.period.PeriodService"/>
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService"/>
<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService"/>
+ <property name="receiveSMSService" ref="org.hisp.dhis.mobile.api.ReceiveSMSService"/>
<property name="smsService" ref="org.hisp.dhis.mobile.SmsService"/>
<property name="dataElementCategoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
<property name="sendSMSService" ref="org.hisp.dhis.mobile.api.SendSMSService"/>
@@ -45,6 +46,16 @@
<property name="sendSMSStore" ref="org.hisp.dhis.mobile.api.SendSMSStore"/>
</bean>
+ <bean id="org.hisp.dhis.mobile.api.ReceiveSMSStore"
+ class="org.hisp.dhis.mobile.impl.HibernateReceiveSMSStore">
+ <property name="sessionFactory" ref="sessionFactory"/>
+ </bean>
+
+ <bean id="org.hisp.dhis.mobile.api.ReceiveSMSService"
+ class="org.hisp.dhis.mobile.impl.DefaultReceiveSMSService">
+ <property name="reveiveSMSStore" ref="org.hisp.dhis.mobile.api.ReceiveSMSStore"/>
+ </bean>
+
<!-- Send ACK Job -->
<bean id="org.hisp.dhis.mobile.SendSMSJob"
=== added file 'dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/ReceiveSMS.hbm.xml'
--- dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/ReceiveSMS.hbm.xml 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/ReceiveSMS.hbm.xml 2010-12-30 05:17:07 +0000
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.hisp.dhis.mobile.api.ReceiveSMS" table="receivesms">
+
+ <id name="receiverInfo" column="receiverInfo" length="230" />
+
+ <property name="receiveingMessage" column="smscontent" not-null="true" length="230"/>
+
+ </class>
+</hibernate-mapping>