From 868887b6137ff4176189534d15feb1d711fba36d Mon Sep 17 00:00:00 2001
From: pkupczyk <pkupczyk>
Date: Mon, 11 Feb 2013 13:40:31 +0000
Subject: [PATCH] SP-467 / BIS-189 : DSS restarted during manual tests =>
 Emptying the trash became impossible bugfix - during storage confirmation
 throw an exception only when a data set doesn't exist but execute normally if
 the data set storage had been already confirmed

SVN: 28329
---
 .../cisd/openbis/generic/server/ETLService.java    |  2 +-
 .../generic/server/dataaccess/IDataDAO.java        | 14 ++++++++++++--
 .../generic/server/dataaccess/db/DataDAO.java      | 11 +++++++++++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java
index 660aeba314a..ba99c6fa3ae 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java
@@ -2394,7 +2394,7 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements
         if (daoFactory.getDataDAO().confirmStorage(dataSetCode))
         {
             daoFactory.getPostRegistrationDAO().addDataSet(dataSetCode);
-        } else
+        } else if (daoFactory.getDataDAO().exists(dataSetCode) == false)
         {
             throw new UserFailureException("Storage confirmation for a dataset: " + dataSetCode
                     + " failed because the data set has been already deleted.");
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDataDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDataDAO.java
index 12aa619e45e..6f44ba178c8 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDataDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDataDAO.java
@@ -162,10 +162,20 @@ public interface IDataDAO extends IGenericDAO<DataPE>
             throws DataAccessException;
 
     /**
-     * Confirms storage for the specified data set.
+     * Confirms a storage for the specified data set. It confirms the storage even if the data set
+     * is in the trash.
      * 
-     * @return Returns true if the storage confirmed value has been changed.
+     * @return Returns true if the data sets exists and the storage confirmed value has been
+     *         changed.
      */
     boolean confirmStorage(String dataSetCode);
 
+    /**
+     * Checks whether a data set with the specified code exists. It takes into consideration also
+     * data sets that are in the trash.
+     * 
+     * @return Returns true if the data set exists.
+     */
+    boolean exists(String dataSetCode);
+
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DataDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DataDAO.java
index 7d9321d8bd6..a9b702e1a47 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DataDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DataDAO.java
@@ -1293,4 +1293,15 @@ final class DataDAO extends AbstractGenericEntityWithPropertiesDAO<DataPE> imple
         query.setString("code", dataSetCode);
         return query.executeUpdate() > 0;
     }
+
+    @Override
+    public boolean exists(String dataSetCode)
+    {
+        SQLQuery query =
+                getSession().createSQLQuery("select count(*) from data_all where code = :code");
+        query.setString("code", dataSetCode);
+        Number count = (Number) query.uniqueResult();
+        return count != null && count.intValue() > 0;
+    }
+
 }
-- 
GitLab