From fd3c74abbca9fa047befd581ea57dd65da421785 Mon Sep 17 00:00:00 2001
From: gpawel <gpawel>
Date: Fri, 2 Sep 2011 08:40:10 +0000
Subject: [PATCH] LMS-2494 Flexible import/upload: support __DELETE__ in
 addition to --DELETE--

SVN: 22768
---
 .../common/parser/AbstractParserObjectFactory.java     |  5 +++--
 .../cisd/openbis/generic/server/CommonServer.java      |  6 +++---
 .../shared/basic/dto/UpdatedBasicExperiment.java       |  2 +-
 .../generic/shared/basic/dto/UpdatedSample.java        |  2 +-
 .../parser/UpdatedSampleParserObjectFactoryTest.java   | 10 +++++-----
 .../plugin/generic/ExperimentRegistrationTest.java     |  2 +-
 6 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java b/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java
index fa71d2490ea..09174265d51 100644
--- a/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java
+++ b/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java
@@ -35,7 +35,8 @@ import ch.systemsx.cisd.common.utilities.ClassUtils;
  */
 public abstract class AbstractParserObjectFactory<E> implements IParserObjectFactory<E>
 {
-    protected static final String DELETE = "--DELETE--";
+    protected static final String[] DELETE = new String[]
+        { "--DELETE--", "__DELETE__" };
 
     /** The <code>IPropertyMapper</code> implementation. */
     private final IPropertyMapper propertyMapper;
@@ -180,7 +181,7 @@ public abstract class AbstractParserObjectFactory<E> implements IParserObjectFac
 
     protected static boolean isDeletionMark(String value)
     {
-        return DELETE.equals(value);
+        return DELETE[0].equals(value) || DELETE[1].equals(value);
     }
 
     private void checkMandatory(String value, String code)
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
index a9d139d16f5..97ddf4e4a61 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
@@ -1669,11 +1669,11 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt
     private static final String UPDATE_TEMPLATE_COMMENT =
             "# If one doesn't want to modify values in a column the column can be removed completely from the file.\n"
                     + "# Empty value in a column also means that the value stored in openBIS shouldn't be changed.\n"
-                    + "# To delete a value/connection from openBIS one needs to put \"--DELETE--\" into the corresponding cell.\n";
+                    + "# To delete a value/connection from openBIS one needs to put \"--DELETE--\" or \"__DELETE__\" into the corresponding cell.\n";
 
     private String createTemplateForType(EntityKind entityKind, boolean autoGenerate,
-            EntityTypePE entityType, boolean addComments, boolean withExperiments, boolean withSpace, 
-            BatchOperationKind operationKind)
+            EntityTypePE entityType, boolean addComments, boolean withExperiments,
+            boolean withSpace, BatchOperationKind operationKind)
     {
         List<String> columns = new ArrayList<String>();
         switch (entityKind)
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/UpdatedBasicExperiment.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/UpdatedBasicExperiment.java
index 6e426fac323..e8b4987a915 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/UpdatedBasicExperiment.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/UpdatedBasicExperiment.java
@@ -26,7 +26,7 @@ public class UpdatedBasicExperiment extends NewBasicExperiment
     public static final String EXPERIMENT_UPDATE_TEMPLATE_COMMENT =
             "# All columns except \"identifier\" can be removed from the file.\n"
                     + "# If a column is removed from the file or a cell in a column is left empty the corresponding values of updated expriments will be preserved.\n"
-                    + "# To delete a value/connection from openBIS one needs to put \"--DELETE--\" into the corresponding cell\n"
+                    + "# To delete a value/connection from openBIS one needs to put \"--DELETE--\" or \"__DELETE__\" into the corresponding cell\n"
                     + "# The \"identifier\" column should contain experiment identifiers, e.g. /SPACE/PROJECT/EXPERIMENT_1,\n"
                     + "# The \"project\" column (if not removed) should contain project identifiers, e.g. /SPACE/PROJECT\n";
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/UpdatedSample.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/UpdatedSample.java
index 45ed065c4d7..75189423d0c 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/UpdatedSample.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/UpdatedSample.java
@@ -28,7 +28,7 @@ public final class UpdatedSample extends NewSample
     public static final String SAMPLE_UPDATE_TEMPLATE_COMMENT =
             "# All columns except \"identifier\" can be removed from the file.\n"
                     + "# If a column is removed from the file or a cell in a column is left empty the corresponding values of updated samples will be preserved.\n"
-                    + "# To delete a value/connection from openBIS one needs to put \"--DELETE--\" into the corresponding cell\n"
+                    + "# To delete a value/connection from openBIS one needs to put \"--DELETE--\"  or \\\"__DELETE__\\\" into the corresponding cell\n"
                     + "# (in particular, a sample can become detached from an experiment, container or all parents this way).\n"
                     + "# Basically the \"identifier\" column should contain sample identifiers, e.g. /SPACE/SAMPLE_1,\n"
                     + "# but for samples from default space (if it was provided in the form) it is enough to put sample codes (e.g. SAMPLE_1) into the column.\n"
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/parser/UpdatedSampleParserObjectFactoryTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/parser/UpdatedSampleParserObjectFactoryTest.java
index 9cc355af7ce..f30b2f16339 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/parser/UpdatedSampleParserObjectFactoryTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/parser/UpdatedSampleParserObjectFactoryTest.java
@@ -78,9 +78,9 @@ public final class UpdatedSampleParserObjectFactoryTest
                 { new String[]
                     { "", "cont1", "", "hello" }, 1, 1 },
                 { new String[]
-                    { "id1", "cont1", "--DELETE--", "--DELETE--" }, 0, 2 },
+                    { "id1", "cont1", "--DELETE--", "__DELETE__" }, 0, 2 },
                 { new String[]
-                    { "--DELETE--", "--DELETE--", "--DELETE--", "hello" }, 1, 2 } };
+                    { "__DELETE__", "--DELETE--", "--DELETE--", "hello" }, 1, 2 } };
     }
 
     @Test(dataProvider = "getLineTokens")
@@ -97,9 +97,9 @@ public final class UpdatedSampleParserObjectFactoryTest
                 (UpdatedSample) parserObjectFactory.createObject(lineTokens);
         // assert that all NewSample properties are set properly
         assertEquals(identifierToken, objectCreated.getIdentifier());
-        assertEquals(
-                StringUtils.isEmpty(containerToken) || "--DELETE--".equals(containerToken) ? null
-                        : containerToken, objectCreated.getContainerIdentifier());
+        assertEquals(StringUtils.isEmpty(containerToken) || "--DELETE--".equals(containerToken)
+                || "__DELETE__".equals(containerToken) ? null : containerToken,
+                objectCreated.getContainerIdentifier());
         final IEntityProperty[] properties = objectCreated.getProperties();
         assertEquals(numberOfProperties, properties.length);
         int index = 2;
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/ExperimentRegistrationTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/ExperimentRegistrationTest.java
index bb32845ea16..36eebdcb4dd 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/ExperimentRegistrationTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/ExperimentRegistrationTest.java
@@ -403,7 +403,7 @@ public class ExperimentRegistrationTest extends GenericSystemTestCase
         codes = new String[]
             { "GENDER" };
         values = new String[]
-            { "--DELETE--" };
+            { "__DELETE__" };
         bulkUpdateString = createBulkUpdateString(expIds, codes, values);
 
         addMultiPartFile(EXPERIMENTS_SESSION_KEY, "experiments.txt",
-- 
GitLab