From 010a1ae33c7e93980de3ccf607ca2be555e86ac8 Mon Sep 17 00:00:00 2001
From: tpylak <tpylak>
Date: Wed, 11 Nov 2009 09:10:22 +0000
Subject: [PATCH] fix integration tests

SVN: 13305
---
 .../openbis/generic/server/ETLService.java    |  3 +-
 .../server/business/bo/ExperimentBO.java      | 33 ++++++++++++++-----
 .../server/business/bo/IExperimentBO.java     |  6 ++++
 3 files changed, 32 insertions(+), 10 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 3d6a8257353..98749707695 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
@@ -305,8 +305,7 @@ public class ETLService extends AbstractServer<IETLService> implements IETLServi
             ExperimentIdentifier experimentIdentifier)
     {
         final IExperimentBO experimentBO = boFactory.createExperimentBO(session);
-        experimentBO.loadByExperimentIdentifier(experimentIdentifier);
-        return experimentBO.getExperiment();
+        return experimentBO.tryFindByExperimentIdentifier(experimentIdentifier);
     }
 
     private SamplePE tryLoadSample(final Session session, SampleIdentifier sampleIdentifier)
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExperimentBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExperimentBO.java
index 23879833ba3..fffbfa85733 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExperimentBO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/ExperimentBO.java
@@ -154,22 +154,41 @@ public final class ExperimentBO extends AbstractBusinessObject implements IExper
         dataChanged = false;
     }
 
+    public final ExperimentPE tryFindByExperimentIdentifier(final ExperimentIdentifier identifier)
+    {
+        final ProjectPE project = tryGetProject(identifier);
+        if (project == null)
+        {
+            return null;
+        }
+        return tryGetExperiment(identifier, project);
+    }
+
     private ExperimentPE getExperimentByIdentifier(final ExperimentIdentifier identifier)
     {
         assert identifier != null : "Experiment identifier unspecified.";
-        final ProjectPE project =
-                getProjectDAO().tryFindProject(identifier.getDatabaseInstanceCode(),
-                        identifier.getGroupCode(), identifier.getProjectCode());
+        final ProjectPE project = tryGetProject(identifier);
         if (project == null)
         {
             throw new UserFailureException("Unkown experiment because of unkown project: "
                     + identifier);
         }
-        final ExperimentPE exp =
-                getExperimentDAO().tryFindByCodeAndProject(project, identifier.getExperimentCode());
+        final ExperimentPE exp = tryGetExperiment(identifier, project);
         return exp;
     }
 
+    private ExperimentPE tryGetExperiment(final ExperimentIdentifier identifier,
+            final ProjectPE project)
+    {
+        return getExperimentDAO().tryFindByCodeAndProject(project, identifier.getExperimentCode());
+    }
+
+    private ProjectPE tryGetProject(final ExperimentIdentifier identifier)
+    {
+        return getProjectDAO().tryFindProject(identifier.getDatabaseInstanceCode(),
+                identifier.getGroupCode(), identifier.getProjectCode());
+    }
+
     public final void enrichWithProperties()
     {
         if (experiment != null)
@@ -297,9 +316,7 @@ public final class ExperimentBO extends AbstractBusinessObject implements IExper
     private void defineExperimentProject(NewExperiment newExperiment,
             final ExperimentIdentifier experimentIdentifier)
     {
-        ProjectPE project =
-                getProjectDAO().tryFindProject(experimentIdentifier.getDatabaseInstanceCode(),
-                        experimentIdentifier.getGroupCode(), experimentIdentifier.getProjectCode());
+        ProjectPE project = tryGetProject(experimentIdentifier);
         if (project == null)
         {
             throw UserFailureException.fromTemplate(ERR_PROJECT_NOT_FOUND, newExperiment);
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IExperimentBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IExperimentBO.java
index f861adc71cb..4541d460387 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IExperimentBO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IExperimentBO.java
@@ -35,6 +35,12 @@ public interface IExperimentBO extends IEntityBusinessObject
     /** Loads a experiment given by its identifier. */
     void loadByExperimentIdentifier(final ExperimentIdentifier identifier);
 
+    /**
+     * Returns an experiment found at the given identifier or null if it does not exist. Does not
+     * change the state of this object, especially the result of {@link #getExperiment()}.
+     */
+    ExperimentPE tryFindByExperimentIdentifier(final ExperimentIdentifier identifier);
+
     /** Returns the sample which has been loaded. */
     ExperimentPE getExperiment();
 
-- 
GitLab