diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IStructuredPropertyConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IStructuredPropertyConverter.java index 04bb8861f6a9c7a3cb66950d8945decaa91c1504..76ef98deebbf79b5197081a31a58063e52446acb 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IStructuredPropertyConverter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IStructuredPropertyConverter.java @@ -36,6 +36,13 @@ public interface IStructuredPropertyConverter */ List<IElement> convertToElements(IManagedProperty property); + /** + * Converts the values of specified String object into a list of elements. + * + * @return an empty list if the value is undefined or special. + */ + List<IElement> convertStringToElements(String propertyValue); + /** * @return a {@link String} representation of the specified elements that can be persisted in * the database. diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/JsonStructuredPropertyConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/JsonStructuredPropertyConverter.java index 21ae35c331d58c890021dbc4dc53a6031911a1b5..8bc476bccabe8f57ad57994ae137d9996821f455 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/JsonStructuredPropertyConverter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/JsonStructuredPropertyConverter.java @@ -83,8 +83,7 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve private int level = 0; @Override - public void writeStartArray(JsonGenerator jg) - throws IOException, JsonGenerationException + public void writeStartArray(JsonGenerator jg) throws IOException, JsonGenerationException { if (level++ == 0) { @@ -129,7 +128,12 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve public boolean canHandle(IManagedProperty property) { - return property.getValue().startsWith("["); + return canHandle(property.getValue()); + } + + public boolean canHandle(String string) + { + return string.startsWith("["); } @Override @@ -138,7 +142,8 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve return convertStringToElements(property.getValue()); } - private List<IElement> convertStringToElements(String propertyValue) + @Override + public List<IElement> convertStringToElements(String propertyValue) { if (ManagedProperty.isSpecialValue(propertyValue) || StringUtils.isBlank(propertyValue)) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlOrJsonStructuredPropertyConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlOrJsonStructuredPropertyConverter.java index 3b3a26e084e9d155d85873664ac46f6fd1ddae41..8b1680908c9beabf70d24f2dd1270fb6792cd8ee 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlOrJsonStructuredPropertyConverter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlOrJsonStructuredPropertyConverter.java @@ -62,6 +62,21 @@ public class XmlOrJsonStructuredPropertyConverter implements IStructuredProperty } } + @Override + public List<IElement> convertStringToElements(String string) + { + if (xmlConverter.canHandle(string)) + { + return xmlConverter.convertStringToElements(string); + } else if (jsonConverter.canHandle(string)) + { + return jsonConverter.convertStringToElements(string); + } else + { + throw new UserFailureException("Illegal managed property value '" + string + "'."); + } + } + @Override public String convertToString(List<IElement> elements) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverter.java index 86154d1f231a8a80851dfeb05a9dbe92f90981ee..70dd58eb93bbe072dc5d271452b01141892011c2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverter.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverter.java @@ -62,10 +62,13 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver public boolean canHandle(IManagedProperty property) { - String propertyValue = property.getValue(); - return propertyValue.startsWith("<" + ROOT_NAME) - || ManagedProperty.isSpecialValue(propertyValue) - || StringUtils.isBlank(propertyValue); + return canHandle(property.getValue()); + } + + public boolean canHandle(String string) + { + return string.startsWith("<" + ROOT_NAME) || ManagedProperty.isSpecialValue(string) + || StringUtils.isBlank(string); } @Override @@ -74,7 +77,8 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver return convertStringToElements(property.getValue()); } - private List<IElement> convertStringToElements(String propertyValue) + @Override + public List<IElement> convertStringToElements(String propertyValue) { if (ManagedProperty.isSpecialValue(propertyValue) || StringUtils.isBlank(propertyValue)) {