diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManager.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManager.java index 73bac51af517a1df831f369132047b4f9608af18..e9aa13b8d34a8e081fab5d0c406fe7aaf2f371ad 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManager.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManager.java @@ -17,7 +17,6 @@ package ch.systemsx.cisd.openbis.generic.server.business; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -147,7 +146,10 @@ public class PropertiesBatchManager implements IPropertiesBatchManager { EntityProperty entityProperty = evaluateManagedProperty(code, entry.getValue(), evalContext); - newProperties.add(entityProperty); + if (entityProperty.getValue() != null) + { + newProperties.add(entityProperty); + } } catch (EvaluatorException ex) { Throwable cause = ex.getCause(); @@ -169,8 +171,6 @@ public class PropertiesBatchManager implements IPropertiesBatchManager EntityProperty entityProperty = createNewEntityProperty(code); if (evalContext == null) { - ManagedPropertyEvaluator.assertBatchColumnNames(code, Collections.<String> emptyList(), - bindings); entityProperty.setValue(bindings.get("")); } else { @@ -178,7 +178,10 @@ public class PropertiesBatchManager implements IPropertiesBatchManager ManagedProperty managedProperty = new ManagedProperty(); managedProperty.setPropertyTypeCode(code); evaluator.updateFromBatchInput(managedProperty, bindings); - entityProperty.setValue(managedProperty.getValue()); + if (false == managedProperty.isSpecialValue()) + { + entityProperty.setValue(managedProperty.getValue()); + } } return entityProperty; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java index 79a8428df862ac71530ff00eaa856741d3cd6e66..5b954a673b5478931d3bed2cfbef765cb9096819 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluator.java @@ -18,16 +18,13 @@ package ch.systemsx.cisd.openbis.generic.shared.managed_property; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import org.apache.log4j.Logger; import ch.systemsx.cisd.common.evaluator.Evaluator; import ch.systemsx.cisd.common.evaluator.EvaluatorException; -import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty; @@ -68,40 +65,6 @@ public class ManagedPropertyEvaluator private static final String PROPERTY_PE_VARIABLE_NAME = "propertyPE"; - /** - * Asserts that for all specified batch column names bindings are specified. If the list of - * column names is empty the value should be bound at an empty string. - * - * @param propertyTypeCode Property type code. Only needed for error messages. - */ - public static void assertBatchColumnNames(String propertyTypeCode, List<String> columnNames, - Map<String, String> bindings) - { - Set<String> names = new HashSet<String>(); - for (String name : bindings.keySet()) - { - if (false == ManagedPropertyFunctions.isOriginalColumnNameBindingKey(name)) - { - names.add(name); - } - } - if (false == columnNames.isEmpty()) - { - List<String> missingColumns = new ArrayList<String>(); - for (String columnName : columnNames) - { - if (names.contains(columnName) == false) - { - missingColumns.add(propertyTypeCode + ":" + columnName); - } - } - if (missingColumns.isEmpty() == false) - { - throw new UserFailureException("Following columns are missing: " + missingColumns); - } - } - } - private final Evaluator evaluator; private final List<String> columnNames; @@ -181,7 +144,6 @@ public class ManagedPropertyEvaluator public void updateFromBatchInput(IManagedProperty managedProperty, Map<String, String> bindings) { - assertBatchColumnNames(managedProperty.getPropertyTypeCode(), columnNames, bindings); if (updateFromBatchFunctionDefined == false) { managedProperty.setValue(bindings.get("")); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManagerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManagerTest.java index 1eecbca46357d365b1910e2e3eb1761c589d5d80..8a5b48e0fbed36c947a87c82946c5ee46b158cdb 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManagerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/PropertiesBatchManagerTest.java @@ -58,11 +58,14 @@ public class PropertiesBatchManagerTest extends AssertJUnit builder.assign(MANAGED_NO_SUBCOLUMNS_BUT_UPDATE).script( ScriptType.MANAGED_PROPERTY, "def updateFromBatchInput(columnValues):\n" + + " if columnValues.get('') is None:\n" + " return\n" + " property.setValue(columnValues.get('') + ' alpha')"); builder.assign(MANAGED_SUBCOLUMNS).script( ScriptType.MANAGED_PROPERTY, "def batchColumnNames():\n return ['1', '2']\n" + "def updateFromBatchInput(columnValues):\n" + + " if columnValues.get('1') is None:\n" + " return\n" + + " if columnValues.get('2') is None:\n" + " return\n" + " property.setValue(columnValues.get('1') + columnValues.get('2'))"); NewBasicExperiment e1 = new NewBasicExperiment(); PropertyBuilder p1 = new PropertyBuilder(UN_MANAGED).value("hello"); @@ -158,26 +161,6 @@ public class PropertiesBatchManagerTest extends AssertJUnit } - @Test - public void testSubColumnsButNoScript() - { - ExperimentTypePEBuilder builder = new ExperimentTypePEBuilder(); - builder.assign(UN_MANAGED); - NewBasicExperiment e1 = new NewBasicExperiment(); - PropertyBuilder p1 = new PropertyBuilder(UN_MANAGED + ":1").value("hello"); - addProperties(e1, p1); - - try - { - new PropertiesBatchManager().manageProperties(builder.getExperimentTypePE(), - Arrays.asList(e1), null); - fail("UserFailureException expected"); - } catch (UserFailureException ex) - { - assertEquals("No subcolumns expected for property 'UN-MANAGED': [1]", ex.getMessage()); - } - } - private void assertProperties(String expectedProperties, IPropertiesBean propertiesBean) { Set<String> expected = new HashSet<String>(); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java index 9f7c6af1272d021abc0d5d5ea696eaab7a7c58a6..a0dc595f1450c25a33e50fdf4798f0fb7c717ef2 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.openbis.generic.shared.managed_property; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -285,37 +284,6 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit assertEquals(expectedMandatory, widget.isMandatory()); } - @Test - public void testAssertBatchColumnNames() - { - Map<String, String> bindings = new HashMap<String, String>(); - bindings.put("", ""); - ManagedPropertyEvaluator.assertBatchColumnNames("p", Arrays.<String> asList(), bindings); - bindings.clear(); - bindings.put("A", "alpha"); - try - { - ManagedPropertyEvaluator - .assertBatchColumnNames("p", Arrays.<String> asList(), bindings); - fail("UserFailureException expected"); - } catch (UserFailureException ex) - { - assertEquals("No subcolumns expected for property 'p': [A]", ex.getMessage()); - } - try - { - ManagedPropertyEvaluator.assertBatchColumnNames("p", Arrays.<String> asList("A", "B"), - bindings); - fail("UserFailureException expected"); - } catch (UserFailureException ex) - { - assertEquals("Following columns are missing: [p:B]", ex.getMessage()); - } - bindings.put("B", "beta"); - ManagedPropertyEvaluator.assertBatchColumnNames("p", Arrays.<String> asList("A", "B"), - bindings); - } - @Test public void testScriptWithBatchColumnNamesFunctionButMissingUpdateFromBatchFunction() {