dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06592
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1825: Fixed Bug 602984 DataLock: Wheen we lock with diffrent users, only last user changes are there
------------------------------------------------------------
revno: 1825
committer: Mithilesh Kumar Thakur<mithilesh.hisp@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-07-08 11:17:38 +0530
message:
Fixed Bug 602984 DataLock: Wheen we lock with diffrent users,only last user changes are there
modified:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lock/DefineLockOnDataSetOrgunitAndPeriod.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/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-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lock/DefineLockOnDataSetOrgunitAndPeriod.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lock/DefineLockOnDataSetOrgunitAndPeriod.java 2009-12-29 07:14:28 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lock/DefineLockOnDataSetOrgunitAndPeriod.java 2010-07-08 05:47:38 +0000
@@ -26,14 +26,18 @@
*/
package org.hisp.dhis.dataadmin.action.lock;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
-
import org.hisp.dhis.datalock.DataSetLock;
import org.hisp.dhis.datalock.DataSetLockService;
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.oust.manager.SelectionTreeManager;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
@@ -88,10 +92,16 @@
this.currentUserService = currentUserService;
}
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
// -------------------------------------------------------------------------
// Input/output
// -------------------------------------------------------------------------
-
private Integer selectedLockedDataSetId;
public void setSelectedLockedDataSetId( Integer selectedLockedDataSetId )
@@ -134,46 +144,70 @@
// Action implementation
// -------------------------------------------------------------------------
- public String execute() throws Exception{
-
- Period period = new Period();
-
- if( periodId != null ){
-
- period = periodService.getPeriod( periodId.intValue() );
- }
-
- else{
- return SUCCESS;
- }
-
- period = periodService.getPeriod( periodId.intValue() );
- storedBy = currentUserService.getCurrentUsername();
-
- // ----------------------------------------------------------------------------------------
- // Data sets lock for specific selected period, and selected
- // organization unit ( or units )
- // ----------------------------------------------------------------------------------------
-
- DataSet dataSet = dataSetService.getDataSet( selectedLockedDataSetId.intValue() );
- Set<Source> organisationUnitsSelectedForLocking = new HashSet<Source>( selectionTreeManager
- .getLockOnSelectedOrganisationUnits() );
- DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( dataSet, period );
-
- if ( organisationUnitsSelectedForLocking.size() < 1 ){
- dataSet.setLocked( false );
- dataSetService.updateDataSet( dataSet );
- dataSetLock.getSources().removeAll( dataSetLock.getSources() );
- dataSetLockService.deleteDataSetLock( dataSetLock );
- return SUCCESS;
- }
-
- dataSetLock.getSources().removeAll( dataSetLock.getSources() );
- dataSetLock.getSources().addAll( organisationUnitsSelectedForLocking );
- dataSetLock.setTimestamp( new Date() );
- dataSetLock.setStoredBy( storedBy );
- dataSetLockService.updateDataSetLock( dataSetLock );
-
+ public String execute()
+ throws Exception
+ {
+
+ Period period = new Period();
+
+ if ( periodId != null )
+ {
+ period = periodService.getPeriod( periodId.intValue() );
+ }
+ else
+ {
+ return SUCCESS;
+ }
+
+ period = periodService.getPeriod( periodId.intValue() );
+ storedBy = currentUserService.getCurrentUsername();
+
+ //----------------------------------------------------------------------
+ // Data sets lock for specific selected period, and selected
+ // organization unit ( or units )
+ //----------------------------------------------------------------------
+
+ DataSet dataSet = dataSetService.getDataSet( selectedLockedDataSetId.intValue() );
+ Set<Source> organisationUnitsSelectedForLocking = new HashSet<Source>( selectionTreeManager
+ .getLockOnSelectedOrganisationUnits() );
+
+ DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( dataSet, period );
+
+ List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( currentUserService.getCurrentUser()
+ .getOrganisationUnits() );
+
+ List<OrganisationUnit> curUserOrgUnitTree = new ArrayList<OrganisationUnit>();
+
+ if( dataSetLock != null )
+ {
+ if( organisationUnits != null && organisationUnits.size() != 0 )
+ {
+ for( OrganisationUnit organisationUnitElement : organisationUnits )
+ {
+ curUserOrgUnitTree.addAll( organisationUnitService
+ .getOrganisationUnitWithChildren( organisationUnitElement.getId() ) );
+ }
+
+ dataSetLock.getSources().removeAll( convert( curUserOrgUnitTree ) );
+ dataSetLock.getSources().addAll( organisationUnitsSelectedForLocking );
+ dataSetLock.setTimestamp( new Date() );
+ dataSetLock.setStoredBy( storedBy );
+ dataSetLockService.updateDataSetLock( dataSetLock );
+ }
+ }
+
return SUCCESS;
}
+
+ private Set<Source> convert( Collection<OrganisationUnit> organisationUnits )
+ {
+ Set<Source> sources = new HashSet<Source>();
+
+ for( OrganisationUnit organisationUnit : organisationUnits )
+ {
+ sources.add( (Source) organisationUnit );
+ }
+
+ return sources;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml 2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml 2010-07-08 05:47:38 +0000
@@ -33,7 +33,7 @@
<ref bean="org.hisp.dhis.period.PeriodService" />
</property>
<property name="dataSetLockService">
- <ref bean="org.hisp.dhis.datalock.DataSetLockService" />
+ <ref bean="org.hisp.dhis.datalock.DataSetLockService"/>
</property>
<property name="currentUserService">
<ref bean="org.hisp.dhis.user.CurrentUserService" />
@@ -45,19 +45,22 @@
class="org.hisp.dhis.dataadmin.action.lock.DefineLockOnDataSetOrgunitAndPeriod"
scope="prototype">
<property name="selectionTreeManager">
- <ref bean="org.hisp.dhis.oust.manager.SelectionTreeManager" />
+ <ref bean="org.hisp.dhis.oust.manager.SelectionTreeManager"/>
</property>
<property name="dataSetService">
- <ref bean="org.hisp.dhis.dataset.DataSetService" />
+ <ref bean="org.hisp.dhis.dataset.DataSetService"/>
</property>
<property name="periodService">
- <ref bean="org.hisp.dhis.period.PeriodService" />
+ <ref bean="org.hisp.dhis.period.PeriodService"/>
</property>
<property name="dataSetLockService">
- <ref bean="org.hisp.dhis.datalock.DataSetLockService" />
+ <ref bean="org.hisp.dhis.datalock.DataSetLockService"/>
</property>
<property name="currentUserService">
- <ref bean="org.hisp.dhis.user.CurrentUserService" />
+ <ref bean="org.hisp.dhis.user.CurrentUserService"/>
+ </property>
+ <property name="organisationUnitService">
+ <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
</property>
</bean>