From 1b4c91279ee600d2ce973ae91bd54b3c868e64b2 Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Thu, 27 May 2010 14:12:07 +0000
Subject: [PATCH] LMS-1503 Work on the put method.

SVN: 16174
---
 .../dss/client/api/cli/CommandGet.java        |  2 +-
 .../server/api/v1/DssServiceRpcGeneric.java   | 23 ++++++-
 .../api/v1/FileInfoDssBuilder.java            | 21 +++----
 .../generic/shared/api/v1/FileInfoDssDTO.java | 48 +++-----------
 .../shared/api/v1/FileReferenceDTO.java       | 58 +++++++++++++++++
 .../shared/api/v1/IDssServiceRpcGeneric.java  | 45 +++++++++++++-
 .../generic/shared/api/v1/NewDatasetDTO.java  | 62 +++++++++++++++++++
 7 files changed, 202 insertions(+), 57 deletions(-)
 rename datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/{shared => server}/api/v1/FileInfoDssBuilder.java (88%)
 create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileReferenceDTO.java
 create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/NewDatasetDTO.java

diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/cli/CommandGet.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/cli/CommandGet.java
index c121be4bae4..0bb5ad827ac 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/cli/CommandGet.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/cli/CommandGet.java
@@ -33,7 +33,7 @@ import ch.systemsx.cisd.openbis.dss.client.api.v1.IDssComponent;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.FileInfoDssDTO;
 
 /**
- * Comand that lists files in the data set.
+ * Command that lists files in the data set.
  * 
  * @author Chandrasekhar Ramakrishnan
  */
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/DssServiceRpcGeneric.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/DssServiceRpcGeneric.java
index d6aa583b5ee..14da6f0f72f 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/DssServiceRpcGeneric.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/DssServiceRpcGeneric.java
@@ -25,9 +25,10 @@ import java.util.ArrayList;
 import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked;
 import ch.systemsx.cisd.openbis.dss.generic.server.AbstractDssServiceRpc;
 import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
-import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.FileInfoDssBuilder;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.FileInfoDssDTO;
+import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.FileReferenceDTO;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric;
+import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.NewDatasetDTO;
 
 /**
  * Implementation of the generic RPC interface.
@@ -85,6 +86,12 @@ public class DssServiceRpcGeneric extends AbstractDssServiceRpc implements IDssS
         }
     }
 
+    public void putDataSet(String sessionToken, NewDatasetDTO newDataSet)
+            throws IOExceptionUnchecked, IllegalArgumentException
+    {
+
+    }
+
     public int getMajorVersion()
     {
         return 1;
@@ -113,4 +120,18 @@ public class DssServiceRpcGeneric extends AbstractDssServiceRpc implements IDssS
         FileInfoDssBuilder factory = new FileInfoDssBuilder(dataSetRoot, listingRoot);
         factory.appendFileInfosForFile(requestedFile, list, isRecursive);
     }
+
+    public InputStream getFileForDataSet(String sessionToken, FileReferenceDTO fileOrFolder)
+            throws IOExceptionUnchecked, IllegalArgumentException
+    {
+        return this.getFileForDataSet(sessionToken, fileOrFolder.getDataSetCode(), fileOrFolder
+                .getPath());
+    }
+
+    public FileInfoDssDTO[] listFilesForDataSet(String sessionToken, FileReferenceDTO fileOrFolder)
+            throws IOExceptionUnchecked, IllegalArgumentException
+    {
+        return this.listFilesForDataSet(sessionToken, fileOrFolder.getDataSetCode(), fileOrFolder
+                .getPath(), fileOrFolder.isRecursive());
+    }
 }
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssBuilder.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/FileInfoDssBuilder.java
similarity index 88%
rename from datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssBuilder.java
rename to datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/FileInfoDssBuilder.java
index c8205f8bb1e..c0f46154c3e 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssBuilder.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/FileInfoDssBuilder.java
@@ -14,12 +14,14 @@
  * limitations under the License.
  */
 
-package ch.systemsx.cisd.openbis.dss.generic.shared.api.v1;
+package ch.systemsx.cisd.openbis.dss.generic.server.api.v1;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 
+import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.FileInfoDssDTO;
+
 /**
  * Helper Class for creating FileInfoDss objects
  * 
@@ -87,19 +89,10 @@ public class FileInfoDssBuilder
 
     private FileInfoDssDTO fileInfoForFile(File file) throws IOException
     {
-        FileInfoDssDTO fileInfo = new FileInfoDssDTO();
-
-        fileInfo.setPathInDataSet(pathRelativeToDataSetRoot(file));
-        fileInfo.setPathInListing(pathRelativeToListingRoot(file));
-        fileInfo.setDirectory(file.isDirectory());
-        if (fileInfo.isDirectory())
-        {
-            fileInfo.setFileSize(-1);
-        } else
-        {
-            fileInfo.setFileSize(file.length());
-        }
-
+        FileInfoDssDTO fileInfo =
+                new FileInfoDssDTO(pathRelativeToDataSetRoot(file),
+                        pathRelativeToListingRoot(file), file.isDirectory(),
+                        (file.isDirectory()) ? -1 : file.length());
         return fileInfo;
     }
 
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssDTO.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssDTO.java
index 20c10bb6de6..dfcf1ead8dd 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssDTO.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssDTO.java
@@ -27,17 +27,21 @@ public class FileInfoDssDTO implements Serializable
 {
     private static final long serialVersionUID = 1L;
 
-    private String pathInDataSet;
+    private final String pathInDataSet;
 
-    private String pathInListing;
+    private final String pathInListing;
 
-    private boolean isDirectory;
+    private final boolean isDirectory;
 
-    private long fileSize;
+    private final long fileSize;
 
-    FileInfoDssDTO()
+    public FileInfoDssDTO(String pathInDataSet, String pathInListing, boolean isDirectory,
+            long fileSize)
     {
-
+        this.pathInDataSet = pathInDataSet;
+        this.pathInListing = pathInListing;
+        this.isDirectory = isDirectory;
+        this.fileSize = fileSize;
     }
 
     /**
@@ -73,38 +77,6 @@ public class FileInfoDssDTO implements Serializable
         return fileSize;
     }
 
-    /**
-     * Package-visible method for configuring instances.
-     */
-    void setPathInDataSet(String pathInDataSet)
-    {
-        this.pathInDataSet = pathInDataSet;
-    }
-
-    /**
-     * Package-visible method for configuring instances.
-     */
-    void setPathInListing(String relativePath)
-    {
-        this.pathInListing = relativePath;
-    }
-
-    /**
-     * Package-visible method for configuring instances.
-     */
-    void setDirectory(boolean isDirectory)
-    {
-        this.isDirectory = isDirectory;
-    }
-
-    /**
-     * Package-visible method for configuring instances.
-     */
-    void setFileSize(long fileSize)
-    {
-        this.fileSize = fileSize;
-    }
-
     @Override
     public String toString()
     {
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileReferenceDTO.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileReferenceDTO.java
new file mode 100644
index 00000000000..85e6c285246
--- /dev/null
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileReferenceDTO.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2010 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.dss.generic.shared.api.v1;
+
+import java.io.Serializable;
+
+/**
+ * Represents a reference to a file/path within a data set.
+ * 
+ * @author Chandrasekhar Ramakrishnan
+ */
+public class FileReferenceDTO implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    private final String dataSetCode;
+
+    private final String path;
+
+    private final boolean isRecursive;
+
+    public FileReferenceDTO(String dataSetCode, String path, boolean isRecursive)
+    {
+        this.dataSetCode = dataSetCode;
+        this.path = path;
+        this.isRecursive = isRecursive;
+    }
+
+    public String getDataSetCode()
+    {
+        return dataSetCode;
+    }
+
+    public String getPath()
+    {
+        return path;
+    }
+
+    public boolean isRecursive()
+    {
+        return isRecursive;
+    }
+
+}
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/IDssServiceRpcGeneric.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/IDssServiceRpcGeneric.java
index 51bdc10b215..5557b9245ec 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/IDssServiceRpcGeneric.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/IDssServiceRpcGeneric.java
@@ -33,19 +33,58 @@ public interface IDssServiceRpcGeneric extends IRpcService
     /**
      * Get an array of FileInfoDss objects that describe the file-system structure of the data set.
      * 
+     * @param sessionToken The session token
+     * @param fileOrFolder The file or folder to get information on
+     * @throws IOExceptionUnchecked Thrown if an IOException occurs when listing the files
+     * @throws IllegalArgumentException Thrown if the dataSetCode or startPath are not valid
+     */
+    public FileInfoDssDTO[] listFilesForDataSet(String sessionToken, FileReferenceDTO fileOrFolder)
+            throws IOExceptionUnchecked, IllegalArgumentException;
+
+    /**
+     * Get an array of FileInfoDss objects that describe the file-system structure of the data set.
+     * 
+     * @param sessionToken The session token
+     * @param fileOrFolder The file or folder to retrieve
+     * @throws IOExceptionUnchecked Thrown if an IOException occurs when listing the files
+     * @throws IllegalArgumentException Thrown if the dataSetCode or startPath are not valid
+     */
+    public InputStream getFileForDataSet(String sessionToken, FileReferenceDTO fileOrFolder)
+            throws IOExceptionUnchecked, IllegalArgumentException;
+
+    /**
+     * Get an array of FileInfoDss objects that describe the file-system structure of the data set.
+     * 
+     * @param sessionToken The session token
+     * @param dataSetCode The data set to retrieve file information about
+     * @param path The path within the data set to retrieve file information about
+     * @param isRecursive Should the result include information for sub folders?
      * @throws IOExceptionUnchecked Thrown if an IOException occurs when listing the files
      * @throws IllegalArgumentException Thrown if the dataSetCode or startPath are not valid
      */
     public FileInfoDssDTO[] listFilesForDataSet(String sessionToken, String dataSetCode,
-            String startPath, boolean isRecursive) throws IOExceptionUnchecked,
-            IllegalArgumentException;
+            String path, boolean isRecursive) throws IOExceptionUnchecked, IllegalArgumentException;
 
     /**
      * Get an array of FileInfoDss objects that describe the file-system structure of the data set.
      * 
+     * @param sessionToken The session token
+     * @param dataSetCode The data set to retrieve file from
+     * @param path The path within the data set to retrieve file information about
+     * @throws IOExceptionUnchecked Thrown if an IOException occurs when listing the files
+     * @throws IllegalArgumentException Thrown if the dataSetCode or startPath are not valid
+     */
+    public InputStream getFileForDataSet(String sessionToken, String dataSetCode, String path)
+            throws IOExceptionUnchecked, IllegalArgumentException;
+
+    /**
+     * Upload a new data set to the DSS.
+     * 
+     * @param sessionToken The session token
+     * @param newDataset The new data set that should be registered
      * @throws IOExceptionUnchecked Thrown if an IOException occurs when listing the files
      * @throws IllegalArgumentException Thrown if the dataSetCode or startPath are not valid
      */
-    public InputStream getFileForDataSet(String sessionToken, String dataSetCode, String startPath)
+    public void putDataSet(String sessionToken, NewDatasetDTO newDataset)
             throws IOExceptionUnchecked, IllegalArgumentException;
 }
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/NewDatasetDTO.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/NewDatasetDTO.java
new file mode 100644
index 00000000000..6f392c51570
--- /dev/null
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/NewDatasetDTO.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2010 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.dss.generic.shared.api.v1;
+
+import java.io.InputStream;
+import java.io.Serializable;
+
+import ch.systemsx.cisd.common.io.ConcatenatedFileInputStream;
+
+/**
+ * Represents a new data set that the DSS should register.
+ * <p>
+ * The information required to register a new data set are the path of the data set and the name of
+ * the storage process that should handle registering it.
+ * 
+ * @author Chandrasekhar Ramakrishnan
+ */
+public class NewDatasetDTO implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    private final String storageProcessName;
+
+    private final InputStream inputStream;
+
+    /**
+     * Constructor
+     * 
+     * @param storageProcessName The storage process that should handle this data set
+     * @param inputStream An input stream on the file or folder to register. If a folder is to be
+     *            registered, the input stream must be a {@link ConcatenatedFileInputStream}.
+     */
+    public NewDatasetDTO(String storageProcessName, InputStream inputStream)
+    {
+        this.storageProcessName = storageProcessName;
+        this.inputStream = inputStream;
+    }
+
+    public String getStorageProcessName()
+    {
+        return storageProcessName;
+    }
+
+    public InputStream getInputStream()
+    {
+        return inputStream;
+    }
+}
-- 
GitLab