From 7e652089ba8479af7bd8a09ff8d02546c3891d5a Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Mon, 11 Oct 2010 09:59:47 +0000 Subject: [PATCH] LMS-1805 provide rendered XML properties in detail views but not in editors SVN: 18239 --- .../ui/PropertyValueRenderers.java | 9 +- .../web/server/AbstractClientService.java | 10 +- .../web/server/CommonClientService.java | 2 + .../experiment/PropertiesEditor.java | 2 +- .../web/server/GenericClientService.java | 3 + .../web/server/CommonClientServiceTest.java | 68 +++++++++- .../web/server/GenericClientServiceTest.java | 126 ++++++++++++++++++ 7 files changed, 209 insertions(+), 11 deletions(-) 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 e2e262244a9..beeb6367777 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 3bcc6594536..12e2e2dcebc 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 0d7d33ed7c5..b982be0084f 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 bdbf202a6df..6d4e67baf59 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 e3573389e29..fd1c523fb70 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 b3d9f708f41..56dad4d68aa 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 7e66c24867d..7b187561a72 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}. * -- GitLab