From 9fba9f86b0e534aeec546f6bf528d976258c2658 Mon Sep 17 00:00:00 2001
From: pkupczyk <pkupczyk>
Date: Tue, 2 Feb 2016 13:19:40 +0000
Subject: [PATCH] SSDM-3081 : V3 DSS API - searchFiles should return
 SearchResult - return SearchResult, add DataSetFileFetchOptions and enable V3
 DSS tests (they were not run at Hudson)

SVN: 35612
---
 .../server/dssapi/v3/DataStoreServerApi.java  |  5 +-
 .../dssapi/v3/DataStoreServerApiLogger.java   |  4 +-
 .../dss/systemtest/api/v3/SearchFileTest.java |  5 +-
 datastore_server/sourceTest/java/tests.xml    |  1 +
 .../sourceTest/java/tests_v3_api.xml          | 14 +++++
 .../dssapi/v3/IDataStoreServerApi.java        |  4 +-
 .../fetchoptions/DataSetFileFetchOptions.java | 52 +++++++++++++++++++
 .../fetchoptions/DataSetFileSortOptions.java  | 30 +++++++++++
 .../generic/sharedapi/v3/dictionary.txt       |  3 +-
 9 files changed, 112 insertions(+), 6 deletions(-)
 create mode 100644 datastore_server/sourceTest/java/tests_v3_api.xml
 create mode 100644 openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/dto/datasetfile/fetchoptions/DataSetFileFetchOptions.java
 create mode 100644 openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/dto/datasetfile/fetchoptions/DataSetFileSortOptions.java

diff --git a/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dssapi/v3/DataStoreServerApi.java b/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dssapi/v3/DataStoreServerApi.java
index b37cbfe8740..df07a8c7922 100644
--- a/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dssapi/v3/DataStoreServerApi.java
+++ b/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dssapi/v3/DataStoreServerApi.java
@@ -44,6 +44,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.search.DataSetSearchCrit
 import ch.ethz.sis.openbis.generic.dssapi.v3.IDataStoreServerApi;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.DataSetFile;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.download.DataSetFileDownloadOptions;
+import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.fetchoptions.DataSetFileFetchOptions;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.id.DataSetFilePermId;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.id.IDataSetFileId;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.search.DataSetFileSearchCriteria;
@@ -128,7 +129,7 @@ public class DataStoreServerApi extends AbstractDssServiceRpc<IDataStoreServerAp
     @Transactional(readOnly = true)
     @RolesAllowed({ RoleWithHierarchy.SPACE_OBSERVER, RoleWithHierarchy.SPACE_ETL_SERVER })
     @Override
-    public List<DataSetFile> searchFiles(String sessionToken, DataSetFileSearchCriteria searchCriteria)
+    public SearchResult<DataSetFile> searchFiles(String sessionToken, DataSetFileSearchCriteria searchCriteria, DataSetFileFetchOptions fetchOptions)
     {
         getOpenBISService().checkSession(sessionToken);
 
@@ -187,7 +188,7 @@ public class DataStoreServerApi extends AbstractDssServiceRpc<IDataStoreServerAp
             }
         }
 
-        return result;
+        return new SearchResult<DataSetFile>(result, result.size());
     }
 
     @Transactional(readOnly = true)
diff --git a/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dssapi/v3/DataStoreServerApiLogger.java b/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dssapi/v3/DataStoreServerApiLogger.java
index 07427f727c5..1bf30c172b2 100644
--- a/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dssapi/v3/DataStoreServerApiLogger.java
+++ b/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dssapi/v3/DataStoreServerApiLogger.java
@@ -3,9 +3,11 @@ package ch.ethz.sis.openbis.generic.server.dssapi.v3;
 import java.io.InputStream;
 import java.util.List;
 
+import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult;
 import ch.ethz.sis.openbis.generic.dssapi.v3.IDataStoreServerApi;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.DataSetFile;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.download.DataSetFileDownloadOptions;
+import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.fetchoptions.DataSetFileFetchOptions;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.id.IDataSetFileId;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.search.DataSetFileSearchCriteria;
 import ch.systemsx.cisd.openbis.common.spring.IInvocationLoggerContext;
@@ -32,7 +34,7 @@ public class DataStoreServerApiLogger extends AbstractServerLogger implements
     }
 
     @Override
-    public List<DataSetFile> searchFiles(String sessionToken, DataSetFileSearchCriteria searchCriteria)
+    public SearchResult<DataSetFile> searchFiles(String sessionToken, DataSetFileSearchCriteria searchCriteria, DataSetFileFetchOptions fetchOptions)
     {
         logAccess(sessionToken, "search-files", "SEARCH_CRITERION:\n%s\n", searchCriteria);
         return null;
diff --git a/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/SearchFileTest.java b/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/SearchFileTest.java
index 6f55d2f1225..7ccd6982ca5 100644
--- a/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/SearchFileTest.java
+++ b/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/SearchFileTest.java
@@ -7,7 +7,9 @@ import java.util.List;
 
 import org.testng.annotations.Test;
 
+import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.DataSetFile;
+import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.fetchoptions.DataSetFileFetchOptions;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.search.DataSetFileSearchCriteria;
 
 public class SearchFileTest extends AbstractFileTest
@@ -19,7 +21,8 @@ public class SearchFileTest extends AbstractFileTest
         DataSetFileSearchCriteria sc = new DataSetFileSearchCriteria();
         sc.withDataSet().withPermId().thatEquals(dataSetCode);
 
-        List<DataSetFile> searchFiles = dss.searchFiles(sessionToken, sc);
+        SearchResult<DataSetFile> searchResult = dss.searchFiles(sessionToken, sc, new DataSetFileFetchOptions());
+        List<DataSetFile> searchFiles = searchResult.getObjects();
 
         assertThat(searchFiles, containsAll(filesAndDirectories));
         /* directory structure [dataset id]/original/[root folder] */
diff --git a/datastore_server/sourceTest/java/tests.xml b/datastore_server/sourceTest/java/tests.xml
index 3bbcfc2ffb3..4f8401125cd 100644
--- a/datastore_server/sourceTest/java/tests.xml
+++ b/datastore_server/sourceTest/java/tests.xml
@@ -11,6 +11,7 @@
             <package name="ch.systemsx.cisd.etlserver.*" />
             <package name="ch.systemsx.cisd.openbis.dss.*" />
             <package name="ch.systemsx.cisd.openbis.datastoreserver.*" />
+            <package name="ch.ethz.sis.openbis.generic.dss.*" />
         </packages>
     </test>
 </suite>
diff --git a/datastore_server/sourceTest/java/tests_v3_api.xml b/datastore_server/sourceTest/java/tests_v3_api.xml
new file mode 100644
index 00000000000..f737a552942
--- /dev/null
+++ b/datastore_server/sourceTest/java/tests_v3_api.xml
@@ -0,0 +1,14 @@
+<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
+
+<suite name="V3" verbose="1">
+    <test name="V3">
+        <groups>
+            <run>
+                <exclude name="broken" />
+            </run>
+        </groups>
+        <packages>
+            <package name="ch.ethz.sis.openbis.generic.dss.systemtest.api.v3.*" />
+        </packages>
+    </test>
+</suite>
diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/IDataStoreServerApi.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/IDataStoreServerApi.java
index 29c204bc309..c30634a75cb 100644
--- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/IDataStoreServerApi.java
+++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/IDataStoreServerApi.java
@@ -19,8 +19,10 @@ package ch.ethz.sis.openbis.generic.dssapi.v3;
 import java.io.InputStream;
 import java.util.List;
 
+import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.DataSetFile;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.download.DataSetFileDownloadOptions;
+import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.fetchoptions.DataSetFileFetchOptions;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.id.IDataSetFileId;
 import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.search.DataSetFileSearchCriteria;
 import ch.systemsx.cisd.common.api.IRpcService;
@@ -42,7 +44,7 @@ public interface IDataStoreServerApi extends IRpcService
 
     public static final String JSON_SERVICE_URL = SERVICE_URL + ".json";
 
-    public List<DataSetFile> searchFiles(String sessionToken, DataSetFileSearchCriteria searchCriteria);
+    public SearchResult<DataSetFile> searchFiles(String sessionToken, DataSetFileSearchCriteria searchCriteria, DataSetFileFetchOptions fetchOptions);
 
     public InputStream downloadFiles(String sessionToken, List<? extends IDataSetFileId> fileIds,
             DataSetFileDownloadOptions downloadOptions);
diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/dto/datasetfile/fetchoptions/DataSetFileFetchOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/dto/datasetfile/fetchoptions/DataSetFileFetchOptions.java
new file mode 100644
index 00000000000..ccf178295ee
--- /dev/null
+++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/dto/datasetfile/fetchoptions/DataSetFileFetchOptions.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2014 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.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.fetchoptions;
+
+import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.fetchoptions.FetchOptions;
+import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.DataSetFile;
+import ch.systemsx.cisd.base.annotation.JsonObject;
+
+/**
+ * @author pkupczyk
+ */
+@JsonObject("dss.dto.datasetfile.fetchoptions.DataSetFileFetchOptions")
+public class DataSetFileFetchOptions extends FetchOptions<DataSetFile> implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    @JsonProperty
+    private DataSetFileSortOptions sort;
+
+    @Override
+    public DataSetFileSortOptions sortBy()
+    {
+        if (sort == null)
+        {
+            sort = new DataSetFileSortOptions();
+        }
+        return sort;
+    }
+
+    @Override
+    public DataSetFileSortOptions getSortBy()
+    {
+        return sort;
+    }
+}
diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/dto/datasetfile/fetchoptions/DataSetFileSortOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/dto/datasetfile/fetchoptions/DataSetFileSortOptions.java
new file mode 100644
index 00000000000..7ef00b47501
--- /dev/null
+++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/dssapi/v3/dto/datasetfile/fetchoptions/DataSetFileSortOptions.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2015 ETH Zuerich, SIS
+ *
+ * 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.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.fetchoptions;
+
+import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.fetchoptions.SortOptions;
+import ch.ethz.sis.openbis.generic.dssapi.v3.dto.datasetfile.DataSetFile;
+import ch.systemsx.cisd.base.annotation.JsonObject;
+
+/**
+ * @author pkupczyk
+ */
+@JsonObject("dss.dto.datasetfile.fetchoptions.DataSetFileSortOptions")
+public class DataSetFileSortOptions extends SortOptions<DataSetFile>
+{
+    private static final long serialVersionUID = 1L;
+}
diff --git a/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/sharedapi/v3/dictionary.txt b/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/sharedapi/v3/dictionary.txt
index 7584a2d14e6..715d6bb4765 100644
--- a/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/sharedapi/v3/dictionary.txt
+++ b/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/sharedapi/v3/dictionary.txt
@@ -996,7 +996,6 @@ getDataProducer
 getDataProductionDate
 setDataProducer
 setDataProductionDate
-
 Custom AS Service
 Custom AS Service Code
 Custom AS Service Context
@@ -1008,3 +1007,5 @@ execute Custom AS Service
 I Custom AS Service Executor
 I Custom AS Service Id
 search Custom AS Services
+DataSetFileFetchOptions
+DataSetFileSortOptions
\ No newline at end of file
-- 
GitLab