← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5931: new dataset exception ui now working

 

------------------------------------------------------------
revno: 5931
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-02-13 13:21:44 +0700
message:
  new dataset exception ui now working
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lockexception/AddLockExceptionAction.java


--
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/lockexception/AddLockExceptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lockexception/AddLockExceptionAction.java	2012-02-08 12:04:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lockexception/AddLockExceptionAction.java	2012-02-13 06:21:44 +0000
@@ -28,6 +28,8 @@
  */
 
 import com.opensymphony.xwork2.Action;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.dataset.LockException;
@@ -42,6 +44,8 @@
 public class AddLockExceptionAction
     implements Action
 {
+    private static final Log log = LogFactory.getLog( AddLockExceptionAction.class );
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -71,9 +75,9 @@
     // Input & Output
     // -------------------------------------------------------------------------
 
-    private int organisationUnitId;
+    private String organisationUnitId;
 
-    public void setOrganisationUnitId( int organisationUnitId )
+    public void setOrganisationUnitId( String organisationUnitId )
     {
         this.organisationUnitId = organisationUnitId;
     }
@@ -99,21 +103,40 @@
     @Override
     public String execute() throws Exception
     {
-        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
-        DataSet dataSet = dataSetService.getDataSet( dataSetId );
-        Period period = periodService.getPeriodByExternalId( periodId );
-
-        if ( organisationUnit == null || dataSet == null || period == null )
-        {
-            return ERROR;
-        }
-
-        LockException lockException = new LockException();
-        lockException.setOrganisationUnit( organisationUnit );
-        lockException.setDataSet( dataSet );
-        lockException.setPeriod( period );
-
-        dataSetService.addLockException( lockException );
+        if ( organisationUnitId.length() == 0 )
+        {
+            return INPUT;
+        }
+
+        for ( String id : organisationUnitId.split( "," ) )
+        {
+            OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( Integer.parseInt( id ) );
+            DataSet dataSet = dataSetService.getDataSet( dataSetId );
+            Period period = periodService.getPeriodByExternalId( periodId );
+
+            if ( organisationUnit == null || dataSet == null || period == null )
+            {
+                return ERROR;
+            }
+
+            if ( organisationUnit.getDataSets().contains( dataSet ) )
+            {
+                LockException lockException = new LockException();
+
+                lockException.setOrganisationUnit( organisationUnit );
+                lockException.setDataSet( dataSet );
+                lockException.setPeriod( period );
+                dataSetService.addLockException( lockException );
+            }
+            else
+            {
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "OrganisationUnit " + organisationUnit.getName() + " does not contain DataSet " +
+                        dataSet.getName() + ", ignoring." );
+                }
+            }
+        }
 
         return SUCCESS;
     }