From cefba98e47b1b3fd204939a0bb30ba13126eb49a Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Thu, 7 Apr 2011 09:02:05 +0000
Subject: [PATCH] [LMS-2171] minor: introduced encapsulation of data set
 location and code to reduce dependency from DatasetDescription in
 DataSetDirectoryProvider

SVN: 20695
---
 .../server/DataSetDirectoryProvider.java      | 12 ++--
 .../shared/IDataSetDirectoryProvider.java     | 12 ++--
 .../generic/server/UploadingCommandTest.java  | 21 +++----
 .../MockDataSetDirectoryProvider.java         |  7 ++-
 .../shared/dto/DatasetDescription.java        |  2 +-
 .../generic/shared/dto/DatasetLocation.java   | 60 +++++++++++++++++++
 .../generic/shared/dto/IDatasetLocation.java  | 29 +++++++++
 7 files changed, 118 insertions(+), 25 deletions(-)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DatasetLocation.java
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/IDatasetLocation.java

diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataSetDirectoryProvider.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataSetDirectoryProvider.java
index 0d9e7a70a41..bf4974d400c 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataSetDirectoryProvider.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataSetDirectoryProvider.java
@@ -20,22 +20,24 @@ import java.io.File;
 
 import ch.systemsx.cisd.openbis.dss.generic.shared.IDataSetDirectoryProvider;
 import ch.systemsx.cisd.openbis.dss.generic.shared.IShareIdManager;
-import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
+import ch.systemsx.cisd.openbis.generic.shared.dto.IDatasetLocation;
 
 /**
  * Implementation of {@link IDataSetDirectoryProvider}.
- *
+ * 
  * @author Franz-Josef Elmer
  */
 public class DataSetDirectoryProvider implements IDataSetDirectoryProvider
 {
     private final File storeRoot;
+
     private final IShareIdManager shareIdManager;
 
-    public DataSetDirectoryProvider(File storeRoot, IShareIdManager shareIdManager){
+    public DataSetDirectoryProvider(File storeRoot, IShareIdManager shareIdManager)
+    {
         this.storeRoot = storeRoot;
         this.shareIdManager = shareIdManager;
-        
+
     }
 
     public File getStoreRoot()
@@ -43,7 +45,7 @@ public class DataSetDirectoryProvider implements IDataSetDirectoryProvider
         return storeRoot;
     }
 
-    public File getDataSetDirectory(DatasetDescription dataSet)
+    public File getDataSetDirectory(IDatasetLocation dataSet)
     {
         String location = dataSet.getDataSetLocation();
         location = location.replace("\\", File.separator);
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/IDataSetDirectoryProvider.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/IDataSetDirectoryProvider.java
index 9f3e0f8c768..11058b2df37 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/IDataSetDirectoryProvider.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/IDataSetDirectoryProvider.java
@@ -18,11 +18,11 @@ package ch.systemsx.cisd.openbis.dss.generic.shared;
 
 import java.io.File;
 
-import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
+import ch.systemsx.cisd.openbis.generic.shared.dto.IDatasetLocation;
 
 /**
  * Provider of the root directory of a data set in the data store.
- *
+ * 
  * @author Franz-Josef Elmer
  */
 public interface IDataSetDirectoryProvider
@@ -31,15 +31,15 @@ public interface IDataSetDirectoryProvider
      * Returns the root directory of data store.
      */
     public File getStoreRoot();
-    
+
     /**
      * Returns the root directory of specified data set.
      */
-    public File getDataSetDirectory(DatasetDescription dataSet);
+    public File getDataSetDirectory(IDatasetLocation dataSet);
 
     /**
-     * Returns the share id manager which is used for
-     * {@link #getDataSetDirectory(DatasetDescription)}.
+     * Returns the share id manager which is used for {@link #getDataSetDirectory(IDatasetLocation)}
+     * .
      */
     public IShareIdManager getShareIdManager();
 }
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommandTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommandTest.java
index fca455531a9..cad37fc4d9f 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommandTest.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommandTest.java
@@ -57,11 +57,11 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetTypePE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUploadContext;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DataStorePE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
 import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE;
 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.ExternalDataPE;
+import ch.systemsx.cisd.openbis.generic.shared.dto.IDatasetLocation;
 import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
@@ -75,9 +75,11 @@ import ch.systemsx.cisd.openbis.generic.shared.translator.ExternalDataTranslator
 public class UploadingCommandTest extends AssertJUnit
 {
     private static final File TEST_FOLDER = new File("targets/upload-test");
+
     private static final File STORE = new File(TEST_FOLDER, "store");
+
     private static final String SHARE_ID = "share-id";
-    
+
     private static final class MockDataSetDirectoryProvider implements IDataSetDirectoryProvider
     {
         public File getStoreRoot()
@@ -85,7 +87,7 @@ public class UploadingCommandTest extends AssertJUnit
             return STORE;
         }
 
-        public File getDataSetDirectory(DatasetDescription dataSet)
+        public File getDataSetDirectory(IDatasetLocation dataSet)
         {
             return new File(new File(getStoreRoot(), SHARE_ID), dataSet.getDataSetLocation());
         }
@@ -95,7 +97,7 @@ public class UploadingCommandTest extends AssertJUnit
             return null;
         }
     }
-    
+
     private static final String ZIP_FILENAME = "myData";
 
     private static final String INFO_UPLOAD_PREFIX = "INFO  OPERATION.UploadingCommand - ";
@@ -104,8 +106,6 @@ public class UploadingCommandTest extends AssertJUnit
 
     private static final String INFO_MAIL_PREFIX = "INFO  OPERATION.MailClient - ";
 
-
-
     private static final File TMP = new File(STORE, "tmp");
 
     private static final File EMAILS = new File(TEST_FOLDER, "emails");
@@ -143,6 +143,7 @@ public class UploadingCommandTest extends AssertJUnit
     private UploadingCommand commandAdminSessionNotAuthenticated;
 
     private File ds2;
+
     private IDataSetDirectoryProvider directoryProvider;
 
     @BeforeMethod
@@ -532,8 +533,8 @@ public class UploadingCommandTest extends AssertJUnit
                         + "experiment\texperiment_code\texp1\n"
                         + "experiment\texperiment_type_code\tE\n"
                         + "experiment\tregistration_timestamp\t1970-01-01 01:00:00 +0100\n"
-                        + "experiment\tregistrator\tCharles Darwin <cd@cd.org>\n", outputStream
-                        .toString());
+                        + "experiment\tregistrator\tCharles Darwin <cd@cd.org>\n",
+                        outputStream.toString());
             } catch (AssertionError err)
             {
                 // We have an ambiguity here: sometimes we get "parent1,parent2", sometimes we get
@@ -546,8 +547,8 @@ public class UploadingCommandTest extends AssertJUnit
                         + "experiment\texperiment_code\texp1\n"
                         + "experiment\texperiment_type_code\tE\n"
                         + "experiment\tregistration_timestamp\t1970-01-01 01:00:00 +0100\n"
-                        + "experiment\tregistrator\tCharles Darwin <cd@cd.org>\n", outputStream
-                        .toString());
+                        + "experiment\tregistrator\tCharles Darwin <cd@cd.org>\n",
+                        outputStream.toString());
             }
         } finally
         {
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/MockDataSetDirectoryProvider.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/MockDataSetDirectoryProvider.java
index 28bc5c797b8..5ada671acee 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/MockDataSetDirectoryProvider.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/MockDataSetDirectoryProvider.java
@@ -20,11 +20,12 @@ import java.io.File;
 
 import ch.systemsx.cisd.openbis.dss.generic.shared.IDataSetDirectoryProvider;
 import ch.systemsx.cisd.openbis.dss.generic.shared.IShareIdManager;
-import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
+import ch.systemsx.cisd.openbis.generic.shared.dto.IDatasetLocation;
 
 public final class MockDataSetDirectoryProvider implements IDataSetDirectoryProvider
 {
     private final File store;
+
     private final String shareID;
 
     public MockDataSetDirectoryProvider(File store, String shareID)
@@ -32,13 +33,13 @@ public final class MockDataSetDirectoryProvider implements IDataSetDirectoryProv
         this.store = store;
         this.shareID = shareID;
     }
-    
+
     public File getStoreRoot()
     {
         return store;
     }
 
-    public File getDataSetDirectory(DatasetDescription dataSet)
+    public File getDataSetDirectory(IDatasetLocation dataSet)
     {
         return new File(new File(getStoreRoot(), shareID), dataSet.getDataSetLocation());
     }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DatasetDescription.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DatasetDescription.java
index fc89df467d8..fe056be9acd 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DatasetDescription.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DatasetDescription.java
@@ -25,7 +25,7 @@ import java.util.List;
  * 
  * @author Tomasz Pylak
  */
-public class DatasetDescription implements Serializable
+public class DatasetDescription implements Serializable, IDatasetLocation
 {
     private static final long serialVersionUID = 20L;
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DatasetLocation.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DatasetLocation.java
new file mode 100644
index 00000000000..12b32cf3830
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DatasetLocation.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2009 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.generic.shared.dto;
+
+import java.io.Serializable;
+
+/**
+ * Encapsulates location and code of a data set in a store.
+ * 
+ * @author Piotr Buczek
+ */
+public class DatasetLocation implements IDatasetLocation, Serializable
+{
+    private static final long serialVersionUID = 20L;
+
+    private String datasetCode;
+
+    private String dataSetLocation;
+
+    public String getDataSetLocation()
+    {
+        return dataSetLocation;
+    }
+
+    public void setDataSetLocation(String dataSetLocation)
+    {
+        this.dataSetLocation = dataSetLocation;
+    }
+
+    public String getDatasetCode()
+    {
+        return datasetCode;
+    }
+
+    public void setDatasetCode(String datasetCode)
+    {
+        this.datasetCode = datasetCode;
+    }
+
+    @Override
+    public String toString()
+    {
+        return String.format("Dataset '%s' location '%s'", datasetCode, dataSetLocation);
+    }
+
+}
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/IDatasetLocation.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/IDatasetLocation.java
new file mode 100644
index 00000000000..92c4dcf118c
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/IDatasetLocation.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 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.generic.shared.dto;
+
+/**
+ * Encapsulates location and code of a data set in a store.
+ * 
+ * @author Piotr Buczek
+ */
+public interface IDatasetLocation
+{
+    String getDataSetLocation();
+
+    String getDatasetCode();
+}
-- 
GitLab