diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java index e2e262244a96b14d2ddcde78dbb1f4d2fec98900..beeb63677772f93f2c4377438e044665c852ff84 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java @@ -278,7 +278,7 @@ public final class PropertyValueRenderers case MULTILINE_VARCHAR: return createMultilineHtmlWidget(object); case XML: - return createXmlWidget(object); + return createHtmlWidget(object.tryGetAsString()); default: return createHtmlWidget(object); } @@ -320,13 +320,6 @@ public final class PropertyValueRenderers .createMultilineHtmlWidget(object.getValue()); } - private Widget createXmlWidget(IEntityProperty object) - { - // TODO 2010-09-24, Piotr Buczek: use XSLT - return MultilineStringPropertyValueRenderer - .createMultilineHtmlWidget(object.getValue()); - } - private Widget createHtmlWidget(String html) { return new InlineHTML(html); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java index 3bcc6594536069679e4bbd9a8f32742666417836..12e2e2dcebcb86a1ab91c4e61c48439a222be72c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java @@ -16,6 +16,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.server; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -51,6 +52,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.IResultSetMa import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.CacheManager.TokenBasedResultSetKeyGenerator; import ch.systemsx.cisd.openbis.generic.client.web.server.translator.ResultSetTranslator; import ch.systemsx.cisd.openbis.generic.client.web.server.translator.UserFailureExceptionTranslator; +import ch.systemsx.cisd.openbis.generic.client.web.server.util.XMLPropertyTransformer; import ch.systemsx.cisd.openbis.generic.server.SessionConstants; import ch.systemsx.cisd.openbis.generic.shared.IServer; import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder; @@ -58,6 +60,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.BasicEntityType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DisplaySettings; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GridCustomColumn; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityPropertiesHolder; import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; /** @@ -76,7 +79,7 @@ public abstract class AbstractClientService implements IClientService, @Resource(name = "common-service") protected CommonClientService commonClientService; - + private String cifexURL; private String cifexRecipient; @@ -99,6 +102,11 @@ public abstract class AbstractClientService implements IClientService, { this.requestContextProvider = requestContextProvider; } + + protected void transformXML(IEntityPropertiesHolder propertiesHolder) + { + new XMLPropertyTransformer().transformXMLProperties(Arrays.asList(propertiesHolder)); + } @SuppressWarnings("unchecked") protected final <K> IResultSetManager<K> getResultSetManager() diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java index 0d7d33ed7c5d14878c16d5a33c59b250135dd6c8..b982be0084fa8101224c2440fa8cd243a076dd3a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java @@ -1780,6 +1780,7 @@ public final class CommonClientService extends AbstractClientService implements final ExperimentIdentifier identifier = new ExperimentIdentifierFactory(experimentIdentifier).createIdentifier(); final Experiment experiment = commonServer.getExperimentInfo(sessionToken, identifier); + transformXML(experiment); return experiment; } catch (final ch.systemsx.cisd.common.exceptions.UserFailureException e) { @@ -1795,6 +1796,7 @@ public final class CommonClientService extends AbstractClientService implements final String sessionToken = getSessionToken(); final Experiment experiment = commonServer.getExperimentInfo(sessionToken, experimentId); + transformXML(experiment); return experiment; } catch (final ch.systemsx.cisd.common.exceptions.UserFailureException e) { 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 bdbf202a6df0500127a375c40f1e98fda571f477..6d4e67baf590fe75b0b5329a0c7687641f8da41e 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 @@ -116,7 +116,7 @@ abstract public class PropertiesEditor<T extends EntityType, S extends EntityTyp for (IEntityProperty p : properties) { result.put(p.getPropertyType().getCode(), StringEscapeUtils.unescapeHtml(p - .tryGetAsString())); + .tryGetOriginalValue())); } return result; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java index e3573389e29784ef8456fcc2c3fd70c8db74f3d6..fd1c523fb70e9dbe7993799b06d479260ab546fe 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientService.java @@ -121,6 +121,7 @@ public class GenericClientService extends AbstractClientService implements IGene final String sessionToken = getSessionToken(); final SampleParentWithDerived sampleParentWithDerived = genericServer.getSampleInfo(sessionToken, sampleId); + transformXML(sampleParentWithDerived.getParent()); return sampleParentWithDerived; } catch (final ch.systemsx.cisd.common.exceptions.UserFailureException e) { @@ -188,6 +189,7 @@ public class GenericClientService extends AbstractClientService implements IGene { final String sessionToken = getSessionToken(); final Material material = genericServer.getMaterialInfo(sessionToken, materialId); + transformXML(material); return material; } catch (final ch.systemsx.cisd.common.exceptions.UserFailureException e) { @@ -201,6 +203,7 @@ public class GenericClientService extends AbstractClientService implements IGene { final String sessionToken = getSessionToken(); final ExternalData dataset = genericServer.getDataSetInfo(sessionToken, datasetId); + transformXML(dataset); return dataset; } catch (final ch.systemsx.cisd.common.exceptions.UserFailureException e) { diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientServiceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientServiceTest.java index b3d9f708f41f62a1da788767b70061687a7deae6..56dad4d68aa0cee49f0ce3b4c7cd96b331ab80a3 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientServiceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientServiceTest.java @@ -36,6 +36,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSetWithEntityTypes; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableExportCriteria; import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.CacheManager; +import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.CacheManager.TokenBasedResultSetKeyGenerator; import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.CachedResultSetManager; import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.CachedResultSetManagerTest; import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.DefaultResultSet; @@ -43,7 +44,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.ICustomColum import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.IOriginalDataProvider; import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.IResultSet; import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.IResultSetKeyGenerator; -import ch.systemsx.cisd.openbis.generic.client.web.server.resultset.CacheManager.TokenBasedResultSetKeyGenerator; import ch.systemsx.cisd.openbis.generic.server.SessionConstants; import ch.systemsx.cisd.openbis.generic.server.business.ManagerTestTool; import ch.systemsx.cisd.openbis.generic.shared.CommonTestUtils; @@ -52,8 +52,11 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; 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.DisplaySettings; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericValueEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GridCustomColumn; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewVocabulary; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; @@ -66,6 +69,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; import ch.systemsx.cisd.openbis.generic.shared.dto.FileFormatTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.translator.ExternalDataTranslator; import ch.systemsx.cisd.openbis.generic.shared.translator.VocabularyTranslator; @@ -148,7 +152,69 @@ public final class CommonClientServiceTest extends AbstractClientServiceTest commonClientService.setCifexURL(CIFEX_URL); commonClientService.setCifexRecipient(CIFEX_RECIPIENT); } + + @Test + public void testGetExperimentInfoByIdentifier() + { + context.checking(new Expectations() + { + { + prepareGetSessionToken(this); + + one(commonServer).getExperimentInfo(SESSION_TOKEN, + new ExperimentIdentifier("p1", "exp1")); + Experiment experiment = new Experiment(); + experiment.setProperties(Arrays.asList(createXmlProperty())); + will(returnValue(experiment)); + } + }); + + Experiment info = commonClientService.getExperimentInfo("p1/exp1"); + + IEntityProperty transformedXMLProperty = info.getProperties().get(0); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><b>hello</b>", transformedXMLProperty.tryGetAsString()); + assertEquals("<root>hello</root>", transformedXMLProperty.tryGetOriginalValue()); + context.assertIsSatisfied(); + } + @Test + public void testGetExperimentInfoByTechId() + { + final TechId id = new TechId(4711L); + context.checking(new Expectations() + { + { + prepareGetSessionToken(this); + + one(commonServer).getExperimentInfo(SESSION_TOKEN, id); + Experiment experiment = new Experiment(); + experiment.setProperties(Arrays.asList(createXmlProperty())); + will(returnValue(experiment)); + } + }); + + Experiment info = commonClientService.getExperimentInfo(id); + + IEntityProperty transformedXMLProperty = info.getProperties().get(0); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><b>hello</b>", transformedXMLProperty.tryGetAsString()); + assertEquals("<root>hello</root>", transformedXMLProperty.tryGetOriginalValue()); + context.assertIsSatisfied(); + } + + private IEntityProperty createXmlProperty() + { + GenericValueEntityProperty property = new GenericValueEntityProperty(); + PropertyType propertyType = new PropertyType(); + propertyType.setDataType(new DataType(DataTypeCode.XML)); + propertyType + .setTransformation(("<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" + + "<xsl:template match='/'><b><xsl:value-of select='.'/></b></xsl:template>" + + "</xsl:stylesheet>")); + property.setPropertyType(propertyType); + property.setValue("<root>hello</root>"); + return property; + } + @SuppressWarnings("unchecked") @Test public final void testListSamples() diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientServiceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientServiceTest.java index 7e66c24867da4c76cda56e7a2c8245903bb5c0e1..7b187561a72fda4b01e400102ae352e8fb01915a 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientServiceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/server/GenericClientServiceTest.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.plugin.generic.client.web.server; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -39,13 +40,21 @@ import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.BatchRegistrationResult; import ch.systemsx.cisd.openbis.generic.client.web.server.AbstractClientServiceTest; import ch.systemsx.cisd.openbis.generic.client.web.server.UploadedFilesBean; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; +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.ExternalData; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericValueEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; @@ -108,7 +117,110 @@ public final class GenericClientServiceTest extends AbstractClientServiceTest multipartFile = context.mock(MultipartFile.class); genericClientService = new GenericClientService(genericServer, requestContextProvider); } + + @Test + public void testGetSampleGenerationInfo() + { + final TechId sampleId = new TechId(4711L); + context.checking(new Expectations() + { + { + prepareGetSessionToken(this); + + one(genericServer).getSampleInfo(SESSION_TOKEN, sampleId); + SampleParentWithDerived parentWithDerived = new SampleParentWithDerived(); + Sample sample = new Sample(); + sample.setProperties(Arrays.asList(createXmlProperty())); + parentWithDerived.setParent(sample); + will(returnValue(parentWithDerived)); + } + }); + + SampleParentWithDerived info = genericClientService.getSampleGenerationInfo(sampleId); + + IEntityProperty transformedXMLProperty = info.getParent().getProperties().get(0); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><b>hello</b>", transformedXMLProperty.tryGetAsString()); + assertEquals("<root>hello</root>", transformedXMLProperty.tryGetOriginalValue()); + context.assertIsSatisfied(); + } + + @Test + public void testGetSampleInfo() + { + final TechId sampleId = new TechId(4711L); + context.checking(new Expectations() + { + { + prepareGetSessionToken(this); + + one(genericServer).getSampleInfo(SESSION_TOKEN, sampleId); + SampleParentWithDerived parentWithDerived = new SampleParentWithDerived(); + Sample sample = new Sample(); + sample.setProperties(Arrays.asList(createXmlProperty())); + parentWithDerived.setParent(sample); + will(returnValue(parentWithDerived)); + } + }); + + Sample info = genericClientService.getSampleInfo(sampleId); + IEntityProperty transformedXMLProperty = info.getProperties().get(0); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><b>hello</b>", + transformedXMLProperty.tryGetAsString()); + assertEquals("<root>hello</root>", transformedXMLProperty.tryGetOriginalValue()); + context.assertIsSatisfied(); + } + + @Test + public void testGetDataSetInfo() + { + final TechId id = new TechId(4711L); + context.checking(new Expectations() + { + { + prepareGetSessionToken(this); + + one(genericServer).getDataSetInfo(SESSION_TOKEN, id); + ExternalData dataSet = new ExternalData(); + dataSet.setDataSetProperties(Arrays.asList(createXmlProperty())); + will(returnValue(dataSet)); + } + }); + + ExternalData info = genericClientService.getDataSetInfo(id); + + IEntityProperty transformedXMLProperty = info.getProperties().get(0); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><b>hello</b>", + transformedXMLProperty.tryGetAsString()); + assertEquals("<root>hello</root>", transformedXMLProperty.tryGetOriginalValue()); + context.assertIsSatisfied(); + } + + @Test + public void testGetMaterialInfo() + { + final TechId id = new TechId(4711L); + context.checking(new Expectations() + { + { + prepareGetSessionToken(this); + + one(genericServer).getMaterialInfo(SESSION_TOKEN, id); + Material material = new Material(); + material.setProperties(Arrays.asList(createXmlProperty())); + will(returnValue(material)); + } + }); + + Material info = genericClientService.getMaterialInfo(id); + + IEntityProperty transformedXMLProperty = info.getProperties().get(0); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><b>hello</b>", + transformedXMLProperty.tryGetAsString()); + assertEquals("<root>hello</root>", transformedXMLProperty.tryGetOriginalValue()); + context.assertIsSatisfied(); + } + @Test public final void testRegisterSample() { @@ -400,6 +512,20 @@ public final class GenericClientServiceTest extends AbstractClientServiceTest return new IsAnything<List<NewSamplesWithTypes>>(); } + private IEntityProperty createXmlProperty() + { + GenericValueEntityProperty property = new GenericValueEntityProperty(); + PropertyType propertyType = new PropertyType(); + propertyType.setDataType(new DataType(DataTypeCode.XML)); + propertyType + .setTransformation(("<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" + + "<xsl:template match='/'><b><xsl:value-of select='.'/></b></xsl:template>" + + "</xsl:stylesheet>")); + property.setPropertyType(propertyType); + property.setValue("<root>hello</root>"); + return property; + } + /** * A {@link BaseMatcher} extension for checking the list of {@link NewSample NewSamples}. *