dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21236
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9989: Fixes
------------------------------------------------------------
revno: 9989
committer: Magnus Korvald <korvald@xxxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2013-03-05 20:06:26 +0300
message:
Fixes
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/smscommand/SMSCommand.hbm.xml
dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java
dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java
dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSParserKeyValue.java
dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/sms-commands.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java 2012-08-30 12:47:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java 2013-03-05 17:06:26 +0000
@@ -2,6 +2,7 @@
import java.util.Set;
+import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.sms.parse.ParserType;
@@ -26,7 +27,8 @@
private String defaultMessage;
-
+ private boolean currentPeriodUsedForReporting = false; // default is
+ // previous
public SMSCommand( String name, String parser, ParserType parserType, String separator, DataSet dataset,
Set<SMSCode> codes, String codeSeparator, String defaultMessage )
@@ -170,7 +172,8 @@
public ParserType getParserType()
{
- if(parserType == null){
+ if ( parserType == null )
+ {
return ParserType.KEY_VALUE_PARSER;
}
return parserType;
@@ -181,4 +184,20 @@
this.parserType = parserType;
}
+ public boolean isCurrentPeriodUsedForReporting()
+ {
+ return currentPeriodUsedForReporting;
+ }
+
+ public void setCurrentPeriodUsedForReporting( Boolean currentPeriodUsedForReporting )
+ {
+ if ( currentPeriodUsedForReporting == null )
+ {
+ this.currentPeriodUsedForReporting = false;
+ }
+ else
+ {
+ this.currentPeriodUsedForReporting = currentPeriodUsedForReporting;
+ }
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/smscommand/SMSCommand.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/smscommand/SMSCommand.hbm.xml 2013-01-17 19:32:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/smscommand/SMSCommand.hbm.xml 2013-03-05 17:06:26 +0000
@@ -5,26 +5,29 @@
[<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
>
<hibernate-mapping package="org.hisp.dhis.smscommand">
-
+
<class name="SMSCommand" table="smscommands">
<cache usage="read-write" />
<id name="id" column="smscommandid">
<generator class="increment" />
</id>
<property name="name" type="text" />
-
+
<property name="parser" type="text" />
-
- <property name="parserType">
+
+ <property name="parserType">
<type name="org.hibernate.type.EnumType">
- <param name="enumClass">org.hisp.dhis.sms.parse.ParserType</param>
+ <param name="enumClass">org.hisp.dhis.sms.parse.ParserType</param>
</type>
- </property>
-
-
+ </property>
+
+
<property name="separator" type="text" column="separatorkey" />
<property name="codeSeparator" type="text" />
<property name="defaultMessage" type="text" />
+ <property name="currentPeriodUsedForReporting" type="boolean" />
+
+
<many-to-one name="dataset" class="org.hisp.dhis.dataset.DataSet" column="datasetid" foreign-key="fk_dataset_datasetid" />
<set name="codes" table="smscommandcodes">
@@ -32,6 +35,8 @@
<key column="id" />
<many-to-many class="org.hisp.dhis.smscommand.SMSCode" column="codeid" unique="true" />
</set>
+
</class>
-
+
+
</hibernate-mapping>
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java 2013-02-09 17:13:30 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java 2013-03-05 17:06:26 +0000
@@ -11,6 +11,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataset.CompleteDataSetRegistration;
@@ -19,16 +20,15 @@
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.CalendarPeriodType;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.sms.incoming.IncomingSms;
import org.hisp.dhis.sms.outbound.OutboundSms;
import org.hisp.dhis.sms.outbound.OutboundSmsService;
+import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
import org.hisp.dhis.smscommand.SMSCode;
import org.hisp.dhis.smscommand.SMSCommand;
import org.hisp.dhis.smscommand.SMSCommandService;
-import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,18 +45,8 @@
private static final Log log = LogFactory.getLog( DefaultParserManager.class );
- private CurrentUserService currentUserService;
-
- @Autowired
- private OrganisationUnitService organisationUnitService;
-
private CompleteDataSetRegistrationService registrationService;
- public void setRegistrationService( CompleteDataSetRegistrationService registrationService )
- {
- this.registrationService = registrationService;
- }
-
private DataValueService dataValueService;
private UserService userService;
@@ -67,33 +57,30 @@
@Autowired
private DataElementCategoryService dataElementCategoryService;
+
+ @Autowired
+ private OutboundSmsTransportService transportService;
@Transactional
public void parse( IncomingSms sms )
{
try
{
- /* Temporarily hack for Uganda.. will need to configure this at the gateway */
- String text = sms.getText();
- if(sms.getText() != null && sms.getText().startsWith( "dhis" )){
- text = sms.getText().substring( 5 );
- }
-
- parse( sms.getOriginator(), text );
+ parse( sms.getOriginator(), sms.getText() );
}
catch ( SMSParserException e )
{
sendSMS( e.getMessage(), sms.getOriginator() );
return;
}
- sendSMS( "Your data report has been received", sms.getOriginator() );
}
private void sendSMS( String message, String sender )
{
+ String gatewayId = transportService.getDefaultGateway();
if ( outboundSmsService != null )
{
- outboundSmsService.sendMessage( new OutboundSms( message, sender ), null );
+ outboundSmsService.sendMessage( new OutboundSms( message, sender ), gatewayId );
}
}
@@ -179,7 +166,7 @@
{
if ( parsedMessage.containsKey( code.getCode().toUpperCase() ) )
{
- storeDataValue( sender, orgUnit, parsedMessage, code, date, command.getDataset(),
+ storeDataValue( sender, orgUnit, parsedMessage, code, command, date, command.getDataset(),
completeForm( command, parsedMessage ) );
valueStored = true;
}
@@ -253,14 +240,7 @@
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService
.getDataElementCategoryOptionCombo( code.getOptionId() );
- period = code.getDataElement().getPeriodType().createPeriod();
- CalendarPeriodType cpt = (CalendarPeriodType) period.getPeriodType();
- period = cpt.getPreviousPeriod( period );
-
- if ( date != null )
- {
- period = cpt.createPeriod( date );
- }
+ period = getPeriod( command, date );
DataValue dv = dataValueService.getDataValue( orgunit, code.getDataElement(), period, optionCombo );
@@ -271,14 +251,19 @@
}
else if ( dv != null )
{
+
String value = dv.getValue();
- if ( "true".equals( value ) )
- {
- value = "Yes";
- }
- else if ( "false".equals( value ) )
- {
- value = "No";
+
+ if ( StringUtils.equals( dv.getDataElement().getType(), DataElement.VALUE_TYPE_BOOL ) )
+ {
+ if ( "true".equals( value ) )
+ {
+ value = "Yes";
+ }
+ else if ( "false".equals( value ) )
+ {
+ value = "No";
+ }
}
reportBack += code.getCode() + "=" + value + " ";
}
@@ -296,6 +281,29 @@
}
}
+ protected Period getPeriod( SMSCommand command, Date date )
+ {
+
+ Period period;
+ period = command.getDataset().getPeriodType().createPeriod();
+ CalendarPeriodType cpt = (CalendarPeriodType) period.getPeriodType();
+ if ( command.isCurrentPeriodUsedForReporting() )
+ {
+ period = cpt.createPeriod( new Date() );
+ }
+ else
+ {
+ period = cpt.getPreviousPeriod( period );
+ }
+
+ if ( date != null )
+ {
+ period = cpt.createPeriod( date );
+ }
+
+ return period;
+ }
+
private Date lookForDate( String message )
{
if ( !message.contains( " " ) )
@@ -322,18 +330,16 @@
cal.set( Calendar.YEAR, year - 1 );
}
date = cal.getTime();
- System.out.println( "\nFound date in SMS:" + date.toString() + "\n" );
}
catch ( Exception e )
{
// no date found
- System.out.println( "\nNo date found in SMS \n" );
}
return date;
}
private void storeDataValue( String sender, OrganisationUnit orgunit, Map<String, String> parsedMessage,
- SMSCode code, Date date, DataSet dataSet, boolean completeForm )
+ SMSCode code, SMSCommand command, Date date, DataSet dataSet, boolean completeForm )
{
String upperCaseCode = code.getCode().toUpperCase();
@@ -347,22 +353,27 @@
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( code
.getOptionId() );
- Period period = code.getDataElement().getPeriodType().createPeriod();
- CalendarPeriodType cpt = (CalendarPeriodType) period.getPeriodType();
- period = cpt.getPreviousPeriod( period );
-
- if ( date != null )
- {
- period = cpt.createPeriod( date );
- }
+ Period period = getPeriod( command, date );
DataValue dv = dataValueService.getDataValue( orgunit, code.getDataElement(), period, optionCombo );
String value = parsedMessage.get( upperCaseCode );
+ boolean newDataValue = false;
+ if ( dv == null )
+ {
+ dv = new DataValue();
+ dv.setOptionCombo( optionCombo );
+ dv.setSource( orgunit );
+ dv.setDataElement( code.getDataElement() );
+ dv.setPeriod( period );
+ dv.setComment( "" );
+ dv.setTimestamp( new java.util.Date() );
+ dv.setStoredBy( storedBy );
+ newDataValue = true;
+ }
-
- if ( value != null)
+ if ( value != null && StringUtils.equals( dv.getDataElement().getType(), DataElement.VALUE_TYPE_BOOL ) )
{
if ( "Y".equals( value.toUpperCase() ) || "YES".equals( value.toUpperCase() ) )
{
@@ -374,23 +385,14 @@
}
}
- if ( dv == null )
+ dv.setValue( value );
+
+ if ( newDataValue )
{
- // New data element
- DataValue dataVal = new DataValue();
- dataVal.setOptionCombo( optionCombo );
- dataVal.setSource( orgunit );
- dataVal.setDataElement( code.getDataElement() );
- dataVal.setPeriod( period );
- dataVal.setComment( "" );
- dataVal.setTimestamp( new java.util.Date() );
- dataVal.setStoredBy( storedBy );
- dataVal.setValue( value );
- dataValueService.addDataValue( dataVal );
+ dataValueService.addDataValue( dv );
}
else
{
- // Update data element
dv.setValue( value );
dv.setOptionCombo( optionCombo );
dataValueService.updateDataValue( dv );
@@ -411,20 +413,12 @@
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService
.getDataElementCategoryOptionCombo( code.getOptionId() );
- period = code.getDataElement().getPeriodType().createPeriod();
- CalendarPeriodType cpt = (CalendarPeriodType) period.getPeriodType();
- period = cpt.getPreviousPeriod( period );
-
- if ( date != null )
- {
- period = cpt.createPeriod( date );
- }
+ period = getPeriod( command, date );
DataValue dv = dataValueService.getDataValue( orgunit, code.getDataElement(), period, optionCombo );
if ( dv == null && !StringUtils.isEmpty( code.getCode() ) )
{
-
return; // not marked as complete
}
}
@@ -528,12 +522,6 @@
}
@Required
- public void setCurrentUserService( CurrentUserService currentUserService )
- {
- this.currentUserService = currentUserService;
- }
-
- @Required
public void setDataValueService( DataValueService dataValueService )
{
this.dataValueService = dataValueService;
@@ -550,9 +538,8 @@
this.outboundSmsService = outboundSmsService;
}
- public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ public void setRegistrationService( CompleteDataSetRegistrationService registrationService )
{
- this.organisationUnitService = organisationUnitService;
+ this.registrationService = registrationService;
}
-
}
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java 2013-02-05 12:21:54 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java 2013-03-05 17:06:26 +0000
@@ -7,6 +7,8 @@
public class SMSConsumer
{
+
+
private ParserManager parserManager;
private MessageQueue messageQueue;
@@ -60,7 +62,6 @@
private void fetchAndParseSMS()
{
IncomingSms message = messageQueue.get();
- System.out.println("starter å spise meldinger..");
while ( message != null )
{
try{
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSParserKeyValue.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSParserKeyValue.java 2012-11-15 08:44:31 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSParserKeyValue.java 2013-03-05 17:06:26 +0000
@@ -9,6 +9,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang.StringUtils;
+
/**
* @author Magnus Korvald
*/
@@ -33,7 +35,7 @@
String key = m.group( 1 );
String value = m.group( 2 );
System.out.println( "Key: " + key + " Value: " + value );
- if ( key != null && value != null )
+ if ( !StringUtils.isEmpty( key ) && !StringUtils.isEmpty( value ) )
{
output.put( key.toUpperCase(), value );
}
@@ -44,8 +46,7 @@
public void setSeparator( String separator )
{
- String x = null;
- x = "(\\w+)\\s*\\" + separator.trim() + "\\s*([\\w ]+)\\s*(\\" + separator.trim() + "|$)*\\s*";
+ String x = "(\\w+)\\s*\\" + separator.trim() + "\\s*([\\w ]+)\\s*(\\" + separator.trim() + "|$)*\\s*";
pattern = Pattern.compile( x );
}
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2013-02-05 12:21:54 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2013-03-05 17:06:26 +0000
@@ -56,7 +56,6 @@
depends-on="org.hisp.dhis.user.UserService">
<property name="userService" ref="org.hisp.dhis.user.UserService" />
<property name="smsCommandService" ref="smsCommandService" />
- <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
<property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
<property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" />
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java 2012-08-30 12:47:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java 2013-03-05 17:06:26 +0000
@@ -7,6 +7,7 @@
import net.sf.json.JSONObject;
+import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataset.DataSet;
@@ -26,9 +27,9 @@
private DataElementService dataElementService;
- private String name;
+ private String name;
- private int selectedDataSetID;
+ private int selectedDataSetID;
private String codeDataelementOption;
@@ -37,9 +38,11 @@
private String codeSeparator;
private String defaultMessage;
-
+
private int selectedCommandID = -1;
+ private boolean currentPeriodUsedForReporting = false;
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -69,11 +72,10 @@
SMSCommand c = getSMSCommand();
if ( selectedDataSetID > -1 && c != null )
{
- // c.setDataset( getDataSetService().getDataSet( getSelectedDataSetID() ) );
+ c.setCurrentPeriodUsedForReporting( currentPeriodUsedForReporting );
c.setName( name );
c.setSeparator( separator );
c.setCodes( codeSet );
- // c.setCodeSeparator( codeSeparator );
c.setDefaultMessage( defaultMessage );
smsCommandService.save( c );
}
@@ -180,7 +182,6 @@
{
this.dataElementService = dataElementService;
}
-
public String getCodeSeparator()
{
@@ -192,12 +193,31 @@
this.codeSeparator = codeSeparator;
}
- public String getDefaultMessage() {
+ public String getDefaultMessage()
+ {
return defaultMessage;
}
- public void setDefaultMessage(String defaultMessage) {
+ public void setDefaultMessage( String defaultMessage )
+ {
this.defaultMessage = defaultMessage;
}
+ public boolean isCurrentPeriodUsedForReporting()
+ {
+ return currentPeriodUsedForReporting;
+ }
+
+ public void setCurrentPeriodUsedForReporting( String currentPeriodUsedForReporting )
+ {
+ if ( !StringUtils.isEmpty( currentPeriodUsedForReporting ) )
+ {
+ this.currentPeriodUsedForReporting = true;
+ }
+ else
+ {
+ this.currentPeriodUsedForReporting = false;
+ }
+ }
+
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm 2012-09-24 03:14:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm 2013-03-05 17:06:26 +0000
@@ -46,6 +46,9 @@
</tr>
<tr>
+ <td>Use current period for reporting</td>
+ <td><input type="checkbox" name="currentPeriodUsedForReporting" #if($SMSCommand.currentPeriodUsedForReporting) checked #end /></td>
+ <tr>
<td>$i18n.getString( "dataset" )</td>
<td>#if($SMSCommand.dataset.name) $SMSCommand.dataset.name #end</td>
<tr>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/sms-commands.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/sms-commands.vm 2012-08-30 12:47:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/sms-commands.vm 2013-03-05 17:06:26 +0000
@@ -30,6 +30,8 @@
<td><a href="deleteSMSCommand.action?deleteCommandId=$command.id">Delete</a></td>
</tr>
#end
+
+
</tbody>
</table>
</td>