← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5995: Modified lock status impl

 

------------------------------------------------------------
revno: 5995
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-02-16 19:13:44 +0100
message:
  Modified lock status impl
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/LockExceptionStore.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/dataset/hibernate/HibernateLockExceptionStore.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetLockStatus.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SaveValueAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml


--
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-16 17:57:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2012-02-16 18:13:44 +0000
@@ -305,14 +305,15 @@
     void deleteLockExceptionCombination( DataSet dataSet, Period period );
 
     /**
-     * For a given ou + ds + period combination, is the data set locked or not
+     * Checks whether the system is locked for data entry for the given input.
      *
-     * @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
+     * @param dataSet the data set
+     * @param period Period the period.s
+     * @param organisationUnit the organisation unit.
+     * @param now the base date for deciding locked date, current date if null.
+     * @return true or false indicating whether the system is locked or not.
      */
-    boolean isLocked( OrganisationUnit organisationUnit, DataSet dataSet, Period period );
+    boolean isLocked( DataSet dataSet, Period period, OrganisationUnit organisationUnit, Date now );
     
     /**
      * Checks whether the system is locked for data entry for the given input.
@@ -320,7 +321,8 @@
      * @param dataElement the data element.
      * @param period the period.
      * @param organisationUnit the organisation unit.
-     * @return true or false indicating whether the system is locked.
+     * @param now the base date for deciding locked date, current date if null.
+     * @return true or false indicating whether the system is locked or not.
      */
     boolean isLocked( DataElement dataElement, Period period, OrganisationUnit organisationUnit, Date now );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/LockExceptionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/LockExceptionStore.java	2012-02-16 15:07:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/LockExceptionStore.java	2012-02-16 18:13:44 +0000
@@ -49,4 +49,6 @@
     void deleteCombination( DataSet dataSet, Period period );
     
     long getCount( DataElement dataElement, Period period, OrganisationUnit organisationUnit );
+    
+    long getCount( DataSet dataSet, Period period, OrganisationUnit organisationUnit );
 }

=== 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-16 17:57:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2012-02-16 18:13:44 +0000
@@ -401,39 +401,20 @@
     }
 
     @Override
-    public boolean isLocked( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    public boolean isLocked( DataSet dataSet, Period period, OrganisationUnit organisationUnit, Date now )
     {
-        // if we don't have any expiryDays, then just return false
-        if ( dataSet.getExpiryDays() == DataSet.NO_EXPIRY )
-        {
-            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;
+        now = now != null ? now : new Date();
+        
+        boolean expired = dataSet.getExpiryDays() != DataSet.NO_EXPIRY && new DateTime( period.getEndDate() ).plusDays( dataSet.getExpiryDays() ).isBefore( new DateTime( now ) );
+        
+        return expired && lockExceptionStore.getCount( dataSet, period, organisationUnit ) == 0l;
     }
-
+    
     @Override
     public boolean isLocked( DataElement dataElement, Period period, OrganisationUnit organisationUnit, Date now )
     {
+        now = now != null ? now : new Date();
+        
         int expiryDays = dataElement.getExpiryDays();
         
         boolean expired = expiryDays != DataSet.NO_EXPIRY && new DateTime( period.getEndDate() ).plusDays( expiryDays ).isBefore( new DateTime( now ) );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateLockExceptionStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateLockExceptionStore.java	2012-02-16 15:07:04 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateLockExceptionStore.java	2012-02-16 18:13:44 +0000
@@ -155,4 +155,14 @@
         
         return (Long) criteria.setProjection( Projections.rowCount() ).uniqueResult();
     }
+    
+    public long getCount( DataSet dataSet, Period period, OrganisationUnit organisationUnit )
+    {
+        Criteria criteria = getCriteria( 
+            Restrictions.eq( "period", period ),
+            Restrictions.eq( "organisationUnit", organisationUnit ),
+            Restrictions.eq( "dataSet", dataSet ) );
+        
+        return (Long) criteria.setProjection( Projections.rowCount() ).uniqueResult();
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetLockStatus.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetLockStatus.java	2012-02-16 12:07:10 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetLockStatus.java	2012-02-16 18:13:44 +0000
@@ -27,15 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 
+import com.opensymphony.xwork2.Action;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -60,15 +60,8 @@
         this.organisationUnitService = organisationUnitService;
     }
 
-    private PeriodService periodService;
-
-    public void setPeriodService( PeriodService periodService )
-    {
-        this.periodService = periodService;
-    }
-
     // -------------------------------------------------------------------------
-    // Input & Output
+    // Input
     // -------------------------------------------------------------------------
 
     private int dataSetId;
@@ -92,6 +85,10 @@
         this.periodId = periodId;
     }
 
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
     private boolean locked;
 
     public boolean isLocked()
@@ -115,7 +112,7 @@
             return INPUT;
         }
 
-        locked = dataSetService.isLocked( organisationUnit, dataSet, period );
+        locked = dataSetService.isLocked( dataSet, period, organisationUnit, null );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SaveValueAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SaveValueAction.java	2012-02-16 17:57:30 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SaveValueAction.java	2012-02-16 18:13:44 +0000
@@ -192,7 +192,7 @@
         // Check locked status
         // ---------------------------------------------------------------------
 
-        if ( dataSetService.isLocked( dataElement, period, organisationUnit, new Date() ) )
+        if ( dataSetService.isLocked( dataElement, period, organisationUnit, null ) )
         {
             return logError( "Entry locked for combination: " + dataElement + ", " + period + ", " + organisationUnit );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2012-02-16 17:57:30 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2012-02-16 18:13:44 +0000
@@ -27,7 +27,6 @@
   <bean id="org.hisp.dhis.de.action.GetLockStatus" class="org.hisp.dhis.de.action.GetLockStatus" scope="prototype">
     <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
-    <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
   </bean>
 
   <bean id="org.hisp.dhis.de.action.GetDataValuesForDataSetAction"