dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13015
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4094: Merge mobile application to trunk from 2.3
------------------------------------------------------------
revno: 4094
committer: Mithilesh Kumar Thakur<mithilesh.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-07-07 17:26:37 +0530
message:
Merge mobile application to trunk from 2.3
modified:
local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SmsService.java
local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java
local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportService.java
local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java
local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/BulkSMSHttpInterface.java
local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendBulkSMSAction.java
local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendBulkSMSThirdPartyAction.java
local/in/dhis-mobile/dhis-web-mobile/src/main/resources/META-INF/dhis/beans.xml
local/in/dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/sendBulkSMSPage.vm
local/in/dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/sendBulkSMSPageThirdParty.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 'local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SmsService.java'
--- local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SmsService.java 2011-06-17 10:06:08 +0000
+++ local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SmsService.java 2011-07-07 11:56:37 +0000
@@ -340,47 +340,127 @@
return status;
}
+ public String sendMessagesToPort( List<SendSMS> sendSMSList ,int dest,int src)
+ {
+ int successCount = 0;
+ int failCount = 0;
+ String status = null;
+ for ( int i = 0; i < sendSMSList.size(); i++ )
+ {
+ //System.out.println("Successfully sent : "+ successCount +" Failed : " + failCount);
+ status = sendMessageToPort( sendSMSList.get( i ).getSenderInfo(), sendSMSList.get( i ).getSendingMessage(),dest,src );
+ if ( status.equalsIgnoreCase( "SUCCESS" ) )
+ {
+ successCount++;
+ } else
+ {
+ if ( status.equalsIgnoreCase( "MODEMERROR" ) )
+ {
+ getService().getLogger().logError( "Modem Stops Responding...Till then successfully sent : " + successCount, null, null );
+ //System.out.println("Successfully sent : "+ successCount +" Failed : " + failCount);
+ System.out.println( "modem is not responding....waiting for it to respond..." );
+ // return "Modem Stops Responding...Till then successfully sent : "+successCount;
+ i--;
+ } else
+ {
+ if ( status.equals( "SERVICE NOT RUNNING" ) )
+ {
+ return "SERVICE NOT RUNNING";
+ }
+ }
+ }
+ }
+
+ return status;
+ }
+
@Override
public String sendMessage( String recipient, String msg )
{
OutboundMessage message = new OutboundMessage( recipient, msg );
- if ( getServiceStatus() )
- {
- try
- {
- if ( serv.sendMessage( message ) )
- {
- getService().getLogger().logInfo( "Message Sent to: " + recipient, null, null );
- return "SUCCESS";
- } else
- {
- getService().getLogger().logError( "Timeout error in sending message to: " + recipient, null, null );
- return "MODEMERROR";
- }
- } catch ( TimeoutException ex )
- {
- getService().getLogger().logError( "Timeout error in sending message", ex, null );
- return "ERROR";
- } catch ( GatewayException ex )
- {
- getService().getLogger().logError( "Gateway Exception in sending message", ex, null );
- return "ERROR";
- } catch ( IOException ex )
- {
- getService().getLogger().logError( "IO Exception in sending message", ex, null );
- return "ERROR";
- } catch ( InterruptedException ex )
- {
- getService().getLogger().logError( "Interrupted Exception in sending message", ex, null );
- return "ERROR";
- }
- } else
- {
- getService().getLogger().logError( "Service not running", null, null );
- return "SERVICE NOT RUNNING";
- }
- }
-
+ message.setDstPort(16000);
+ message.setSrcPort(0);
+ if ( getServiceStatus() )
+ {
+ try
+ {
+ if ( serv.sendMessage( message ) )
+ {
+ getService().getLogger().logInfo( "Message Sent to: " + recipient, null, null );
+ return "SUCCESS";
+ } else
+ {
+ getService().getLogger().logError( "Timeout error in sending message to: " + recipient, null, null );
+ return "MODEMERROR";
+ }
+ } catch ( TimeoutException ex )
+ {
+ getService().getLogger().logError( "Timeout error in sending message", ex, null );
+ return "ERROR";
+ } catch ( GatewayException ex )
+ {
+ getService().getLogger().logError( "Gateway Exception in sending message", ex, null );
+ return "ERROR";
+ } catch ( IOException ex )
+ {
+ getService().getLogger().logError( "IO Exception in sending message", ex, null );
+ return "ERROR";
+ } catch ( InterruptedException ex )
+ {
+ getService().getLogger().logError( "Interrupted Exception in sending message", ex, null );
+ return "ERROR";
+ }
+ } else
+ {
+ getService().getLogger().logError( "Service not running", null, null );
+ return "SERVICE NOT RUNNING";
+ }
+ }
+
+ public String sendMessageToPort( String recipient, String msg,int dest,int src )
+ {
+
+ OutboundMessage message = new OutboundMessage( recipient, msg );
+ message.setDstPort( dest);
+ message.setSrcPort( src );
+ if ( getServiceStatus() )
+ {
+ try
+ {
+ if ( serv.sendMessage( message ) )
+ {
+ getService().getLogger().logInfo( "Message Sent to: " + recipient, null, null );
+ return "SUCCESS";
+ } else
+ {
+ getService().getLogger().logError( "Timeout error in sending message to: " + recipient, null, null );
+ return "MODEMERROR";
+ }
+ } catch ( TimeoutException ex )
+ {
+ getService().getLogger().logError( "Timeout error in sending message", ex, null );
+ return "ERROR";
+ } catch ( GatewayException ex )
+ {
+ getService().getLogger().logError( "Gateway Exception in sending message", ex, null );
+ return "ERROR";
+ } catch ( IOException ex )
+ {
+ getService().getLogger().logError( "IO Exception in sending message", ex, null );
+ return "ERROR";
+ } catch ( InterruptedException ex )
+ {
+ getService().getLogger().logError( "Interrupted Exception in sending message", ex, null );
+ return "ERROR";
+ }
+ } else
+ {
+ getService().getLogger().logError( "Service not running", null, null );
+ return "SERVICE NOT RUNNING";
+ }
+ }
+
+
@Override
public void processMessage( Object message )
{
@@ -391,10 +471,18 @@
InboundBinaryMessage binaryMsg = (InboundBinaryMessage) message;
byte[] compressedData = binaryMsg.getDataBytes();
String unCompressedText = new String( Compressor.decompress( compressedData ), "UTF-8" );
-
String sender = binaryMsg.getOriginator();
Date sendTime = binaryMsg.getDate();
+
+ if(unCompressedText.startsWith("i"))
+ {
+ mobileImportService.importInteractionMessage(unCompressedText, sender, sendTime);
+ }
+
+ else
+ {
+
// Creating XML File
getService().getLogger().logInfo( "Creating XML file...", null, null );
createXMLFile( sender, sendTime, unCompressedText );
@@ -428,6 +516,8 @@
//getService().getLogger().logInfo( "Saved Report. Sending Acknowledgement to " + sender, null, null );
//sendAck( sender, "REPORT", unCompressedText );
//sendMessage( sender, statusMessage );
+
+ }
} catch ( UnsupportedEncodingException uneex )
{
@@ -464,6 +554,7 @@
}
getService().getLogger().logInfo( "---Message Processing Finished---", null, null );
}
+
}
@Override
=== modified file 'local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java'
--- local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java 2011-06-17 10:06:08 +0000
+++ local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java 2011-07-07 11:56:37 +0000
@@ -1,3 +1,4 @@
+
/*
* Copyright (c) 2004-2007, University of Oslo
* All rights reserved.
@@ -32,12 +33,15 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -71,6 +75,8 @@
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserStore;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -80,490 +86,489 @@
import org.xml.sax.SAXParseException;
public class DefaultMobileImportService
- implements MobileImportService
+implements MobileImportService
{
- private static final Log LOG = LogFactory.getLog( DefaultMobileImportService.class );
-
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private SendSMSService sendSMSService;
-
- public void setSendSMSService( SendSMSService sendSMSService )
- {
- this.sendSMSService = sendSMSService;
- }
-
- private ReceiveSMSService receiveSMSService;
-
- public void setReceiveSMSService( ReceiveSMSService receiveSMSService )
- {
- this.receiveSMSService = receiveSMSService;
- }
-
- SmsService smsService;
-
- public void setSmsService( SmsService smsService )
- {
- this.smsService = smsService;
- }
-
- private JdbcTemplate jdbcTemplate;
-
- public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
- {
- this.jdbcTemplate = jdbcTemplate;
- }
-
- private LocationManager locationManager;
-
- public void setLocationManager( LocationManager locationManager )
- {
- this.locationManager = locationManager;
- }
-
- private UserStore userStore;
-
- public void setUserStore( UserStore userStore )
- {
- this.userStore = userStore;
- }
-
- private PeriodService periodService;
-
- public void setPeriodService( PeriodService periodService )
- {
- this.periodService = periodService;
- }
-
- private DataElementService dataElementService;
-
- public void setDataElementService( DataElementService dataElementService )
- {
- this.dataElementService = dataElementService;
- }
-
- private DataValueService dataValueService;
-
- public void setDataValueService( DataValueService dataValueService )
- {
- this.dataValueService = dataValueService;
- }
-
- private DataElementCategoryService dataElementCategoryService;
-
- public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
- {
- this.dataElementCategoryService = dataElementCategoryService;
- }
-
- private OrganisationUnitService organisationUnitService;
-
- public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
- {
- this.organisationUnitService = organisationUnitService;
- }
-
- private BatchHandlerFactory batchHandlerFactory;
-
- public void setBatchHandlerFactory( BatchHandlerFactory batchHandlerFactory )
- {
- this.batchHandlerFactory = batchHandlerFactory;
- }
-
- // -------------------------------------------------------------------------
- // Parameters
- // -------------------------------------------------------------------------
-
- private String storedBy;
-
- // -------------------------------------------------------------------------
- // Services
- // -------------------------------------------------------------------------
-
- @Override
- public void readAllMessages()
- {
- smsService.readAllMessages();
- System.out.println("Message reading done");
- }
-
- @Override
- public User getUserInfo( String mobileNumber )
- {
- Collection<User> userList = userStore.getUsersByPhoneNumber( mobileNumber );
-
- User selectedUser = null;
-
- if ( userList != null && userList.size() > 0 )
- {
- selectedUser = userList.iterator().next();
- }
-
- return selectedUser;
- }
-
- @Override
- public Period getPeriodInfo( String startDate, String periodType )
+ private static final Log LOG = LogFactory.getLog( DefaultMobileImportService.class );
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private SendSMSService sendSMSService;
+
+ public void setSendSMSService( SendSMSService sendSMSService )
+ {
+ this.sendSMSService = sendSMSService;
+ }
+
+ private ReceiveSMSService receiveSMSService;
+
+ public void setReceiveSMSService( ReceiveSMSService receiveSMSService )
+ {
+ this.receiveSMSService = receiveSMSService;
+ }
+
+ SmsService smsService;
+
+ public void setSmsService( SmsService smsService )
+ {
+ this.smsService = smsService;
+ }
+
+ private JdbcTemplate jdbcTemplate;
+
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+ {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ private LocationManager locationManager;
+
+ public void setLocationManager( LocationManager locationManager )
+ {
+ this.locationManager = locationManager;
+ }
+
+ private UserStore userStore;
+
+ public void setUserStore( UserStore userStore )
+ {
+ this.userStore = userStore;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ private DataValueService dataValueService;
+
+ public void setDataValueService( DataValueService dataValueService )
+ {
+ this.dataValueService = dataValueService;
+ }
+
+ private DataElementCategoryService dataElementCategoryService;
+
+ public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
+ {
+ this.dataElementCategoryService = dataElementCategoryService;
+ }
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private BatchHandlerFactory batchHandlerFactory;
+
+ public void setBatchHandlerFactory( BatchHandlerFactory batchHandlerFactory )
+ {
+ this.batchHandlerFactory = batchHandlerFactory;
+ }
+
+ // -------------------------------------------------------------------------
+ // Parameters
+ // -------------------------------------------------------------------------
+
+ private String storedBy;
+
+ // -------------------------------------------------------------------------
+ // Services
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void readAllMessages()
+ {
+ smsService.readAllMessages();
+ System.out.println("Message reading done");
+ }
+
+ @Override
+ public User getUserInfo( String mobileNumber )
+ {
+ Collection<User> userList = userStore.getUsersByPhoneNumber( mobileNumber );
+
+ User selectedUser = null;
+
+ if ( userList != null && userList.size() > 0 )
+ {
+ selectedUser = userList.iterator().next();
+ }
+
+ return selectedUser;
+ }
+
+ @Override
+ public Period getPeriodInfo( String startDate, String periodType )
throws Exception
- {
-
- SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
-
- List<Period> periods = null;
- PeriodType pt = null;
- if ( periodType.equals( "3" ) )
- {
- pt = new MonthlyPeriodType();
- periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
- }
- else if ( periodType.equals( "1" ) )
- {
- pt = new DailyPeriodType();
- periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
- }
- else if( periodType.equals( "6" ) )
- {
- pt = new YearlyPeriodType();
- periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
- }
- else if( periodType.equals( "2" ) )
- {
- pt = new WeeklyPeriodType();
- periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
- }
-
- for ( Period period : periods )
- {
- String tempDate = dateFormat.format( period.getStartDate() );
- if ( tempDate.equalsIgnoreCase( startDate ) )
- {
+ {
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
+
+ List<Period> periods = null;
+ PeriodType pt = null;
+ if ( periodType.equals( "3" ) )
+ {
+ pt = new MonthlyPeriodType();
+ periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
+ }
+ else if ( periodType.equals( "1" ) )
+ {
+ pt = new DailyPeriodType();
+ periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
+ }
+ else if( periodType.equals( "6" ) )
+ {
+ pt = new YearlyPeriodType();
+ periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
+ }
+ else if( periodType.equals( "2" ) )
+ {
+ pt = new WeeklyPeriodType();
+ periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
+ }
+
+ for ( Period period : periods )
+ {
+ String tempDate = dateFormat.format( period.getStartDate() );
+ if ( tempDate.equalsIgnoreCase( startDate ) )
+ {
+ return period;
+ }
+ }
+
+ Period period = pt.createPeriod( dateFormat.parse( startDate ) );
+ period = reloadPeriodForceAdd( period );
+ periodService.addPeriod( period );
+
return period;
- }
- }
-
- Period period = pt.createPeriod( dateFormat.parse( startDate ) );
- period = reloadPeriodForceAdd( period );
- periodService.addPeriod( period );
-
- return period;
- }
-
- private final Period reloadPeriod( Period period )
- {
- return periodService.getPeriod( period.getStartDate(), period.getEndDate(), period.getPeriodType() );
- }
-
- private final Period reloadPeriodForceAdd( Period period )
- {
- Period storedPeriod = reloadPeriod( period );
-
- if ( storedPeriod == null )
- {
- periodService.addPeriod( period );
-
- return period;
- }
-
- return storedPeriod;
- }
-
- @Override
- public MobileImportParameters getParametersFromXML( String fileName )
- throws Exception
- {
- File importFile = locationManager.getFileForReading( fileName, "mi", "pending" );
-
- String mobileNumber;
- String smsTime;
- String startDate;
- String periodType;
- String formType;
- String anmName;
- String anmQuery;
-
- String tempDeid;
- String tempDataValue;
-
- Map<String, String> dataValues = new HashMap<String, String>();
-
- MobileImportParameters mobileImportParameters = new MobileImportParameters();
-
- try
- {
- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
- Document doc = docBuilder.parse( importFile );
- if ( doc == null )
- {
- return null;
- }
-
- // To get Mobile Number
- NodeList sourceInfo = doc.getElementsByTagName( "source" );
- Element sourceInfoElement = (Element) sourceInfo.item( 0 );
- NodeList textsourceInfoNameList = sourceInfoElement.getChildNodes();
- mobileNumber = textsourceInfoNameList.item( 0 ).getNodeValue().trim();
-
- mobileImportParameters.setMobileNumber( mobileNumber );
-
- // To get Period
- NodeList periodInfo = doc.getElementsByTagName( "period" );
- Element periodInfoElement = (Element) periodInfo.item( 0 );
- NodeList textperiodInfoNameList = periodInfoElement.getChildNodes();
- startDate = textperiodInfoNameList.item( 0 ).getNodeValue().trim();
-
- mobileImportParameters.setStartDate( startDate );
-
- // To get TimeStamp
- NodeList timeStampInfo = doc.getElementsByTagName( "timeStamp" );
- Element timeStampInfoElement = (Element) timeStampInfo.item( 0 );
- NodeList texttimeStampInfoNameList = timeStampInfoElement.getChildNodes();
- smsTime = texttimeStampInfoNameList.item( 0 ).getNodeValue().trim();
-
- mobileImportParameters.setSmsTime( smsTime );
-
- // To get PeriodType
- NodeList periodTypeInfo = doc.getElementsByTagName( "periodType" );
- Element periodTypeInfoElement = (Element) periodTypeInfo.item( 0 );
- NodeList textPeriodTypeInfoNameList = periodTypeInfoElement.getChildNodes();
- periodType = textPeriodTypeInfoNameList.item( 0 ).getNodeValue().trim();
-
- mobileImportParameters.setPeriodType( periodType );
-
- // To get FormType
- NodeList formTypeInfo = doc.getElementsByTagName( "formtype" );
- Element formTypeInfoElement = (Element) formTypeInfo.item( 0 );
- NodeList formTypeInfoNameList = formTypeInfoElement.getChildNodes();
- formType = formTypeInfoNameList.item( 0 ).getNodeValue().trim();
-
- mobileImportParameters.setFormType( formType );
-
- if( formType.equalsIgnoreCase( MobileImportParameters.FORM_TYPE_DATAFORM ) )
- {
- NodeList listOfDataValues = doc.getElementsByTagName( "dataValue" );
- int totalDataValues = listOfDataValues.getLength();
- for ( int s = 0; s < totalDataValues; s++ )
- {
- Node dataValueNode = listOfDataValues.item( s );
- if ( dataValueNode.getNodeType() == Node.ELEMENT_NODE )
- {
- Element dataValueElement = (Element) dataValueNode;
-
- NodeList dataElementIdList = dataValueElement.getElementsByTagName( "dataElement" );
- Element dataElementElement = (Element) dataElementIdList.item( 0 );
- NodeList textdataElementIdList = dataElementElement.getChildNodes();
- tempDeid = textdataElementIdList.item( 0 ).getNodeValue().trim();
-
- NodeList valueList = dataValueElement.getElementsByTagName( "value" );
- Element valueElement = (Element) valueList.item( 0 );
- NodeList textValueElementList = valueElement.getChildNodes();
- tempDataValue = textValueElementList.item( 0 ).getNodeValue();
-
- String tempDeID = tempDeid;
- //Integer tempDV = Integer.parseInt( tempDataValue );
-
- dataValues.put( tempDeID, tempDataValue );
- }
- }// end of for loop with s var
-
- mobileImportParameters.setDataValues( dataValues );
- }
- else if( formType.equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMREGFORM ) )
- {
- // To get ANM Name
- NodeList anmNameInfo = doc.getElementsByTagName( "anmname" );
- Element anmNameInfoElement = (Element) anmNameInfo.item( 0 );
- NodeList anmNameInfoNameList = anmNameInfoElement.getChildNodes();
- anmName = anmNameInfoNameList.item( 0 ).getNodeValue().trim();
-
- 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 )
- {
- System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId() );
- System.out.println( " " + err.getMessage() );
- }
- catch ( SAXException e )
- {
- Exception x = e.getException();
- ((x == null) ? e : x).printStackTrace();
- }
- catch ( Throwable t )
- {
- t.printStackTrace();
- }
-
- return mobileImportParameters;
-
- }// getParametersFromXML end
-
- @Override
- public List<String> getImportFiles()
- {
- List<String> fileNames = new ArrayList<String>();
-
- try
- {
- String importFolderPath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator
- + "mi" + File.separator + "pending";
-
- String newpath = System.getenv( "DHIS2_HOME" );
- if ( newpath != null )
- {
- importFolderPath = newpath + File.separator + "mi" + File.separator + "pending";
- }
-
- File dir = new File( importFolderPath );
-
- String[] files = dir.list();
-
- fileNames = Arrays.asList( files );
- }
- catch ( Exception e )
- {
- System.out.println( e.getMessage() );
- }
-
- return fileNames;
- }
-
- public int moveFile( File source, File dest )
+ }
+
+ private final Period reloadPeriod( Period period )
+ {
+ return periodService.getPeriod( period.getStartDate(), period.getEndDate(), period.getPeriodType() );
+ }
+
+ private final Period reloadPeriodForceAdd( Period period )
+ {
+ Period storedPeriod = reloadPeriod( period );
+
+ if ( storedPeriod == null )
+ {
+ periodService.addPeriod( period );
+
+ return period;
+ }
+
+ return storedPeriod;
+ }
+
+ @Override
+ public MobileImportParameters getParametersFromXML( String fileName ) throws Exception
+ {
+ File importFile = locationManager.getFileForReading( fileName, "mi", "pending" );
+
+ String mobileNumber;
+ String smsTime;
+ String startDate;
+ String periodType;
+ String formType;
+ String anmName;
+ String anmQuery;
+
+ String tempDeid;
+ String tempDataValue;
+
+ Map<String, String> dataValues = new HashMap<String, String>();
+
+ MobileImportParameters mobileImportParameters = new MobileImportParameters();
+
+ try
+ {
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+ Document doc = docBuilder.parse( importFile );
+ if ( doc == null )
+ {
+ return null;
+ }
+
+ // To get Mobile Number
+ NodeList sourceInfo = doc.getElementsByTagName( "source" );
+ Element sourceInfoElement = (Element) sourceInfo.item( 0 );
+ NodeList textsourceInfoNameList = sourceInfoElement.getChildNodes();
+ mobileNumber = textsourceInfoNameList.item( 0 ).getNodeValue().trim();
+
+ mobileImportParameters.setMobileNumber( mobileNumber );
+
+ // To get Period
+ NodeList periodInfo = doc.getElementsByTagName( "period" );
+ Element periodInfoElement = (Element) periodInfo.item( 0 );
+ NodeList textperiodInfoNameList = periodInfoElement.getChildNodes();
+ startDate = textperiodInfoNameList.item( 0 ).getNodeValue().trim();
+
+ mobileImportParameters.setStartDate( startDate );
+
+ // To get TimeStamp
+ NodeList timeStampInfo = doc.getElementsByTagName( "timeStamp" );
+ Element timeStampInfoElement = (Element) timeStampInfo.item( 0 );
+ NodeList texttimeStampInfoNameList = timeStampInfoElement.getChildNodes();
+ smsTime = texttimeStampInfoNameList.item( 0 ).getNodeValue().trim();
+
+ mobileImportParameters.setSmsTime( smsTime );
+
+ // To get PeriodType
+ NodeList periodTypeInfo = doc.getElementsByTagName( "periodType" );
+ Element periodTypeInfoElement = (Element) periodTypeInfo.item( 0 );
+ NodeList textPeriodTypeInfoNameList = periodTypeInfoElement.getChildNodes();
+ periodType = textPeriodTypeInfoNameList.item( 0 ).getNodeValue().trim();
+
+ mobileImportParameters.setPeriodType( periodType );
+
+ // To get FormType
+ NodeList formTypeInfo = doc.getElementsByTagName( "formtype" );
+ Element formTypeInfoElement = (Element) formTypeInfo.item( 0 );
+ NodeList formTypeInfoNameList = formTypeInfoElement.getChildNodes();
+ formType = formTypeInfoNameList.item( 0 ).getNodeValue().trim();
+
+ mobileImportParameters.setFormType( formType );
+
+ if( formType.equalsIgnoreCase( MobileImportParameters.FORM_TYPE_DATAFORM ) )
+ {
+ NodeList listOfDataValues = doc.getElementsByTagName( "dataValue" );
+ int totalDataValues = listOfDataValues.getLength();
+ for ( int s = 0; s < totalDataValues; s++ )
+ {
+ Node dataValueNode = listOfDataValues.item( s );
+ if ( dataValueNode.getNodeType() == Node.ELEMENT_NODE )
+ {
+ Element dataValueElement = (Element) dataValueNode;
+
+ NodeList dataElementIdList = dataValueElement.getElementsByTagName( "dataElement" );
+ Element dataElementElement = (Element) dataElementIdList.item( 0 );
+ NodeList textdataElementIdList = dataElementElement.getChildNodes();
+ tempDeid = textdataElementIdList.item( 0 ).getNodeValue().trim();
+
+ NodeList valueList = dataValueElement.getElementsByTagName( "value" );
+ Element valueElement = (Element) valueList.item( 0 );
+ NodeList textValueElementList = valueElement.getChildNodes();
+ tempDataValue = textValueElementList.item( 0 ).getNodeValue();
+
+ String tempDeID = tempDeid;
+ //Integer tempDV = Integer.parseInt( tempDataValue );
+
+ dataValues.put( tempDeID, tempDataValue );
+ }
+ }// end of for loop with s var
+
+ mobileImportParameters.setDataValues( dataValues );
+ }
+ else if( formType.equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMREGFORM ) )
+ {
+ // To get ANM Name
+ NodeList anmNameInfo = doc.getElementsByTagName( "anmname" );
+ Element anmNameInfoElement = (Element) anmNameInfo.item( 0 );
+ NodeList anmNameInfoNameList = anmNameInfoElement.getChildNodes();
+ anmName = anmNameInfoNameList.item( 0 ).getNodeValue().trim();
+
+ 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 )
+ {
+ System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId() );
+ System.out.println( " " + err.getMessage() );
+ }
+ catch ( SAXException e )
+ {
+ Exception x = e.getException();
+ ((x == null) ? e : x).printStackTrace();
+ }
+ catch ( Throwable t )
+ {
+ t.printStackTrace();
+ }
+
+ return mobileImportParameters;
+
+ }// getParametersFromXML end
+
+ @Override
+ public List<String> getImportFiles()
+ {
+ List<String> fileNames = new ArrayList<String>();
+
+ try
+ {
+ String importFolderPath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator
+ + "mi" + File.separator + "pending";
+
+ String newpath = System.getenv( "DHIS2_HOME" );
+ if ( newpath != null )
+ {
+ importFolderPath = newpath + File.separator + "mi" + File.separator + "pending";
+ }
+
+ File dir = new File( importFolderPath );
+
+ String[] files = dir.list();
+
+ fileNames = Arrays.asList( files );
+ }
+ catch ( Exception e )
+ {
+ System.out.println( e.getMessage() );
+ }
+
+ return fileNames;
+ }
+
+ public int moveFile( File source, File dest )
throws IOException
- {
-
- if ( !dest.exists() )
- {
- dest.createNewFile();
- }
-
- InputStream in = null;
-
- OutputStream out = null;
-
- try
- {
-
- in = new FileInputStream( source );
-
- out = new FileOutputStream( dest );
-
- byte[] buf = new byte[1024];
-
- int len;
-
- while ( (len = in.read( buf )) > 0 )
- {
- out.write( buf, 0, len );
- }
- }
- catch ( Exception e )
- {
- return -1;
- }
- finally
- {
- in.close();
-
- out.close();
- }
-
- return 1;
-
- }
-
- @Override
- public void moveImportedFile( String fileName )
- {
- try
- {
- String sourceFilePath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + "mi"
- + File.separator + "pending" + File.separator + fileName;
-
- String destFilePath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + "mi"
- + File.separator + "completed" + File.separator + fileName;
-
- String newpath = System.getenv( "DHIS2_HOME" );
- if ( newpath != null )
- {
- sourceFilePath = newpath + File.separator + "mi" + File.separator + "pending" + File.separator
- + fileName;
-
- destFilePath = newpath + File.separator + "mi" + File.separator + "completed" + File.separator
- + fileName;
- }
-
- File sourceFile = new File( sourceFilePath );
-
- File destFile = new File( destFilePath );
-
- int status = moveFile( sourceFile, destFile );
-
- if ( status == 1 )
- {
- sourceFile.delete();
- }
-
- }
- catch ( Exception e )
- {
- System.out.println( e.getMessage() );
- }
-
- }
-
- @Override
- public void moveFailedFile( String fileName )
- {
- try
- {
- String sourceFilePath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + "mi"
- + File.separator + "pending" + File.separator + fileName;
-
- String destFilePath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + "mi"
- + File.separator + "bounced" + File.separator + fileName;
-
- String newpath = System.getenv( "DHIS2_HOME" );
- if ( newpath != null )
- {
- sourceFilePath = newpath + File.separator + "mi" + File.separator + "pending" + File.separator
- + fileName;
-
- destFilePath = newpath + File.separator + "mi" + File.separator + "bounced" + File.separator + fileName;
- }
-
- File sourceFile = new File( sourceFilePath );
-
- File destFile = new File( destFilePath );
-
- int status = moveFile( sourceFile, destFile );
-
- if ( status == 1 )
- {
- sourceFile.delete();
- }
-
- }
- catch ( Exception e )
- {
- System.out.println( e.getMessage() );
- }
- }
-
- /*
+ {
+
+ if ( !dest.exists() )
+ {
+ dest.createNewFile();
+ }
+
+ InputStream in = null;
+
+ OutputStream out = null;
+
+ try
+ {
+
+ in = new FileInputStream( source );
+
+ out = new FileOutputStream( dest );
+
+ byte[] buf = new byte[1024];
+
+ int len;
+
+ while ( (len = in.read( buf )) > 0 )
+ {
+ out.write( buf, 0, len );
+ }
+ }
+ catch ( Exception e )
+ {
+ return -1;
+ }
+ finally
+ {
+ in.close();
+
+ out.close();
+ }
+
+ return 1;
+
+ }
+
+ @Override
+ public void moveImportedFile( String fileName )
+ {
+ try
+ {
+ String sourceFilePath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + "mi"
+ + File.separator + "pending" + File.separator + fileName;
+
+ String destFilePath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + "mi"
+ + File.separator + "completed" + File.separator + fileName;
+
+ String newpath = System.getenv( "DHIS2_HOME" );
+ if ( newpath != null )
+ {
+ sourceFilePath = newpath + File.separator + "mi" + File.separator + "pending" + File.separator
+ + fileName;
+
+ destFilePath = newpath + File.separator + "mi" + File.separator + "completed" + File.separator
+ + fileName;
+ }
+
+ File sourceFile = new File( sourceFilePath );
+
+ File destFile = new File( destFilePath );
+
+ int status = moveFile( sourceFile, destFile );
+
+ if ( status == 1 )
+ {
+ sourceFile.delete();
+ }
+
+ }
+ catch ( Exception e )
+ {
+ System.out.println( e.getMessage() );
+ }
+
+ }
+
+ @Override
+ public void moveFailedFile( String fileName )
+ {
+ try
+ {
+ String sourceFilePath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + "mi"
+ + File.separator + "pending" + File.separator + fileName;
+
+ String destFilePath = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + "mi"
+ + File.separator + "bounced" + File.separator + fileName;
+
+ String newpath = System.getenv( "DHIS2_HOME" );
+ if ( newpath != null )
+ {
+ sourceFilePath = newpath + File.separator + "mi" + File.separator + "pending" + File.separator
+ + fileName;
+
+ destFilePath = newpath + File.separator + "mi" + File.separator + "bounced" + File.separator + fileName;
+ }
+
+ File sourceFile = new File( sourceFilePath );
+
+ File destFile = new File( destFilePath );
+
+ int status = moveFile( sourceFile, destFile );
+
+ if ( status == 1 )
+ {
+ sourceFile.delete();
+ }
+
+ }
+ catch ( Exception e )
+ {
+ System.out.println( e.getMessage() );
+ }
+ }
+
+ /*
@Transactional
public void importAllFiles()
{
@@ -729,29 +734,29 @@
}
}
}
-*/
- @Override
- @Transactional
- public void importPendingFiles()
- {
- List<String> fileNames = new ArrayList<String>( getImportFiles() );
-
- for ( String importFile : fileNames )
+ */
+ @Override
+ @Transactional
+ public void importPendingFiles()
{
- String statusMsg = importXMLFile( importFile );
-
- SendSMS sendSMS = new SendSMS( importFile.replace( ".xml", "" ), statusMsg );
-
- sendSMSService.addSendSMS( sendSMS );
+ List<String> fileNames = new ArrayList<String>( getImportFiles() );
+
+ for ( String importFile : fileNames )
+ {
+ String statusMsg = importXMLFile( importFile );
+
+ SendSMS sendSMS = new SendSMS( importFile.replace( ".xml", "" ), statusMsg );
+
+ sendSMSService.addSendSMS( sendSMS );
+ }
}
- }
-
- /*
+
+ /*
@Transactional
public List<String> importPendingFile( String importFile )
{
List<String> statusMsgs = new ArrayList<String>();
-
+
int insertFlag = 1;
String insertQuery = "INSERT INTO datavalue (dataelementid, periodid, sourceid, categoryoptioncomboid, value, storedby, lastupdated ) VALUES ";
String importStatus="";
@@ -764,10 +769,10 @@
{
LOG.error( importFile + " Import File is not Properly Formated First" );
moveFailedFile( importFile );
-
+
statusMsgs.add( 0, "1" );
statusMsgs.add( 1, "Data not Received Properly, Please send again" );
-
+
return statusMsgs;
}
@@ -786,10 +791,10 @@
LOG.error( " Import File Contains Unrecognised Phone Numbers : "
+ mobImportParameters.getMobileNumber() );
moveFailedFile( importFile );
-
+
statusMsgs.add( 0, "2" );
statusMsgs.add( 1, "Phone number is not registered to any facility. Please contact admin" );
-
+
return statusMsgs;
}
@@ -803,10 +808,10 @@
statusMsgs.add( 0, "2" );
statusMsgs.add( 1, "Phone number is not registered to any facility. Please contact admin" );
-
+
return statusMsgs;
}
-
+
Source source = sources.get( 0 );
Period period = getPeriodInfo( mobImportParameters.getStartDate(), mobImportParameters.getPeriodType() );
@@ -815,7 +820,7 @@
SimpleDateFormat monthFormat = new SimpleDateFormat("MMM-yy");
Date timeStamp = dateFormat.parse( mobImportParameters.getSmsTime() );
-
+
long t;
if ( timeStamp == null )
{
@@ -855,7 +860,7 @@
statusMsgs.add( 0, "1" );
statusMsgs.add( 1, "Data not Received Properly, Please send again" );
-
+
return statusMsgs;
}
@@ -884,7 +889,7 @@
if ( value != null )
{
insertQuery += "( "+ dataElement.getId() + ", " + period.getId() + ", "+ source.getId() +", " + optionCombo.getId() + ", '" + value + "', '" + storedBy + "', '" + lastUpdatedDate + "' ), ";
-
+
insertFlag = 2;
}
}
@@ -899,20 +904,20 @@
dataValueService.updateDataValue( dataValue );
}
}
-
+
if( insertFlag != 1 )
{
insertQuery = insertQuery.substring( 0, insertQuery.length()-2 );
-
+
jdbcTemplate.update( insertQuery );
}
moveImportedFile( importFile );
-
+
if( period.getPeriodType().getName().equalsIgnoreCase( "monthly" ))
{
importStatus = "THANK YOU FOR SENDING MONTHLY REPORT FOR " + monthFormat.format( period.getStartDate() );
-
+
statusMsgs.add( 0, "3" );
statusMsgs.add( 1, importStatus );
}
@@ -926,7 +931,7 @@
else
{
importStatus = "THANK YOU FOR SENDING REPORT FOR " + dateFormat.format( period.getStartDate() ) + " : " + dateFormat.format( period.getEndDate() );
-
+
statusMsgs.add( 0, "5" );
statusMsgs.add( 1, importStatus );
}
@@ -935,7 +940,7 @@
{
LOG.error( importFile + " Phone number not found... Sending to Bounced" );
importStatus = "Phone number is not registered to any facility. Please contact admin";
-
+
statusMsgs.add( 0, "2" );
statusMsgs.add( 1, importStatus );
@@ -947,9 +952,9 @@
e.printStackTrace();
LOG.error( e.getMessage() );
LOG.error( "Exception caused in importing... Moving to Bounced" );
-
+
importStatus = "Data not Received Properly, Please send again";
-
+
statusMsgs.add( 0, "1" );
statusMsgs.add( 1, importStatus );
@@ -961,362 +966,577 @@
return statusMsgs;
}
- */
-
- @Transactional
- public String importANMRegData( 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";
- }
-
- OrganisationUnit source = sources.get( 0 );
- String anmName = mobImportParameters.getAnmName();
-
- if ( source == null || anmName == null || anmName.trim().equalsIgnoreCase( "" ) )
- {
- LOG.error( importFile + " Import File is not Properly Formated" );
- moveFailedFile( importFile );
-
- return "Data not Received Properly, Please send again";
- }
-
- source.setComment( anmName );
-
- organisationUnitService.updateOrganisationUnit( source );
-
- moveImportedFile( importFile );
-
- importStatus = "YOUR NAME 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;
- }
-
- @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 )
- {
- int insertFlag = 1;
- String insertQuery = "INSERT INTO datavalue (dataelementid, periodid, sourceid, categoryoptioncomboid, value, storedby, lastupdated ) VALUES ";
- String importStatus="";
-
- try
- {
- MobileImportParameters mobImportParameters = getParametersFromXML( importFile );
-
- if ( mobImportParameters == null )
- {
- LOG.error( importFile + " Import File is not Properly Formated First" );
- moveFailedFile( importFile );
-
- return "Data not Received Properly, Please send again";
- }
-
- // Checking for FormType, if formtype is ANMREG
- if( mobImportParameters.getFormType().equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMREGFORM ) )
- {
- importStatus = importANMRegData( importFile, mobImportParameters );
-
- return importStatus;
- }
- else if( mobImportParameters.getFormType().equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMQUERYFORM ) )
- {
- importStatus = importANMQueryData( importFile, mobImportParameters );
-
- return importStatus;
- }
-
- User curUser = getUserInfo( mobImportParameters.getMobileNumber() );
-
- if ( curUser != null )
- {
-
- UserCredentials userCredentials = userStore.getUserCredentials( curUser );
-
- if ( (userCredentials != null)
- && (mobImportParameters.getMobileNumber().equals( curUser.getPhoneNumber() )) )
- {
- storedBy = userCredentials.getUsername();
- }
- 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";
- }
-
- OrganisationUnit source = sources.get( 0 );
-
- Period period = getPeriodInfo( mobImportParameters.getStartDate(), mobImportParameters.getPeriodType() );
-
- SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
- SimpleDateFormat monthFormat = new SimpleDateFormat("MMM-yy");
-
- Date timeStamp = dateFormat.parse( mobImportParameters.getSmsTime() );
-
- long t;
- if ( timeStamp == null )
- {
- Date d = new Date();
- t = d.getTime();
- }
- else
- {
- t = timeStamp.getTime();
- }
-
- java.sql.Date lastUpdatedDate = new java.sql.Date( t );
-
- Map<String, String> dataValueMap = new HashMap<String, String>( mobImportParameters.getDataValues() );
-
- if ( dataValueMap == null || dataValueMap.size() <= 0 )
- {
- LOG.error( "dataValue map is null" );
- }
- else if ( source == null )
- {
- LOG.error( "source is null" );
- }
- else if ( period == null )
- {
- LOG.error( "period is null" );
- }
- else if ( timeStamp == null )
- {
- LOG.error( "timeStamp is null" );
- }
-
- if ( source == null || period == null || timeStamp == null || dataValueMap == null
- || dataValueMap.size() <= 0 )
- {
-
- LOG.error( importFile + " Import File is not Properly Formated" );
- moveFailedFile( importFile );
-
- return "Data not Received Properly, Please send again";
- }
-
- Set<String> keys = dataValueMap.keySet();
-
- for ( String key : keys )
- {
- String parts[] = key.split( "\\." );
-
- String deStr = parts[0];
-
- String optStr = parts[1];
-
- String value = String.valueOf( dataValueMap.get( key ) );
-
- DataElement dataElement = dataElementService.getDataElement( Integer.valueOf( deStr ) );
-
- DataElementCategoryOptionCombo optionCombo = new DataElementCategoryOptionCombo();
-
- optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer
- .valueOf( optStr ) );
-
- DataValue dataValue = dataValueService.getDataValue( source, dataElement, period, optionCombo );
-
- if ( dataValue == null )
- {
- if ( value != null )
- {
- insertQuery += "( "+ dataElement.getId() + ", " + period.getId() + ", "+ source.getId() +", " + optionCombo.getId() + ", '" + value + "', '" + storedBy + "', '" + lastUpdatedDate + "' ), ";
-
- insertFlag = 2;
- }
- }
- else
- {
- dataValue.setValue( value );
-
- dataValue.setTimestamp( timeStamp );
-
- dataValue.setStoredBy( storedBy );
-
- dataValueService.updateDataValue( dataValue );
- }
- }
-
- if( insertFlag != 1 )
- {
- insertQuery = insertQuery.substring( 0, insertQuery.length()-2 );
-
- jdbcTemplate.update( insertQuery );
- }
-
- moveImportedFile( importFile );
-
- if( period.getPeriodType().getName().equalsIgnoreCase( "monthly" ))
- {
- importStatus = "THANK YOU FOR SENDING MONTHLY REPORT FOR " + monthFormat.format( period.getStartDate() );
- }
- else if( period.getPeriodType().getName().equalsIgnoreCase( "daily" ))
- {
- importStatus = "THANK YOU FOR SENDING DAILY REPORT FOR " + dateFormat.format( period.getStartDate() );
- }
- else
- {
- importStatus = "THANK YOU FOR SENDING REPORT FOR " + dateFormat.format( period.getStartDate() ) + " : " + dateFormat.format( period.getEndDate() );
- }
- }
- 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;
- }
-
+ */
+
+ @Transactional
+ public String importANMRegData( 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";
+ }
+
+ OrganisationUnit source = sources.get( 0 );
+ String anmName = mobImportParameters.getAnmName();
+
+ if ( source == null || anmName == null || anmName.trim().equalsIgnoreCase( "" ) )
+ {
+ LOG.error( importFile + " Import File is not Properly Formated" );
+ moveFailedFile( importFile );
+
+ return "Data not Received Properly, Please send again";
+ }
+ source.setComment( anmName );
+ organisationUnitService.updateOrganisationUnit( source );
+
+ moveImportedFile( importFile );
+
+ importStatus = "YOUR NAME 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;
+ }
+
+ @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;
+ }
+
+ private OrganisationUnit getOrganisationUnitByPhone( String phoneNumber )
+ {
+ String query="SELECT * FROM organisationunit WHERE phoneNumber LIKE '"+ phoneNumber +"'";
+
+ /*
+ SqlRowSet sqlResultSet = jdbcTemplate.queryForRowSet( query );
+ if ( sqlResultSet != null && sqlResultSet.next() )
+ {
+ Integer orgUnitId = sqlResultSet.getInt( 1 );
+ OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( orgUnitId );
+ if( orgUnit != null )
+ return orgUnit;
+ }
+
+ return null;
+ */
+
+ OrganisationUnit result = null;
+
+ result = ( OrganisationUnit) jdbcTemplate.queryForObject( query, new RowMapper<OrganisationUnit>()
+ {
+ @Override
+ public OrganisationUnit mapRow( ResultSet rs, int i ) throws SQLException
+ {
+ OrganisationUnit orgUnit=new OrganisationUnit();
+ orgUnit.setId( rs.getInt( "organisationunitid") );
+ orgUnit.setUuid( rs.getString( "uuid") );
+ orgUnit.setName( rs.getString( "name") );
+ orgUnit.setPhoneNumber( rs.getString( "phoneNumber") );
+
+ return orgUnit;
+ // throw new UnsupportedOperationException( "Not supported yet." );
+ }
+
+ } );
+
+ return result;
+ }
+
+ private User getUserbyOrgUnit( int orgUnitId )
+ {
+ //int userid;
+ String query = "SELECT userinfoid FROM usermembership WHERE organisationunitid =" + orgUnitId;
+ //userid = jdbcTemplate.queryForInt( query );
+ //return userid;
+
+ SqlRowSet sqlResultSet = jdbcTemplate.queryForRowSet( query );
+ if ( sqlResultSet != null && sqlResultSet.next() )
+ {
+ Integer userId = sqlResultSet.getInt( 1 );
+ User user = userStore.getUser( userId );
+ if( user != null )
+ return user;
+ }
+
+ return null;
+ }
+
+ @Override
+ @Transactional
+ public String importXMLFile( String importFile )
+ {
+ int insertFlag = 1;
+ String insertQuery = "INSERT INTO datavalue (dataelementid, periodid, sourceid, categoryoptioncomboid, value, storedby, lastupdated ) VALUES ";
+ String importStatus="";
+
+ try
+ {
+ MobileImportParameters mobImportParameters = getParametersFromXML( importFile );
+
+ if ( mobImportParameters == null )
+ {
+ LOG.error( importFile + " Import File is not Properly Formatted" );
+
+ moveFailedFile( importFile );
+
+ return "Data not Received Properly, Please send again";
+ }
+
+ // Checking for FormType, if formtype is ANMREG
+ if( mobImportParameters.getFormType().equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMREGFORM ) )
+ {
+ importStatus = importANMRegData( importFile, mobImportParameters );
+
+ return importStatus;
+ }
+ else if( mobImportParameters.getFormType().equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMQUERYFORM ) )
+ {
+ importStatus = importANMQueryData( importFile, mobImportParameters );
+
+ return importStatus;
+ }
+
+ OrganisationUnit source = getOrganisationUnitByPhone( mobImportParameters.getMobileNumber() );
+
+ if ( source == null )
+ {
+ LOG.error( " No Faciliy Exists with corresponding Phone Number : " + mobImportParameters.getMobileNumber() );
+
+ moveFailedFile( importFile );
+
+ return "Phone number is not registered to any facility. Please contact admin";
+ }
+
+ User curUser = getUserbyOrgUnit( source.getId() );
+
+ if ( curUser == null )
+ {
+ LOG.error( " No User Exists with corresponding Facility : " + mobImportParameters.getMobileNumber() );
+
+ storedBy = "[unknown]-"+mobImportParameters.getMobileNumber();
+ }
+ else
+ {
+ UserCredentials userCredentials = userStore.getUserCredentials( curUser );
+
+ storedBy = userCredentials.getUsername();
+ }
+
+ Period period = getPeriodInfo( mobImportParameters.getStartDate(), mobImportParameters.getPeriodType() );
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
+ SimpleDateFormat monthFormat = new SimpleDateFormat("MMM-yy");
+
+ Date timeStamp = dateFormat.parse( mobImportParameters.getSmsTime() );
+
+ long t;
+ if ( timeStamp == null )
+ {
+ Date d = new Date();
+ t = d.getTime();
+ }
+ else
+ {
+ t = timeStamp.getTime();
+ }
+
+ java.sql.Date lastUpdatedDate = new java.sql.Date( t );
+
+ Map<String, String> dataValueMap = new HashMap<String, String>( mobImportParameters.getDataValues() );
+
+ if ( dataValueMap == null || dataValueMap.size() <= 0 )
+ {
+ LOG.error( "dataValue map is null" );
+ }
+ else if ( source == null )
+ {
+ LOG.error( "source is null" );
+ }
+ else if ( period == null )
+ {
+ LOG.error( "period is null" );
+ }
+ else if ( timeStamp == null )
+ {
+ LOG.error( "timeStamp is null" );
+ }
+
+ if ( source == null || period == null || timeStamp == null || dataValueMap == null || dataValueMap.size() <= 0 )
+ {
+ LOG.error( importFile + " Import File is not Properly Formated" );
+
+ moveFailedFile( importFile );
+
+ return "Data not Received Properly, Please send again";
+ }
+
+ Set<String> keys = dataValueMap.keySet();
+
+ for ( String key : keys )
+ {
+ String parts[] = key.split( "\\." );
+
+ String deStr = parts[0];
+
+ String optStr = parts[1];
+
+ String value = String.valueOf( dataValueMap.get( key ) );
+
+ DataElement dataElement = dataElementService.getDataElement( Integer.valueOf( deStr ) );
+
+ DataElementCategoryOptionCombo optionCombo = new DataElementCategoryOptionCombo();
+
+ optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.valueOf( optStr ) );
+
+ DataValue dataValue = dataValueService.getDataValue( source, dataElement, period, optionCombo );
+
+ if( value.trim().equalsIgnoreCase("") )
+ {
+ value = null;
+ }
+
+ if ( dataValue == null )
+ {
+ if ( value != null )
+ {
+ insertQuery += "( "+ dataElement.getId() + ", " + period.getId() + ", "+ source.getId() +", " + optionCombo.getId() + ", '" + value + "', '" + storedBy + "', '" + lastUpdatedDate + "' ), ";
+
+ insertFlag = 2;
+ }
+ }
+ else
+ {
+ dataValue.setValue( value );
+
+ dataValue.setTimestamp( timeStamp );
+
+ dataValue.setStoredBy( storedBy );
+
+ dataValueService.updateDataValue( dataValue );
+ }
+ }
+
+ if( insertFlag != 1 )
+ {
+ insertQuery = insertQuery.substring( 0, insertQuery.length()-2 );
+
+ jdbcTemplate.update( insertQuery );
+ }
+
+ moveImportedFile( importFile );
+
+ if( period.getPeriodType().getName().equalsIgnoreCase( "monthly" ))
+ {
+ importStatus = "THANK YOU FOR SENDING MONTHLY REPORT FOR " + monthFormat.format( period.getStartDate() );
+ }
+ else if( period.getPeriodType().getName().equalsIgnoreCase( "daily" ))
+ {
+ importStatus = "THANK YOU FOR SENDING DAILY REPORT FOR " + dateFormat.format( period.getStartDate() );
+ }
+ else
+ {
+ importStatus = "THANK YOU FOR SENDING REPORT FOR " + dateFormat.format( period.getStartDate() ) + " : " + dateFormat.format( period.getEndDate() );
+ }
+ }
+ 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;
+ }
+
+ public void importInteractionMessage( String smsText, String sender, Date sendTime )
+ {
+
+ String insertQuery = "INSERT INTO datavalue (dataelementid, periodid, sourceid, categoryoptioncomboid, value, storedby, lastupdated ) VALUES ";
+
+ try
+ {
+ String [] smstext = smsText.split( "#" );
+
+ System.out.println( "original text: " + smsText );
+
+ String dataelementid = smstext[1];
+ String periodid = smstext[2];
+ String comboid = smstext[3];
+ String value = smstext[4];
+
+
+ OrganisationUnit source = getOrganisationUnitByPhone( sender );
+
+ System.out.println( "-----------------source--------------" + source );
+
+ User curUser = getUserbyOrgUnit( source.getId() );
+
+ //User curUser = userStore.getUser(1);
+
+ //User curUser = null;
+
+ if ( curUser == null )
+ {
+ LOG.error( " No User Exists with corresponding Facility : " + sender );
+
+ storedBy = "[unknown]-"+sender;
+ }
+ else
+ {
+ UserCredentials userCredentials = userStore.getUserCredentials( curUser );
+
+ storedBy = userCredentials.getUsername();
+ }
+ DataElement dataElement = dataElementService.getDataElement( dataelementid );
+
+ DataElementCategoryOptionCombo optionCombo = new DataElementCategoryOptionCombo();
+
+ optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( comboid );
+
+ Period period = periodService.getPeriod( Integer.parseInt( periodid ));
+
+ DataValue dataValue = dataValueService.getDataValue( source, dataElement, period, optionCombo );
+
+ /*if( value.trim().equalsIgnoreCase("") )
+ {
+ value = null;
+ }*/
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
+ SimpleDateFormat monthFormat = new SimpleDateFormat("MMM-yy");
+
+ int date = sendTime.getDate();
+ int month = sendTime.getMonth()+1;
+ int year = sendTime.getYear()+1900;
+ int hour = sendTime.getHours();
+ int minutes = sendTime.getMinutes();
+ int seconds = sendTime.getSeconds();
+
+ String sendtime = "";
+
+ sendtime += "" + year;
+
+ sendtime += "-";
+
+ if( month < 10 )
+ {
+ sendtime += "0" + month;
+ }
+ else
+ {
+ sendtime += "" + month;
+ }
+
+ sendtime += "-";
+
+ if( date < 10 )
+ {
+ sendtime += "0" + date;
+ }
+ else
+ {
+ sendtime += "" + date;
+ }
+
+ sendtime += "_";
+
+ if( hour < 10 )
+ {
+ sendtime += "0" + hour;
+ }
+ else
+ {
+ sendtime += "" + hour;
+ }
+
+ sendtime += "-";
+
+ if( minutes < 10 )
+ {
+ sendtime += "0" + minutes;
+ }
+ else
+ {
+ sendtime += "" + minutes;
+ }
+
+ sendtime += "-";
+
+ if( seconds < 10 )
+ {
+ sendtime += "0" + seconds;
+ }
+ else
+ {
+ sendtime += "" + seconds;
+ }
+
+ System.out.println( "Time: " + sendtime );
+ Date timeStamp = dateFormat.parse( sendtime );
+
+ long t;
+ if ( timeStamp == null )
+ {
+ Date d = new Date();
+ t = d.getTime();
+ }
+ else
+ {
+ t = timeStamp.getTime();
+ }
+
+ java.sql.Date lastUpdatedDate = new java.sql.Date( t );
+
+ System.out.println("( "+ Integer.parseInt(dataelementid) + ", " + period.getId() + ", "+ source.getId() +", " + Integer.parseInt(comboid) + ", '" + value + "', '" + storedBy + "', '" + lastUpdatedDate + "' ) ");
+ if ( dataValue == null )
+ {
+ if ( value != null )
+ {
+ insertQuery += "( "+ Integer.parseInt(dataelementid) + ", " + period.getId() + ", "+ source.getId() +", " + Integer.parseInt(comboid) + ", '" + value + "', '" + storedBy + "', '" + lastUpdatedDate + "' ) ";
+ jdbcTemplate.update( insertQuery );
+ }
+ }
+ else
+ {
+ dataValue.setValue( value );
+
+ dataValue.setTimestamp( timeStamp );
+
+ dataValue.setStoredBy( storedBy );
+
+ dataValueService.updateDataValue( dataValue );
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ LOG.error( e.getMessage() );
+ LOG.error( "Interactive message not processed" );
+ }
+
+ }
}
+
=== modified file 'local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportService.java'
--- local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportService.java 2011-04-15 11:41:30 +0000
+++ local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportService.java 2011-07-07 11:56:37 +0000
@@ -27,6 +27,7 @@
package org.hisp.dhis.mobile.api;
+import java.util.Date;
import java.util.List;
import org.hisp.dhis.period.Period;
@@ -54,4 +55,6 @@
public void importPendingFiles();
public void readAllMessages();
+
+ public void importInteractionMessage( String smsText, String sender, Date sendTime );
}
=== modified file 'local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java'
--- local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java 2011-04-15 11:41:30 +0000
+++ local/in/dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java 2011-07-07 11:56:37 +0000
@@ -136,9 +136,16 @@
writer.write( "<timeStamp>" + sendTime + "</timeStamp>\n" );
for ( int i = 0; i < elementIds.length; i++ )
{
- if ( ( dataValues.length - 1 ) < i || dataValues[i].isEmpty() )
- {
- }
+ if ( ( dataValues.length - 1 ) < i )
+ {
+ }
+ else if( dataValues[i].isEmpty() )
+ {
+ writer.write( "<dataValue>\n" );
+ writer.write( "<dataElement>" + elementIds[i] + "</dataElement>\n" );
+ writer.write( "<value> </value>\n" );
+ writer.write( "</dataValue>\n" );
+ }
else
{
writer.write( "<dataValue>\n" );
=== modified file 'local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/BulkSMSHttpInterface.java'
--- local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/BulkSMSHttpInterface.java 2011-06-17 10:06:08 +0000
+++ local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/BulkSMSHttpInterface.java 2011-07-07 11:56:37 +0000
@@ -6,6 +6,7 @@
import java.io.BufferedReader;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
@@ -41,8 +42,8 @@
// FileReader bulkSMSconfig= new FileReader( "BulkSMS.conf");
properties = new Properties();
- properties.load( new FileReader( System.getenv( "DHIS2_HOME" ) + "BulkSMS.conf" ) );
-
+ properties.load( new FileReader( System.getenv( "DHIS2_HOME" ) + File.separator+"SMSServer.conf" ) );
+System.out.println(System.getenv( "DHIS2_HOME" ) + File.separator+"SMSServer.conf");
username = getUsername();
password = getPassword();
senderName = getSenderName();
=== modified file 'local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendBulkSMSAction.java'
--- local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendBulkSMSAction.java 2011-06-17 11:44:03 +0000
+++ local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendBulkSMSAction.java 2011-07-07 11:56:37 +0000
@@ -7,13 +7,25 @@
import com.opensymphony.xwork2.Action;
import java.io.BufferedReader;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.util.AbstractList;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Vector;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataelement.DefaultDataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DefaultSectionService;
import org.hisp.dhis.mobile.BulkSMSHttpInterface;
import org.hisp.dhis.mobile.SmsService;
import org.hisp.dhis.mobile.api.SendSMS;
@@ -22,6 +34,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupNameComparator;
import org.smslib.http.BulkSmsHTTPGateway;
+import org.w3c.dom.NodeList;
/**
*
@@ -30,6 +43,14 @@
public class SendBulkSMSAction
implements Action
{
+
+ DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
SmsService smsService;
@@ -82,6 +103,7 @@
return availableOrganisationUnitGroups;
}
+
String message;
public void setMessage( String message )
@@ -109,7 +131,34 @@
{
return result;
}
-
+ public List<String> availableDataElements;
+
+ public List<String> getAvailableDataElements()
+ {
+ return availableDataElements;
+ }
+
+public int countavailableDataElements;
+
+ public void setAvailableDataElements( List<String> availableDataElements )
+ {
+ this.availableDataElements = availableDataElements;
+ }
+public String isMessageDisabled;
+
+ public void setIsMessageDisabled( String isMessageDisabled )
+ {
+ this.isMessageDisabled = isMessageDisabled;
+ }
+ public String selectedAvailableDataElements;
+
+ public void setSelectedAvailableDataElements( String selectedAvailableDataElements )
+ {
+ this.selectedAvailableDataElements = selectedAvailableDataElements;
+ }
+
+
+
@Override
public String execute()
throws Exception
@@ -117,9 +166,45 @@
//selectedOrganisationUnitGroup=new ArrayList<OrganisationUnitGroup>();
availableOrganisationUnitGroups = new ArrayList<OrganisationUnitGroup>( orgUnitGrpService.getAllOrganisationUnitGroups() );
- System.out.println( "size(bulksmsmaction)==" + availableOrganisationUnitGroups.size() );
+ System.out.println( "size(bulksmsmaction)==" + availableOrganisationUnitGroups.size() );
Collections.sort( availableOrganisationUnitGroups, new OrganisationUnitGroupNameComparator() );
-
+Iterator it=orgUnitGrpService.getAllOrganisationUnitGroups().iterator();
+while(it.hasNext()){
+System.out.println(it.next());
+}
+//dataElementService=new DefaultDataElementService();
+
+//System.out.println("------------------------------------->"+dataElementService.getDataElementGroupCount());
+ // DataElementGroup dataElementGrp=dataElementService.getDataElementGroupByName( "Mobile Daily");
+
+
+ availableDataElements=new ArrayList<String>();
+ // availableDataElements.add(">>"+ dataElementGrp.getMembers().size());
+ // availableDataElements.add( "do you like this service?");
+ // availableDataElements.add( "randomly answer this question as yes or no");
+
+ File file=new File( System.getenv( "DHIS2_HOME" ) + File.separator+"mobile.xml");
+ if (!file.exists()){
+ result="make a file mobile.xml in the directory\""+System.getenv( "DHIS2_HOME" )+"\" with dataelements in it and try again";
+ return SUCCESS;
+ }
+ System.out.println( file.getAbsolutePath());
+ DocumentBuilderFactory docBuiderFactory=DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder= docBuiderFactory.newDocumentBuilder();
+ org.w3c.dom.Document doc= docBuilder.parse(file);
+NodeList nodelist=doc.getElementsByTagName( "dataelement");
+ for (int i=0;i<nodelist.getLength();i++){
+ org.w3c.dom.Node node=nodelist.item( i);
+ String id=node.getChildNodes().item( 3).getTextContent();
+ String name=node.getChildNodes().item( 1).getTextContent();
+ String periodId=node.getChildNodes().item( 5).getTextContent();
+ String comboId=node.getChildNodes().item( 7).getTextContent();
+ String messageType=node.getChildNodes().item( 9).getTextContent();
+
+ availableDataElements.add( id +"#"+messageType+"#"+name);
+ System.out.println(id +name+periodId+comboId+messageType);
+ }
+
conn = new BulkSMSHttpInterface();
phonenos = new ArrayList<String>();
@@ -136,7 +221,7 @@
System.out.println( "strArrid=" + strArr[i] );
int parseInt = Integer.parseInt( strArr[i] );
-
+//13321
for ( int j = 0; j < availableOrganisationUnitGroups.size(); j++ )
{
if ( availableOrganisationUnitGroups.get( j ).getId() == parseInt )
@@ -151,14 +236,38 @@
{
phonenos.add( temp.getPhoneNumber() );
}
- System.out.println( " phone=" + temp.getPhoneNumber() );
+ System.out.println( "id="+temp.getUuid()+" phone=" + temp.getPhoneNumber() );
}
}
}
}
}
-
+// System.out.print( countavailableDataElements+" "+availableDataElements.get( 1)+" "+isMessageDisabled+"sel="+selectedAvailableDataElements+"<----" );
+ if (isMessageDisabled.equals( "true") )
+ {
+ message=selectedAvailableDataElements;
+ // System.out.println(selectedAvailableDataElements);
+ String[] split = message.split( "#");
+ for (int i=0;i<split.length;i++){
+ // System.out.println(split[i]+","+i+split.length+message);
+ }
+
+ message=split[0]+"#"+"1"+"#"+"1"+"#"+split[1]+"#"+split[2];
+ System.out.println(message);
+ // System.out.print( "sdsd---------------------"+countavailableDataElements);
+ }
+
+ if (message.isEmpty()){
+ result="No Message Selected/Written";
+ return SUCCESS;
+ }
+ else if (phonenos.isEmpty()){
+ result="No Phone Numbers Found";
+ return SUCCESS;
+
+ }
+
// fill in the sendSMS fields...
List<SendSMS> sendSMSList = new ArrayList();
SendSMS tempSendSMS;
@@ -183,30 +292,25 @@
/*
+
// for third party=
- if (phonenos.size()>0)
- {
result= conn.sendMessages( message, phonenos);
System.out.println(result);
String temp=conn.checkBalance();
result+="Balance="+temp;
- }else result="no numbers found";
+
+
*/
+ System.out.println(message);
// for gsm modem
- if ( !sendSMSList.isEmpty() )
- {
+ if (isMessageDisabled.equals( "true"))
+ result=smsService.sendMessagesToPort(sendSMSList, 16000,0);
+ else
result = smsService.sendMessages( sendSMSList );
- } else
- {
- result = "no numbers found";
- }
-
-
-
/* for testing...
if (message.startsWith( "group") )
result= sendGroupMessage();
=== modified file 'local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendBulkSMSThirdPartyAction.java'
--- local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendBulkSMSThirdPartyAction.java 2011-06-17 10:06:08 +0000
+++ local/in/dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendBulkSMSThirdPartyAction.java 2011-07-07 11:56:37 +0000
@@ -10,10 +10,15 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.DefaultDataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DefaultSectionService;
import org.hisp.dhis.mobile.BulkSMSHttpInterface;
import org.hisp.dhis.mobile.SmsService;
import org.hisp.dhis.mobile.api.SendSMS;
@@ -30,6 +35,14 @@
public class SendBulkSMSThirdPartyAction
implements Action
{
+
+ DefaultDataElementService dataElementService;
+
+ public void setDataElementService( DefaultDataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
SmsService smsService;
@@ -82,6 +95,7 @@
return availableOrganisationUnitGroups;
}
+
String message;
public void setMessage( String message )
@@ -109,6 +123,31 @@
{
return result;
}
+ public List<String> availableDataElements;
+
+ public List<String> getAvailableDataElements()
+ {
+ return availableDataElements;
+ }
+
+public int countavailableDataElements;
+
+ public void setAvailableDataElements( List<String> availableDataElements )
+ {
+ this.availableDataElements = availableDataElements;
+ }
+public String isMessageDisabled;
+
+ public void setIsMessageDisabled( String isMessageDisabled )
+ {
+ this.isMessageDisabled = isMessageDisabled;
+ }
+ public String selectedAvailableDataElements;
+
+ public void setSelectedAvailableDataElements( String selectedAvailableDataElements )
+ {
+ this.selectedAvailableDataElements = selectedAvailableDataElements;
+ }
@Override
public String execute()
@@ -117,9 +156,21 @@
//selectedOrganisationUnitGroup=new ArrayList<OrganisationUnitGroup>();
availableOrganisationUnitGroups = new ArrayList<OrganisationUnitGroup>( orgUnitGrpService.getAllOrganisationUnitGroups() );
- System.out.println( "size(bulksmsmaction)==" + availableOrganisationUnitGroups.size() );
+ System.out.println( "size(bulksmsmaction)==" + availableOrganisationUnitGroups.size() );
Collections.sort( availableOrganisationUnitGroups, new OrganisationUnitGroupNameComparator() );
-
+Iterator it=orgUnitGrpService.getAllOrganisationUnitGroups().iterator();
+while(it.hasNext()){
+System.out.println(it.next());
+}
+//dataElementService=new DefaultDataElementService();
+//System.out.println("------------------------------------->"+dataElementService.getDataElementGroupCount());
+ // DataElementGroup dataElementGrp=dataElementService.getDataElementGroupByName( "MObile Daily");
+
+ availableDataElements=new ArrayList<String>();
+ // availableDataElements.add(">>"+ dataElementGrp.getMembers().size());
+ // availableDataElements.add( "do you like this service?");
+ // availableDataElements.add( "randomly answer this question as yes or no");
+
conn = new BulkSMSHttpInterface();
phonenos = new ArrayList<String>();
@@ -136,13 +187,13 @@
System.out.println( "strArrid=" + strArr[i] );
int parseInt = Integer.parseInt( strArr[i] );
-
+//13321
for ( int j = 0; j < availableOrganisationUnitGroups.size(); j++ )
{
if ( availableOrganisationUnitGroups.get( j ).getId() == parseInt )
{
- //System.out.println( " -" + availableOrganisationUnitGroups.get( j ).getMembers().size() );
+ System.out.println( " -" + availableOrganisationUnitGroups.get( j ).getMembers().size() );
Iterator itr = availableOrganisationUnitGroups.get( j ).getMembers().iterator();
while ( itr.hasNext() )
{
@@ -151,14 +202,30 @@
{
phonenos.add( temp.getPhoneNumber() );
}
- // System.out.println( " phone=" + temp.getPhoneNumber() );
+ System.out.println( "id="+temp.getUuid()+" phone=" + temp.getPhoneNumber() );
}
}
}
}
}
-
+// System.out.print( countavailableDataElements+" "+availableDataElements.get( 1)+" "+isMessageDisabled+"sel="+selectedAvailableDataElements+"<----" );
+ if (isMessageDisabled.equals( "true") )
+ {
+ message=selectedAvailableDataElements;
+ // System.out.print( "sdsd---------------------"+countavailableDataElements);
+ }
+
+ if (message.isEmpty()){
+ result="No Message Selected/Written";
+ return SUCCESS;
+ }
+ else if (phonenos.isEmpty()){
+ result="No Phone Numbers Found";
+ return SUCCESS;
+
+ }
+
// fill in the sendSMS fields...
List<SendSMS> sendSMSList = new ArrayList();
SendSMS tempSendSMS;
@@ -181,28 +248,21 @@
result =smsService.sendMessages( sendSMSListForTesting );
*/
+
+
// for third party=
- if ( phonenos.size() > 0 )
- {
- result = conn.sendMessages( message, phonenos );
- System.out.println( result );
-
- String temp = conn.checkBalance();
- result += "Balance=" + temp;
- } else
- {
- result = "no numbers found";
- }
-
- /*
- // for gsm modem
- if (!sendSMSList.isEmpty()){
- result=smsService.sendMessages(sendSMSList);
-
- }else result="no numbers found";
- */
-
-
+ result= conn.sendMessages( message, phonenos);
+ System.out.println(result);
+
+ String temp=conn.checkBalance();
+ result+="Balance="+temp;
+
+
+
+ System.out.println(message);
+ /* // for gsm modem
+ result = smsService.sendMessages( sendSMSList );
+ */
/* for testing...
if (message.startsWith( "group") )
result= sendGroupMessage();
=== modified file 'local/in/dhis-mobile/dhis-web-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-mobile/dhis-web-mobile/src/main/resources/META-INF/dhis/beans.xml 2011-06-17 10:06:08 +0000
+++ local/in/dhis-mobile/dhis-web-mobile/src/main/resources/META-INF/dhis/beans.xml 2011-07-07 11:56:37 +0000
@@ -62,6 +62,7 @@
<bean id="org.hisp.dhis.mobile.action.SendBulkSMSAction"
class="org.hisp.dhis.mobile.action.SendBulkSMSAction"
scope="prototype">
+ <!-- <property name="dataElementService" ref="org.hisp.dhis.dataelement.DefaultDataElementService" /> -->
<property name="orgUnitGrpService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
<property name="smsService" ref="org.hisp.dhis.mobile.SmsService" />
</bean>
=== modified file 'local/in/dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/sendBulkSMSPage.vm'
--- local/in/dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/sendBulkSMSPage.vm 2011-06-17 11:44:03 +0000
+++ local/in/dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/sendBulkSMSPage.vm 2011-07-07 11:56:37 +0000
@@ -1,14 +1,86 @@
<script type="text/javascript" src="javascript/bulkSMS.js"></script>
<script type="text/javascript" language="javascript">
+
function Select()
{
##alert("Size= "+$availableOrganisationUnitGroups.size());
-
-##alert(document.theForm.availableOrganisationUnitGroups.selectedIndex);
-document.theForm.selectedIdString.value=document.theForm.selectedIdString.value +","+ document.theForm.availableOrganisationUnitGroups.options[document.theForm.availableOrganisationUnitGroups.selectedIndex].value;
+##alert("size sele="+document.getElementById("selectedOrganisationUnitGroups").options);
+
+ if (document.theForm.texttype.checked == true)
+ {
+document.theForm.selectedAvailableDataElements.value=document.theForm.availableDataElements.value;
+##alert("sel"+document.theForm.selectedAvailableDataElements.value);
+ }
+for ( i=0;i<document.getElementById("selectedOrganisationUnitGroups").length;i++){
+##alert(document.getElementById("selectedOrganisationUnitGroups").options[i].value);
+
+if (document.theForm.selectedIdString.value.length==0){
+document.theForm.selectedIdString.value= document.getElementById("selectedOrganisationUnitGroups").options[i].value;
+}else {
+document.theForm.selectedIdString.value=document.theForm.selectedIdString.value +","+ document.getElementById("selectedOrganisationUnitGroups").options[i].value;
+ }
+}
##alert("....>"+document.theForm.selectedIdString.value);
-}
+
+}
+
+
+function checkCheckBox() {
+ if (document.theForm.texttype.checked == false)
+ {
+ document.theForm.message.disabled = false;
+ document.theForm.availableDataElements.disabled = true;
+
+ }
+ else
+ {
+ document.theForm.message.disabled = true;
+ document.theForm.availableDataElements.disabled = false;
+ document.theForm.isMessageDisabled.value="true";
+
+ }
+}
+
+
+function validateSend()
+{
+ var validate=true;
+ if (document.theForm.texttype.checked == false)
+ {
+ if(document.theForm.message.value.length == 0)
+
+ {
+ alert("Enter the message");
+ validate=false;
+ }
+ }
+ else
+ if(document.theForm.availableDataElements.selectedIndex < 0)
+ {
+ alert("Select a data element");
+ validate=false;
+ }
+
+ if (document.theForm.selectedOrganisationUnitGroups.value.length==0)
+ {
+ alert("Select atleast 1 organization unit group");
+ validate=false;
+ }
+ if(validate==true)
+ {
+ if (document.theForm.texttype.checked == true)
+ {
+document.theForm.selectedAvailableDataElements.value=document.theForm.availableDataElements.value;
+//alert("sel"+document.theForm.selectedAvailableDataElements.value);
+ }
+
+ Select();
+ alert("Sending");
+ }
+
+}
+
</script>
@@ -38,36 +110,72 @@
<div>
<form method="post" name="theForm">
<textarea ID="selectedIdString" name="selectedIdString" style="display:none;"></textarea>
- <INPUT TYPE=CHECKBOX NAME="texttype" ID="p" VALUE="p" onClick="checkCheckBox()"/>Predefined Text <BR>
+ <textarea ID="isMessageDisabled" name="isMessageDisabled" style="display:none;"></textarea>
+ <textarea ID="selectedAvailableDataElements" name="selectedAvailableDataElements" style="display:none;"></textarea>
+
+
+ <INPUT TYPE=CHECKBOX NAME="texttype" ID="p" VALUE="p" onClick="checkCheckBox()"/>Predefined Text <BR>
<select size="1" id="availableDataElements" disabled=true name="availableDataElements" style="min-width:400px">
- #foreach ( $group in $availableDataElements )
- <option value="$unit.id">$unit.name</option>
- #end
- </select><BR><BR>
- Enter Text<BR>
- <textarea name="message" ID="message" cols="70" rows="5" style="width: 397px; height: 97px;"></textarea><BR><BR>
- User Groups<BR>
- <select multiple id="availableOrganisationUnitGroups" name="availableOrganisationUnitGroups" style="min-width:400px" onClick="Select();moveSelectedById( 'availableOrganisationUnitGroups', 'selectedOrganisationUnitGroups' );">
- #foreach ( $group in $availableOrganisationUnitGroups )
- <option value="$group.id">$group.name</option>
- #end
- </select><BR><BR>
- Selected Groups</BR>
- <select multiple id="selectedOrganisationUnitGroups" name="selectedOrganisationUnitGroups" style="min-width:400px">
- #foreach ( $group in $selectedOrganisationUnitGroups )
- <option value="$group.id">$group.name</option>
- #end
- </select><BR><BR>
+
+ #set($countavailableDataElements=0);
+ #foreach ( $str in $availableDataElements )
+
+ <option value="$str">$str</option>
+ #set($countavailableDataElements=$countavailableDataElements+1);
+ #end
+
+ </select><BR><BR>
+ Enter Text<BR>
+ <textarea name="message" ID="message" cols="68" rows="3"></textarea><BR><BR>
+<table id="groupSelectionArea">
+ <col/> ## Available Organisation Unit Groups
+ <col/> ## Filter
+ <col/> ## Selected Organisation Unit Groups
+ <thead>
+ <tr>
+ <th>$i18n.getString( "Available Organisation Unit Groups" )</th>
+<th>$i18n.getString( "filter" )</th>
+ <th>$i18n.getString( "Selected Organisation Unit Groups" )</th>
+ </tr>
+ </thead>
+ <tbody>
+<tr>
+ <!---->
+ <td>
+ <select size="5" id="availableOrganisationUnitGroups" name="availableOrganisationUnitGroups" multiple="multiple" style="min-width:20em;height:17em" ondblclick="moveSelectedById( 'availableOrganisationUnitGroups', 'selectedOrganisationUnitGroups');">
+ #foreach( $group in $availableOrganisationUnitGroups )
+ <option value="$group.id">$encoder.htmlEncode( $group.name )</option>
+ #end
+ </select>
+ </td>
+ <td>
+ <input type="button" value=">" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="moveSelectedById( 'availableOrganisationUnitGroups', 'selectedOrganisationUnitGroups');"/><br/>
+ <input type="button" value="<" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="moveSelectedById( 'selectedOrganisationUnitGroups', 'availableOrganisationUnitGroups');"/><br/>
+ <input type="button" value=">>" title="$i18n.getString('move_all')" style="width:50px" onclick="moveAllById( 'availableOrganisationUnitGroups', 'selectedOrganisationUnitGroups' );"/><br/>
+ <input type="button" value="<<" title="$i18n.getString('remove_all')" style="width:50px" onclick="moveAllById( 'selectedOrganisationUnitGroups', 'availableOrganisationUnitGroups' );"/>
+ </td>
+ <td>
+ <!---->
+ <select size="5" id="selectedOrganisationUnitGroups" name="selectedOrganisationUnitGroups" multiple="multiple" style="min-width:20em;height:17em" ondblclick="moveSelectedById( 'selectedOrganisationUnitGroups', 'availableOrganisationUnitGroups');">
+ #foreach( $group in $selectedOrganisationUnitGroups )
+ <option value="$group.id">$encoder.htmlEncode( $group.name )</option>
+ #end
+ </select>
+ </td>
+
+ </tr>
+ </tbody>
+</table>
## </form>
-
+
#if ($smsServiceStatus)
##<form method="post" >
- <BUTTON type="submit" name="send" value="Send" onClick="validateSend();">Send</BUTTON>
+ <BUTTON type="submit" name="send" value="Send" onClick="Select();">Send</BUTTON>
##</form>
#else
##<form method="post">
- <BUTTON type="submit" name="send" value="Send" disabled onClick="validateSend();">Send</BUTTON>
-
+ <BUTTON type="submit" name="send" value="Send" onClick="Select();">Send</BUTTON>
+
#end
</form>
@@ -78,3 +186,4 @@
border:3px; padding:.3em;#end"> $result
</span>
+
=== modified file 'local/in/dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/sendBulkSMSPageThirdParty.vm'
--- local/in/dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/sendBulkSMSPageThirdParty.vm 2011-06-17 11:44:03 +0000
+++ local/in/dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/sendBulkSMSPageThirdParty.vm 2011-07-07 11:56:37 +0000
@@ -1,14 +1,81 @@
<script type="text/javascript" src="javascript/bulkSMS.js"></script>
<script type="text/javascript" language="javascript">
+
function Select()
{
##alert("Size= "+$availableOrganisationUnitGroups.size());
-
-##alert(document.theForm.availableOrganisationUnitGroups.selectedIndex);
-document.theForm.selectedIdString.value=document.theForm.selectedIdString.value +","+ document.theForm.availableOrganisationUnitGroups.options[document.theForm.availableOrganisationUnitGroups.selectedIndex].value;
+##alert("size sele="+document.getElementById("selectedOrganisationUnitGroups").options);
+
+for ( i=0;i<document.getElementById("selectedOrganisationUnitGroups").length;i++){
+##alert(document.getElementById("selectedOrganisationUnitGroups").options[i].value);
+
+if (document.theForm.selectedIdString.value.length==0){
+document.theForm.selectedIdString.value= document.getElementById("selectedOrganisationUnitGroups").options[i].value;
+}else {
+document.theForm.selectedIdString.value=document.theForm.selectedIdString.value +","+ document.getElementById("selectedOrganisationUnitGroups").options[i].value;
+ }
+}
##alert("....>"+document.theForm.selectedIdString.value);
-}
+
+}
+
+
+function checkCheckBox() {
+ if (document.theForm.texttype.checked == false)
+ {
+ document.theForm.message.disabled = false;
+ document.theForm.availableDataElements.disabled = true;
+
+ }
+ else
+ {
+ document.theForm.message.disabled = true;
+ document.theForm.availableDataElements.disabled = false;
+ document.theForm.isMessageDisabled.value="true";
+
+ }
+}
+
+
+function validateSend()
+{
+ var validate=true;
+ if (document.theForm.texttype.checked == false)
+ {
+ if(document.theForm.message.value.length == 0)
+
+ {
+ alert("Enter the message");
+ validate=false;
+ }
+ }
+ else
+ if(document.theForm.availableDataElements.selectedIndex < 0)
+ {
+ alert("Select a data element");
+ validate=false;
+ }
+
+ if (document.theForm.selectedOrganisationUnitGroups.value.length==0)
+ {
+ alert("Select atleast 1 organization unit group");
+ validate=false;
+ }
+ if(validate==true)
+ {
+ if (document.theForm.texttype.checked == true)
+ {
+document.theForm.selectedAvailableDataElements.value=document.theForm.availableDataElements.value;
+//alert("sel"+document.theForm.selectedAvailableDataElements.value);
+ }
+
+ Select();
+ alert("Sending");
+ }
+
+}
+
</script>
@@ -27,30 +94,73 @@
<div>
<form method="post" name="theForm">
<textarea ID="selectedIdString" name="selectedIdString" style="display:none;"></textarea>
- <INPUT TYPE=CHECKBOX NAME="texttype" ID="p" VALUE="p" onClick="checkCheckBox()"/>Predefined Text <BR>
+ <textarea ID="isMessageDisabled" name="isMessageDisabled" style="display:none;"></textarea>
+ <textarea ID="selectedAvailableDataElements" name="selectedAvailableDataElements" style="display:none;"></textarea>
+
+
+ <INPUT TYPE=CHECKBOX NAME="texttype" ID="p" VALUE="p" onClick="checkCheckBox()"/>Predefined Text <BR>
<select size="1" id="availableDataElements" disabled=true name="availableDataElements" style="min-width:400px">
- #foreach ( $group in $availableDataElements )
- <option value="$unit.id">$unit.name</option>
- #end
- </select><BR><BR>
- Enter Text<BR>
- <textarea name="message" ID="message" cols="70" rows="5" style="width: 397px; height: 97px;"></textarea><BR><BR>
- User Groups<BR>
- <select multiple id="availableOrganisationUnitGroups" name="availableOrganisationUnitGroups" style="min-width:400px" onClick="Select();moveSelectedById( 'availableOrganisationUnitGroups', 'selectedOrganisationUnitGroups' );">
- #foreach ( $group in $availableOrganisationUnitGroups )
- <option value="$group.id">$group.name</option>
- #end
- </select><BR><BR>
- Selected Groups</BR>
- <select multiple id="selectedOrganisationUnitGroups" name="selectedOrganisationUnitGroups" style="min-width:400px">
- #foreach ( $group in $selectedOrganisationUnitGroups )
- <option value="$group.id">$group.name</option>
- #end
- </select><BR><BR>
+
+ #set($countavailableDataElements=0);
+ #foreach ( $str in $availableDataElements )
+
+ <option value="$str">$str</option>
+ #set($countavailableDataElements=$countavailableDataElements+1);
+ #end
+
+ </select><BR><BR>
+ Enter Text<BR>
+ <textarea name="message" ID="message" cols="68" rows="3"></textarea><BR><BR>
+<table id="groupSelectionArea">
+ <col/> ## Available Organisation Unit Groups
+ <col/> ## Filter
+ <col/> ## Selected Organisation Unit Groups
+ <thead>
+ <tr>
+ <th>$i18n.getString( "Available Organisation Unit Groups" )</th>
+<th>$i18n.getString( "filter" )</th>
+ <th>$i18n.getString( "Selected Organisation Unit Groups" )</th>
+ </tr>
+ </thead>
+ <tbody>
+<tr>
+ <!---->
+ <td>
+ <select size="5" id="availableOrganisationUnitGroups" name="availableOrganisationUnitGroups" multiple="multiple" style="min-width:20em;height:17em" ondblclick="moveSelectedById( 'availableOrganisationUnitGroups', 'selectedOrganisationUnitGroups');">
+ #foreach( $group in $availableOrganisationUnitGroups )
+ <option value="$group.id">$encoder.htmlEncode( $group.name )</option>
+ #end
+ </select>
+ </td>
+ <td>
+ <input type="button" value=">" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="moveSelectedById( 'availableOrganisationUnitGroups', 'selectedOrganisationUnitGroups');"/><br/>
+ <input type="button" value="<" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="moveSelectedById( 'selectedOrganisationUnitGroups', 'availableOrganisationUnitGroups');"/><br/>
+ <input type="button" value=">>" title="$i18n.getString('move_all')" style="width:50px" onclick="moveAllById( 'availableOrganisationUnitGroups', 'selectedOrganisationUnitGroups' );"/><br/>
+ <input type="button" value="<<" title="$i18n.getString('remove_all')" style="width:50px" onclick="moveAllById( 'selectedOrganisationUnitGroups', 'availableOrganisationUnitGroups' );"/>
+ </td>
+ <td>
+ <!---->
+ <select size="5" id="selectedOrganisationUnitGroups" name="selectedOrganisationUnitGroups" multiple="multiple" style="min-width:20em;height:17em" ondblclick="moveSelectedById( 'selectedOrganisationUnitGroups', 'availableOrganisationUnitGroups');">
+ #foreach( $group in $selectedOrganisationUnitGroups )
+ <option value="$group.id">$encoder.htmlEncode( $group.name )</option>
+ #end
+ </select>
+ </td>
+
+ </tr>
+ </tbody>
+</table>
## </form>
-
- <BUTTON type="submit" name="send" value="Send" onClick="validateSend();">Send</BUTTON>
-
+
+ #if ($smsServiceStatus)
+ ##<form method="post" >
+ <BUTTON type="submit" name="send" value="Send" onClick="Select();">Send</BUTTON>
+ ##</form>
+ #else
+ ##<form method="post">
+ <BUTTON type="submit" name="send" value="Send" onClick="Select();">Send</BUTTON>
+
+ #end
</form>
@@ -60,3 +170,4 @@
border:3px; padding:.3em;#end"> $result
</span>
+