From ccf9de7f20c7857ffdb3508b221a2a89dc49f76d Mon Sep 17 00:00:00 2001
From: vkovtun <viktor.kovtun@id.ethz.ch>
Date: Fri, 11 Aug 2023 17:16:33 +0200
Subject: [PATCH] SSDM-13926: First draft version of the import API.

---
 .../asapi/v3/IApplicationServerApi.java       |   4 +
 .../asapi/v3/dto/importer/ImportModes.java    |  27 +++++
 .../v3/dto/importer/ImportOperation.java      |  45 ++++++++
 .../dto/importer/ImportOperationResult.java   |  39 +++++++
 .../asapi/v3/dto/importer/ImportOptions.java  | 107 ++++++++++++++++++
 5 files changed, 222 insertions(+)
 create mode 100644 api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportModes.java
 create mode 100644 api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOperation.java
 create mode 100644 api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOperationResult.java
 create mode 100644 api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOptions.java

diff --git a/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java
index adbc705142b..aeb40a54d8e 100644
--- a/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java
+++ b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java
@@ -83,6 +83,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.externaldms.update.ExternalDmsUp
 import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.GlobalSearchObject;
 import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.fetchoptions.GlobalSearchObjectFetchOptions;
 import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.search.GlobalSearchCriteria;
+import ch.ethz.sis.openbis.generic.asapi.v3.dto.importer.ImportOptions;
 import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.Material;
 import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.MaterialType;
 import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.create.MaterialCreation;
@@ -245,6 +246,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.update.VocabularyUpda
 import ch.systemsx.cisd.common.api.IRpcService;
 import ch.systemsx.cisd.common.exceptions.UserFailureException;
 
+import java.nio.file.Path;
 import java.util.List;
 import java.util.Map;
 
@@ -2243,4 +2245,6 @@ public interface IApplicationServerApi extends IRpcService
      */
     public List<String> createCodes(String sessionToken, String prefix, EntityKind entityKind, int count);
 
+    public void doImport(String sessionToken, Path path, ImportOptions importOptions);
+
 }
diff --git a/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportModes.java b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportModes.java
new file mode 100644
index 00000000000..9fcc477528b
--- /dev/null
+++ b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportModes.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright ETH 2022 - 2023 Zürich, Scientific IT Services
+ *
+ * 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.asapi.v3.dto.importer;
+
+public enum ImportModes
+{
+
+    UPDATE_IF_EXISTS, // default mode
+
+    IGNORE_EXISTING,
+
+    FAIL_IF_EXISTS
+
+}
diff --git a/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOperation.java b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOperation.java
new file mode 100644
index 00000000000..a772260e5ba
--- /dev/null
+++ b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOperation.java
@@ -0,0 +1,45 @@
+/*
+ *  Copyright ETH 2023 Zürich, Scientific IT Services
+ *
+ *  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.asapi.v3.dto.importer;
+
+import java.nio.file.Path;
+
+import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.operation.IOperation;
+import ch.systemsx.cisd.base.annotation.JsonObject;
+
+@JsonObject("as.dto.importer.ImportOperation")
+public class ImportOperation implements IOperation
+{
+
+    private final Path path;
+
+    private final ImportOptions importOptions;
+
+    public ImportOperation(final Path path, final ImportOptions importOptions)
+    {
+        this.path = path;
+        this.importOptions = importOptions;
+    }
+
+    @Override
+    public String getMessage()
+    {
+        return toString();
+    }
+
+}
diff --git a/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOperationResult.java b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOperationResult.java
new file mode 100644
index 00000000000..e1483c3ef6f
--- /dev/null
+++ b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOperationResult.java
@@ -0,0 +1,39 @@
+/*
+ *  Copyright ETH 2023 Zürich, Scientific IT Services
+ *
+ *  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.asapi.v3.dto.importer;
+
+import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.operation.IOperationResult;
+
+public class ImportOperationResult implements IOperationResult
+{
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public String getMessage()
+    {
+        return toString();
+    }
+
+    @Override
+    public String toString()
+    {
+        return this.getClass().getSimpleName();
+    }
+
+}
diff --git a/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOptions.java b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOptions.java
new file mode 100644
index 00000000000..16e4f2f46b5
--- /dev/null
+++ b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/importer/ImportOptions.java
@@ -0,0 +1,107 @@
+/*
+ *  Copyright ETH 2023 Zürich, Scientific IT Services
+ *
+ *  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.asapi.v3.dto.importer;
+
+import java.util.Map;
+
+public class ImportOptions
+{
+
+    private ImportModes importMode;
+
+    private Map<String, String> experimentsByType;
+
+    private Map<String, String> spacesByType;
+
+    private boolean definitionsOnly = false;
+
+    private boolean disallowEntityCreations = false;
+
+    private boolean ignoreVersioning = false;
+
+    private boolean renderResult = true;
+
+    private boolean allowProjectSamples = true;
+
+    public ImportModes getImportMode()
+    {
+        return importMode;
+    }
+
+    public void setImportMode(final ImportModes importMode)
+    {
+        this.importMode = importMode;
+    }
+
+    public Map<String, String> getExperimentsByType() {
+        return experimentsByType;
+    }
+
+    public void setExperimentsByType(Map<String, String> experimentsByType) {
+        this.experimentsByType = experimentsByType;
+    }
+
+    public Map<String, String> getSpacesByType() {
+        return spacesByType;
+    }
+
+    public void setSpacesByType(Map<String, String> spacesByType) {
+        this.spacesByType = spacesByType;
+    }
+
+    public boolean getDefinitionsOnly() {
+        return definitionsOnly;
+    }
+
+    public void setDefinitionsOnly(boolean definitionsOnly) {
+        this.definitionsOnly = definitionsOnly;
+    }
+
+    public boolean getDisallowEntityCreations() {
+        return disallowEntityCreations;
+    }
+
+    public void setDisallowEntityCreations(boolean disallowEntityCreations) {
+        this.disallowEntityCreations = disallowEntityCreations;
+    }
+
+    public boolean getIgnoreVersioning() {
+        return ignoreVersioning;
+    }
+
+    public void setIgnoreVersioning(boolean ignoreVersioning) {
+        this.ignoreVersioning = ignoreVersioning;
+    }
+
+    public boolean getRenderResult() {
+        return renderResult;
+    }
+
+    public void setRenderResult(boolean renderResult) {
+        this.renderResult = renderResult;
+    }
+
+    public boolean getAllowProjectSamples() {
+        return allowProjectSamples;
+    }
+
+    public void setAllowProjectSamples(boolean allowProjectSamples) {
+        this.allowProjectSamples = allowProjectSamples;
+    }
+
+}
-- 
GitLab