diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverter.java index 45c729f69b2ce6d846c105fbb682f010d7520b8c..5a1af7bb5d5af2bdb701b3b594dcde4eca257fb3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverter.java @@ -581,14 +581,19 @@ public final class EntityPropertiesConverter implements IEntityPropertiesConvert @SuppressWarnings("unchecked") String translate(String propertyValue) { - if (inputWidgetDescriptions.isEmpty() || propertyValue == null - || propertyValue.startsWith(BasicConstant.ERROR_PROPERTY_PREFIX)) + if (inputWidgetDescriptions.isEmpty() + || propertyValue == null + || propertyValue.startsWith(BasicConstant.ERROR_PROPERTY_PREFIX) + || propertyValue.startsWith(BasicConstant.MANAGED_PROPERTY_JSON_PREFIX) == false) { return propertyValue; } try { - List<?> readValue = new ObjectMapper().readValue(propertyValue, List.class); + List<?> readValue = + new ObjectMapper().readValue(propertyValue + .substring(BasicConstant.MANAGED_PROPERTY_JSON_PREFIX.length()), + List.class); ManagedProperty managedProperty = new ManagedProperty(); for (Object row : readValue) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java index 91133d7c82e1d136e47f0198dcc4b33b8c65f9dc..1887e6157c1c149f76243a358f99e7e154baf3ae 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java @@ -51,6 +51,9 @@ public class BasicConstant public static final String MANAGED_PROPERTY_PLACEHOLDER_VALUE = ERROR_PROPERTY_PREFIX + "(undefined)"; + /** Prefix of managed property in JSON format as delivered by registration forms. */ + public static final String MANAGED_PROPERTY_JSON_PREFIX = "__JSON__:"; + /** Template part of Vocabulary URL that that is replaced with vocabulary term code. */ public static final String VOCABULARY_URL_TEMPLATE_TERM_PART = "${term}"; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java index e96b6ec02af782874c2d74b9aa2649de2e971a23..636f83454014759a51268b03fbe48c53f0a52b50 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/PropertiesEditor.java @@ -38,6 +38,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.P import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.FieldUtil; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.lang.StringEscapeUtils; +import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityTypePropertyType; @@ -218,7 +219,8 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp } jsonArray.set(i, jsonObject); } - valueAsString = jsonArray.toString(); + valueAsString = + BasicConstant.MANAGED_PROPERTY_JSON_PREFIX + jsonArray.toString(); } entityProperty.setValue(valueAsString); entityProperty.setPropertyType(propertyType); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverterTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverterTest.java index af4b72aa708d0b72996a30180e6e1a1088c4b40d..ec3f455863f0c3c625beab2c05572f62c34f63d2 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverterTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/EntityPropertiesConverterTest.java @@ -34,11 +34,13 @@ import ch.systemsx.cisd.common.test.RecordingMatcher; import ch.systemsx.cisd.openbis.generic.server.business.ManagerTestTool; import ch.systemsx.cisd.openbis.generic.server.business.bo.AbstractBOTest; import ch.systemsx.cisd.openbis.generic.server.business.bo.CollectionMatcher; +import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ScriptType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.PropertyBuilder; import ch.systemsx.cisd.openbis.generic.shared.dto.DataTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE; @@ -48,6 +50,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePropertyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePropertyTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.ScriptPE; import ch.systemsx.cisd.openbis.generic.shared.dto.builders.SamplePEBuilder; import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind; @@ -204,6 +207,8 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest createEntityPropertiesConverter(EntityKind.SAMPLE); final PropertyTypePE propertyTypePE = createPropertyType(); final IEntityProperty[] properties = createSampleProperties(false); + final String value = BasicConstant.MANAGED_PROPERTY_JSON_PREFIX + "[{\"A\":\"alpha\"}]"; + properties[0].setValue(value); final RecordingMatcher<Set<IEntityProperty>> definedPropertiesMatcher = RecordingMatcher.create(); @@ -215,6 +220,12 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest final SampleTypePropertyTypePE sampleTypePropertyTypePE = createETPT(VARCHAR_PROPERTY_TYPE_CODE, sampleType); sampleTypePropertyTypePE.setMandatory(true); + ScriptPE script = new ScriptPE(); + script.setScriptType(ScriptType.MANAGED_PROPERTY); + script.setScript("def batchColumnNames():\n return ['A']\n" + + "def updateFromBatchInput(bindings):\n" + + " property.setValue('Hello ' + bindings.get('A'))"); + sampleTypePropertyTypePE.setScript(script); final SampleTypePE sampleType2 = createSampleType(SAMPLE_TYPE2_CODE); final SampleTypePropertyTypePE sampleTypePropertyTypePE2 = @@ -232,6 +243,11 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest this.allowing(entityPropertyTypeDAO).listEntityPropertyTypes(sampleType); this.will(Expectations.returnValue(Arrays.asList(sampleTypePropertyTypePE))); + one(placeholderCreator).addManagedPropertiesPlaceholders( + new HashSet<IEntityProperty>(Arrays.asList(properties)), + new HashSet<String>(Arrays.asList(VARCHAR_PROPERTY_TYPE_CODE + .toUpperCase()))); + this.allowing(entityPropertyTypeDAO).listEntityPropertyTypes(sampleType2); this.will(Expectations.returnValue(Arrays.asList(sampleTypePropertyTypePE2))); @@ -239,7 +255,8 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest will(returnValue(propertyTypePE)); atLeast(1).of(propertyValueValidator).validatePropertyValue(propertyTypePE, - "blue"); + value); + will(returnValue(value)); CollectionMatcher<Set<String>> dynamicPropertiesMatcher = new CollectionMatcher<Set<String>>(new HashSet<String>( @@ -252,7 +269,7 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest } exactly(2).of(placeholderCreator).addDynamicPropertiesPlaceholders( with(definedPropertiesMatcher), with(dynamicPropertiesMatcher)); - exactly(2).of(placeholderCreator).addManagedPropertiesPlaceholders( + one(placeholderCreator).addManagedPropertiesPlaceholders( with(definedPropertiesMatcher), with(dynamicPropertiesMatcher)); } }); @@ -268,7 +285,7 @@ public final class EntityPropertiesConverterTest extends AbstractBOTest + "databaseInstance=DatabaseInstancePE{code=MY_DATABASE_INSTANCE}," + "listable=<null>,containerHierarchyDepth=<null>," + "generatedFromHierarchyDepth=<null>},ordinal=<null>," - + "section=<null>,dynamic=false,managed=false},value=}]", + + "section=<null>,dynamic=false,managed=true},value=Hello alpha}]", convertedProperties.toString()); // Check that for sample type SAMPLE_TYPE2_CODE property is not mandatory as for previous