diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/HTMLDirectoryRenderer.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/HTMLDirectoryRenderer.java index fb6da06f3d187e245a3eefb8e9c9efb49ef8349b..6460f6a0c6d9fa8383ebe22ca76bac477c6a6d06 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/HTMLDirectoryRenderer.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/HTMLDirectoryRenderer.java @@ -37,14 +37,12 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; */ final class HTMLDirectoryRenderer implements IDirectoryRenderer { - private static final String DATASET_DESCRIPTION = - "${group}/${project}/${experiment}/${sample}/${dataset}"; - - private static final String DATASET_DOWNLOAD_SERVICE = "Data Set Download Service"; - - private static final String TITLE = - "<title> " + DATASET_DOWNLOAD_SERVICE + ": " + DATASET_DESCRIPTION + "</title>"; + private static final Template SAMPLE_DATASET_DESCRIPTION_TEMPLATE = + new Template("${group}/${project}/${experiment}/${sample}/${dataset}"); + private static final Template EXPERIMENT_DATASET_DESCRIPTION_TEMPLATE = + new Template("${group}/${project}/${experiment}/${dataset}"); + private static final String CSS = "<style type='text/css'> " + "* { margin: 3px; }" @@ -64,13 +62,14 @@ final class HTMLDirectoryRenderer implements IDirectoryRenderer "<tr><td class='td_file'><a href='${path}'>${name}</td><td>${size}</td></tr>"); private static final Template HEADER_TEMPLATE = - new Template("<html><head>" + TITLE + CSS + "</head>" - + "<body><div class='wrapper'><h1>" + DATASET_DOWNLOAD_SERVICE + "</h1>" + new Template("<html><head><title>Data Set Download Service: ${dataset-description}</title>" + + CSS + "</head>" + + "<body><div class='wrapper'><h1>" + "Data Set Download Service" + "</h1>" + "<div class='div_hd'>Information about data set</div>" + "<table>" + "<tr><td class='td_hd'>Group:</td><td>${group}</td></tr>" + "<tr><td class='td_hd'>Project:</td><td>${project}</td></tr>" + "<tr><td class='td_hd'>Experiment:</td><td>${experiment}</td></tr>" - + "${sample}" + + "${sampleLine}" + "<tr><td class='td_hd'>Data Set Code:</td><td>${dataset}</td></tr></table> " + "<div class='div_hd'>Files</div>" + "<table> " + "${folder}" + ""); @@ -109,10 +108,11 @@ final class HTMLDirectoryRenderer implements IDirectoryRenderer final Group group = project.getGroup(); final String groupCode = group.getCode(); final Template template = HEADER_TEMPLATE.createFreshCopy(); + template.bind("dataset-description", renderDataSetDescription(dataSet)); template.bind("group", groupCode); template.bind("project", projectCode); template.bind("experiment", experimentCode); - template.bind("sample", createSampleLine(sampleCode)); + template.bind("sampleLine", createSampleLine(sampleCode)); template.bind("dataset", datasetCode); if (StringUtils.isNotBlank(relativePathOrNull)) { @@ -124,6 +124,28 @@ final class HTMLDirectoryRenderer implements IDirectoryRenderer } writer.println(template.createText()); } + + private String renderDataSetDescription(ExternalData dataSet) + { + String sampleCode = dataSet.getSampleCode(); + Template template; + if (sampleCode != null) + { + template = SAMPLE_DATASET_DESCRIPTION_TEMPLATE.createFreshCopy(); + template.bind("sample", sampleCode); + } else + { + template = EXPERIMENT_DATASET_DESCRIPTION_TEMPLATE.createFreshCopy(); + } + Experiment experiment = dataSet.getExperiment(); + template.bind("experiment", experiment.getCode()); + Project project = experiment.getProject(); + template.bind("project", project.getCode()); + template.bind("group", project.getGroup().getCode()); + template.bind("dataset", dataSet.getCode()); + return template.createText(); + } + private String createSampleLine(final String sampleCode) { diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java index 78f123803741778adf447c5f870a7c15548d4877..4ac117b304205d80f12e3df3b26b6fd61914b7b5 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java @@ -179,7 +179,7 @@ public class DatasetDownloadServletTest DatasetDownloadServlet servlet = createServlet(); servlet.doGet(request, response); assertEquals( - "<html><head><title> Data Set Download Service: GROUP-G/PROJECT-P/EPERIMENT-E/SAMPLE-S/1234-1</title><style type=\'text/css\'> * { margin: 3px; }html { height: 100%; }body { height: 100%; font-family: verdana, tahoma, helvetica; font-size: 11px; text-align:left; }h1 { text-align: center; padding: 1em; color: #1E4E8F;}.td_hd { border: 1px solid #FFFFFF; padding 3px; background-color: #DDDDDD; height: 1.5em; }.div_hd { background-color: #1E4E8F; color: white; font-weight: bold; padding: 3px; }table { border-collapse: collapse; padding: 1em; }tr, td { font-family: verdana, tahoma, helvetica; font-size: 11px; }.td_file { font-family: verdana, tahoma, helvetica; font-size: 11px; height: 1.5em }.wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0em auto -4em; }.footer { height: 4em; text-align: center; }</style></head><body><div class=\'wrapper\'><h1>Data Set Download Service</h1><div class=\'div_hd\'>Information about data set</div><table><tr><td class=\'td_hd\'>Group:</td><td>GROUP-G</td></tr><tr><td class=\'td_hd\'>Project:</td><td>PROJECT-P</td></tr><tr><td class=\'td_hd\'>Experiment:</td><td>EPERIMENT-E</td></tr><tr><td class=\'td_hd\'>Sample:</td><td>SAMPLE-S</td></tr><tr><td class=\'td_hd\'>Data Set Code:</td><td>1234-1</td></tr></table> <div class=\'div_hd\'>Files</div><table> " + "<html><head><title>Data Set Download Service: GROUP-G/PROJECT-P/EPERIMENT-E/SAMPLE-S/1234-1</title><style type=\'text/css\'> * { margin: 3px; }html { height: 100%; }body { height: 100%; font-family: verdana, tahoma, helvetica; font-size: 11px; text-align:left; }h1 { text-align: center; padding: 1em; color: #1E4E8F;}.td_hd { border: 1px solid #FFFFFF; padding 3px; background-color: #DDDDDD; height: 1.5em; }.div_hd { background-color: #1E4E8F; color: white; font-weight: bold; padding: 3px; }table { border-collapse: collapse; padding: 1em; }tr, td { font-family: verdana, tahoma, helvetica; font-size: 11px; }.td_file { font-family: verdana, tahoma, helvetica; font-size: 11px; height: 1.5em }.wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0em auto -4em; }.footer { height: 4em; text-align: center; }</style></head><body><div class=\'wrapper\'><h1>Data Set Download Service</h1><div class=\'div_hd\'>Information about data set</div><table><tr><td class=\'td_hd\'>Group:</td><td>GROUP-G</td></tr><tr><td class=\'td_hd\'>Project:</td><td>PROJECT-P</td></tr><tr><td class=\'td_hd\'>Experiment:</td><td>EPERIMENT-E</td></tr><tr><td class=\'td_hd\'>Sample:</td><td>SAMPLE-S</td></tr><tr><td class=\'td_hd\'>Data Set Code:</td><td>1234-1</td></tr></table> <div class=\'div_hd\'>Files</div><table> " + OSUtilities.LINE_SEPARATOR + "<tr><td class=\'td_file\'><a href=\'/datastore_server/1234-1/%2B+s+%25+%21+%23+%40\'>+ s % ! # @</td><td></td></tr>" + OSUtilities.LINE_SEPARATOR @@ -195,6 +195,41 @@ public class DatasetDownloadServletTest context.assertIsSatisfied(); } + @Test + public void testInitialDoGetNoSample() throws Exception + { + final StringWriter writer = new StringWriter(); + final ExternalData externalData = createExternalData(false); + prepareParseRequestURL(); + prepareForObtainingDataSetFromServer(externalData); + prepareForGettingDataSetFromSession(externalData, ""); + prepareForCreatingHTML(writer); + + DatasetDownloadServlet servlet = createServlet(); + servlet.doGet(request, response); + assertEquals( + "<html><head><title>Data Set Download Service: GROUP-G/PROJECT-P/EPERIMENT-E/1234-1</title>" + + "<style type=\'text/css\'> * { margin: 3px; }html { height: 100%; }body { height: 100%; font-family: verdana, tahoma, helvetica; font-size: 11px; text-align:left; }h1 { text-align: center; padding: 1em; color: #1E4E8F;}.td_hd { border: 1px solid #FFFFFF; padding 3px; background-color: #DDDDDD; height: 1.5em; }.div_hd { background-color: #1E4E8F; color: white; font-weight: bold; padding: 3px; }table { border-collapse: collapse; padding: 1em; }tr, td { font-family: verdana, tahoma, helvetica; font-size: 11px; }.td_file { font-family: verdana, tahoma, helvetica; font-size: 11px; height: 1.5em }.wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0em auto -4em; }.footer { height: 4em; text-align: center; }</style></head>" + + "<body><div class=\'wrapper\'><h1>Data Set Download Service</h1><div class=\'div_hd\'>Information about data set</div><table><tr><td class=\'td_hd\'>Group:</td>" + + "<td>GROUP-G</td></tr><tr><td class=\'td_hd\'>Project:</td><td>PROJECT-P</td></tr>" + + "<tr><td class=\'td_hd\'>Experiment:</td><td>EPERIMENT-E</td></tr>" + + "<tr><td class=\'td_hd\'>Data Set Code:</td><td>1234-1</td></tr>" + + "</table> <div class=\'div_hd\'>Files</div><table> " + + OSUtilities.LINE_SEPARATOR + + "<tr><td class=\'td_file\'><a href=\'/datastore_server/1234-1/%2B+s+%25+%21+%23+%40\'>+ s % ! # @</td><td></td></tr>" + + OSUtilities.LINE_SEPARATOR + + "<tr><td class=\'td_file\'><a href=\'/datastore_server/1234-1/read+me+%40home.txt\'>read me @home.txt</td><td>12 bytes</td></tr>" + + OSUtilities.LINE_SEPARATOR + + "</table> </div> <div class=\'footer\'>Copyright © 2008 ETHZ - <a href=\'http://www.cisd.systemsx.ethz.ch/\'>CISD</a> </div> </body></html>" + + OSUtilities.LINE_SEPARATOR + "", writer.toString()); + assertEquals(LOG_INFO + "Data set '1234-1' obtained from openBIS server." + + OSUtilities.LINE_SEPARATOR + LOG_INFO + + "For data set '1234-1' show directory <wd>/data set #123", + getNormalizedLogContent()); + + context.assertIsSatisfied(); + } + private void prepareParseRequestURL() { context.checking(new Expectations() @@ -294,7 +329,14 @@ public class DatasetDownloadServletTest DatasetDownloadServlet servlet = createServlet(); servlet.doGet(request, response); assertEquals( - "<html><head><title> Data Set Download Service: GROUP-G/PROJECT-P/EPERIMENT-E/SAMPLE-S/1234-1</title><style type=\'text/css\'> * { margin: 3px; }html { height: 100%; }body { height: 100%; font-family: verdana, tahoma, helvetica; font-size: 11px; text-align:left; }h1 { text-align: center; padding: 1em; color: #1E4E8F;}.td_hd { border: 1px solid #FFFFFF; padding 3px; background-color: #DDDDDD; height: 1.5em; }.div_hd { background-color: #1E4E8F; color: white; font-weight: bold; padding: 3px; }table { border-collapse: collapse; padding: 1em; }tr, td { font-family: verdana, tahoma, helvetica; font-size: 11px; }.td_file { font-family: verdana, tahoma, helvetica; font-size: 11px; height: 1.5em }.wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0em auto -4em; }.footer { height: 4em; text-align: center; }</style></head><body><div class=\'wrapper\'><h1>Data Set Download Service</h1><div class=\'div_hd\'>Information about data set</div><table><tr><td class=\'td_hd\'>Group:</td><td>GROUP-G</td></tr><tr><td class=\'td_hd\'>Project:</td><td>PROJECT-P</td></tr><tr><td class=\'td_hd\'>Experiment:</td><td>EPERIMENT-E</td></tr><tr><td class=\'td_hd\'>Sample:</td><td>SAMPLE-S</td></tr><tr><td class=\'td_hd\'>Data Set Code:</td><td>1234-1</td></tr></table> <div class=\'div_hd\'>Files</div><table> <tr><td class=\'td_hd\'>Folder:</td><td>+ s % ! # @</td></tr>" + "<html><head><title>Data Set Download Service: GROUP-G/PROJECT-P/EPERIMENT-E/SAMPLE-S/1234-1</title>" + + "<style type=\'text/css\'> * { margin: 3px; }html { height: 100%; }body { height: 100%; font-family: verdana, tahoma, helvetica; font-size: 11px; text-align:left; }h1 { text-align: center; padding: 1em; color: #1E4E8F;}.td_hd { border: 1px solid #FFFFFF; padding 3px; background-color: #DDDDDD; height: 1.5em; }.div_hd { background-color: #1E4E8F; color: white; font-weight: bold; padding: 3px; }table { border-collapse: collapse; padding: 1em; }tr, td { font-family: verdana, tahoma, helvetica; font-size: 11px; }.td_file { font-family: verdana, tahoma, helvetica; font-size: 11px; height: 1.5em }.wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0em auto -4em; }.footer { height: 4em; text-align: center; }</style></head>" + + "<body><div class=\'wrapper\'><h1>Data Set Download Service</h1><div class=\'div_hd\'>Information about data set</div>" + + "<table><tr><td class=\'td_hd\'>Group:</td><td>GROUP-G</td></tr>" + + "<tr><td class=\'td_hd\'>Project:</td><td>PROJECT-P</td></tr>" + + "<tr><td class=\'td_hd\'>Experiment:</td><td>EPERIMENT-E</td></tr>" + + "<tr><td class=\'td_hd\'>Sample:</td><td>SAMPLE-S</td></tr>" + + "<tr><td class=\'td_hd\'>Data Set Code:</td><td>1234-1</td></tr></table> <div class=\'div_hd\'>Files</div><table> <tr><td class=\'td_hd\'>Folder:</td><td>+ s % ! # @</td></tr>" + OSUtilities.LINE_SEPARATOR + "<tr><td class=\'td_file\'><a href=\'/datastore_server/1234-1/\'>..</td><td></td></tr>" + OSUtilities.LINE_SEPARATOR @@ -542,6 +584,11 @@ public class DatasetDownloadServletTest } private ExternalData createExternalData() + { + return createExternalData(true); + } + + private ExternalData createExternalData(boolean withSample) { Group group = new Group(); group.setCode(GROUP_CODE); @@ -554,9 +601,12 @@ public class DatasetDownloadServletTest final ExternalData externalData = new ExternalData(); externalData.setExperiment(experiment); externalData.setCode(EXAMPLE_DATA_SET_CODE); - Sample sample = new Sample(); - sample.setCode(SAMPLE_CODE); - externalData.setSample(sample); + if (withSample) + { + Sample sample = new Sample(); + sample.setCode(SAMPLE_CODE); + externalData.setSample(sample); + } LocatorType locatorType = new LocatorType(); locatorType.setCode(LocatorType.DEFAULT_LOCATOR_TYPE_CODE); externalData.setLocatorType(locatorType);