=== 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 organisationUnitsSelectedForLocking = new HashSet( 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 organisationUnitsSelectedForLocking = new HashSet( selectionTreeManager + .getLockOnSelectedOrganisationUnits() ); + + DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( dataSet, period ); + + List organisationUnits = new ArrayList( currentUserService.getCurrentUser() + .getOrganisationUnits() ); + + List curUserOrgUnitTree = new ArrayList(); + + 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 convert( Collection organisationUnits ) + { + Set sources = new HashSet(); + + 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 @@ - + @@ -45,19 +45,22 @@ class="org.hisp.dhis.dataadmin.action.lock.DefineLockOnDataSetOrgunitAndPeriod" scope="prototype"> - + - + - + - + - + + + +