← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5965: added methods for checking if a ou+ds+period combo is locked, also made locking work in mobile da...

 

------------------------------------------------------------
revno: 5965
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-02-15 20:19:34 +0700
message:
  added methods for checking if a ou+ds+period combo is locked, also made locking work in mobile data entry (web), normal data entry is not finished
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/images/wrench.png
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/removeLockExceptionBatch.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/dataset/DataSetService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2012-02-14 02:58:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2012-02-15 13:19:34 +0000
@@ -302,4 +302,14 @@
      * @param period  Period part of the combination
      */
     public void deleteLockExceptionCombination( DataSet dataSet, Period period );
+
+    /**
+     * For a given ou + ds + period combination, is the data set locked or not
+     *
+     * @param organisationUnit OrganisationUnit instance
+     * @param dataSet DataSet instance
+     * @param period Period instance
+     * @return true or false depending on the lock status of the ou + ds + period combination
+     */
+    public boolean isLocked( OrganisationUnit organisationUnit, DataSet dataSet, Period period );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2012-02-14 07:51:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2012-02-15 13:19:34 +0000
@@ -40,6 +40,7 @@
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
 import org.hisp.dhis.user.CurrentUserService;
+import org.joda.time.DateTime;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
@@ -336,6 +337,13 @@
     {
         Validate.notNull( lockException );
 
+        DataSet dataSet = lockException.getDataSet();
+
+        if ( !dataSet.getLockExceptions().contains( lockException ) )
+        {
+            dataSet.getLockExceptions().add( lockException );
+        }
+
         return lockExceptionStore.save( lockException );
     }
 
@@ -352,6 +360,13 @@
     {
         Validate.notNull( lockException );
 
+        DataSet dataSet = lockException.getDataSet();
+
+        if ( dataSet.getLockExceptions().contains( lockException ) )
+        {
+            dataSet.getLockExceptions().remove( lockException );
+        }
+
         lockExceptionStore.delete( lockException );
     }
 
@@ -390,4 +405,35 @@
     {
         lockExceptionStore.deleteCombination( dataSet, period );
     }
+
+    @Override
+    public boolean isLocked( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    {
+        // if we don't have any expiryDays, then just return false
+        if ( dataSet.getExpiryDays() == null || dataSet.getExpiryDays() <= 0 )
+        {
+            return false;
+        }
+
+        // using current time, see if we are over or under the current expiryDays limit
+        DateTime serverDate = new DateTime();
+        DateTime expiredDate = new DateTime( period.getEndDate() ).plusDays( dataSet.getExpiryDays() );
+
+        if ( serverDate.compareTo( expiredDate ) == -1 )
+        {
+            return false;
+        }
+
+        // if we are over the expiryDays limit, then check if there is an lockException for ou+ds+period combo
+        for ( LockException lockException : dataSet.getLockExceptions() )
+        {
+            if ( lockException.getOrganisationUnit().equals( organisationUnit ) &&
+                lockException.getDataSet().equals( dataSet ) && lockException.getPeriod().equals( period ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java	2012-02-15 13:19:34 +0000
@@ -204,12 +204,12 @@
     {
         return dataValueStore.getOperandsWithDataValues( operands );
     }
-    
+
     public int getDataValueCount( int days )
     {
         Calendar cal = PeriodType.createCalendarInstance();
         cal.add( Calendar.DAY_OF_YEAR, (days * -1) );
-        
+
         return dataValueStore.getDataValueCount( cal.getTime() );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css	2012-02-13 19:27:46 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css	2012-02-15 13:19:34 +0000
@@ -412,6 +412,11 @@
 	background: url(../images/warning.png) no-repeat 10px 10px
 }
 
+div.waiting
+{
+	background: url(../images/wrench.png) no-repeat 10px 10px
+}
+
 div.growlUI h1, div.growlUI h2 
 {
 	color: white; padding: 5px 5px 5px 75px; text-align: left;font-size:medium 

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/images/wrench.png'
Binary files dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/images/wrench.png	1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/images/wrench.png	2012-02-15 13:19:34 +0000 differ
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2012-02-14 16:03:54 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2012-02-15 13:19:34 +0000
@@ -1258,6 +1258,11 @@
 	jQuery.growlUI( i18n_warning, message, 'warning', time ); 	
 }
 
+function showWaitMessage( message, time )
+{
+	jQuery.growlUI( i18n_waiting, message, 'waiting', time );
+}
+
 function markInvalid( elementId, message )
 {	
 	var element = jQuery("#" + elementId );

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java	2012-01-23 10:49:32 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java	2012-02-15 13:19:34 +0000
@@ -229,25 +229,10 @@
     {
         for ( Period period : periods )
         {
-            boolean locked = dataSetLocked( organisationUnit, dataSet, period );
-
-            if ( locked )
+            if ( dataSetService.isLocked( organisationUnit, dataSet, period ) )
             {
                 lockedPeriods.add( period );
             }
         }
     }
-
-    private boolean dataSetLocked( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
-    {
-        // HACK workaround since get dataSetLock by unit/dataSet/period fails
-        DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( dataSet, period );
-
-        if ( dataSetLock != null && dataSetLock.getSources().contains( organisationUnit ) )
-        {
-            return true;
-        }
-
-        return false;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2012-02-14 02:58:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2012-02-15 13:19:34 +0000
@@ -404,3 +404,4 @@
 lock_exception_batch_removal=Lock exception batch removal
 back_to_lock_exceptions=Back to lock exception
 batch_delete=Batch deletion
+deleting_lock_exceptions=Deleting lock exceptions

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/removeLockExceptionBatch.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/removeLockExceptionBatch.vm	2012-02-14 07:18:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/removeLockExceptionBatch.vm	2012-02-15 13:19:34 +0000
@@ -1,5 +1,6 @@
 <script type="text/javascript">
     var i18n_confirm_deletes = '$encoder.jsEscape( $i18n.getString( "confirm_delete_lock_exceptions" ) , "'")';
+    var i18n_deleting_lock_exceptions = '$encoder.jsEscape( $i18n.getString( "deleting_lock_exceptions" ) , "'")';
 
     function removeLockExceptions( dataSetId, periodId, name )
     {
@@ -7,6 +8,8 @@
 
         if(result)
         {
+            showWaitMessage( i18n_deleting_lock_exceptions, 0 );
+
             $.postJSON(
            	    "batchRemoveLockException.action",
            	    {
@@ -64,7 +67,7 @@
 				<tr id="ds${lockException.dataSet.id}p${lockException.period.id}">
 					<td>$encoder.htmlEncode( $lockException.name )</td>
 					<td style="text-align:right">
-                        <a href="javascript:removeLockExceptions($lockException.dataSet.id, $lockException.period.id, '$encoder.htmlEncode( $lockException.name )')" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a>
+                        <a href="javascript:removeLockExceptions($lockException.dataSet.id, $lockException.period.id, '$encoder.jsEncode( $lockException.name )')" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a>
 					</td>
 				</tr>
 				#end