dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11477
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3281: Import manually into dataValueService. Should use common dataValueImport. Remove Autoimport job. ...
------------------------------------------------------------
revno: 3281
committer: Saptarshi <sunbiz@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-04-05 03:04:43 +0200
message:
Import manually into dataValueService. Should use common dataValueImport. Remove Autoimport job. Remove automatic jar creator
removed:
dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStoreTest.java
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/CreateMobileAppAction.java
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/GetDataElementsAction.java
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/JarGeneratorAction.java
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/SplashUploadAction.java
dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/createMobileApp.js
dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/jquery-form.js
added:
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/DefaultSmsImportService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/DefaultSmsInboundStoreService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsFormat.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsImportService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStoreService.java
dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/DefaultSmsInboundStoreServiceTest.java
dhis-mobile/dhis-web-mobile/log4j.properties
modified:
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/scheduler/CheckDataStatusJob.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStore.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/SmsService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStore.java
dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml
dhis-mobile/dhis-web-mobile/pom.xml
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/ReceiveImportPageAction.java
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.java
dhis-mobile/dhis-web-mobile/src/main/resources/META-INF/dhis/beans.xml
dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/log4j.properties
dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/user.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java 2011-01-17 06:56:53 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java 2011-04-05 01:04:43 +0000
@@ -563,173 +563,394 @@
}
}
- /*
- @Transactional
- public void importAllFiles()
- {
- BatchHandler<DataValue> batchHandler = batchHandlerFactory.createBatchHandler( DataValueBatchHandler.class );
- batchHandler.init();
-
- String importStatus;
- importStatus = "";
-
- List<String> fileNames = new ArrayList<String>( getImportFiles() );
-
- for ( String importFile : fileNames )
- {
- try
- {
- MobileImportParameters mobImportParameters = getParametersFromXML( importFile );
-
- if ( mobImportParameters == null )
- {
- LOG.error( importFile + " Import File is not Properly Formated First" );
- importStatus += "<br>" + new Date() + ": " + importFile + " Import File is not Properly Formated.";
- moveFailedFile( importFile );
- continue;
- }
-
- 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() );
- importStatus += "<br><font color=red><b>Import File Contains Unrecognised Phone Numbers :"
- + mobImportParameters.getMobileNumber() + ".</b></font>";
- moveFailedFile( importFile );
- continue;
- }
-
- List<Source> sources = new ArrayList<Source>( curUser.getOrganisationUnits() );
-
- if ( sources == null || sources.size() <= 0 )
- {
- importStatus += "<br><font color=red><b>No User Exist Who Registered Phone No. Is :"
- + mobImportParameters.getMobileNumber() + ".</b></font>";
- moveFailedFile( importFile );
- continue;
- }
- Source source = sources.get( 0 );
-
- System.out.println( "getStartDate = " + mobImportParameters.getStartDate() + " getPeriodType = "
- + mobImportParameters.getPeriodType() );
-
- 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() );
-
- 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" );
- importStatus += "<br>" + new Date() + ": " + importFile
- + " Import File is not Properly Formated.<br>";
- moveFailedFile( importFile );
- continue;
- }
-
- 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 = new DataValue( dataElement, period, source, value, storedBy, timeStamp,
- null, optionCombo );
- boolean exists = batchHandler.objectExists( dataValue );
-
- if ( !exists )
- {
- if ( value != null )
- {
- batchHandler.addObject( dataValue );
- }
- }
- else
- {
- dataValue.setValue( value );
-
- dataValue.setTimestamp( timeStamp );
-
- dataValue.setStoredBy( storedBy );
-
- batchHandler.updateObject( dataValue );
- }
- }
-
- importStatus += "<br>" + new Date() + ": " + importFile + " is Imported Successfully.";
-
- moveImportedFile( importFile );
- }
- else
- {
- LOG.error( importFile + " Phone number not found... Sending to Bounced" );
- moveFailedFile( importFile );
- }
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- LOG.error( e.getMessage() );
- LOG.error( "Exception caused in importing... Moving to Bounced" );
- moveFailedFile( importFile );
- }
- finally
- {
- batchHandler.flush();
- }
- }
- }
-*/
+ //<editor-fold defaultstate="collapsed" desc="TODO: discard = old code">
+ /*
+ * @Transactional
+ * public void importAllFiles()
+ * {
+ * BatchHandler<DataValue> batchHandler = batchHandlerFactory.createBatchHandler( DataValueBatchHandler.class );
+ * batchHandler.init();
+ *
+ * String importStatus;
+ * importStatus = "";
+ *
+ * List<String> fileNames = new ArrayList<String>( getImportFiles() );
+ *
+ * for ( String importFile : fileNames )
+ * {
+ * try
+ * {
+ * MobileImportParameters mobImportParameters = getParametersFromXML( importFile );
+ *
+ * if ( mobImportParameters == null )
+ * {
+ * LOG.error( importFile + " Import File is not Properly Formated First" );
+ * importStatus += "<br>" + new Date() + ": " + importFile + " Import File is not Properly Formated.";
+ * moveFailedFile( importFile );
+ * continue;
+ * }
+ *
+ * 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() );
+ * importStatus += "<br><font color=red><b>Import File Contains Unrecognised Phone Numbers :"
+ * + mobImportParameters.getMobileNumber() + ".</b></font>";
+ * moveFailedFile( importFile );
+ * continue;
+ * }
+ *
+ * List<Source> sources = new ArrayList<Source>( curUser.getOrganisationUnits() );
+ *
+ * if ( sources == null || sources.size() <= 0 )
+ * {
+ * importStatus += "<br><font color=red><b>No User Exist Who Registered Phone No. Is :"
+ * + mobImportParameters.getMobileNumber() + ".</b></font>";
+ * moveFailedFile( importFile );
+ * continue;
+ * }
+ * Source source = sources.get( 0 );
+ *
+ * System.out.println( "getStartDate = " + mobImportParameters.getStartDate() + " getPeriodType = "
+ * + mobImportParameters.getPeriodType() );
+ *
+ * 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() );
+ *
+ * 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" );
+ * importStatus += "<br>" + new Date() + ": " + importFile
+ * + " Import File is not Properly Formated.<br>";
+ * moveFailedFile( importFile );
+ * continue;
+ * }
+ *
+ * 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 = new DataValue( dataElement, period, source, value, storedBy, timeStamp,
+ * null, optionCombo );
+ * boolean exists = batchHandler.objectExists( dataValue );
+ *
+ * if ( !exists )
+ * {
+ * if ( value != null )
+ * {
+ * batchHandler.addObject( dataValue );
+ * }
+ * }
+ * else
+ * {
+ * dataValue.setValue( value );
+ *
+ * dataValue.setTimestamp( timeStamp );
+ *
+ * dataValue.setStoredBy( storedBy );
+ *
+ * batchHandler.updateObject( dataValue );
+ * }
+ * }
+ *
+ * importStatus += "<br>" + new Date() + ": " + importFile + " is Imported Successfully.";
+ *
+ * moveImportedFile( importFile );
+ * }
+ * else
+ * {
+ * LOG.error( importFile + " Phone number not found... Sending to Bounced" );
+ * moveFailedFile( importFile );
+ * }
+ * }
+ * catch ( Exception e )
+ * {
+ * e.printStackTrace();
+ * LOG.error( e.getMessage() );
+ * LOG.error( "Exception caused in importing... Moving to Bounced" );
+ * moveFailedFile( importFile );
+ * }
+ * finally
+ * {
+ * batchHandler.flush();
+ * }
+ * }
+ * }
+ */
+ //</editor-fold>
+ //<editor-fold defaultstate="collapsed" desc="TODO: discard = old code">
+ /*
+ * @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="";
+ *
+ * try
+ * {
+ * MobileImportParameters mobImportParameters = getParametersFromXML( importFile );
+ *
+ * if ( mobImportParameters == null )
+ * {
+ * 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;
+ * }
+ *
+ * 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 );
+ *
+ * statusMsgs.add( 0, "2" );
+ * statusMsgs.add( 1, "Phone number is not registered to any facility. Please contact admin" );
+ *
+ * return statusMsgs;
+ * }
+ *
+ * List<Source> sources = new ArrayList<Source>( curUser.getOrganisationUnits() );
+ *
+ * if ( sources == null || sources.size() <= 0 )
+ * {
+ * LOG.error( " No User Exists with corresponding 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;
+ * }
+ *
+ * Source 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 );
+ *
+ * statusMsgs.add( 0, "1" );
+ * statusMsgs.add( 1, "Data not Received Properly, Please send again" );
+ *
+ * return statusMsgs;
+ * }
+ *
+ * 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() );
+ *
+ * statusMsgs.add( 0, "3" );
+ * statusMsgs.add( 1, importStatus );
+ * }
+ * else if( period.getPeriodType().getName().equalsIgnoreCase( "daily" ))
+ * {
+ * importStatus = "THANK YOU FOR SENDING DAILY REPORT FOR " + dateFormat.format( period.getStartDate() );
+ *
+ * statusMsgs.add( 0, "4" );
+ * statusMsgs.add( 1, importStatus );
+ * }
+ * else
+ * {
+ * importStatus = "THANK YOU FOR SENDING REPORT FOR " + dateFormat.format( period.getStartDate() ) + " : " + dateFormat.format( period.getEndDate() );
+ *
+ * statusMsgs.add( 0, "5" );
+ * statusMsgs.add( 1, importStatus );
+ * }
+ * }
+ * else
+ * {
+ * 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 );
+ *
+ * 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";
+ *
+ * statusMsgs.add( 0, "1" );
+ * statusMsgs.add( 1, importStatus );
+ *
+ * moveFailedFile( importFile );
+ * }
+ * finally
+ * {
+ * }
+ *
+ * return statusMsgs;
+ * }
+ */
+ //</editor-fold>
+
@Override
@Transactional
public void importPendingFiles()
@@ -745,223 +966,6 @@
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="";
-
- try
- {
- MobileImportParameters mobImportParameters = getParametersFromXML( importFile );
-
- if ( mobImportParameters == null )
- {
- 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;
- }
-
- 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 );
-
- statusMsgs.add( 0, "2" );
- statusMsgs.add( 1, "Phone number is not registered to any facility. Please contact admin" );
-
- return statusMsgs;
- }
-
- List<Source> sources = new ArrayList<Source>( curUser.getOrganisationUnits() );
-
- if ( sources == null || sources.size() <= 0 )
- {
- LOG.error( " No User Exists with corresponding 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;
- }
-
- Source 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 );
-
- statusMsgs.add( 0, "1" );
- statusMsgs.add( 1, "Data not Received Properly, Please send again" );
-
- return statusMsgs;
- }
-
- 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() );
-
- statusMsgs.add( 0, "3" );
- statusMsgs.add( 1, importStatus );
- }
- else if( period.getPeriodType().getName().equalsIgnoreCase( "daily" ))
- {
- importStatus = "THANK YOU FOR SENDING DAILY REPORT FOR " + dateFormat.format( period.getStartDate() );
-
- statusMsgs.add( 0, "4" );
- statusMsgs.add( 1, importStatus );
- }
- else
- {
- importStatus = "THANK YOU FOR SENDING REPORT FOR " + dateFormat.format( period.getStartDate() ) + " : " + dateFormat.format( period.getEndDate() );
-
- statusMsgs.add( 0, "5" );
- statusMsgs.add( 1, importStatus );
- }
- }
- else
- {
- 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 );
-
- 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";
-
- statusMsgs.add( 0, "1" );
- statusMsgs.add( 1, importStatus );
-
- moveFailedFile( importFile );
- }
- finally
- {
- }
-
- return statusMsgs;
- }
- */
@Transactional
public String importANMRegData( String importFile, MobileImportParameters mobImportParameters )
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/scheduler/CheckDataStatusJob.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/scheduler/CheckDataStatusJob.java 2011-01-11 16:58:18 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/scheduler/CheckDataStatusJob.java 2011-04-05 01:04:43 +0000
@@ -160,10 +160,10 @@
{
OrganisationUnit orgUnit = orgUnitIterator.next();
- if( !dataSetService.getDataSetsBySource( orgUnit ).contains( dataSet ) )
+ /*if( !dataSetService.getDataSetsBySource( orgUnit ).contains( dataSet ) )
{
orgUnitIterator.remove();
- }
+ }*/
}
String deInfoAndCount = getDataSetMembersUsingQuery( dataSet.getId() );
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/DefaultSmsImportService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/DefaultSmsImportService.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/DefaultSmsImportService.java 2011-04-05 01:04:43 +0000
@@ -0,0 +1,306 @@
+package org.hisp.dhis.mobile.sms;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.mobile.sms.api.SmsFormat;
+import org.hisp.dhis.mobile.sms.api.SmsImportService;
+import org.hisp.dhis.mobile.sms.api.SmsInbound;
+import org.hisp.dhis.mobile.sms.api.SmsInboundStoreService;
+import org.hisp.dhis.period.DailyPeriodType;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.WeeklyPeriodType;
+import org.hisp.dhis.period.YearlyPeriodType;
+import org.hisp.dhis.source.Source;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserStore;
+import org.smslib.helper.Logger;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author Saptarshi
+ */
+public class DefaultSmsImportService implements SmsImportService
+{
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ private DataElementCategoryService dataElementCategoryService;
+
+ public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
+ {
+ this.dataElementCategoryService = dataElementCategoryService;
+ }
+
+ private DataValueService dataValueService;
+
+ public void setDataValueService( DataValueService dataValueService )
+ {
+ this.dataValueService = dataValueService;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+ private UserStore userStore;
+
+ public void setUserStore( UserStore userStore )
+ {
+ this.userStore = userStore;
+ }
+
+ private SmsInboundStoreService smsInboundStoreService;
+
+ public void setSmsInboundStoreService( SmsInboundStoreService smsInboundStoreService )
+ {
+ this.smsInboundStoreService = smsInboundStoreService;
+ }
+
+ // -------------------------------------------------------------------------
+ // Helper Methods
+ // -------------------------------------------------------------------------
+ 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;
+ }
+
+ public Period getPeriodInfo( String startDate, String periodTypeId )
+ throws Exception
+ {
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
+
+ List<Period> periods = null;
+ PeriodType pt = null;
+ if ( periodTypeId.equals( "3" ) )
+ {
+ pt = new MonthlyPeriodType();
+ periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
+ } else
+ {
+ if ( periodTypeId.equals( "1" ) )
+ {
+ pt = new DailyPeriodType();
+ periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
+ } else
+ {
+ if ( periodTypeId.equals( "6" ) )
+ {
+ pt = new YearlyPeriodType();
+ periods = new ArrayList<Period>( periodService.getPeriodsByPeriodType( pt ) );
+ } else
+ {
+ if ( periodTypeId.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;
+ }
+
+ private Period reloadPeriod( Period period )
+ {
+ return periodService.getPeriod( period.getStartDate(), period.getEndDate(), period.getPeriodType() );
+ }
+
+ private Period reloadPeriodForceAdd( Period period )
+ {
+ Period storedPeriod = reloadPeriod( period );
+
+ if ( storedPeriod == null )
+ {
+ periodService.addPeriod( period );
+
+ return period;
+ }
+
+ return storedPeriod;
+ }
+
+ // -------------------------------------------------------------------------
+ // Implementation
+ // -------------------------------------------------------------------------
+ @Override
+ @Transactional
+ public int saveDataValues()
+ {
+ int importedMessages = 0;
+
+ try
+ {
+ File deIdFile = new File( System.getenv( "DHIS2_HOME" ) + File.separator + "formIDLayout.csv" );
+ if ( deIdFile.exists() )
+ {
+ FileInputStream f = new FileInputStream( deIdFile );
+ Properties props = new Properties();
+ props.load( f );
+ f.close();
+
+ Collection<SmsInbound> msgs = smsInboundStoreService.getAllReceivedSms();
+ for ( SmsInbound sms : msgs )
+ {
+ SmsFormat dataSms = new SmsFormat( sms );
+ String storedBy = "";
+ User curUser = getUserInfo( sms.getOriginator() );
+ if ( curUser != null )
+ {
+ UserCredentials userCredentials = userStore.getUserCredentials( curUser );
+ if ( userCredentials != null )
+ {
+ storedBy = userCredentials.getUsername();
+ } else
+ {
+ Logger.getInstance().logError( "User with phone number not found : "
+ + sms.getOriginator(), null, null );
+ return -1;
+ }
+ List<Source> sources = new ArrayList<Source>( curUser.getOrganisationUnits() );
+ if ( sources == null || sources.size() <= 0 )
+ {
+ Logger.getInstance().logError( " User with phone number not assigned any organization unit : "
+ + sms.getOriginator(), null, null );
+ return -1;
+ }
+ Source source = sources.get( 0 );
+ Period period = getPeriodInfo( dataSms.getPeriodText(), dataSms.getPeriodTypeId() );
+
+ String[] deIds = props.getProperty( dataSms.getFormId() ).split( "\\," );
+ String[] dataValues = dataSms.getDataValues();
+ if ( dataValues.length == deIds.length )
+ {
+ int saveCount = 0;
+ for ( int i = 0; i < dataValues.length; i++ )
+ {
+ String parts[] = deIds[i].split( "\\." );
+
+ String deStr = parts[0];
+
+ String optStr = parts[1];
+
+ 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 ( dataValues[i] != null )
+ {
+ dataValue = new DataValue( dataElement, period, source, optionCombo );
+ dataValueService.addDataValue( dataValue );
+ saveCount++;
+ }
+ } else
+ {
+ dataValue.setValue( dataValues[i] );
+ dataValue.setStoredBy( storedBy );
+ dataValueService.updateDataValue( dataValue );
+ saveCount++;
+ }
+ }
+ } else
+ {
+ Logger.getInstance().logError( "Incorrect formatted IdLayout file for : DV = "
+ + dataValues.length + " DE = " + deIds.length, null, null );
+ return -1;
+ }
+
+ } else
+ {
+ Logger.getInstance().logError( "Unrecognised Phone Numbers : " + sms.getOriginator(), null, null );
+ return -1;
+ }
+ }
+ } else
+ {
+ Logger.getInstance().logError( "Error finding dataelement ids file: ", null, null );
+ return -1;
+ }
+ } catch ( Exception ex )
+ {
+ Logger.getInstance().logError( "Error getting Period!", ex, null );
+ return -1;
+ }
+ return importedMessages;
+ }
+}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/DefaultSmsInboundStoreService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/DefaultSmsInboundStoreService.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/DefaultSmsInboundStoreService.java 2011-04-05 01:04:43 +0000
@@ -0,0 +1,99 @@
+package org.hisp.dhis.mobile.sms;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+import org.hisp.dhis.mobile.sms.api.SmsInbound;
+import org.hisp.dhis.mobile.sms.api.SmsInboundStore;
+import org.hisp.dhis.mobile.sms.api.SmsInboundStoreService;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author Saptarshi
+ */
+@Transactional
+public class DefaultSmsInboundStoreService implements SmsInboundStoreService
+{
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+ private SmsInboundStore smsInboundStore;
+
+ public void setSmsInboundStore( SmsInboundStore smsInboundStore )
+ {
+ this.smsInboundStore = smsInboundStore;
+ }
+
+ // -------------------------------------------------------------------------
+ // Implementation
+ // -------------------------------------------------------------------------
+ @Override
+ public void saveSms( SmsInbound sms )
+ {
+ smsInboundStore.saveSms( sms );
+ }
+
+ @Override
+ public Collection<SmsInbound> getSmsByDate( Date startDate, Date endDate )
+ {
+ return smsInboundStore.getSms( null, null, startDate, endDate);
+ }
+
+ @Override
+ public Collection<SmsInbound> getSmsByOriginator( String originator )
+ {
+ return smsInboundStore.getSms( originator, null, null, null );
+ }
+
+ @Override
+ public Collection<SmsInbound> getSmsByProcess( int process )
+ {
+ return smsInboundStore.getSms( null, process, null, null );
+ }
+
+ @Override
+ public Collection<SmsInbound> getAllReceivedSms()
+ {
+ return smsInboundStore.getSms( null, null, null, null );
+ }
+
+ @Override
+ public void updateSms( SmsInbound sms )
+ {
+ smsInboundStore.updateSms( sms );
+ }
+
+ @Override
+ public long getSmsCount()
+ {
+ return smsInboundStore.getSmsCount();
+ }
+}
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStore.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStore.java 2011-03-28 16:36:44 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStore.java 2011-04-05 01:04:43 +0000
@@ -64,33 +64,22 @@
}
@Override
- public Collection<SmsInbound> getSmsByDate( Date startDate, Date endDate )
- {
- return sessionFactory.getCurrentSession().createCriteria( SmsInbound.class )
- .add( Restrictions.between("receiveDate", startDate, endDate) )
- .list();
- }
-
- @Override
- public Collection<SmsInbound> getSmsByOriginator( String originator )
- {
- return sessionFactory.getCurrentSession().createCriteria( SmsInbound.class )
- .add(Restrictions.eq("originator", originator))
- .list();
- }
-
- @Override
- public Collection<SmsInbound> getSmsByProcess( int process )
- {
- return sessionFactory.getCurrentSession().createCriteria( SmsInbound.class )
- .add(Restrictions.eq("process", process))
- .list();
- }
-
- @Override
- public Collection<SmsInbound> getAllReceiveSMS()
- {
- return sessionFactory.getCurrentSession().createCriteria( SmsInbound.class ).list();
+ public Collection<SmsInbound> getSms( String originator, Integer process, Date startDate, Date endDate )
+ {
+ Criteria crit = sessionFactory.getCurrentSession().createCriteria( SmsInbound.class );
+ if ( originator != null && !originator.equals( "" ) )
+ {
+ crit.add( Restrictions.eq( "originator", originator ) );
+ }
+ if ( process != null )
+ {
+ crit.add( Restrictions.eq( "process", process ) );
+ }
+ if ( startDate != null && endDate != null )
+ {
+ crit.add( Restrictions.between( "receiveDate", startDate, endDate ) );
+ }
+ return crit.list();
}
@Override
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/SmsService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/SmsService.java 2011-03-28 16:36:44 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/SmsService.java 2011-04-05 01:04:43 +0000
@@ -32,10 +32,16 @@
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
+import org.hisp.dhis.mobile.Compressor;
import org.hisp.dhis.mobile.sms.api.SmsInbound;
+import org.hisp.dhis.mobile.sms.api.SmsInboundStoreService;
import org.smslib.AGateway;
import org.smslib.AGateway.Protocols;
import org.smslib.GatewayException;
@@ -44,6 +50,7 @@
import org.smslib.IOrphanedMessageNotification;
import org.smslib.IOutboundMessageNotification;
import org.smslib.IQueueSendingNotification;
+import org.smslib.InboundBinaryMessage;
import org.smslib.InboundMessage;
import org.smslib.Message.MessageEncodings;
import org.smslib.Message.MessageTypes;
@@ -61,17 +68,17 @@
*/
public class SmsService
{
-
+
/*------------------------------------------------------------------
* Dependencies
------------------------------------------------------------------*/
- HibernateSmsInboundStore hibernateSmsInboundStore;
-
- public void setHibernateSmsStore( HibernateSmsInboundStore hibernateSmsInboundStore )
+ SmsInboundStoreService smsInboundStoreService;
+
+ public void setSmsInboundStoreService( SmsInboundStoreService smsInboundStoreService )
{
- this.hibernateSmsInboundStore = hibernateSmsInboundStore;
+ this.smsInboundStoreService = smsInboundStoreService;
}
-
+
/*------------------------------------------------------------------
* Implementation
------------------------------------------------------------------*/
@@ -87,6 +94,8 @@
private OrphanedMessageNotification orphanedMessageNotification;
+ private Timer inboundPollingTimer;
+
/*
* Constructor called when SmsService is loaded
*/
@@ -117,11 +126,16 @@
if ( !result.contains( "ERROR" ) )
{
Service.getInstance().startService();
+ int inbound_interval = Integer.parseInt( props.getProperty( "settings.inbound_interval", "60" ) );
+ inboundPollingTimer = new Timer( "SmsService - InboundPollingTask" );
+ InboundPollingTask inboundPollingTask = new InboundPollingTask();
+ inboundPollingTimer.schedule( inboundPollingTask, inbound_interval * 1000, inbound_interval * 1000 );
}
return result;
} catch ( Exception ex )
{
- return "ERROR";
+ Logger.getInstance().logError( "Exception starting service: ", ex, null );
+ return "ERROR = " + ex.getMessage();
}
} else
{
@@ -142,9 +156,11 @@
try
{
Service.getInstance().stopService();
+ inboundPollingTimer.cancel();
return "SERVICE STOPPED";
} catch ( Exception ex )
{
+ Logger.getInstance().logError( "Exception stopping service: ", ex, null );
return "ERROR";
}
} else
@@ -255,10 +271,34 @@
}
//</editor-fold>
+ /**
+ *
+ * @param recipient
+ * @param msg
+ * @return
+ * @throws Exception
+ */
+ public String sendMessage( String recipient, String msg ) throws Exception
+ {
+ OutboundMessage outboundMessage = new OutboundMessage( recipient, msg );
+ if ( isServiceRunning() )
+ {
+ Service.getInstance().sendMessage( outboundMessage );
+ return "MESSAGE SENT SUCCESSFULLY TO: " + recipient;
+ } else
+ {
+ return "SERVICE IS NOT RUNNING";
+ }
+ }
+
/*------------------------------------------------------------------
* SMSLIB CALLBACKS NOT IMPLEMENTED - ONLY USED FOR LOGGING
------------------------------------------------------------------*/
//<editor-fold defaultstate="collapsed" desc="smslib callbacks">
+ /**
+ * Callback called when inbound message is received at the modem.
+ * Depends on correct CNMI implementation by the modem
+ */
class InboundNotification implements IInboundMessageNotification
{
@@ -269,6 +309,9 @@
}
}
+ /**
+ * Callback called when attempt for outbound message is made.
+ */
class OutboundNotification implements IOutboundMessageNotification
{
@@ -279,6 +322,9 @@
}
}
+ /**
+ * Functions as a caller id to notify when call is received on the modem
+ */
class CallNotification implements ICallNotification
{
@@ -289,6 +335,9 @@
}
}
+ /**
+ * Callback to manage the messages that are queued for sending. Any failed outgoing messages are stored in the queue
+ */
class QueueSendingNotification implements IQueueSendingNotification
{
@@ -318,15 +367,41 @@
/*------------------------------------------------------------------
* Helper Methods
------------------------------------------------------------------*/
+ /**
+ * The Thread that polls the modem to check for all messages on the SIM
+ * NOTE: THE POLLING TIME, SIM MEMORY LOCATION ARE SET THROUGH CONFIGURATION
+ */
+ //<editor-fold defaultstate="collapsed" desc="InboundPollingTask">
+ class InboundPollingTask extends TimerTask
+ {
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ if ( isServiceRunning() )
+ {
+ Logger.getInstance().logDebug( "InboundPollingTask() run.", null, null );
+ readMessages();
+ }
+ } catch ( Exception e )
+ {
+ Logger.getInstance().logDebug( "Error in InboundPollingTask()", e, null );
+ }
+ }
+ }
+ //</editor-fold>
+
public Properties getProperties()
{
return props;
}
+ /**
+ * Read the messages from the memory location and save it in the sms_inbound
+ */
//<editor-fold defaultstate="collapsed" desc="readMessages()">
- /**
- * Read the messages from the memory location and save it in the sms_inbound
- */
void readMessages()
{
List<InboundMessage> msgList = new ArrayList<InboundMessage>();
@@ -336,39 +411,76 @@
Service.getInstance().readMessages( msgList, InboundMessage.MessageClasses.ALL );
if ( msgList.size() > 0 )
{
- for ( InboundMessage msg : msgList )
+ for ( InboundMessage inMsg : msgList )
{
- //Creating sms to store in database
- SmsInbound sms = new SmsInbound();
-
- //Set sms encoding
- if(msg.getEncoding() == MessageEncodings.ENC7BIT)
- sms.setEncoding( '7' );
- else if(msg.getEncoding() == MessageEncodings.ENC8BIT)
- sms.setEncoding( '8' );
- else if(msg.getEncoding() == MessageEncodings.ENCUCS2)
- sms.setEncoding( 'U' );
-
- sms.setGatewayId( msg.getGatewayId());
- sms.setMessageDate( msg.getDate() );
- sms.setOriginalReceiveDate( msg.getDate() );
- sms.setOriginalRefNo( String.valueOf( msg.getMpRefNo() ) );
- sms.setOriginator( msg.getOriginator() );
- sms.setProcess( 0 );
- sms.setReceiveDate( msg.getDate());
- sms.setText( msg.getText() );
- sms.setType( 'I' );
-
- //saving sms into database
- hibernateSmsInboundStore.saveSms( sms );
-
- //Delete message based on configuration
- if ( getProperties().getProperty( "settings.delete_after_processing", "no" ).equalsIgnoreCase( "yes" ) )
- {
- Service.getInstance().deleteMessage( msg );
+ try
+ {
+ InboundBinaryMessage msg = (InboundBinaryMessage) inMsg;
+ //Creating sms to store in database
+ SmsInbound sms = new SmsInbound();
+
+ //Set sms encoding
+ if ( msg.getEncoding() == MessageEncodings.ENC7BIT )
+ {
+ sms.setEncoding( '7' );
+ } else
+ {
+ if ( msg.getEncoding() == MessageEncodings.ENC8BIT )
+ {
+ sms.setEncoding( '8' );
+ } else
+ {
+ if ( msg.getEncoding() == MessageEncodings.ENCUCS2 )
+ {
+ sms.setEncoding( 'U' );
+ }
+ }
+ }
+
+ sms.setGatewayId( msg.getGatewayId() );
+ sms.setMessageDate( new Date() );
+ sms.setOriginalReceiveDate( msg.getDate() );
+ sms.setOriginalRefNo( String.valueOf( msg.getMpRefNo() ) );
+ sms.setOriginator( msg.getOriginator() );
+ sms.setProcess( 0 );
+ sms.setReceiveDate( msg.getDate() );
+ sms.setText( new String( Compressor.decompress( msg.getDataBytes() ), "UTF-8" ) );
+ if ( msg.getType() == MessageTypes.INBOUND )
+ {
+ sms.setType( 'I' );
+ } else
+ {
+ if ( msg.getType() == MessageTypes.OUTBOUND )
+ {
+ sms.setType( 'O' );
+ } else
+ {
+ if ( msg.getType() == MessageTypes.STATUSREPORT )
+ {
+ sms.setType( 'S' );
+ } else
+ {
+ sms.setType( 'U' );
+ }
+ }
+ }
+
+ //saving sms into database
+ smsInboundStoreService.saveSms( sms );
+ Logger.getInstance().logDebug( "Saved Sms from " + msg.getOriginator(), null, null );
+
+ //Delete message based on configuration
+ if ( getProperties().getProperty( "settings.delete_after_processing", "no" ).equalsIgnoreCase( "yes" ) )
+ {
+ Service.getInstance().deleteMessage( msg );
+ }
+ } catch ( ClassCastException ccex )
+ {
+ Logger.getInstance().logInfo( "Ignoring incorrect formatted message", ccex, null );
}
}
}
+ Logger.getInstance().logInfo( "Total messages read at " + Calendar.getInstance().getTime() + " = " + msgList.size(), null, null );
} catch ( Exception e )
{
Logger.getInstance().logError( "SMSServer: reading messages exception!", e, null );
@@ -376,92 +488,6 @@
}
//</editor-fold>
- /*void sendMessages()
- {
- boolean foundOutboundGateway = false;
- for ( org.smslib.AGateway gtw : Service.getInstance().getGateways() )
- {
- if ( gtw.isOutbound() )
- {
- foundOutboundGateway = true;
- break;
- }
- }
- if ( foundOutboundGateway )
- {
- List<OutboundMessage> msgList = new ArrayList<OutboundMessage>();
- try
- {
- for ( Interface<? extends Object> inf : getInfList() )
- {
- if ( inf.isOutbound() )
- {
- msgList.addAll( inf.getMessagesToSend() );
- }
- }
- } catch ( Exception e )
- {
- Logger.getInstance().logError( "SMSServer: sending messages exception!", e, null );
- }
- if ( getProperties().getProperty( "settings.send_mode", "sync" ).equalsIgnoreCase( ( "sync" ) ) )
- {
- Logger.getInstance().logInfo( "SMSServer: sending synchronously...", null, null );
- for ( OutboundMessage msg : msgList )
- {
- try
- {
- Service.getInstance().sendMessage( msg );
- for ( Interface<? extends Object> inf : getInfList() )
- {
- if ( inf.isOutbound() )
- {
- inf.markMessage( msg );
- }
- }
- } catch ( Exception e )
- {
- Logger.getInstance().logError( "SMSServer: sending messages exception!", e, null );
- try
- {
- for ( Interface<? extends Object> inf : getInfList() )
- {
- if ( inf.isOutbound() )
- {
- inf.markMessage( msg );
- }
- }
- } catch ( Exception e1 )
- {
- Logger.getInstance().logError( "SMSServer: sending messages exception!", e1, null );
- }
- }
- }
- } else
- {
- Logger.getInstance().logInfo( "SMSServer: sending asynchronously... [" + msgList.size() + "]", null, null );
- for ( OutboundMessage msg : msgList )
- {
- if ( !Service.getInstance().queueMessage( msg ) )
- {
- try
- {
- for ( Interface<? extends Object> inf : getInfList() )
- {
- if ( inf.isOutbound() )
- {
- inf.markMessage( msg );
- }
- }
- } catch ( Exception e )
- {
- Logger.getInstance().logError( "SMSServer: sending messages exception!", e, null );
- }
- }
- }
- }
- }
- }*/
-
/**
* Loads the configuration settings from SMSServer.conf, which should be located in the DHIS2_HOME directory
* @return The message to be displayed on UI after loading of configuration from file is complete
@@ -474,9 +500,11 @@
if ( new File( configFile ).exists() )
{
+ Collection<AGateway> existingGateways = new ArrayList<AGateway>();
+ existingGateways.addAll( Service.getInstance().getGateways() );
+
//Remove all existing gateways
- Collection<AGateway> gateways = Service.getInstance().getGateways();
- for ( AGateway gateway : gateways )
+ for ( AGateway gateway : existingGateways )
{
Service.getInstance().removeGateway( gateway );
}
@@ -536,7 +564,6 @@
{
gateway.setSimPin( pin );
}
-
if ( inbound.equalsIgnoreCase( "yes" ) )
{
gateway.setInbound( true );
@@ -551,10 +578,11 @@
{
gateway.setOutbound( false );
}
- Logger.getInstance().logInfo( "SMSServer: added gateway " + i + " / ", null, null );
+ Service.getInstance().addGateway( gateway );
+ Logger.getInstance().logInfo( "Load Configuration: added gateway " + i + " / ", null, null );
} catch ( Exception e )
{
- Logger.getInstance().logError( "SMSServer: Unknown Gateway in configuration file!, " + e.getMessage(), null, null );
+ Logger.getInstance().logError( "Load Configuration: Unknown Gateway in configuration file!, " + e.getMessage(), null, null );
}
}
//</editor-fold>
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsFormat.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsFormat.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsFormat.java 2011-04-05 01:04:43 +0000
@@ -0,0 +1,109 @@
+package org.hisp.dhis.mobile.sms.api;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/**
+ *
+ * @author Saptarshi
+ */
+public class SmsFormat
+{
+
+ String version;
+
+ String formId;
+
+ String periodTypeId;
+
+ String periodText;
+
+ String[] dataValues;
+
+ public SmsFormat( SmsInbound sms )
+ {
+ String info = sms.getText();
+ String[] text = info.split( "#" );
+ version = text[0];
+ text = text[1].split( "\\*" );
+ formId = text[0];
+ text = text[1].split( "\\?" );
+ periodTypeId = text[0];
+ text = text[1].split( "\\$" );
+ periodText = text[0];
+ dataValues = text[1].split( "\\|", 1000 );
+ }
+
+ public String[] getDataValues()
+ {
+ return dataValues;
+ }
+
+ public void setDataValues( String[] dataValues )
+ {
+ this.dataValues = dataValues;
+ }
+
+ public String getFormId()
+ {
+ return formId;
+ }
+
+ public void setFormId( String formId )
+ {
+ this.formId = formId;
+ }
+
+ public String getPeriodText()
+ {
+ return periodText;
+ }
+
+ public void setPeriodText( String periodText )
+ {
+ this.periodText = periodText;
+ }
+
+ public String getPeriodTypeId()
+ {
+ return periodTypeId;
+ }
+
+ public void setPeriodTypeId( String periodTypeId )
+ {
+ this.periodTypeId = periodTypeId;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsImportService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsImportService.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsImportService.java 2011-04-05 01:04:43 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.mobile.sms.api;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ *
+ * @author Saptarshi
+ */
+public interface SmsImportService
+{
+ int saveDataValues();
+}
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStore.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStore.java 2011-03-28 16:36:44 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStore.java 2011-04-05 01:04:43 +0000
@@ -31,7 +31,7 @@
import java.util.Date;
/**
- * The API for CRUD into the sms_incoming table
+ * The API for CRUD into the sms_inbound table
* @author Saptarshi
*/
public interface SmsInboundStore
@@ -41,13 +41,7 @@
void saveSms( SmsInbound sms );
- Collection<SmsInbound> getSmsByDate( Date startDate, Date endDate);
-
- Collection<SmsInbound> getSmsByOriginator (String originator);
-
- Collection<SmsInbound> getSmsByProcess (int process);
-
- Collection<SmsInbound> getAllReceiveSMS();
+ Collection<SmsInbound> getSms( String originator, Integer process, Date startDate, Date endDate);
void updateSms (SmsInbound sms);
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStoreService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStoreService.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStoreService.java 2011-04-05 01:04:43 +0000
@@ -0,0 +1,55 @@
+package org.hisp.dhis.mobile.sms.api;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ *
+ * @author Saptarshi
+ */
+public interface SmsInboundStoreService
+{
+
+ String ID = SmsInboundStoreService.class.getName();
+
+ void saveSms( SmsInbound sms );
+
+ Collection<SmsInbound> getSmsByDate( Date startDate, Date endDate );
+
+ Collection<SmsInbound> getSmsByOriginator( String originator );
+
+ Collection<SmsInbound> getSmsByProcess( int process );
+
+ Collection<SmsInbound> getAllReceivedSms();
+
+ void updateSms( SmsInbound sms );
+
+ long getSmsCount();
+}
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml 2011-03-28 16:36:44 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml 2011-04-05 01:04:43 +0000
@@ -10,6 +10,28 @@
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
+ <bean id="org.hisp.dhis.mobile.sms.api.SmsInboundStoreService"
+ class="org.hisp.dhis.mobile.sms.DefaultSmsInboundStoreService">
+ <property name="smsInboundStore" ref="org.hisp.dhis.mobile.sms.api.SmsInboundStore"/>
+ </bean>
+
+ <bean id="org.hisp.dhis.mobile.sms.SmsService"
+ class="org.hisp.dhis.mobile.sms.SmsService">
+ <property name="smsInboundStoreService" ref="org.hisp.dhis.mobile.sms.api.SmsInboundStoreService"/>
+ </bean>
+
+ <bean id="org.hisp.dhis.mobile.sms.api.SmsImportService"
+ class="org.hisp.dhis.mobile.sms.DefaultSmsImportService"
+ scope="prototype">
+ <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService"/>
+ <property name="dataElementCategoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
+ <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService"/>
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService"/>
+ <property name="userStore" ref="org.hisp.dhis.user.UserStore"/>
+ <property name="smsInboundStoreService" ref="org.hisp.dhis.mobile.sms.api.SmsInboundStoreService" />
+ </bean>
+
+
<!-- ========================================================================================== -->
<!-- Service definitions -->
<bean id="org.hisp.dhis.mobile.SmsService"
=== added file 'dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/DefaultSmsInboundStoreServiceTest.java'
--- dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/DefaultSmsInboundStoreServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/DefaultSmsInboundStoreServiceTest.java 2011-04-05 01:04:43 +0000
@@ -0,0 +1,140 @@
+package org.hisp.dhis.mobile.sms;
+
+
+import org.hisp.dhis.mobile.sms.api.SmsInboundStoreService;
+import java.util.Calendar;
+import org.hisp.dhis.DhisSpringTest;
+import java.util.Collection;
+import java.util.Date;
+import org.hisp.dhis.mobile.sms.api.SmsInbound;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author Saptarshi
+ */
+public class DefaultSmsInboundStoreServiceTest extends DhisSpringTest
+{
+
+ private SmsInboundStoreService smsInboundStoreService;
+
+ private SmsInbound testSms;
+
+ // -------------------------------------------------------------------------
+ // Fixture
+ // -------------------------------------------------------------------------
+ @Override
+ public void setUpTest()
+ throws Exception
+ {
+ smsInboundStoreService = (SmsInboundStoreService) getBean( HibernateSmsInboundStore.ID );
+ testSms = new SmsInbound();
+ testSms.setEncoding( 'U' );
+ testSms.setGatewayId( "modem1" );
+ testSms.setMessageDate( new Date() );
+ testSms.setOriginalReceiveDate( new Date() );
+ testSms.setOriginalRefNo( "1" );
+ testSms.setProcess( 0 );
+ testSms.setReceiveDate( new Date() );
+ testSms.setText( "I AM A DISCO DANCER" );
+ testSms.setType( 'I' );
+ testSms.setOriginator( "+919867192752" );
+ }
+
+ /**
+ * Test of saveSms method, of class HibernateSmsInboundStore.
+ */
+ @Test
+ public void testSaveSms()
+ {
+ System.out.println( "testSaveSms" );
+ smsInboundStoreService.saveSms( testSms );
+
+ for ( SmsInbound savedSms : smsInboundStoreService.getAllReceivedSms() )
+ {
+ assertEquals( testSms, savedSms );
+ }
+ }
+
+ /**
+ * Test of getSmsByDate method, of class HibernateSmsInboundStore.
+ */
+ @Test
+ public void testGetSmsByDate() throws Exception
+ {
+ System.out.println( "testSaveSms" );
+ Calendar today = Calendar.getInstance();
+ Calendar prevDay = ( (Calendar) today.clone() );
+ prevDay.add( Calendar.DAY_OF_YEAR, -1 );
+ Calendar nextDay = ( (Calendar) today.clone() );
+ nextDay.add( Calendar.DAY_OF_YEAR, 1 );
+ System.out.println( "testGetSmsByDate" );
+ Date startDate = prevDay.getTime();
+ Date endDate = nextDay.getTime();
+ smsInboundStoreService.saveSms( testSms );
+ Collection<SmsInbound> smsByDate = smsInboundStoreService.getSmsByDate( startDate, endDate );
+ for ( SmsInbound sms : smsByDate )
+ {
+ assertEquals( sms, testSms );
+ }
+ }
+
+ /**
+ * Test of getSmsByRecipient method, of class HibernateSmsInboundStore.
+ */
+ @Test
+ public void testGetSmsByRecipient()
+ {
+ System.out.println( "testGetSmsByRecipient" );
+ String originator = "+919867192752";
+ smsInboundStoreService.saveSms( testSms );
+ Collection<SmsInbound> result = smsInboundStoreService.getSmsByOriginator( originator );
+ for ( SmsInbound sms : result )
+ {
+ assertEquals( sms, testSms );
+ }
+ }
+
+ /**
+ * Test of getSmsByProcess method, of class HibernateSmsInboundStore.
+ */
+ @Test
+ public void testGetSmsByProcess()
+ {
+ System.out.println( "testGetSmsByProcess" );
+ smsInboundStoreService.saveSms( testSms );
+ Collection<SmsInbound> result = smsInboundStoreService.getSmsByProcess( 0 );
+ for ( SmsInbound sms : result )
+ {
+ assertEquals( sms, testSms );
+ }
+ }
+
+ /**
+ * Test of getAllReceiveSMS method, of class HibernateSmsInboundStore.
+ */
+ public void testGetAllReceiveSMS()
+ {
+ // TODO review the generated test code and remove the default call to fail.
+ fail( "The test case is a prototype." );
+ }
+
+ /**
+ * Test of updateSms method, of class HibernateSmsInboundStore.
+ */
+ public void testUpdateSms()
+ {
+ // TODO review the generated test code and remove the default call to fail.
+ fail( "The test case is a prototype." );
+ }
+
+ /**
+ * Test of getSmsCount method, of class HibernateSmsInboundStore.
+ */
+ public void testGetSmsCount()
+ {
+ // TODO review the generated test code and remove the default call to fail.
+ fail( "The test case is a prototype." );
+ }
+}
=== removed file 'dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStoreTest.java'
--- dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStoreTest.java 2011-03-28 16:36:44 +0000
+++ dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStoreTest.java 1970-01-01 00:00:00 +0000
@@ -1,139 +0,0 @@
-package org.hisp.dhis.mobile.sms;
-
-
-import java.util.Calendar;
-import org.hisp.dhis.DhisSpringTest;
-import java.util.Collection;
-import java.util.Date;
-import org.hisp.dhis.mobile.sms.api.SmsInbound;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-/**
- *
- * @author Saptarshi
- */
-public class HibernateSmsInboundStoreTest extends DhisSpringTest
-{
-
- private HibernateSmsInboundStore hibernateSmsInboundStore;
-
- private SmsInbound testSms;
-
- // -------------------------------------------------------------------------
- // Fixture
- // -------------------------------------------------------------------------
- @Override
- public void setUpTest()
- throws Exception
- {
- hibernateSmsInboundStore = (HibernateSmsInboundStore) getBean( HibernateSmsInboundStore.ID );
- testSms = new SmsInbound();
- testSms.setEncoding( 'U' );
- testSms.setGatewayId( "modem1" );
- testSms.setMessageDate( new Date() );
- testSms.setOriginalReceiveDate( new Date() );
- testSms.setOriginalRefNo( "1" );
- testSms.setProcess( 0 );
- testSms.setReceiveDate( new Date() );
- testSms.setText( "I AM A DISCO DANCER" );
- testSms.setType( 'I' );
- testSms.setOriginator( "+919867192752" );
- }
-
- /**
- * Test of saveSms method, of class HibernateSmsInboundStore.
- */
- @Test
- public void testSaveSms()
- {
- System.out.println( "testSaveSms" );
- hibernateSmsInboundStore.saveSms( testSms );
-
- for ( SmsInbound savedSms : hibernateSmsInboundStore.getAllReceiveSMS() )
- {
- assertEquals( testSms, savedSms );
- }
- }
-
- /**
- * Test of getSmsByDate method, of class HibernateSmsInboundStore.
- */
- @Test
- public void testGetSmsByDate() throws Exception
- {
- System.out.println( "testSaveSms" );
- Calendar today = Calendar.getInstance();
- Calendar prevDay = ( (Calendar) today.clone() );
- prevDay.add( Calendar.DAY_OF_YEAR, -1 );
- Calendar nextDay = ( (Calendar) today.clone() );
- nextDay.add( Calendar.DAY_OF_YEAR, 1 );
- System.out.println( "testGetSmsByDate" );
- Date startDate = prevDay.getTime();
- Date endDate = nextDay.getTime();
- hibernateSmsInboundStore.saveSms( testSms );
- Collection<SmsInbound> smsByDate = hibernateSmsInboundStore.getSmsByDate( startDate, endDate );
- for ( SmsInbound sms : smsByDate )
- {
- assertEquals( sms, testSms );
- }
- }
-
- /**
- * Test of getSmsByRecipient method, of class HibernateSmsInboundStore.
- */
- @Test
- public void testGetSmsByRecipient()
- {
- System.out.println( "testGetSmsByRecipient" );
- String originator = "+919867192752";
- hibernateSmsInboundStore.saveSms( testSms );
- Collection<SmsInbound> result = hibernateSmsInboundStore.getSmsByOriginator( originator );
- for ( SmsInbound sms : result )
- {
- assertEquals( sms, testSms );
- }
- }
-
- /**
- * Test of getSmsByProcess method, of class HibernateSmsInboundStore.
- */
- @Test
- public void testGetSmsByProcess()
- {
- System.out.println( "testGetSmsByProcess" );
- hibernateSmsInboundStore.saveSms( testSms );
- Collection<SmsInbound> result = hibernateSmsInboundStore.getSmsByProcess( 0 );
- for ( SmsInbound sms : result )
- {
- assertEquals( sms, testSms );
- }
- }
-
- /**
- * Test of getAllReceiveSMS method, of class HibernateSmsInboundStore.
- */
- public void testGetAllReceiveSMS()
- {
- // TODO review the generated test code and remove the default call to fail.
- fail( "The test case is a prototype." );
- }
-
- /**
- * Test of updateSms method, of class HibernateSmsInboundStore.
- */
- public void testUpdateSms()
- {
- // TODO review the generated test code and remove the default call to fail.
- fail( "The test case is a prototype." );
- }
-
- /**
- * Test of getSmsCount method, of class HibernateSmsInboundStore.
- */
- public void testGetSmsCount()
- {
- // TODO review the generated test code and remove the default call to fail.
- fail( "The test case is a prototype." );
- }
-}
=== added file 'dhis-mobile/dhis-web-mobile/log4j.properties'
--- dhis-mobile/dhis-web-mobile/log4j.properties 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-web-mobile/log4j.properties 2011-04-05 01:04:43 +0000
@@ -0,0 +1,29 @@
+
+# Configuration file for log4j
+
+# Log to file setup
+log4j.appender.file = org.apache.log4j.RollingFileAppender
+log4j.appender.file.File = dhis.log
+log4j.appender.file.MaxFileSize = 100KB
+log4j.appender.file.MaxBackupIndex = 3
+log4j.appender.file.layout = org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern = * %-5p %d{ABSOLUTE} %m (%F [%t])%n
+
+# Log to console setup
+log4j.appender.console = org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout = org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern = * %-5p %d{ABSOLUTE} %m (%F [%t])%n
+
+#Audit log level
+log4j.appender.AUDIT=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.AUDIT.File= audit.log
+log4j.appender.AUDIT.DatePattern='.'yyyy-MM-dd
+log4j.appender.AUDIT.threshold=AUDIT_TRAIL#org.hisp.dhis.system.util.AuditLogLevel
+log4j.appender.AUDIT.layout=org.apache.log4j.PatternLayout
+log4j.appender.AUDIT.layout.ConversionPattern= * %-5p %d{ABSOLUTE} %m %n
+
+# Categories (order: DEBUG, INFO, WARN, ERROR, FATAL)
+log4j.rootCategory = WARN, console
+log4j.category.org.hisp.dhis = INFO, AUDIT
+log4j.category.org.amplecode = INFO
+log4j.category.smslib = INFO
\ No newline at end of file
=== modified file 'dhis-mobile/dhis-web-mobile/pom.xml'
--- dhis-mobile/dhis-web-mobile/pom.xml 2011-03-02 03:38:25 +0000
+++ dhis-mobile/dhis-web-mobile/pom.xml 2011-04-05 01:04:43 +0000
@@ -43,7 +43,6 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- <version>1.3.2</version>
</dependency>
</dependencies>
=== modified file 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/ReceiveImportPageAction.java'
--- dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/ReceiveImportPageAction.java 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/ReceiveImportPageAction.java 2011-04-05 01:04:43 +0000
@@ -29,12 +29,10 @@
import com.opensymphony.xwork2.Action;
import java.io.File;
-import java.io.FilenameFilter;
import java.util.List;
import org.apache.commons.io.FileUtils;
-import org.hisp.dhis.mobile.SmsService;
-import org.hisp.dhis.mobile.XMLFilter;
-import org.hisp.dhis.mobile.api.MobileImportService;
+import org.hisp.dhis.mobile.sms.SmsService;
+import org.hisp.dhis.mobile.sms.api.SmsImportService;
public class ReceiveImportPageAction implements Action
{
@@ -49,11 +47,11 @@
this.smsService = smsService;
}
- private MobileImportService mobileImportService;
+ private SmsImportService smsImportService;
- public void setMobileImportService( MobileImportService mobileImportService )
+ public void setSmsImportService( SmsImportService smsImportService )
{
- this.mobileImportService = mobileImportService;
+ this.smsImportService = smsImportService;
}
// -------------------------------------------------------------------------
@@ -70,8 +68,10 @@
public boolean getSmsServiceStatus()
{
- smsServiceStatus = smsService.getServiceStatus();
- return smsServiceStatus;
+ if(smsService.isServiceRunning())
+ return true;
+ else
+ return false;
}
String statAction;
@@ -80,10 +80,10 @@
{
if ( statAction.equalsIgnoreCase( "Start" ) )
{
- this.result = smsService.startService();
+ this.result = smsService.startSmsService();
} else
{
- this.result = smsService.stopService();
+ this.result = smsService.stopSmsService();
}
}
@@ -99,8 +99,6 @@
public List<File> getPending()
{
File pendingFolder = new File( System.getenv( "DHIS2_HOME" ) + File.separator + "mi" + File.separator + "pending" );
-// FilenameFilter filter = new XMLFilter();
-
pending = (List<File>) FileUtils.listFiles( pendingFolder, new String[]
{
"xml"
@@ -134,8 +132,7 @@
public void startImportingMessages()
{
- //mobileImportService.importAllFiles();
- mobileImportService.importPendingFiles();
+ smsImportService.saveDataValues();
}
@Override
=== modified file 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.java'
--- dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.java 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.java 2011-04-05 01:04:43 +0000
@@ -28,7 +28,7 @@
*/
import com.opensymphony.xwork2.Action;
-import org.hisp.dhis.mobile.SmsService;
+import org.hisp.dhis.mobile.sms.SmsService;
public class SendSMSAction implements Action
{
@@ -50,8 +50,7 @@
public boolean getSmsServiceStatus()
{
- smsServiceStatus = smsService.getServiceStatus();
- return smsServiceStatus;
+ return smsService.isServiceRunning();
}
String statAction;
@@ -60,10 +59,10 @@
{
if ( statAction.equalsIgnoreCase( "Start" ) )
{
- this.message = smsService.startService();
+ this.message = smsService.startSmsService();
} else
{
- this.message = smsService.stopService();
+ this.message = smsService.stopSmsService();
}
}
=== removed directory 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app'
=== removed directory 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action'
=== removed file 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/CreateMobileAppAction.java'
--- dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/CreateMobileAppAction.java 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/CreateMobileAppAction.java 1970-01-01 00:00:00 +0000
@@ -1,175 +0,0 @@
-package org.hisp.dhis.mobile.app.action;
-
-/*
- * Copyright (c) 2004-2007, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-import com.opensymphony.xwork2.Action;
-import java.io.File;
-import java.util.Collection;
-import org.apache.struts2.ServletActionContext;
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.period.PeriodService;
-
-public class CreateMobileAppAction implements Action {
-
- private String mvnPath;
- private String mvnStatus;
- private String[] splashImg;
- private String[] availableDatasets;
- private String mobileAppFilename;
-
- public String getMobileAppFilename() {
- String webappPath = ServletActionContext.getServletContext().getRealPath("/");
- String appPath = webappPath + "/dhis-web-mobile/javame_src/target";
- File appFile = new File(appPath, "dhis-javame-1.0.0-me.jar");
- if (appFile.exists()) {
- mobileAppFilename = appFile.getName();
- }
- return mobileAppFilename;
- }
-
- public String[] getSplashImg() {
- String webappPath = ServletActionContext.getServletContext().getRealPath("/");
- String imgPath = webappPath + "/dhis-web-mobile/javame_src/src/main/resources/splash";
- File imgFolder = new File(imgPath);
- File[] images;
- if (imgFolder.exists()) {
- if (imgFolder.isDirectory()) {
- images = imgFolder.listFiles();
- String[] imageNames = new String[images.length];
- for (int i = 0; i < images.length; i++) {
- if (images[i].getName().contains(".png")) {
- imageNames[i] = images[i].getName();
- }
- }
- splashImg = imageNames;
- }
- }
- return splashImg;
- }
-
- public String getMvnPath() {
- String PATH = System.getenv("PATH");
- String[] locations;
- if (getOSName().equals("win")) {
- locations = PATH.split(";");
- } else {
- locations = PATH.split(":");
- }
- for (String location : locations) {
- File folder = new File(location);
- String filePath = scanPath(getOSName(), folder);
- if (!filePath.equals("")) {
- mvnPath = filePath;
- break;
- }
- }
- return mvnPath;
- }
-
- public void setMvnPath(String path) {
- File mvnFolder = new File(path);
- String filePath = scanPath(getOSName(), mvnFolder);
- if (!filePath.equals("")) {
- this.mvnPath = filePath;
- } else {
- mvnStatus = "Could not find mvn.bat at the location you entered";
- }
- }
-
- public String getMvnStatus() {
- return mvnStatus;
- }
-
- public void setMvnStatus(String status) {
- this.mvnStatus = status;
- }
-
- private String getOSName() {
- String osName;
- if (System.getProperty("os.name").toLowerCase().contains("windows")) {
- osName = "win";
- } else {
- osName = "nix";
- }
- return osName;
- }
-
- private String scanPath(String osName, File folder) {
- String filePath = new String();
- if (folder.exists()) {
- if (folder.isDirectory()) {
- File[] files = folder.listFiles();
- for (File file : files) {
- if (osName.equals("win")) {
- if (file.getName().equals("mvn.bat")) {
- filePath = file.getAbsolutePath();
- break;
- }
- } else {
- if (osName.equals("nix")) {
- if (file.getName().equals("mvn")) {
- filePath = file.getAbsolutePath();
- break;
- }
- }
- }
- }
- }
- }
- return filePath;
- }
- private DataSetService dataSetService;
-
- public void setDataSetService(DataSetService dataSetService) {
- this.dataSetService = dataSetService;
- }
- private PeriodService periodService;
-
- public void setPeriodService(PeriodService periodService) {
- this.periodService = periodService;
- }
-
- public String[] getAvailableDatasets() {
- int i = 0;
- Collection<DataSet> allDataSets = dataSetService.getAllDataSets();
- availableDatasets = new String[allDataSets.size()];
- for (DataSet dataSet : allDataSets) {
- availableDatasets[i] = dataSet.getName();
- i++;
- }
- return availableDatasets;
- }
-
- @Override
- public String execute()
- throws Exception {
- //SMSService service = new SMSService();
- //service.testSMSService();
- return SUCCESS;
- }
-}
=== removed file 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/GetDataElementsAction.java'
--- dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/GetDataElementsAction.java 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/GetDataElementsAction.java 1970-01-01 00:00:00 +0000
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2004-2007, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.hisp.dhis.mobile.app.action;
-
-
-import com.opensymphony.xwork2.Action;
-import java.util.Collection;
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.DataSetService;
-
-public class GetDataElementsAction implements Action
-{
-
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
- private DataSetService dataSetService;
-
- public void setDataSetService( DataSetService dataSetService )
- {
- this.dataSetService = dataSetService;
- }
-
- // -------------------------------------------------------------------------
- // Input
- // -------------------------------------------------------------------------
- private String dataSetName;
-
- public void setDataSetName( String dataSetName )
- {
- this.dataSetName = dataSetName;
- }
-
- public String getDataSetName(){
- return this.dataSetName;
- }
-
- // -------------------------------------------------------------------------
- // Output
- // -------------------------------------------------------------------------
- private Collection<DataElement> dataElements;
-
- public Collection<DataElement> getDataElements()
- {
- return dataElements;
- }
-
- // -------------------------------------------------------------------------
- // Action implementation
- // -------------------------------------------------------------------------
- @Override
- public String execute()
- throws Exception
- {
- DataSet dataSet = dataSetService.getDataSetByName( dataSetName );
- dataElements = dataSet.getDataElements();
- return SUCCESS;
- }
-}
=== removed file 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/JarGeneratorAction.java'
--- dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/JarGeneratorAction.java 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/JarGeneratorAction.java 1970-01-01 00:00:00 +0000
@@ -1,135 +0,0 @@
-package org.hisp.dhis.mobile.app.action;
-
-/*
- * Copyright (c) 2004-2007, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-import com.opensymphony.xwork2.Action;
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import org.apache.commons.io.FileUtils;
-import org.apache.struts2.ServletActionContext;
-
-public class JarGeneratorAction implements Action {
-
- private String mvnBin;
- private String splash;
- private String selectDataSet;
- private String dataElements;
-
- public void setDataElements(String dataElements) {
- this.dataElements = dataElements;
- }
-
- public void setSelectDataSet(String selectDataSet) {
- this.selectDataSet = selectDataSet;
- }
-
- public String getMvnBin() {
- return mvnBin;
- }
-
- public void setMvnBin(String mvnBin) {
- this.mvnBin = mvnBin;
- }
-
- public String getSplash() {
- return splash;
- }
-
- public void setSplash(String splash) {
- this.splash = splash;
- }
-
- private static String readFileAsString(File file) throws java.io.IOException {
- byte[] buffer = new byte[(int) file.length()];
- BufferedInputStream f = new BufferedInputStream(new FileInputStream(file));
- f.read(buffer);
- f.close();
- return new String(buffer);
- }
-
- public void replaceStringInFile(File dir, String fileName, String match, String replacingString) {
- try {
- File srcFile = new File(dir, fileName);
- File destFile = new File(dir, "temp");
- if (srcFile.exists()) {
- String str = readFileAsString(srcFile);
- str = str.replaceFirst(match, replacingString);
- FileWriter fw = new FileWriter(destFile);
- fw.write(str);
- fw.close();
- }
- FileUtils.copyFile(destFile, srcFile);
- destFile.delete();
- } catch (FileNotFoundException ex) {
- ex.printStackTrace();
- } catch (IOException ex) {
- ex.printStackTrace();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- @Override
- public String execute() throws Exception {
- String webappPath = ServletActionContext.getServletContext().getRealPath("/");
- String javameSrc = webappPath + "/dhis-web-mobile/javame_src/src/main/java/org/hisp/dhis/mobile";
- File dir = new File(javameSrc);
-
- //For splash screen
- replaceStringInFile(dir, "DHISMobile.java", "\\w*.png", splash);
-
- //For dataset
- replaceStringInFile(dir, "FormsListPage.java", "formNames\\[].*;", "formNames[] = {\"" + selectDataSet + "\"};");
-
- //For dataElements
- replaceStringInFile(dir, "DHISMobile.java", "dataElements =.*\\},\\{", "dataElements = {{" + dataElements + "},{");
-
- //For language
- //replaceStringInFile(dir, "DHISMobile.java", "", language);
-
- //For patient-program stage
- //replaceStringInFile(dir, "DHISMobile.java", "", patient_program);
-
- ProcessBuilder pb = new ProcessBuilder(mvnBin, "install", "-f", ServletActionContext.getServletContext().getRealPath("/") + "/dhis-web-mobile/javame_src/pom.xml");
- pb.redirectErrorStream(true);
- Process p = pb.start();
- InputStream is = p.getInputStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
- String str;
- while ((str = br.readLine()) != null) {
- System.out.println(str);
- }
- return SUCCESS;
- }
-}
=== removed file 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/SplashUploadAction.java'
--- dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/SplashUploadAction.java 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/app/action/SplashUploadAction.java 1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
-package org.hisp.dhis.mobile.app.action;
-
-/*
- * Copyright (c) 2004-2007, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-import com.opensymphony.xwork2.ActionSupport;
-import java.io.File;
-import java.io.IOException;
-import org.apache.commons.io.FileUtils;
-import org.apache.struts2.ServletActionContext;
-
-public class SplashUploadAction extends ActionSupport {
-
- private File file;
- private String contentType;
- private String filename;
- private String[] splashImg;
-
- public String[] getSplashImg() {
- String webappPath = ServletActionContext.getServletContext().getRealPath("/");
- String imgPath = webappPath + "/dhis-web-mobile/javame_src/src/main/resources/splash";
- File imgFolder = new File(imgPath);
- File[] images;
- if (imgFolder.exists()) {
- if (imgFolder.isDirectory()) {
- images = imgFolder.listFiles();
- String[] imageNames = new String[images.length];
- for (int i = 0; i < images.length; i++) {
- if (images[i].getName().contains(".png")) {
- imageNames[i] = images[i].getName();
- }
- }
- splashImg = imageNames;
- }
- }
- return splashImg;
- }
-
- public void setUpload(File file) {
- this.file = file;
- }
-
- public void setUploadContentType(String contentType) {
- this.contentType = contentType;
- }
-
- public void setUploadFileName(String filename) {
- this.filename = filename;
- }
-
- @Override
- public String execute() {
- try {
- String webappPath = ServletActionContext.getServletContext().getRealPath("/");
- String imgPath = webappPath + "/dhis-web-mobile/javame_src/src/main/resources/splash";
- File imgFolder = new File(imgPath);
- FileUtils.copyFile(file, new File(imgFolder, String.valueOf(imgFolder.listFiles().length + 1) + ".png"));
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- return SUCCESS;
- }
-}
=== modified file 'dhis-mobile/dhis-web-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-mobile/dhis-web-mobile/src/main/resources/META-INF/dhis/beans.xml 2010-12-23 12:27:24 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/resources/META-INF/dhis/beans.xml 2011-04-05 01:04:43 +0000
@@ -11,15 +11,15 @@
<bean id="org.hisp.dhis.mobile.action.ReceiveImportPageAction"
class="org.hisp.dhis.mobile.action.ReceiveImportPageAction"
scope="prototype">
- <property name="smsService" ref="org.hisp.dhis.mobile.SmsService" />
- <property name="mobileImportService" ref="org.hisp.dhis.mobile.api.MobileImportService"/>
+ <property name="smsService" ref="org.hisp.dhis.mobile.sms.SmsService" />
+ <property name="smsImportService" ref="org.hisp.dhis.mobile.sms.api.SmsImportService"/>
</bean>
<!-- Inbox -->
<bean id="org.hisp.dhis.mobile.action.ReceiveMessagesPageAction"
class="org.hisp.dhis.mobile.action.ReceiveMessagesPageAction"
scope="prototype">
- <property name="smsService" ref="org.hisp.dhis.mobile.SmsService" />
+ <property name="smsService" ref="org.hisp.dhis.mobile.sms.SmsService" />
<property name="mobileImportService" ref="org.hisp.dhis.mobile.api.MobileImportService"/>
</bean>
<!-- Draft -->
@@ -56,7 +56,7 @@
<bean id="org.hisp.dhis.mobile.action.SendSMSAction"
class="org.hisp.dhis.mobile.action.SendSMSAction"
scope="prototype">
- <property name="smsService" ref="org.hisp.dhis.mobile.SmsService" />
+ <property name="smsService" ref="org.hisp.dhis.mobile.sms.SmsService" />
</bean>
<bean id="org.hisp.dhis.mobile.action.SendOtaAction"
=== modified file 'dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/log4j.properties'
--- dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/log4j.properties 2011-03-28 16:36:44 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/log4j.properties 2011-04-05 01:04:43 +0000
@@ -1,8 +1,29 @@
-
-# Configuration file for log4j
-
-#Smslib logging
-log4j.logger.smslib=INFO, smslib
-log4j.appender.smslib=org.apache.log4j.ConsoleAppender
-log4j.appender.smslib.layout=org.apache.log4j.PatternLayout
-log4j.appender.smslib.layout.ConversionPattern=%d %-5p::%x- %m%n
+
+# Configuration file for log4j
+
+# Log to file setup
+log4j.appender.file = org.apache.log4j.RollingFileAppender
+log4j.appender.file.File = dhis.log
+log4j.appender.file.MaxFileSize = 100KB
+log4j.appender.file.MaxBackupIndex = 3
+log4j.appender.file.layout = org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern = * %-5p %d{ABSOLUTE} %m (%F [%t])%n
+
+# Log to console setup
+log4j.appender.console = org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout = org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern = * %-5p %d{ABSOLUTE} %m (%F [%t])%n
+
+#Audit log level
+log4j.appender.AUDIT=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.AUDIT.File= audit.log
+log4j.appender.AUDIT.DatePattern='.'yyyy-MM-dd
+log4j.appender.AUDIT.threshold=AUDIT_TRAIL#org.hisp.dhis.system.util.AuditLogLevel
+log4j.appender.AUDIT.layout=org.apache.log4j.PatternLayout
+log4j.appender.AUDIT.layout.ConversionPattern= * %-5p %d{ABSOLUTE} %m %n
+
+# Categories (order: DEBUG, INFO, WARN, ERROR, FATAL)
+log4j.rootCategory = WARN, console
+log4j.category.org.hisp.dhis = INFO, AUDIT
+log4j.category.org.amplecode = INFO
+log4j.category.smslib = INFO
=== removed file 'dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/createMobileApp.js'
--- dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/createMobileApp.js 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/createMobileApp.js 1970-01-01 00:00:00 +0000
@@ -1,77 +0,0 @@
-$(document).ready(function() {
- $("#mvnDiv").hide();
- $("#accordion").accordion({
- collapsible: true
- });
- $("#splashUpdate input:radio:first").attr("checked","checked");
- var splashOptions = {
- url: 'splashUpload.action',
- target: '#splashUpdate',
- success: function(){
- $("#splashUpdate input:radio:first").attr("checked","checked");
- }
- }
- $("#splashForm").ajaxForm(splashOptions);
-
- var dataElementsOptions = {
- url: 'getDataElements.action',
- type: 'POST',
- target: '#dataElementsListDiv'
- /* TODO: Multiple datasets
- success: function(responseXML){
- $("#dataElementsListDiv").append(responseXML);
- }*/
- }
- $("#dataSetForm").ajaxForm(dataElementsOptions);
-});
-
-function showPathField(){
- $("#mvnDiv").toggle(200);
-}
-
-function submitMvnForm(){
- $("#mvnForm").submit();
-}
-
-function submitJarGenerator(){
- var form = document.createElement("form");
- form.style.visibility = "hidden";
- form.setAttribute("method", "post");
- form.setAttribute("action", "jarGenerator.action");
-
- var aField = document.createElement("input");
- aField.setAttribute("type", "radio");
- aField.setAttribute("name", "splash");
- aField.setAttribute("checked", "checked");
- aField.setAttribute("value", $("input[name=splash]:checked").val());
- form.appendChild(aField);
- var bField = document.createElement("input");
- bField.setAttribute("type", "text");
- bField.setAttribute("name", "mvnBin");
- bField.setAttribute("value", $("#mvnBin").attr("value"));
- form.appendChild(bField);
- var cField = document.createElement("input");
- cField.setAttribute("type", "text");
- cField.setAttribute("name", "selectDataSet");
- cField.setAttribute("value", $("select[name=dataSet]").attr('id'));
- form.appendChild(cField);
- var deStr="";
- $("select[name=dataSet] option").each(function(){
- deStr += "\""+$(this).text()+"\",";
- });
- deStr = deStr.substring(0,deStr.length-1)
- var dField = document.createElement("input");
- dField.setAttribute("type", "text");
- dField.setAttribute("name", "dataElements");
- dField.setAttribute("value", deStr);
- form.appendChild(dField);
-
- document.body.appendChild(form);
- form.submit();
-
- $("#genButton").attr('disabled', 'disabled');
-}
-
-function addDataSet(){
- $("#dataSetForm").submit();
-}
\ No newline at end of file
=== removed file 'dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/jquery-form.js'
--- dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/jquery-form.js 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/jquery-form.js 1970-01-01 00:00:00 +0000
@@ -1,714 +0,0 @@
-/*
- * jQuery Form Plugin
- * version: 2.36 (07-NOV-2009)
- * @requires jQuery v1.2.6 or later
- *
- * Examples and documentation at: http://malsup.com/jquery/form/
- * Dual licensed under the MIT and GPL licenses:
- * http://www.opensource.org/licenses/mit-license.php
- * http://www.gnu.org/licenses/gpl.html
- */
-;
-(function($) {
-
- /*
- Usage Note:
- -----------
- Do not use both ajaxSubmit and ajaxForm on the same form. These
- functions are intended to be exclusive. Use ajaxSubmit if you want
- to bind your own submit handler to the form. For example,
-
- $(document).ready(function() {
- $('#myForm').bind('submit', function() {
- $(this).ajaxSubmit({
- target: '#output'
- });
- return false; // <-- important!
- });
- });
-
- Use ajaxForm when you want the plugin to manage all the event binding
- for you. For example,
-
- $(document).ready(function() {
- $('#myForm').ajaxForm({
- target: '#output'
- });
- });
-
- When using ajaxForm, the ajaxSubmit function will be invoked for you
- at the appropriate time.
-*/
-
- /**
- * ajaxSubmit() provides a mechanism for immediately submitting
- * an HTML form using AJAX.
- */
- $.fn.ajaxSubmit = function(options) {
- // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
- if (!this.length) {
- log('ajaxSubmit: skipping submit process - no element selected');
- return this;
- }
-
- if (typeof options == 'function')
- options = {
- success: options
- };
-
- var url = $.trim(this.attr('action'));
- if (url) {
- // clean url (don't include hash vaue)
- url = (url.match(/^([^#]+)/)||[])[1];
- }
- url = url || window.location.href || '';
-
- options = $.extend({
- url: url,
- type: this.attr('method') || 'GET',
- iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
- }, options || {});
-
- // hook for manipulating the form data before it is extracted;
- // convenient for use with rich editors like tinyMCE or FCKEditor
- var veto = {};
- this.trigger('form-pre-serialize', [this, options, veto]);
- if (veto.veto) {
- log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
- return this;
- }
-
- // provide opportunity to alter form data before it is serialized
- if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
- log('ajaxSubmit: submit aborted via beforeSerialize callback');
- return this;
- }
-
- var a = this.formToArray(options.semantic);
- if (options.data) {
- options.extraData = options.data;
- for (var n in options.data) {
- if(options.data[n] instanceof Array) {
- for (var k in options.data[n])
- a.push( {
- name: n,
- value: options.data[n][k]
- } );
- }
- else
- a.push( {
- name: n,
- value: options.data[n]
- } );
- }
- }
-
- // give pre-submit callback an opportunity to abort the submit
- if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
- log('ajaxSubmit: submit aborted via beforeSubmit callback');
- return this;
- }
-
- // fire vetoable 'validate' event
- this.trigger('form-submit-validate', [a, this, options, veto]);
- if (veto.veto) {
- log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
- return this;
- }
-
- var q = $.param(a);
-
- if (options.type.toUpperCase() == 'GET') {
- options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
- options.data = null; // data is null for 'get'
- }
- else
- options.data = q; // data is the query string for 'post'
-
- var $form = this, callbacks = [];
- if (options.resetForm) callbacks.push(function() {
- $form.resetForm();
- });
- if (options.clearForm) callbacks.push(function() {
- $form.clearForm();
- });
-
- // perform a load on the target only if dataType is not provided
- if (!options.dataType && options.target) {
- var oldSuccess = options.success || function(){};
- callbacks.push(function(data) {
- $(options.target).html(data).each(oldSuccess, arguments);
- });
- }
- else if (options.success)
- callbacks.push(options.success);
-
- options.success = function(data, status) {
- for (var i=0, max=callbacks.length; i < max; i++)
- callbacks[i].apply(options, [data, status, $form]);
- };
-
- // are there files to upload?
- var files = $('input:file', this).fieldValue();
- var found = false;
- for (var j=0; j < files.length; j++)
- if (files[j])
- found = true;
-
- var multipart = false;
- // var mp = 'multipart/form-data';
- // multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
-
- // options.iframe allows user to force iframe mode
- // 06-NOV-09: now defaulting to iframe mode if file input is detected
- if ((files.length && options.iframe !== false) || options.iframe || found || multipart) {
- // hack to fix Safari hang (thanks to Tim Molendijk for this)
- // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
- if (options.closeKeepAlive)
- $.get(options.closeKeepAlive, fileUpload);
- else
- fileUpload();
- }
- else
- $.ajax(options);
-
- // fire 'notify' event
- this.trigger('form-submit-notify', [this, options]);
- return this;
-
-
- // private function for handling file uploads (hat tip to YAHOO!)
- function fileUpload() {
- var form = $form[0];
-
- if ($(':input[name=submit]', form).length) {
- alert('Error: Form elements must not be named "submit".');
- return;
- }
-
- var opts = $.extend({}, $.ajaxSettings, options);
- var s = $.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);
-
- var id = 'jqFormIO' + (new Date().getTime());
- var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ opts.iframeSrc +'" />');
- var io = $io[0];
-
- $io.css({
- position: 'absolute',
- top: '-1000px',
- left: '-1000px'
- });
-
- var xhr = { // mock object
- aborted: 0,
- responseText: null,
- responseXML: null,
- status: 0,
- statusText: 'n/a',
- getAllResponseHeaders: function() {},
- getResponseHeader: function() {},
- setRequestHeader: function() {},
- abort: function() {
- this.aborted = 1;
- $io.attr('src', opts.iframeSrc); // abort op in progress
- }
- };
-
- var g = opts.global;
- // trigger ajax global events so that activity/block indicators work like normal
- if (g && ! $.active++) $.event.trigger("ajaxStart");
- if (g) $.event.trigger("ajaxSend", [xhr, opts]);
-
- if (s.beforeSend && s.beforeSend(xhr, s) === false) {
- s.global && $.active--;
- return;
- }
- if (xhr.aborted)
- return;
-
- var cbInvoked = 0;
- var timedOut = 0;
-
- // add submitting element to data if we know it
- var sub = form.clk;
- if (sub) {
- var n = sub.name;
- if (n && !sub.disabled) {
- options.extraData = options.extraData || {};
- options.extraData[n] = sub.value;
- if (sub.type == "image") {
- options.extraData[name+'.x'] = form.clk_x;
- options.extraData[name+'.y'] = form.clk_y;
- }
- }
- }
-
- // take a breath so that pending repaints get some cpu time before the upload starts
- setTimeout(function() {
- // make sure form attrs are set
- var t = $form.attr('target'), a = $form.attr('action');
-
- // update form attrs in IE friendly way
- form.setAttribute('target',id);
- if (form.getAttribute('method') != 'POST')
- form.setAttribute('method', 'POST');
- if (form.getAttribute('action') != opts.url)
- form.setAttribute('action', opts.url);
-
- // ie borks in some cases when setting encoding
- if (! options.skipEncodingOverride) {
- $form.attr({
- encoding: 'multipart/form-data',
- enctype: 'multipart/form-data'
- });
- }
-
- // support timout
- if (opts.timeout)
- setTimeout(function() {
- timedOut = true;
- cb();
- }, opts.timeout);
-
- // add "extra" data to form if provided in options
- var extraInputs = [];
- try {
- if (options.extraData)
- for (var n in options.extraData)
- extraInputs.push(
- $('<input type="hidden" name="'+n+'" value="'+options.extraData[n]+'" />')
- .appendTo(form)[0]);
-
- // add iframe to doc and submit the form
- $io.appendTo('body');
- io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
- form.submit();
- }
- finally {
- // reset attrs and remove "extra" input elements
- form.setAttribute('action',a);
- t ? form.setAttribute('target', t) : $form.removeAttr('target');
- $(extraInputs).remove();
- }
- }, 10);
-
- var domCheckCount = 50;
-
- function cb() {
- if (cbInvoked++) return;
-
- io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
-
- var ok = true;
- try {
- if (timedOut) throw 'timeout';
- // extract the server response from the iframe
- var data, doc;
-
- doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
-
- var isXml = opts.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
- log('isXml='+isXml);
- if (!isXml && (doc.body == null || doc.body.innerHTML == '')) {
- if (--domCheckCount) {
- // in some browsers (Opera) the iframe DOM is not always traversable when
- // the onload callback fires, so we loop a bit to accommodate
- cbInvoked = 0;
- setTimeout(cb, 100);
- return;
- }
- log('Could not access iframe DOM after 50 tries.');
- return;
- }
-
- xhr.responseText = doc.body ? doc.body.innerHTML : null;
- xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
- xhr.getResponseHeader = function(header){
- var headers = {
- 'content-type': opts.dataType
- };
- return headers[header];
- };
-
- if (opts.dataType == 'json' || opts.dataType == 'script') {
- // see if user embedded response in textarea
- var ta = doc.getElementsByTagName('textarea')[0];
- if (ta)
- xhr.responseText = ta.value;
- else {
- // account for browsers injecting pre around json response
- var pre = doc.getElementsByTagName('pre')[0];
- if (pre)
- xhr.responseText = pre.innerHTML;
- }
- }
- else if (opts.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
- xhr.responseXML = toXml(xhr.responseText);
- }
- data = $.httpData(xhr, opts.dataType);
- }
- catch(e){
- ok = false;
- $.handleError(opts, xhr, 'error', e);
- }
-
- // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
- if (ok) {
- opts.success(data, 'success');
- if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
- }
- if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
- if (g && ! --$.active) $.event.trigger("ajaxStop");
- if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');
-
- // clean up
- setTimeout(function() {
- $io.remove();
- xhr.responseXML = null;
- }, 100);
- };
-
- function toXml(s, doc) {
- if (window.ActiveXObject) {
- doc = new ActiveXObject('Microsoft.XMLDOM');
- doc.async = 'false';
- doc.loadXML(s);
- }
- else
- doc = (new DOMParser()).parseFromString(s, 'text/xml');
- return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
- };
- };
- };
-
- /**
- * ajaxForm() provides a mechanism for fully automating form submission.
- *
- * The advantages of using this method instead of ajaxSubmit() are:
- *
- * 1: This method will include coordinates for <input type="image" /> elements (if the element
- * is used to submit the form).
- * 2. This method will include the submit element's name/value data (for the element that was
- * used to submit the form).
- * 3. This method binds the submit() method to the form for you.
- *
- * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
- * passes the options argument along after properly binding events for submit elements and
- * the form itself.
- */
- $.fn.ajaxForm = function(options) {
- return this.ajaxFormUnbind().bind('submit.form-plugin', function() {
- $(this).ajaxSubmit(options);
- return false;
- }).bind('click.form-plugin', function(e) {
- var target = e.target;
- var $el = $(target);
- if (!($el.is(":submit,input:image"))) {
- // is this a child element of the submit el? (ex: a span within a button)
- var t = $el.closest(':submit');
- if (t.length == 0)
- return;
- target = t[0];
- }
- var form = this;
- form.clk = target;
- if (target.type == 'image') {
- if (e.offsetX != undefined) {
- form.clk_x = e.offsetX;
- form.clk_y = e.offsetY;
- } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
- var offset = $el.offset();
- form.clk_x = e.pageX - offset.left;
- form.clk_y = e.pageY - offset.top;
- } else {
- form.clk_x = e.pageX - target.offsetLeft;
- form.clk_y = e.pageY - target.offsetTop;
- }
- }
- // clear form vars
- setTimeout(function() {
- form.clk = form.clk_x = form.clk_y = null;
- }, 100);
- });
- };
-
- // ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
- $.fn.ajaxFormUnbind = function() {
- return this.unbind('submit.form-plugin click.form-plugin');
- };
-
- /**
- * formToArray() gathers form element data into an array of objects that can
- * be passed to any of the following ajax functions: $.get, $.post, or load.
- * Each object in the array has both a 'name' and 'value' property. An example of
- * an array for a simple login form might be:
- *
- * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
- *
- * It is this array that is passed to pre-submit callback functions provided to the
- * ajaxSubmit() and ajaxForm() methods.
- */
- $.fn.formToArray = function(semantic) {
- var a = [];
- if (this.length == 0) return a;
-
- var form = this[0];
- var els = semantic ? form.getElementsByTagName('*') : form.elements;
- if (!els) return a;
- for(var i=0, max=els.length; i < max; i++) {
- var el = els[i];
- var n = el.name;
- if (!n) continue;
-
- if (semantic && form.clk && el.type == "image") {
- // handle image inputs on the fly when semantic == true
- if(!el.disabled && form.clk == el) {
- a.push({
- name: n,
- value: $(el).val()
- });
- a.push({
- name: n+'.x',
- value: form.clk_x
- }, {
- name: n+'.y',
- value: form.clk_y
- });
- }
- continue;
- }
-
- var v = $.fieldValue(el, true);
- if (v && v.constructor == Array) {
- for(var j=0, jmax=v.length; j < jmax; j++)
- a.push({
- name: n,
- value: v[j]
- });
- }
- else if (v !== null && typeof v != 'undefined')
- a.push({
- name: n,
- value: v
- });
- }
-
- if (!semantic && form.clk) {
- // input type=='image' are not found in elements array! handle it here
- var $input = $(form.clk), input = $input[0], n = input.name;
- if (n && !input.disabled && input.type == 'image') {
- a.push({
- name: n,
- value: $input.val()
- });
- a.push({
- name: n+'.x',
- value: form.clk_x
- }, {
- name: n+'.y',
- value: form.clk_y
- });
- }
- }
- return a;
- };
-
- /**
- * Serializes form data into a 'submittable' string. This method will return a string
- * in the format: name1=value1&name2=value2
- */
- $.fn.formSerialize = function(semantic) {
- //hand off to jQuery.param for proper encoding
- return $.param(this.formToArray(semantic));
- };
-
- /**
- * Serializes all field elements in the jQuery object into a query string.
- * This method will return a string in the format: name1=value1&name2=value2
- */
- $.fn.fieldSerialize = function(successful) {
- var a = [];
- this.each(function() {
- var n = this.name;
- if (!n) return;
- var v = $.fieldValue(this, successful);
- if (v && v.constructor == Array) {
- for (var i=0,max=v.length; i < max; i++)
- a.push({
- name: n,
- value: v[i]
- });
- }
- else if (v !== null && typeof v != 'undefined')
- a.push({
- name: this.name,
- value: v
- });
- });
- //hand off to jQuery.param for proper encoding
- return $.param(a);
- };
-
- /**
- * Returns the value(s) of the element in the matched set. For example, consider the following form:
- *
- * <form><fieldset>
- * <input name="A" type="text" />
- * <input name="A" type="text" />
- * <input name="B" type="checkbox" value="B1" />
- * <input name="B" type="checkbox" value="B2"/>
- * <input name="C" type="radio" value="C1" />
- * <input name="C" type="radio" value="C2" />
- * </fieldset></form>
- *
- * var v = $(':text').fieldValue();
- * // if no values are entered into the text inputs
- * v == ['','']
- * // if values entered into the text inputs are 'foo' and 'bar'
- * v == ['foo','bar']
- *
- * var v = $(':checkbox').fieldValue();
- * // if neither checkbox is checked
- * v === undefined
- * // if both checkboxes are checked
- * v == ['B1', 'B2']
- *
- * var v = $(':radio').fieldValue();
- * // if neither radio is checked
- * v === undefined
- * // if first radio is checked
- * v == ['C1']
- *
- * The successful argument controls whether or not the field element must be 'successful'
- * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
- * The default value of the successful argument is true. If this value is false the value(s)
- * for each element is returned.
- *
- * Note: This method *always* returns an array. If no valid value can be determined the
- * array will be empty, otherwise it will contain one or more values.
- */
- $.fn.fieldValue = function(successful) {
- for (var val=[], i=0, max=this.length; i < max; i++) {
- var el = this[i];
- var v = $.fieldValue(el, successful);
- if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
- continue;
- v.constructor == Array ? $.merge(val, v) : val.push(v);
- }
- return val;
- };
-
- /**
- * Returns the value of the field element.
- */
- $.fieldValue = function(el, successful) {
- var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
- if (typeof successful == 'undefined') successful = true;
-
- if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
- (t == 'checkbox' || t == 'radio') && !el.checked ||
- (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
- tag == 'select' && el.selectedIndex == -1))
- return null;
-
- if (tag == 'select') {
- var index = el.selectedIndex;
- if (index < 0) return null;
- var a = [], ops = el.options;
- var one = (t == 'select-one');
- var max = (one ? index+1 : ops.length);
- for(var i=(one ? index : 0); i < max; i++) {
- var op = ops[i];
- if (op.selected) {
- var v = op.value;
- if (!v) // extra pain for IE...
- v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
- if (one) return v;
- a.push(v);
- }
- }
- return a;
- }
- return el.value;
- };
-
- /**
- * Clears the form data. Takes the following actions on the form's input fields:
- * - input text fields will have their 'value' property set to the empty string
- * - select elements will have their 'selectedIndex' property set to -1
- * - checkbox and radio inputs will have their 'checked' property set to false
- * - inputs of type submit, button, reset, and hidden will *not* be effected
- * - button elements will *not* be effected
- */
- $.fn.clearForm = function() {
- return this.each(function() {
- $('input,select,textarea', this).clearFields();
- });
- };
-
- /**
- * Clears the selected form elements.
- */
- $.fn.clearFields = $.fn.clearInputs = function() {
- return this.each(function() {
- var t = this.type, tag = this.tagName.toLowerCase();
- if (t == 'text' || t == 'password' || tag == 'textarea')
- this.value = '';
- else if (t == 'checkbox' || t == 'radio')
- this.checked = false;
- else if (tag == 'select')
- this.selectedIndex = -1;
- });
- };
-
- /**
- * Resets the form data. Causes all form elements to be reset to their original value.
- */
- $.fn.resetForm = function() {
- return this.each(function() {
- // guard against an input with the name of 'reset'
- // note that IE reports the reset function as an 'object'
- if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
- this.reset();
- });
- };
-
- /**
- * Enables or disables any matching elements.
- */
- $.fn.enable = function(b) {
- if (b == undefined) b = true;
- return this.each(function() {
- this.disabled = !b;
- });
- };
-
- /**
- * Checks/unchecks any matching checkboxes or radio buttons and
- * selects/deselects and matching option elements.
- */
- $.fn.selected = function(select) {
- if (select == undefined) select = true;
- return this.each(function() {
- var t = this.type;
- if (t == 'checkbox' || t == 'radio')
- this.checked = select;
- else if (this.tagName.toLowerCase() == 'option') {
- var $sel = $(this).parent('select');
- if (select && $sel[0] && $sel[0].type == 'select-one') {
- // deselect all other options
- $sel.find('option').selected(false);
- }
- this.selected = select;
- }
- });
- };
-
- // helper fn for console logging
- // set $.fn.ajaxSubmit.debug to true to enable debug logging
- function log() {
- if ($.fn.ajaxSubmit.debug && window.console && window.console.log)
- window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,''));
- };
-
-})(jQuery);
=== modified file 'dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/user.js'
--- dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/user.js 2010-10-28 09:17:13 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/webapp/dhis-web-mobile/javascript/user.js 2011-04-05 01:04:43 +0000
@@ -3,9 +3,6 @@
removeItem( userGroupId, userGroupName, i18n_confirm_delete, "removeUserGroup.action" );
}
-
-
-
function showUserGroupDetails( userGroupId )
{
var request = new Request();