From a92273c3eca79a458fef463d51ebea6b07660ddb Mon Sep 17 00:00:00 2001
From: felmer <franz-josef.elmer@id.ethz.ch>
Date: Sun, 4 Jun 2023 07:23:25 +0200
Subject: [PATCH] SSDM-13672: V3 API: Remove flag codeBeatsAutoGeneratedCode
 from SampleCreation. Fix bug in behavior of sample creation: Specified sample
 code suppersede auto generated code flags.

---
 .../v3/dto/sample/create/SampleCreation.java   | 12 ------------
 .../v3/as/dto/sample/create/SampleCreation.js  |  7 -------
 .../executor/sample/CreateSampleExecutor.java  |  5 -----
 .../systemtest/asapi/v3/CreateSampleTest.java  | 18 ------------------
 4 files changed, 42 deletions(-)

diff --git a/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/sample/create/SampleCreation.java b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/sample/create/SampleCreation.java
index 6710ffe9a35..6f97aa030db 100644
--- a/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/sample/create/SampleCreation.java
+++ b/api-openbis-java/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/sample/create/SampleCreation.java
@@ -60,8 +60,6 @@ public class SampleCreation implements ICreation, ICreationIdHolder, IProperties
 
     private boolean autoGeneratedCode;
 
-    private boolean codeBeatsAutoGeneratedCode;
-
     private List<? extends ITagId> tagIds;
 
     private Map<String, String> properties = new HashMap<String, String>();
@@ -141,16 +139,6 @@ public class SampleCreation implements ICreation, ICreationIdHolder, IProperties
         this.autoGeneratedCode = autoGeneratedCode;
     }
 
-    public boolean isCodeBeatsAutoGeneratedCode()
-    {
-        return codeBeatsAutoGeneratedCode;
-    }
-
-    public void setCodeBeatsAutoGeneratedCode(boolean codeBeatsAutoGeneratedCode)
-    {
-        this.codeBeatsAutoGeneratedCode = codeBeatsAutoGeneratedCode;
-    }
-
     public List<? extends ITagId> getTagIds()
     {
         return tagIds;
diff --git a/api-openbis-javascript/src/v3/as/dto/sample/create/SampleCreation.js b/api-openbis-javascript/src/v3/as/dto/sample/create/SampleCreation.js
index daeb9d993a6..61e717b3f8e 100644
--- a/api-openbis-javascript/src/v3/as/dto/sample/create/SampleCreation.js
+++ b/api-openbis-javascript/src/v3/as/dto/sample/create/SampleCreation.js
@@ -24,7 +24,6 @@ define([ "stjs", "as/dto/common/Relationship" ], function(stjs, Relationship) {
 		prototype.attachments = null;
 		prototype.creationId = null;
 		prototype.autoGeneratedCode = null;
-        prototype.codeBeatsAutoGeneratedCode = null;
 		prototype.getTypeId = function() {
 			return this.typeId;
 		};
@@ -61,12 +60,6 @@ define([ "stjs", "as/dto/common/Relationship" ], function(stjs, Relationship) {
 		prototype.setAutoGeneratedCode = function(autoGeneratedCode) {
 			this.autoGeneratedCode = autoGeneratedCode;
 		};
-        prototype.isCodeBeatsAutoGeneratedCode = function() {
-            return this.codeBeatsAutoGeneratedCode;
-        }
-        prototype.setCodeBeatsAutoGeneratedCode = function(codeBeatsAutoGeneratedCode) {
-            this.codeBeatsAutoGeneratedCode = codeBeatsAutoGeneratedCode;
-        };
 		prototype.getTagIds = function() {
 			return this.tagIds;
 		};
diff --git a/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/sample/CreateSampleExecutor.java b/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/sample/CreateSampleExecutor.java
index 73b1f7f94f8..00c15b29cf3 100644
--- a/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/sample/CreateSampleExecutor.java
+++ b/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/sample/CreateSampleExecutor.java
@@ -191,11 +191,6 @@ public class CreateSampleExecutor extends AbstractCreateEntityExecutor<SampleCre
                     } else if (type == null)
                     {
                         throw new ObjectNotFoundException(creation.getTypeId());
-                    } else if (false == StringUtils.isEmpty(creation.getCode()) 
-                            && (type.isAutoGeneratedCode() || creation.isAutoGeneratedCode())
-                            && creation.isCodeBeatsAutoGeneratedCode() == false)
-                    {
-                        throw new UserFailureException("Code should be empty when auto generated code is selected.");
                     } else if (StringUtils.isEmpty(creation.getCode()) && false == type.isAutoGeneratedCode()
                             && false == creation.isAutoGeneratedCode())
                     {
diff --git a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/CreateSampleTest.java b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/CreateSampleTest.java
index bd9981986ce..98fc64eb0d8 100644
--- a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/CreateSampleTest.java
+++ b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/CreateSampleTest.java
@@ -164,24 +164,6 @@ public class CreateSampleTest extends AbstractSampleTest
         }, "Code cannot be empty for a non auto generated code", patternContains("checking data (1/1)"));
     }
 
-    @Test
-    public void testCreateWithAutogeneratedCodeNotNull()
-    {
-        final String sessionToken = v3api.login(TEST_USER, PASSWORD);
-        final SampleCreation sample = sampleCreation("SAMPLE_WITH_USER_GIVEN_CODE");
-        sample.setAutoGeneratedCode(true);
-
-        assertUserFailureException(new IDelegatedAction()
-                                   {
-                                       @Override
-                                       public void execute()
-                                       {
-                                           v3api.createSamples(sessionToken, Arrays.asList(sample));
-                                       }
-                                   }, "Code should be empty when auto generated code is selected",
-                patternContains("checking data (1/1)", toDblQuotes("'code' : 'SAMPLE_WITH_USER_GIVEN_CODE'")));
-    }
-
     @Test
     public void testCreateWithAutogeneratedCodeNull()
     {
-- 
GitLab