From 704fa0150c2e976f6cd4dd53a2e4a75a544c9b3c Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Wed, 7 Jul 2010 10:24:26 +0000
Subject: [PATCH] LMS-1622 providing data source by DSS code instead of data
 set code

SVN: 16919
---
 .../IScreeningBusinessObjectFactory.java      |  3 ++-
 .../ScreeningBusinessObjectFactory.java       |  6 +++--
 .../dataaccess/IScreeningDAOFactory.java      |  2 +-
 .../dataaccess/db/ScreeningDAOFactory.java    | 12 +++++----
 .../logic/GenePlateLocationsLoader.java       | 26 ++++++++++++-------
 .../server/logic/PlateContentLoader.java      |  2 +-
 6 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/IScreeningBusinessObjectFactory.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/IScreeningBusinessObjectFactory.java
index 97248a938d6..4af7433834f 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/IScreeningBusinessObjectFactory.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/IScreeningBusinessObjectFactory.java
@@ -24,6 +24,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO;
 import ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister.IDatasetLister;
 import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.IMaterialLister;
 import ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.ISampleLister;
+import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.IHCSDatasetLoader;
 
@@ -34,7 +35,7 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.IHCSDatasetLoade
  */
 public interface IScreeningBusinessObjectFactory
 {
-    public IHCSDatasetLoader createHCSDatasetLoader(final String datasetPermId);
+    public IHCSDatasetLoader createHCSDatasetLoader(final ExternalDataPE dataSet);
 
     public ISampleBO createSampleBO(final Session session);
 
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningBusinessObjectFactory.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningBusinessObjectFactory.java
index 94b91bfaad9..75439defbcc 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningBusinessObjectFactory.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningBusinessObjectFactory.java
@@ -28,6 +28,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO;
 import ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister.IDatasetLister;
 import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.IMaterialLister;
 import ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.ISampleLister;
+import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
 import ch.systemsx.cisd.openbis.plugin.AbstractPluginBusinessObjectFactory;
 import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.IScreeningDAOFactory;
@@ -52,9 +53,10 @@ public final class ScreeningBusinessObjectFactory extends AbstractPluginBusiness
     {
     }
 
-    public final IHCSDatasetLoader createHCSDatasetLoader(final String datasetPermId)
+    public IHCSDatasetLoader createHCSDatasetLoader(ExternalDataPE dataSet)
     {
-        return new HCSDatasetLoader(specificDAOFactory.getImagingQueryDAO(datasetPermId), datasetPermId);
+        String dssCode = dataSet.getDataStore().getCode();
+        return new HCSDatasetLoader(specificDAOFactory.getImagingQueryDAO(dssCode), dataSet.getCode());
     }
 
     public final ISampleBO createSampleBO(final Session session)
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/IScreeningDAOFactory.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/IScreeningDAOFactory.java
index bf74bea5e8e..f3b0d4d1286 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/IScreeningDAOFactory.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/IScreeningDAOFactory.java
@@ -25,5 +25,5 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.IImag
  */
 public interface IScreeningDAOFactory
 {
-    public IImagingQueryDAO getImagingQueryDAO(String datasetPermId);
+    public IImagingQueryDAO getImagingQueryDAO(String dssCode);
 }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/db/ScreeningDAOFactory.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/db/ScreeningDAOFactory.java
index f8abfc1f196..c7dbaaafb5a 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/db/ScreeningDAOFactory.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/db/ScreeningDAOFactory.java
@@ -42,8 +42,9 @@ public class ScreeningDAOFactory implements IScreeningDAOFactory
             LogFactory.getLogger(LogCategory.OPERATION, ScreeningDAOFactory.class);
 
     private final IDataSourceProvider dataSourceProvider;
-    
-    private final Map<DataSource, IImagingQueryDAO> daos = new HashMap<DataSource, IImagingQueryDAO>();
+
+    private final Map<DataSource, IImagingQueryDAO> daos =
+            new HashMap<DataSource, IImagingQueryDAO>();
 
     public ScreeningDAOFactory(IDataSourceProvider dataSourceProvider)
     {
@@ -51,13 +52,14 @@ public class ScreeningDAOFactory implements IScreeningDAOFactory
         if (operationLog.isInfoEnabled())
         {
             operationLog.info("DAO factory for Screening created. Data source provider: "
-                    + dataSourceProvider.getClass());
+                    + dataSourceProvider.getClass().getName());
         }
     }
 
-    public IImagingQueryDAO getImagingQueryDAO(String datasetPermId)
+    public IImagingQueryDAO getImagingQueryDAO(String dssCode)
     {
-        DataSource dataSource = dataSourceProvider.getDataSourceByDataSetCode(datasetPermId, TECHNOLOGY);
+        DataSource dataSource =
+                dataSourceProvider.getDataSourceByDataStoreServerCode(dssCode, TECHNOLOGY);
         IImagingQueryDAO dao = daos.get(dataSource);
         if (dao == null)
         {
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/GenePlateLocationsLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/GenePlateLocationsLoader.java
index 3db21a5002b..6423a27e8ae 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/GenePlateLocationsLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/GenePlateLocationsLoader.java
@@ -197,27 +197,33 @@ public class GenePlateLocationsLoader
     }
 
     private Map<String/* dataset code */, PlateImageParameters> loadImagesReport(
-            List<ExternalDataPE> usedDatasets)
+            List<ExternalDataPE> usedDataSets)
     {
-        List<String> datasetCodes = extractDatasetCodes(usedDatasets);
         List<PlateImageParameters> imageParameters = new ArrayList<PlateImageParameters>();
-        for (String datasetCode : datasetCodes)
+        List<ExternalDataPE> distinctDataSets = getDistinctDataSets(usedDataSets);
+        for (ExternalDataPE dataSet : distinctDataSets)
         {
             final IHCSDatasetLoader loader =
-                    businessObjectFactory.createHCSDatasetLoader(datasetCode);
+                    businessObjectFactory.createHCSDatasetLoader(dataSet);
             imageParameters.add(PlateImageParametersFactory.create(loader));
         }
         return asDatasetToParamsMap(imageParameters);
     }
-
-    private static List<String> extractDatasetCodes(List<ExternalDataPE> usedDatasets)
+    
+    private List<ExternalDataPE> getDistinctDataSets(List<ExternalDataPE> usedDataSets)
     {
-        Set<String> codes = new HashSet<String>();
-        for (ExternalDataPE dataset : usedDatasets)
+        List<ExternalDataPE> result = new ArrayList<ExternalDataPE>();
+        Set<String> dataSetCodes = new HashSet<String>();
+        for (ExternalDataPE dataSet : usedDataSets)
         {
-            codes.add(dataset.getCode());
+            String code = dataSet.getCode();
+            if (dataSetCodes.contains(code) == false)
+            {
+                dataSetCodes.add(code);
+                result.add(dataSet);
+            }
         }
-        return new ArrayList<String>(codes);
+        return result;
     }
 
     private static Map<String/* dataset code */, PlateImageParameters> asDatasetToParamsMap(
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/PlateContentLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/PlateContentLoader.java
index 08f94ca9fb7..aedef42cfdd 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/PlateContentLoader.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/PlateContentLoader.java
@@ -273,7 +273,7 @@ public class PlateContentLoader
             IExternalDataTable externalDataTable)
     {
         final IHCSDatasetLoader loader =
-                businessObjectFactory.createHCSDatasetLoader(dataset.getCode());
+                businessObjectFactory.createHCSDatasetLoader(dataset);
         return PlateImageParametersFactory.create(loader);
     }
 
-- 
GitLab