Skip to content
Snippets Groups Projects
Commit bd60a43d authored by cramakri's avatar cramakri
Browse files

BIS-224 SP-333 : Scaffolding for implementation of SP-333

SVN: 28409
parent a38ff480
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,7 @@ public abstract class AbstractTabularDataGraphServlet extends AbstractDatasetDow
sessionId = getRequiredParameter(request, Utils.SESSION_ID_PARAM);
datasetCode = getRequiredParameter(request, DATASET_CODE_PARAM);
filePathOrNull = getOptionalParameter(request, FILE_PATH_PARAM);
graphName = getRequiredParameter(request, GRAPH_TYPE_CODE);
graphName = getOptionalParameter(request, GRAPH_TYPE_CODE, "dynamic");
width = getIntParam(request, WIDTH_PARAM, 0);
height = getIntParam(request, HEIGHT_PARAM, 0);
}
......@@ -108,6 +108,17 @@ public abstract class AbstractTabularDataGraphServlet extends AbstractDatasetDow
return value;
}
private static String getOptionalParameter(final HttpServletRequest request,
String paramName, String defaultValue)
{
String value = request.getParameter(paramName);
if (null == value)
{
return defaultValue;
}
return value;
}
private static String getRequiredParameter(final HttpServletRequest request,
String paramName)
{
......@@ -119,6 +130,11 @@ public abstract class AbstractTabularDataGraphServlet extends AbstractDatasetDow
}
return value;
}
public String getSessionId()
{
return sessionId;
}
}
/**
......@@ -176,11 +192,12 @@ public abstract class AbstractTabularDataGraphServlet extends AbstractDatasetDow
ensureDatasetAccessible(datasetCode, session, sessionId);
// Get the tabular data
ITabularData fileLines = getDatasetLines(datasetCode, filePathOrNull);
ITabularData fileLines = getDatasetLines(request, datasetCode, filePathOrNull);
// Generate an image into the stream
ITabularDataGraph generator =
configuration.getGraph(params.graphName, fileLines, response.getOutputStream());
getConfiguration(request).getGraph(params.graphName, fileLines,
response.getOutputStream());
response.setContentType(Utils.CONTENT_TYPE_PNG);
String headerContentDisposition = "inline; filename=plot_" + (new Date().getTime());
......@@ -201,7 +218,16 @@ public abstract class AbstractTabularDataGraphServlet extends AbstractDatasetDow
}
}
protected abstract ITabularData getDatasetLines(String dataSetCode, String filePathOrNull)
/**
* Get the configuration for this graph. Defaults to the configuration ivar. Subclasses may
* override.
*/
protected TabularDataGraphCollectionConfiguration getConfiguration(HttpServletRequest request)
{
return configuration;
}
protected abstract ITabularData getDatasetLines(HttpServletRequest request, String dataSetCode, String filePathOrNull)
throws IOException;
}
\ No newline at end of file
/*
* Copyright 2013 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.dss.generic.server;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import ch.systemsx.cisd.openbis.dss.generic.server.graph.TabularDataGraphCollectionConfiguration;
import ch.systemsx.cisd.openbis.dss.generic.server.graph.TabularDataGraphCollectionConfiguration.DynamicTabularDataGraphCollectionConfiguration;
/**
* @author cramakri
*/
public class DynamicFileTabularDataGraphServlet extends FileTabularDataGraphServlet
{
private static final String DYNAMIC_GRAPH_NAME = "dynamic";
private static final long serialVersionUID = 1L;
@Override
protected TabularDataGraphCollectionConfiguration getConfiguration(HttpServletRequest request)
{
// TODO Implement this properly
DynamicTabularDataGraphCollectionConfiguration config =
new DynamicTabularDataGraphCollectionConfiguration();
config.setColumnDelimiter('\t');
Properties props = new Properties();
props.setProperty(TabularDataGraphCollectionConfiguration.GRAPHS_KEY,
DynamicTabularDataGraphCollectionConfiguration.DYNAMIC_GRAPH_NAME);
props.setProperty(DYNAMIC_GRAPH_NAME + "."
+ TabularDataGraphCollectionConfiguration.TITLE_KEY, "Title");
props.setProperty(DYNAMIC_GRAPH_NAME + "."
+ TabularDataGraphCollectionConfiguration.GRAPHS_TYPES_KEY, "SCATTERPLOT");
props.setProperty(DYNAMIC_GRAPH_NAME + "."
+ TabularDataGraphCollectionConfiguration.X_AXIS_KEY, "col1");
props.setProperty(DYNAMIC_GRAPH_NAME + "."
+ TabularDataGraphCollectionConfiguration.Y_AXIS_KEY, "col2");
config.setProperties(props);
return TabularDataGraphCollectionConfiguration.getConfiguration(config);
}
@Override
protected synchronized void doSpecificInitialization(Enumeration<String> parameterNames,
ServletConfig servletConfig)
{
// Do not initialize the configuration variable -- we never use it
configuration = null;
}
}
......@@ -16,10 +16,14 @@
package ch.systemsx.cisd.openbis.dss.generic.server;
import java.io.File;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContent;
import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContentNode;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.CsvFileReaderHelper;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.ITabularData;
......@@ -34,14 +38,27 @@ public class FileTabularDataGraphServlet extends AbstractTabularDataGraphServlet
* Return the tabular data from a file as a DatasetFileLines.
*/
@Override
protected ITabularData getDatasetLines(String dataSetCode, String pathOrNull)
throws IOException
protected ITabularData getDatasetLines(HttpServletRequest request, String dataSetCode,
String pathOrNull) throws IOException
{
if (pathOrNull == null)
{
throw new UserFailureException("No value for the parameter " + FILE_PATH_PARAM
+ " found in the URL");
}
return CsvFileReaderHelper.getDatasetFileLines(new File(pathOrNull), configuration);
RequestParams requestParams = new RequestParams(request);
IHierarchicalContentProvider contentProvider =
applicationContext.getHierarchicalContentProvider(requestParams.getSessionId());
IHierarchicalContent content = contentProvider.asContent(dataSetCode);
IHierarchicalContentNode node = content.getNode(pathOrNull);
ITabularData data =
CsvFileReaderHelper.getDatasetFileLines(node.getFile(), getConfiguration(request));
content.close();
return data;
}
}
......@@ -46,7 +46,7 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
private static final String LABEL_POSTFIX = ".label";
private static final String SEPARATOR_PROPERTY_KEY = "separator";
public static final String SEPARATOR_PROPERTY_KEY = "separator";
private static final String IGNORE_COMMENTS_PROPERTY_KEY = "ignore-comments";
......@@ -63,17 +63,17 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
private static final String THUMBNAIL_HEIGHT_KEY = "column-height";
// the graphs to display -- each one is shown in a column.
private static final String GRAPHS_KEY = "graphs";
public static final String GRAPHS_KEY = "graphs";
// the type of graph. See @{link GraphType} for valid types.
private static final String GRAPHS_TYPES_KEY = "graph-type";
public static final String GRAPHS_TYPES_KEY = "graph-type";
// keys for the different kinds of graphs
private static final String TITLE_KEY = "title";
public static final String TITLE_KEY = "title";
private static final String X_AXIS_KEY = "x-axis";
public static final String X_AXIS_KEY = "x-axis";
private static final String Y_AXIS_KEY = "y-axis";
public static final String Y_AXIS_KEY = "y-axis";
private static final String COLUMN_KEY = "column";
......@@ -98,6 +98,101 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
private final HashMap<String, TabularDataGraphConfiguration> graphTypeMap;
/**
* Class used to dynamically initialize a TabularDataGraphCollectionConfiguration;
*
* @author cramakri
*/
public static class DynamicTabularDataGraphCollectionConfiguration
{
public static String DYNAMIC_GRAPH_NAME = "dynamic";
private char columnDelimiter = ';';
private boolean ignoreComments = true;
private int imageWidth = 800;
private int imageHeight = 600;
private int thumbnailWidth = 300;
private int thumbnailHeight = 200;
private Properties properties = new Properties();
public char getColumnDelimiter()
{
return columnDelimiter;
}
public void setColumnDelimiter(char columnDelimiter)
{
this.columnDelimiter = columnDelimiter;
}
public boolean isIgnoreComments()
{
return ignoreComments;
}
public void setIgnoreComments(boolean ignoreComments)
{
this.ignoreComments = ignoreComments;
}
public int getImageWidth()
{
return imageWidth;
}
public void setImageWidth(int imageWidth)
{
this.imageWidth = imageWidth;
}
public int getImageHeight()
{
return imageHeight;
}
public void setImageHeight(int imageHeight)
{
this.imageHeight = imageHeight;
}
public int getThumbnailWidth()
{
return thumbnailWidth;
}
public void setThumbnailWidth(int thumbnailWidth)
{
this.thumbnailWidth = thumbnailWidth;
}
public int getThumbnailHeight()
{
return thumbnailHeight;
}
public void setThumbnailHeight(int thumbnailHeight)
{
this.thumbnailHeight = thumbnailHeight;
}
public Properties getProperties()
{
return properties;
}
public void setProperties(Properties properties)
{
this.properties = properties;
}
}
/**
* Create a configuration from the properties file located at path.
*
......@@ -122,6 +217,18 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
return new TabularDataGraphCollectionConfiguration(configurationProps);
}
/**
* Create a configuration from the properties file located at path.
*
* @param path Path to the properties file.
*/
public static TabularDataGraphCollectionConfiguration getConfiguration(
DynamicTabularDataGraphCollectionConfiguration config)
throws EnvironmentFailureException
{
return new TabularDataGraphCollectionConfiguration(config);
}
/**
* Initialize the configuration based on the properties object.
*/
......@@ -148,6 +255,27 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
}
/**
* Initialize the configuration based on the configuration object.
*/
private TabularDataGraphCollectionConfiguration(
DynamicTabularDataGraphCollectionConfiguration config)
{
comment = '#';
this.columnDelimiter = config.getColumnDelimiter();
this.ignoreComments = config.isIgnoreComments();
imageWidth = config.getImageWidth();
imageHeight = config.getImageHeight();
thumbnailWidth = config.getThumbnailWidth();
thumbnailHeight = config.getThumbnailHeight();
graphNames = new ArrayList<String>();
graphNames.add(DynamicTabularDataGraphCollectionConfiguration.DYNAMIC_GRAPH_NAME);
graphTypeMap = new HashMap<String, TabularDataGraphConfiguration>();
initialzeGraphTypeMap(config.getProperties());
}
private void initializeGraphTypeCodes(Properties properties)
{
String graphTypeCodesString = properties.getProperty(GRAPHS_KEY, "");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment