← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6073: Refactored locking functionality in data entry. Current solution was clearing greyed fields of se...

 

------------------------------------------------------------
revno: 6073
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-02-21 19:45:10 +0100
message:
  Refactored locking functionality in data entry. Current solution was clearing greyed fields of sections. It also used an unnecessary synchronous request.
removed:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetLockStatus.java
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/RegisterCompleteDataSetAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/UndoCompleteDataSetAction.java
  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/struts.xml
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.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-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java	2012-02-16 19:58:55 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java	2012-02-21 18:45:10 +0000
@@ -195,7 +195,9 @@
                 complete = true;
                 date = registration.getDate();
                 storedBy = registration.getStoredBy();
-            }
+            }            
+
+            locked = dataSetService.isLocked( dataSet, period, organisationUnit, null );
         }
 
         return SUCCESS;

=== removed 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 19:58:55 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetLockStatus.java	1970-01-01 00:00:00 +0000
@@ -1,118 +0,0 @@
-package org.hisp.dhis.de.action;
-
-/*
- * Copyright (c) 2004-2012, 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 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.PeriodType;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class GetLockStatus
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private DataSetService dataSetService;
-
-    public void setDataSetService( DataSetService dataSetService )
-    {
-        this.dataSetService = dataSetService;
-    }
-
-    private OrganisationUnitService organisationUnitService;
-
-    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
-    {
-        this.organisationUnitService = organisationUnitService;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private int dataSetId;
-
-    public void setDataSetId( int dataSetId )
-    {
-        this.dataSetId = dataSetId;
-    }
-
-    private int organisationUnitId;
-
-    public void setOrganisationUnitId( int organisationUnitId )
-    {
-        this.organisationUnitId = organisationUnitId;
-    }
-
-    private String periodId;
-
-    public void setPeriodId( String periodId )
-    {
-        this.periodId = periodId;
-    }
-
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
-    private boolean locked;
-
-    public boolean isLocked()
-    {
-        return locked;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action Implementation
-    // -------------------------------------------------------------------------
-
-    @Override
-    public String execute() throws Exception
-    {
-        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
-        DataSet dataSet = dataSetService.getDataSet( dataSetId );
-        Period period = PeriodType.createPeriodExternalId( periodId );
-
-        if ( organisationUnit == null || dataSet == null || period == null )
-        {
-            return INPUT;
-        }
-
-        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/RegisterCompleteDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/RegisterCompleteDataSetAction.java	2012-02-17 12:29:45 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/RegisterCompleteDataSetAction.java	2012-02-21 18:45:10 +0000
@@ -181,11 +181,6 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private String logError( String message )
-    {
-        return logError( message, 1 );
-    }
-
     private String logError( String message, int statusCode )
     {
         log.info( message );

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/UndoCompleteDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/UndoCompleteDataSetAction.java	2012-02-17 12:29:45 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/UndoCompleteDataSetAction.java	2012-02-21 18:45:10 +0000
@@ -143,11 +143,6 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private String logError( String message )
-    {
-        return logError( message, 1 );
-    }
-
     private String logError( String message, int statusCode )
     {
         log.info( message );

=== 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 18:13:44 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2012-02-21 18:45:10 +0000
@@ -24,11 +24,6 @@
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
   </bean>
 
-  <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" />
-  </bean>
-
   <bean id="org.hisp.dhis.de.action.GetDataValuesForDataSetAction"
       class="org.hisp.dhis.de.action.GetDataValuesForDataSetAction" scope="prototype">
     <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml	2012-02-16 12:07:10 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml	2012-02-21 18:45:10 +0000
@@ -27,10 +27,6 @@
       <result name="success" type="velocity-json">/dhis-web-dataentry/responseDataValues.vm</result>
     </action>
 
-    <action name="getLockStatus" class="org.hisp.dhis.de.action.GetLockStatus">
-      <result name="success" type="velocity-json">/dhis-web-dataentry/responseLockStatus.vm</result>
-    </action>
-
     <action name="loadForm" class="org.hisp.dhis.de.action.LoadFormAction">
       <result name="custom" type="velocity">/dhis-web-dataentry/customForm.vm</result>
       <result name="section" type="velocity">/dhis-web-dataentry/sectionForm.vm</result>

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2012-02-17 12:39:25 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2012-02-21 18:45:10 +0000
@@ -205,7 +205,7 @@
             cache: false,
             success: function( data, textStatus, jqXHR )
             {
-                if( data.status == 2 )
+                if ( data.status == 2 )
                 {
                     log( 'DataSet is locked' );
                     setHeaderMessage( i18n_register_complete_failed_dataset_is_locked );
@@ -526,37 +526,6 @@
 }
 
 // -----------------------------------------------------------------------------
-// Locking
-// -----------------------------------------------------------------------------
-
-function getLockStatus()
-{
-    var periodId = $( '#selectedPeriodId' ).val();
-    var dataSetId = $( '#selectedDataSetId' ).val();
-    var locked = false;
-
-    if ( periodId == null || dataSetId == -1 )
-    {
-        return false;
-    }
-
-    $.ajax( {
-      url: 'getLockStatus.action',
-      async: false,
-      data: {
-          'organisationUnitId': currentOrganisationUnitId,
-          'dataSetId': dataSetId,
-          'periodId': periodId
-      },
-      success: function (data) {
-          locked = data.locked;
-      }
-    } );
-
-    return locked;
-}
-
-// -----------------------------------------------------------------------------
 // Next/Previous Periods Selection
 // -----------------------------------------------------------------------------
 
@@ -711,6 +680,19 @@
 	    dataType: 'json',
 	    success: function( json )
 	    {
+	    	if ( json.locked )
+	    	{
+	    		$( '#contentDiv' ).hide();
+	    		$( '#completenessDiv' ).hide();
+	    		setHeaderDelayMessage( i18n_dataset_is_locked );
+	    		return;
+	    	}
+	    	else
+	    	{	    		
+	    		$( '#contentDiv' ).show();
+	    		$( '#completenessDiv' ).show();
+	    	}
+	    	
 	        // Set data values, works for select lists too as data
 	        // value = select value
 
@@ -774,8 +756,6 @@
 	            $( '#undoButton' ).attr( 'disabled', 'disabled' );
 	            $( '#infoDiv' ).css( 'display', 'none' );
 	        }
-
-	        // TODO locking
 	    }
 	} );
 }
@@ -788,21 +768,6 @@
 
     dataEntryFormIsLoaded = true;
     hideLoader();
-
-    if( getLockStatus() )
-    {
-        $( '#contentDiv :input' ).attr( 'disabled', true );
-        $( '#currentDataElement' ).html( i18n_dataset_is_locked );
-        $( '#completenessDiv' ).css( 'display', 'none' );
-    }
-    else
-    {
-        $( '#contentDiv :input' ).removeAttr( 'disabled' );
-        $( '#completenessDiv' ).css( 'display', 'block' );
-        $( '#currentDataElement' ).html( i18n_no_dataelement_selected );
-    }
-
-    $( '#contentDiv :input' ).css( 'background-color', 'white' );
 }
 
 function valueFocus( e )