← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10102: Added check for locked dataset

 

------------------------------------------------------------
revno: 10102
committer: Magnus Korvald <korvald@xxxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2013-03-09 13:23:42 +0100
message:
  Added check for locked dataset
modified:
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java


--
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-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-03-08 16:22:03 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java	2013-03-09 12:23:42 +0000
@@ -17,6 +17,7 @@
 import org.hisp.dhis.dataset.CompleteDataSetRegistration;
 import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -61,6 +62,9 @@
     @Autowired
     private OutboundSmsTransportService transportService;
 
+    @Autowired
+    private DataSetService dataSetService;
+
     @Transactional
     public void parse( IncomingSms sms )
     {
@@ -155,19 +159,24 @@
         }
 
         Map<String, String> parsedMessage = p.parse( message );
-
         Date date = lookForDate( message );
+        OrganisationUnit orgUnit = selectOrganisationUnit( orgUnits, parsedMessage );
+        Period period = getPeriod( command, date );
+
+        // Check if Data Set is locked
+        if ( dataSetService.isLocked( command.getDataset(), period, orgUnit, null ) )
+        {
+            throw new SMSParserException( "Dataset is locked for the period " + period.getStartDate() + " - "
+                + period.getEndDate() );
+        }
 
         boolean valueStored = false;
-
-        OrganisationUnit orgUnit = selectOrganisationUnit( orgUnits, parsedMessage );
-
         for ( SMSCode code : command.getCodes() )
         {
             if ( parsedMessage.containsKey( code.getCode().toUpperCase() ) )
             {
                 storeDataValue( sender, orgUnit, parsedMessage, code, command, date, command.getDataset(),
-                    completeForm( command, parsedMessage ) );
+                    formIsComplete( command, parsedMessage ) );
                 valueStored = true;
             }
         }
@@ -434,7 +443,7 @@
 
     }
 
-    private boolean completeForm( SMSCommand command, Map<String, String> parsedMessage )
+    private boolean formIsComplete( SMSCommand command, Map<String, String> parsedMessage )
     {
         for ( SMSCode code : command.getCodes() )
         {