From ed90978ce4911c3286477529de2cc61d8aca0092 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Tue, 20 Mar 2012 15:21:37 +0000
Subject: [PATCH] LMS-2846 tests for AnalysisSettings and
 ExperimentFeatureVectorSummaryLoader added.

SVN: 24756
---
 .../screening/server/ScreeningServer.java     |   2 +-
 .../server/logic/AbstractContentLoader.java   |   4 +-
 .../server/logic/AnalysisSettings.java        |   1 +
 .../ExperimentFeatureVectorSummaryLoader.java |  34 +-
 .../MaterialFeatureVectorSummaryLoader.java   |  10 +-
 ...erialFeaturesFromAllExperimentsLoader.java |  10 +-
 .../server/logic/WellContentLoader.java       |  17 +-
 .../server/logic/WellDataLoader.java          |   7 +-
 .../logic/WellFeatureCollectionLoader.java    |   6 +-
 .../server/logic/AnalysisSettingsTest.java    |  73 ++++
 ...erimentFeatureVectorSummaryLoaderTest.java | 334 ++++++++++++++++++
 ...aterialFeatureVectorSummaryLoaderTest.java |   2 +-
 12 files changed, 462 insertions(+), 38 deletions(-)
 create mode 100644 screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AnalysisSettingsTest.java
 create mode 100644 screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ExperimentFeatureVectorSummaryLoaderTest.java

diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java
index 1e859e6f1e7..918cdf4206a 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java
@@ -330,7 +330,7 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl
         MaterialSummarySettings settings = createDefaultSettings();
         ExperimentFeatureVectorSummaryLoader experimentFeatureVectorSummaryLoader =
                 new ExperimentFeatureVectorSummaryLoader(session, businessObjectFactory,
-                        getDAOFactory(), settings);
+                        getDAOFactory(), null, settings);
         return experimentFeatureVectorSummaryLoader.loadExperimentFeatureVectors(experimentId,
                 analysisProcedureCriteria, analysisSettings);
     }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AbstractContentLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AbstractContentLoader.java
index b30a9b41855..62333474dc0 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AbstractContentLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AbstractContentLoader.java
@@ -58,11 +58,13 @@ abstract class AbstractContentLoader
     private IScreeningQuery screeningDao = null;
 
     protected AbstractContentLoader(Session session,
-            IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory)
+            IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory,
+            IScreeningQuery screeningDaoOrNull)
     {
         this.session = session;
         this.businessObjectFactory = businessObjectFactory;
         this.daoFactory = daoFactory;
+        screeningDao = screeningDaoOrNull;
     }
 
     protected IScreeningQuery getScreeningDAO()
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AnalysisSettings.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AnalysisSettings.java
index a3b52678825..91c153ee061 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AnalysisSettings.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AnalysisSettings.java
@@ -48,6 +48,7 @@ public class AnalysisSettings
             String[] splittedProperty = property.split(",");
             for (String dataSetTypeSetting : splittedProperty)
             {
+                dataSetTypeSetting = dataSetTypeSetting.trim();
                 int indexOfColon = dataSetTypeSetting.indexOf(':');
                 if (indexOfColon < 0)
                 {
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ExperimentFeatureVectorSummaryLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ExperimentFeatureVectorSummaryLoader.java
index 274a9f9c398..3e88ac38407 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ExperimentFeatureVectorSummaryLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ExperimentFeatureVectorSummaryLoader.java
@@ -39,6 +39,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
 import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
 import ch.systemsx.cisd.openbis.plugin.screening.server.IScreeningBusinessObjectFactory;
+import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.IScreeningQuery;
 import ch.systemsx.cisd.openbis.plugin.screening.server.logic.WellDataLoader.MaterialIdSummariesAndFeatures;
 import ch.systemsx.cisd.openbis.plugin.screening.server.logic.dto.MaterialIdFeatureVectorSummary;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ExperimentFeatureVectorSummary;
@@ -60,12 +61,13 @@ public class ExperimentFeatureVectorSummaryLoader extends AbstractContentLoader
 
     public ExperimentFeatureVectorSummaryLoader(Session session,
             IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory,
-            MaterialSummarySettings settings)
+            IScreeningQuery screeningQuery, MaterialSummarySettings settings)
     {
-        super(session, businessObjectFactory, daoFactory);
+        super(session, businessObjectFactory, daoFactory, screeningQuery);
         this.settings = settings;
         this.wellDataLoader =
-                new WellDataLoader(session, businessObjectFactory, daoFactory, settings);
+                new WellDataLoader(session, businessObjectFactory, daoFactory, screeningQuery,
+                        settings);
     }
 
     public ExperimentFeatureVectorSummary loadExperimentFeatureVectors(TechId experimentId,
@@ -101,7 +103,7 @@ public class ExperimentFeatureVectorSummaryLoader extends AbstractContentLoader
                             message +=
                                     "\n\nHint: The file pattern for the data set type "
                                             + ds.getDataSetType().getCode()
-                                            + " could be wrong.";
+                                            + " might be wrong.";
                         }
                         throw decorateException(ex, ds, "Reason: " + message);
                     } catch (Exception ex)
@@ -112,6 +114,12 @@ public class ExperimentFeatureVectorSummaryLoader extends AbstractContentLoader
             }
         }
         
+        return calculatedSummary(experimentId, analysisProcedureCriteria, experiment);
+    }
+
+    ExperimentFeatureVectorSummary calculatedSummary(TechId experimentId,
+            AnalysisProcedureCriteria analysisProcedureCriteria, ExperimentReference experiment)
+    {
         MaterialIdSummariesAndFeatures summaries =
                 wellDataLoader.tryCalculateExperimentFeatureVectorSummaries(experimentId,
                         settings.getReplicaMaterialTypeSubstrings(), analysisProcedureCriteria,
@@ -126,19 +134,18 @@ public class ExperimentFeatureVectorSummaryLoader extends AbstractContentLoader
                 summaries.getFeatureNames(), null);
     }
 
-    UserFailureException decorateException(Exception ex, ExternalData dataSet, String message)
+    private UserFailureException decorateException(Exception ex, ExternalData dataSet, String message)
     {
-        return new UserFailureException(
-                "Analysis summary for data set "
-                        + dataSet.getCode()
-                        + " couldn't retrieved from Data Store Server. "
-                                + message, ex);
+        return new UserFailureException("Analysis summary for data set " + dataSet.getCode()
+                + " couldn't retrieved from Data Store Server. " + message, ex);
     }
 
-    List<ExternalData> getMatchingDataSets(TechId experimentId,
+    private List<ExternalData> getMatchingDataSets(TechId experimentId,
             AnalysisProcedureCriteria analysisProcedureCriteria)
     {
-        List<ExternalData> dataSets = businessObjectFactory.createDatasetLister(session).listByExperimentTechId(experimentId, true);
+        List<ExternalData> dataSets =
+                businessObjectFactory.createDatasetLister(session).listByExperimentTechId(
+                        experimentId, true);
         List<ExternalData> matchingDataSets = new ArrayList<ExternalData>();
         for (ExternalData dataSet : dataSets)
         {
@@ -213,6 +220,7 @@ public class ExperimentFeatureVectorSummaryLoader extends AbstractContentLoader
     {
         List<MaterialFeatureVectorSummary> materialsSummary = Collections.emptyList();
         List<CodeAndLabel> featureDescriptions = Collections.emptyList();
-        return new ExperimentFeatureVectorSummary(experiment, materialsSummary, featureDescriptions, null);
+        return new ExperimentFeatureVectorSummary(experiment, materialsSummary,
+                featureDescriptions, null);
     }
 }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeatureVectorSummaryLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeatureVectorSummaryLoader.java
index baddb66e429..0ff99e1cfcc 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeatureVectorSummaryLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeatureVectorSummaryLoader.java
@@ -32,6 +32,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.utils.GroupByMap;
 import ch.systemsx.cisd.openbis.generic.shared.basic.utils.IGroupKeyExtractor;
 import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
 import ch.systemsx.cisd.openbis.plugin.screening.server.IScreeningBusinessObjectFactory;
+import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.IScreeningQuery;
 import ch.systemsx.cisd.openbis.plugin.screening.server.logic.WellDataLoader.MaterialIdSummariesAndFeatures;
 import ch.systemsx.cisd.openbis.plugin.screening.server.logic.dto.MaterialAllReplicasFeatureVectors;
 import ch.systemsx.cisd.openbis.plugin.screening.server.logic.dto.MaterialBiologicalReplicateFeatureVector;
@@ -63,7 +64,7 @@ public class MaterialFeatureVectorSummaryLoader extends AbstractContentLoader
     {
         MaterialAllReplicasFeatureVectors resultOrNull =
                 new MaterialFeatureVectorSummaryLoader(session, businessObjectFactory, daoFactory,
-                        settings).tryLoadMaterialFeatureVectors(criteria);
+                        null, settings).tryLoadMaterialFeatureVectors(criteria);
 
         List<MaterialReplicaFeatureSummary> replicaRows = convertToFeatureRows(resultOrNull);
         List<String> subgroupLabels = tryGetSubgroupLabels(resultOrNull);
@@ -183,12 +184,13 @@ public class MaterialFeatureVectorSummaryLoader extends AbstractContentLoader
     @Private
     MaterialFeatureVectorSummaryLoader(Session session,
             IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory,
-            MaterialSummarySettings settings)
+            IScreeningQuery screeningQuery, MaterialSummarySettings settings)
     {
-        super(session, businessObjectFactory, daoFactory);
+        super(session, businessObjectFactory, daoFactory, screeningQuery);
         this.settings = settings;
         this.wellDataLoader =
-                new WellDataLoader(session, businessObjectFactory, daoFactory, settings);
+                new WellDataLoader(session, businessObjectFactory, daoFactory, screeningQuery,
+                        settings);
 
     }
 
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeaturesFromAllExperimentsLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeaturesFromAllExperimentsLoader.java
index 7fc4f354217..97f5b9f5f26 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeaturesFromAllExperimentsLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeaturesFromAllExperimentsLoader.java
@@ -17,7 +17,6 @@
 package ch.systemsx.cisd.openbis.plugin.screening.server.logic;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.apache.commons.lang.time.StopWatch;
@@ -55,7 +54,7 @@ public class MaterialFeaturesFromAllExperimentsLoader extends AbstractContentLoa
     {
         MaterialFeaturesFromAllExperimentsLoader loader =
                 new MaterialFeaturesFromAllExperimentsLoader(session, businessObjectFactory,
-                        daoFactory, settings);
+                        daoFactory, null, settings);
         List<ExperimentReference> experiments =
                 loader.fetchExperiments(materialId, projectTechIdOrNull);
         return loader.loadMaterialFeatureVectorsFromAllAssays(materialId,
@@ -103,11 +102,12 @@ public class MaterialFeaturesFromAllExperimentsLoader extends AbstractContentLoa
 
     private MaterialFeaturesFromAllExperimentsLoader(Session session,
             IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory,
-            MaterialSummarySettings settings)
+            IScreeningQuery screeningQuery, MaterialSummarySettings settings)
     {
-        super(session, businessObjectFactory, daoFactory);
+        super(session, businessObjectFactory, daoFactory, screeningQuery);
         this.wellDataLoader =
-                new WellDataLoader(session, businessObjectFactory, daoFactory, settings);
+                new WellDataLoader(session, businessObjectFactory, daoFactory, screeningQuery,
+                        settings);
     }
 
     /**
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java
index f2e86eee98f..bdbbb2e706e 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java
@@ -99,7 +99,7 @@ public class WellContentLoader extends AbstractContentLoader
             TechId materialId, TechId experimentId)
     {
         WellContentLoader loader =
-                new WellContentLoader(session, businessObjectFactory, daoFactory);
+                new WellContentLoader(session, businessObjectFactory, daoFactory, null);
         return loader.loadLocations(materialId, experimentId);
     }
 
@@ -109,7 +109,7 @@ public class WellContentLoader extends AbstractContentLoader
             TechId materialId)
     {
         final WellContentLoader loader =
-                new WellContentLoader(session, businessObjectFactory, daoFactory);
+                new WellContentLoader(session, businessObjectFactory, daoFactory, null);
         return loader.loadLocations(materialId);
     }
 
@@ -119,7 +119,7 @@ public class WellContentLoader extends AbstractContentLoader
             TechId materialId, TechId projectId)
     {
         final WellContentLoader loader =
-                new WellContentLoader(session, businessObjectFactory, daoFactory);
+                new WellContentLoader(session, businessObjectFactory, daoFactory, null);
         return loader.loadLocationsForProject(materialId, projectId);
     }
 
@@ -134,7 +134,7 @@ public class WellContentLoader extends AbstractContentLoader
     {
         long start = System.currentTimeMillis();
         WellContentLoader loader =
-                new WellContentLoader(session, businessObjectFactory, daoFactory);
+                new WellContentLoader(session, businessObjectFactory, daoFactory, null);
         List<WellContent> locations = loader.loadLocations(materialCriteria);
 
         operationLog.info(String.format("[%d msec] Load %d locations.",
@@ -161,7 +161,7 @@ public class WellContentLoader extends AbstractContentLoader
             TechId materialId, TechId experimentId, MaterialSummarySettings settings)
     {
         WellContentLoader loader =
-                new WellContentLoader(session, businessObjectFactory, daoFactory);
+                new WellContentLoader(session, businessObjectFactory, daoFactory, null);
         List<WellContent> locations = loader.loadLocations(materialId, experimentId);
         locations = loader.enrichWithSingleImageDatasets(locations);
         return annotateWithReplicaLabels(locations, settings);
@@ -277,7 +277,7 @@ public class WellContentLoader extends AbstractContentLoader
             WellSearchCriteria materialCriteria)
     {
         Iterable<WellContentQueryResult> locations =
-                new WellContentLoader(session, businessObjectFactory, daoFactory)
+                new WellContentLoader(session, businessObjectFactory, daoFactory, null)
                         .loadRawLocations(materialCriteria);
         Collection<Long> materialIds = extractMaterialIds(locations);
         return businessObjectFactory.createMaterialLister(session).list(
@@ -296,9 +296,10 @@ public class WellContentLoader extends AbstractContentLoader
     }
 
     private WellContentLoader(Session session,
-            IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory)
+            IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory,
+            IScreeningQuery screeningQuery)
     {
-        super(session, businessObjectFactory, daoFactory);
+        super(session, businessObjectFactory, daoFactory, screeningQuery);
     }
 
     private List<WellContent> enrichWithWellProperties(List<WellContent> locations)
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellDataLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellDataLoader.java
index af7796e0944..a7cfbf7afde 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellDataLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellDataLoader.java
@@ -42,6 +42,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
 import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
 import ch.systemsx.cisd.openbis.plugin.screening.server.IScreeningBusinessObjectFactory;
 import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.BasicWellContentQueryResult;
+import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.IScreeningQuery;
 import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.IWellReference;
 import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.PatternMatchingUtils;
 import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.WellContentQueryResult;
@@ -69,9 +70,9 @@ class WellDataLoader extends AbstractContentLoader
     private final MaterialSummarySettings settings;
 
     public WellDataLoader(Session session, IScreeningBusinessObjectFactory businessObjectFactory,
-            IDAOFactory daoFactory, MaterialSummarySettings settings)
+            IDAOFactory daoFactory, IScreeningQuery screeningQuery, MaterialSummarySettings settings)
     {
-        super(session, businessObjectFactory, daoFactory);
+        super(session, businessObjectFactory, daoFactory, screeningQuery);
         this.settings = settings;
     }
 
@@ -490,7 +491,7 @@ class WellDataLoader extends AbstractContentLoader
     private WellFeatureCollection<FeatureVectorValues> tryLoadWellSingleFeatureVectors(
             Set<PlateIdentifier> plates, AnalysisProcedureCriteria analysisProcedureCriteria)
     {
-        return new WellFeatureCollectionLoader(session, businessObjectFactory, daoFactory)
+        return new WellFeatureCollectionLoader(session, businessObjectFactory, daoFactory, null)
                 .tryLoadWellSingleFeatureVectors(plates, settings.getFeatureCodes(),
                         analysisProcedureCriteria);
     }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellFeatureCollectionLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellFeatureCollectionLoader.java
index d4b83bfbd05..ea81651cfe6 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellFeatureCollectionLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellFeatureCollectionLoader.java
@@ -36,6 +36,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.utils.GroupByMap;
 import ch.systemsx.cisd.openbis.generic.shared.basic.utils.IGroupKeyExtractor;
 import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
 import ch.systemsx.cisd.openbis.plugin.screening.server.IScreeningBusinessObjectFactory;
+import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.IScreeningQuery;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.PlateIdentifier;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.DatasetReference;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.FeatureValue;
@@ -52,9 +53,10 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.IHCSFeatureVecto
 public class WellFeatureCollectionLoader extends AbstractContentLoader
 {
     public WellFeatureCollectionLoader(Session session,
-            IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory)
+            IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory,
+            IScreeningQuery screeningQuery)
     {
-        super(session, businessObjectFactory, daoFactory);
+        super(session, businessObjectFactory, daoFactory, screeningQuery);
     }
 
     /** Loads feature vectors for chosen plates and set of features */
diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AnalysisSettingsTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AnalysisSettingsTest.java
new file mode 100644
index 00000000000..d83b38efea5
--- /dev/null
+++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AnalysisSettingsTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2012 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.plugin.screening.server.logic;
+
+import java.util.Properties;
+
+import org.testng.AssertJUnit;
+import org.testng.annotations.Test;
+
+import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataSetBuilder;
+
+/**
+ * 
+ *
+ * @author Franz-Josef Elmer
+ */
+public class AnalysisSettingsTest extends AssertJUnit
+{
+    @Test
+    public void testNoSettings()
+    {
+        AnalysisSettings analysisSettings = new AnalysisSettings(new Properties());
+        
+        assertEquals(true, analysisSettings.noAnalysisSettings());
+    }
+    
+    @Test
+    public void testInvalidSettings()
+    {
+        Properties properties = new Properties();
+        properties.setProperty(AnalysisSettings.KEY, "TYPE1");
+        try
+        {
+            new AnalysisSettings(properties);
+            fail("ConfigurationFailureException expected");
+        } catch (ConfigurationFailureException ex)
+        {
+            assertEquals(
+                    "Invalid property '" + AnalysisSettings.KEY + "': missing ':' in 'TYPE1'.",
+                    ex.getMessage());
+        }
+    }
+    
+    @Test
+    public void testSettings()
+    {
+        Properties properties = new Properties();
+        properties.setProperty(AnalysisSettings.KEY, "TYPE1:viewer1, TYPE2:viewer2");
+        AnalysisSettings analysisSettings = new AnalysisSettings(properties);
+        
+        assertEquals("viewer1", analysisSettings.tryToGetReportingPluginKey(new DataSetBuilder().type("TYPE1").getDataSet()));
+        assertEquals("viewer2", analysisSettings.tryToGetReportingPluginKey(new DataSetBuilder().type("TYPE2").getDataSet()));
+        assertEquals(null, analysisSettings.tryToGetReportingPluginKey(new DataSetBuilder().type("TYPE3").getDataSet()));
+        assertEquals(false, analysisSettings.noAnalysisSettings());
+    }
+    
+    
+}
diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ExperimentFeatureVectorSummaryLoaderTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ExperimentFeatureVectorSummaryLoaderTest.java
new file mode 100644
index 00000000000..d7906782b9a
--- /dev/null
+++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ExperimentFeatureVectorSummaryLoaderTest.java
@@ -0,0 +1,334 @@
+/*
+ * Copyright 2012 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.plugin.screening.server.logic;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Properties;
+
+import org.jmock.Expectations;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import ch.systemsx.cisd.common.exceptions.UserFailureException;
+import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
+import ch.systemsx.cisd.openbis.generic.shared.AbstractServerTestCase;
+import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelColumnHeader;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelRow;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataSetBuilder;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataStoreBuilder;
+import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
+import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePE;
+import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
+import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
+import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
+import ch.systemsx.cisd.openbis.plugin.screening.server.IScreeningBusinessObjectFactory;
+import ch.systemsx.cisd.openbis.plugin.screening.server.ScreeningServer;
+import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.IScreeningQuery;
+import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ExperimentFeatureVectorSummary;
+import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ExperimentReference;
+import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.MaterialSummarySettings;
+import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ScreeningConstants;
+import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.WellSearchCriteria.AnalysisProcedureCriteria;
+
+/**
+ * @author Franz-Josef Elmer
+ */
+public class ExperimentFeatureVectorSummaryLoaderTest extends AbstractServerTestCase
+{
+    private static final class ExperimentFeatureVectorSummaryLoaderWithNoCalculation extends ExperimentFeatureVectorSummaryLoader
+    {
+        public ExperimentFeatureVectorSummaryLoaderWithNoCalculation(Session session,
+                IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory,
+                IScreeningQuery screeningQuery, MaterialSummarySettings settings)
+        {
+            super(session, businessObjectFactory, daoFactory, screeningQuery, settings);
+        }
+
+        @Override
+        ExperimentFeatureVectorSummary calculatedSummary(TechId experimentId,
+                AnalysisProcedureCriteria analysisProcedureCriteria, ExperimentReference experiment)
+        {
+            return null;
+        }
+    }
+        
+    private static final String DATA_STORE_CODE = "DSS";
+
+    private static final TechId EXPERIMENT_ID = new TechId(42);
+
+    private IScreeningBusinessObjectFactory screeningBOFactory;
+
+    private IScreeningQuery screeningQuery;
+
+    private MaterialSummarySettings materialSummarySettings;
+
+    @BeforeMethod
+    public void beforeMethod()
+    {
+        screeningBOFactory = context.mock(IScreeningBusinessObjectFactory.class);
+        screeningQuery = context.mock(IScreeningQuery.class);
+        materialSummarySettings = ScreeningServer.createDefaultSettings();
+    }
+
+    @Test
+    public void testLoadAnalysisSummaryFromReport()
+    {
+        Properties properties = new Properties();
+        properties.setProperty(AnalysisSettings.KEY, "T1:viewer1");
+        prepareLoadExperiment();
+        DataSet ds1 =
+                new DataSetBuilder().code("ds1").type("T1")
+                        .property(ScreeningConstants.ANALYSIS_PROCEDURE, "extern")
+                        .store(new DataStoreBuilder(DATA_STORE_CODE).getStore()).getDataSet();
+        DataSet ds2 = new DataSetBuilder().code("ds2").type("T2").getDataSet();
+        prepareListDataSetsByExperiment(ds1, ds2);
+        TableModel tabelModel =
+                new TableModel(Collections.<TableModelColumnHeader> emptyList(),
+                        Collections.<TableModelRow> emptyList());
+        prepareCreateReport(tabelModel, "viewer1", ds1);
+
+        ExperimentFeatureVectorSummary summary =
+                createLoaderWithoutCalculation().loadExperimentFeatureVectors(EXPERIMENT_ID,
+                        AnalysisProcedureCriteria.createFromCode("extern"),
+                        new AnalysisSettings(properties));
+
+        assertSame(tabelModel, summary.getTableModelOrNull());
+        context.assertIsSatisfied();
+    }
+
+    @Test
+    public void testLoadAnalysisSummaryFromReportWithFileNotFound()
+    {
+        Properties properties = new Properties();
+        properties.setProperty(AnalysisSettings.KEY, "T1:viewer1");
+        prepareLoadExperiment();
+        DataSet ds1 =
+                new DataSetBuilder().code("ds1").type("T1")
+                        .property(ScreeningConstants.ANALYSIS_PROCEDURE, "extern")
+                        .store(new DataStoreBuilder(DATA_STORE_CODE).getStore()).getDataSet();
+        prepareListDataSetsByExperiment(ds1);
+        prepareCreateReportFails(new UserFailureException("Main TSV file could not be found."),
+                "viewer1", ds1);
+
+        try
+        {
+            createLoaderWithoutCalculation().loadExperimentFeatureVectors(EXPERIMENT_ID,
+                    AnalysisProcedureCriteria.createFromCode("extern"),
+                    new AnalysisSettings(properties));
+            fail("UserFailureException expected");
+        } catch (UserFailureException ex)
+        {
+            assertEquals("Analysis summary for data set ds1 couldn't retrieved from "
+                    + "Data Store Server. Reason: Main TSV file could not be found.\n" + "\n"
+                    + "Hint: The file pattern for the data set type T1 might be wrong.",
+                    ex.getMessage());
+        }
+
+        context.assertIsSatisfied();
+    }
+
+    @Test
+    public void testLoadAnalysisSummaryFromReportWithOtherUserFailureException()
+    {
+        Properties properties = new Properties();
+        properties.setProperty(AnalysisSettings.KEY, "T1:viewer1");
+        prepareLoadExperiment();
+        DataSet ds1 =
+                new DataSetBuilder().code("ds1").type("T1")
+                .property(ScreeningConstants.ANALYSIS_PROCEDURE, "extern")
+                .store(new DataStoreBuilder(DATA_STORE_CODE).getStore()).getDataSet();
+        prepareListDataSetsByExperiment(ds1);
+        prepareCreateReportFails(new UserFailureException("Oohps!"), "viewer1", ds1);
+
+        try
+        {
+            createLoaderWithoutCalculation().loadExperimentFeatureVectors(EXPERIMENT_ID,
+                    AnalysisProcedureCriteria.createFromCode("extern"),
+                    new AnalysisSettings(properties));
+            fail("UserFailureException expected");
+        } catch (UserFailureException ex)
+        {
+            assertEquals("Analysis summary for data set ds1 couldn't retrieved from "
+                    + "Data Store Server. Reason: Oohps!",
+                    ex.getMessage());
+        }
+        
+        context.assertIsSatisfied();
+    }
+    
+    @Test
+    public void testLoadAnalysisSummaryFromReportWithOtherException()
+    {
+        Properties properties = new Properties();
+        properties.setProperty(AnalysisSettings.KEY, "T1:viewer1");
+        prepareLoadExperiment();
+        DataSet ds1 =
+                new DataSetBuilder().code("ds1").type("T1")
+                .property(ScreeningConstants.ANALYSIS_PROCEDURE, "extern")
+                .store(new DataStoreBuilder(DATA_STORE_CODE).getStore()).getDataSet();
+        prepareListDataSetsByExperiment(ds1);
+        prepareCreateReportFails(new IllegalArgumentException("Oohps!"), "viewer1", ds1);
+        
+        try
+        {
+            createLoaderWithoutCalculation().loadExperimentFeatureVectors(EXPERIMENT_ID,
+                    AnalysisProcedureCriteria.createFromCode("extern"),
+                    new AnalysisSettings(properties));
+            fail("UserFailureException expected");
+        } catch (UserFailureException ex)
+        {
+            assertEquals("Analysis summary for data set ds1 couldn't retrieved from "
+                    + "Data Store Server. See server logs for the reason.",
+                    ex.getMessage());
+        }
+        
+        context.assertIsSatisfied();
+    }
+    
+    @Test
+    public void testLoadAnalysisForMoreThanOne()
+    {
+        Properties properties = new Properties();
+        properties.setProperty(AnalysisSettings.KEY, "T1:viewer1");
+        prepareLoadExperiment();
+        DataSet ds1 =
+                new DataSetBuilder().code("ds1").type("T1")
+                        .property(ScreeningConstants.ANALYSIS_PROCEDURE, "extern").getDataSet();
+        DataSet ds2 =
+                new DataSetBuilder().code("ds2").type("T1")
+                        .property(ScreeningConstants.ANALYSIS_PROCEDURE, "extern").getDataSet();
+        prepareListDataSetsByExperiment(ds1, ds2);
+
+        ExperimentFeatureVectorSummary summary =
+                createLoaderWithoutCalculation().loadExperimentFeatureVectors(EXPERIMENT_ID,
+                        AnalysisProcedureCriteria.createFromCode("extern"),
+                        new AnalysisSettings(properties));
+
+        assertEquals(null, summary);
+        context.assertIsSatisfied();
+    }
+
+    @Test
+    public void testLoadAnalysisForWrongAnalysisProcedure()
+    {
+        Properties properties = new Properties();
+        properties.setProperty(AnalysisSettings.KEY, "T1:viewer1");
+        prepareLoadExperiment();
+        DataSet ds1 =
+                new DataSetBuilder().code("ds1").type("T1")
+                        .property(ScreeningConstants.ANALYSIS_PROCEDURE, "extern")
+                        .store(new DataStoreBuilder(DATA_STORE_CODE).getStore()).getDataSet();
+        DataSet ds2 = new DataSetBuilder().code("ds2").type("T2").getDataSet();
+        prepareListDataSetsByExperiment(ds1, ds2);
+
+        ExperimentFeatureVectorSummary summary =
+                createLoaderWithoutCalculation().loadExperimentFeatureVectors(EXPERIMENT_ID,
+                        AnalysisProcedureCriteria.createFromCode("intern"),
+                        new AnalysisSettings(properties));
+
+        assertEquals(null, summary);
+        context.assertIsSatisfied();
+    }
+
+    @Test
+    public void testLoadAnalysisForNoAnalysisSetting()
+    {
+        Properties properties = new Properties();
+        prepareLoadExperiment();
+        
+        ExperimentFeatureVectorSummary summary = createLoaderWithoutCalculation().loadExperimentFeatureVectors(EXPERIMENT_ID,
+                AnalysisProcedureCriteria.createFromCode("extern"), new AnalysisSettings(properties));
+        
+        assertEquals(null, summary);
+        context.assertIsSatisfied();
+    }
+    
+    private ExperimentFeatureVectorSummaryLoader createLoaderWithoutCalculation()
+    {
+        return new ExperimentFeatureVectorSummaryLoaderWithNoCalculation(SESSION,
+                screeningBOFactory, daoFactory, screeningQuery, materialSummarySettings);
+    }
+    
+    private void prepareLoadExperiment()
+    {
+        context.checking(new Expectations()
+            {
+                {
+                    one(experimentDAO).tryGetByTechId(EXPERIMENT_ID);
+                    ExperimentPE experiment = new ExperimentPE();
+                    experiment.setId(EXPERIMENT_ID.getId());
+                    experiment.setPermId("123-" + EXPERIMENT_ID);
+                    experiment.setExperimentType(new ExperimentTypePE());
+                    ProjectPE project = new ProjectPE();
+                    project.setSpace(new SpacePE());
+                    experiment.setProject(project);
+                    will(returnValue(experiment));
+                }
+            });
+    }
+    
+    private void prepareListDataSetsByExperiment(final DataSet... dataSets)
+    {
+        context.checking(new Expectations()
+            {
+                {
+                    one(screeningBOFactory).createDatasetLister(SESSION);
+                    will(returnValue(datasetLister));
+                    
+                    one(datasetLister).listByExperimentTechId(EXPERIMENT_ID, true);
+                    will(returnValue(Arrays.asList(dataSets)));
+                }
+            });
+    }
+
+    private void prepareCreateReport(final TableModel report, final String reportingPluginKey,
+            final DataSet dataSet)
+    {
+        context.checking(new Expectations()
+            {
+                {
+                    one(screeningBOFactory).createDataSetTable(SESSION);
+                    will(returnValue(dataSetTable));
+
+                    one(dataSetTable).createReportFromDatasets(reportingPluginKey, DATA_STORE_CODE,
+                            Arrays.asList(dataSet.getCode()));
+                    will(returnValue(report));
+                }
+            });
+    }
+    
+    private void prepareCreateReportFails(final Exception exception, final String reportingPluginKey,
+            final DataSet dataSet)
+    {
+        context.checking(new Expectations()
+            {
+                {
+                    one(screeningBOFactory).createDataSetTable(SESSION);
+                    will(returnValue(dataSetTable));
+
+                    one(dataSetTable).createReportFromDatasets(reportingPluginKey, DATA_STORE_CODE,
+                            Arrays.asList(dataSet.getCode()));
+                    will(throwException(exception));
+                }
+            });
+    }
+
+}
diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeatureVectorSummaryLoaderTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeatureVectorSummaryLoaderTest.java
index 3bdb054b34d..9da51222ca1 100644
--- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeatureVectorSummaryLoaderTest.java
+++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/MaterialFeatureVectorSummaryLoaderTest.java
@@ -80,7 +80,7 @@ public class MaterialFeatureVectorSummaryLoaderTest extends AssertJUnit
                 Arrays.asList(new CodeAndLabel("A", "A"), new CodeAndLabel("B", "B"));
 
         MaterialAllReplicasFeatureVectors featureVectors =
-                new MaterialFeatureVectorSummaryLoader(null, null, null, settings)
+                new MaterialFeatureVectorSummaryLoader(null, null, null, null, settings)
                         .createMaterialFeatureVectors(new TechId(replId), wellDataList, null,
                                 featuresDesc);
 
-- 
GitLab