Skip to content
Snippets Groups Projects
Commit 540366f9 authored by anttil's avatar anttil
Browse files

BIS-224 / SP-333 : Simplified, Flexible Graph Generation

SVN: 28460
parent 7643ad09
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,7 @@ public abstract class AbstractTabularDataGraphServlet extends AbstractDatasetDow
protected TabularDataGraphCollectionConfiguration configuration;
private static final String PROPERTIES_FILE_KEY = "properties-file";
protected static final String PROPERTIES_FILE_KEY = "properties-file";
public static final String FILE_PATH_PARAM = "file";
......@@ -227,7 +227,8 @@ public abstract class AbstractTabularDataGraphServlet extends AbstractDatasetDow
return configuration;
}
protected abstract ITabularData getDatasetLines(HttpServletRequest request, String dataSetCode, String filePathOrNull)
protected abstract ITabularData getDatasetLines(HttpServletRequest request, String dataSetCode,
String filePathOrNull)
throws IOException;
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ 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;
import ch.systemsx.cisd.openbis.dss.generic.server.graph.TabularDataGraphConfiguration;
/**
* @author cramakri
......@@ -33,37 +34,177 @@ public class DynamicFileTabularDataGraphServlet extends FileTabularDataGraphServ
private static final String DYNAMIC_GRAPH_NAME = "dynamic";
private static final String PARAM_TITLE = "title";
private static final String PARAM_X_AXIS_COLUMN = "col-x";
private static final String PARAM_Y_AXIS_COLUMN = "col-y";
private static final String PARAM_X_AXIS_LABEL = "label-x";
private static final String PARAM_Y_AXIS_LABEL = "label-y";
private static final String PARAM_IMAGE_HEIGHT = "image-height";
private static final String PARAM_IMAGE_WIDTH = "image-width";
private static final String PARAM_GRAPH_TYPE = "graph-type";
private static final String PARAM_GRAPH_NAME = "graph-name";
private static final String PARAM_DELIMITER = "delimiter";
private static final long serialVersionUID = 1L;
private TabularDataGraphCollectionConfiguration commonConfig;
@Override
protected TabularDataGraphCollectionConfiguration getConfiguration(HttpServletRequest request)
{
// TODO Implement this properly
String name = request.getParameter(PARAM_GRAPH_NAME);
DynamicTabularDataGraphCollectionConfiguration config =
new DynamicTabularDataGraphCollectionConfiguration();
config.setColumnDelimiter('\t');
config.setColumnDelimiter(commonConfig.getColumnDelimiter());
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");
if (name != null)
{
TabularDataGraphConfiguration graphConfig = commonConfig.getGraphConfiguration(name);
props.setProperty(TabularDataGraphCollectionConfiguration.TITLE_KEY, graphConfig
.getTitle());
props.setProperty(TabularDataGraphCollectionConfiguration.X_AXIS_KEY, graphConfig
.getTitle());
props.setProperty(TabularDataGraphCollectionConfiguration.Y_AXIS_KEY, graphConfig
.getTitle());
props.setProperty(TabularDataGraphCollectionConfiguration.GRAPHS_TYPES_KEY, graphConfig
.getGraphType().toString());
config.setImageHeight(graphConfig.getImageHeight());
config.setImageWidth(graphConfig.getImageWidth());
} else
{
name = DYNAMIC_GRAPH_NAME;
}
String delimiter = request.getParameter(PARAM_DELIMITER);
if (delimiter != null && delimiter.toCharArray().length > 0)
{
config.setColumnDelimiter(delimiter.toCharArray()[0]);
}
props.setProperty(TabularDataGraphCollectionConfiguration.GRAPHS_KEY, name);
propertyOverride(TabularDataGraphCollectionConfiguration.TITLE_KEY, PARAM_TITLE,
props, name, request);
String xColumn =
propertyOverride(TabularDataGraphCollectionConfiguration.X_AXIS_KEY,
PARAM_X_AXIS_COLUMN,
props, name, request);
if (xColumn != null && xColumn.indexOf("<") == -1)
{
propertyOverride(TabularDataGraphCollectionConfiguration.X_AXIS_KEY,
props, name, "<" + xColumn + ">" + request.getParameter(PARAM_X_AXIS_LABEL));
}
String yColumn =
propertyOverride(TabularDataGraphCollectionConfiguration.Y_AXIS_KEY,
PARAM_Y_AXIS_COLUMN,
props, name, request);
if (yColumn != null && yColumn.indexOf("<") == -1)
{
propertyOverride(TabularDataGraphCollectionConfiguration.Y_AXIS_KEY,
props, name, "<" + yColumn + ">" + request.getParameter(PARAM_Y_AXIS_LABEL));
}
propertyOverride(TabularDataGraphCollectionConfiguration.GRAPHS_TYPES_KEY,
PARAM_GRAPH_TYPE,
props, name, request);
int width =
parsePositiveInt(propertyOverride(PARAM_IMAGE_WIDTH, PARAM_IMAGE_WIDTH, props,
name, request));
int height =
parsePositiveInt(propertyOverride(PARAM_IMAGE_HEIGHT, PARAM_IMAGE_HEIGHT, props,
name, request));
if (width > 0)
{
config.setImageWidth(width);
}
if (height > 0)
{
config.setImageHeight(height);
}
propertyOverride(TabularDataGraphCollectionConfiguration.COLUMN_KEY,
props, name, "col3");
propertyOverride(TabularDataGraphCollectionConfiguration.NUMBER_OF_BINS_KEY,
props, name, "8");
config.setProperties(props);
return TabularDataGraphCollectionConfiguration.getConfiguration(config);
}
private String propertyOverride(String propertyName, String parameterName, Properties props,
String name, HttpServletRequest request)
{
String value = request.getParameter(parameterName);
return propertyOverride(propertyName, props, name, value);
}
private String propertyOverride(String propertyName, Properties props,
String name, String value)
{
if (value != null && value.trim().isEmpty() == false)
{
props.setProperty(name + "." + propertyName, value);
return value;
}
return props.getProperty(name + "." + propertyName);
}
private int parsePositiveInt(String string)
{
if (string == null || string.isEmpty())
{
return -1;
}
try
{
int value = Integer.parseInt(string);
if (value < 1)
{
return -1;
}
return value;
} catch (NumberFormatException e)
{
return -1;
}
}
@Override
protected synchronized void doSpecificInitialization(Enumeration<String> parameterNames,
ServletConfig servletConfig)
{
// Do not initialize the configuration variable -- we never use it
configuration = null;
if (commonConfig == null)
{
String propertiesFilePath = servletConfig.getInitParameter(PROPERTIES_FILE_KEY);
if (propertiesFilePath != null)
{
commonConfig =
TabularDataGraphCollectionConfiguration
.getConfiguration(propertiesFilePath);
}
}
}
}
......@@ -28,8 +28,8 @@ import java.util.Properties;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.properties.PropertyParametersUtil;
import ch.systemsx.cisd.common.properties.PropertyUtils;
import ch.systemsx.cisd.common.properties.PropertyParametersUtil.SectionProperties;
import ch.systemsx.cisd.common.properties.PropertyUtils;
import ch.systemsx.cisd.openbis.dss.generic.server.graph.TabularDataGraphConfiguration.GraphType;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.CodeAndLabelUtil;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.CsvFileReaderHelper.ICsvFileReaderConfiguration;
......@@ -75,9 +75,9 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
public static final String Y_AXIS_KEY = "y-axis";
private static final String COLUMN_KEY = "column";
public static final String COLUMN_KEY = "column";
private static final String NUMBER_OF_BINS_KEY = "number-of-bins";
public static final String NUMBER_OF_BINS_KEY = "number-of-bins";
private final char columnDelimiter;
......
......@@ -53,7 +53,8 @@ public class TabularDataGraphConfiguration
* @param imageWidth The desired width of the resulting image
* @param imageHeight The desired height of the resulting image
*/
protected TabularDataGraphConfiguration(GraphType graphType, String title, CodeAndLabel xAxisColumn,
protected TabularDataGraphConfiguration(GraphType graphType, String title,
CodeAndLabel xAxisColumn,
CodeAndLabel yAxisColumn, int imageWidth, int imageHeight)
{
this.graphType = graphType;
......@@ -96,7 +97,7 @@ public class TabularDataGraphConfiguration
/**
* The width of the resulting image.
*/
protected int getImageWidth()
public int getImageWidth()
{
return imageWidth;
}
......@@ -104,8 +105,18 @@ public class TabularDataGraphConfiguration
/**
* The height of the resulting image.
*/
protected int getImageHeight()
public int getImageHeight()
{
return imageHeight;
}
public String getXLabel()
{
return xAxisColumn.getLabel();
}
public String getYLabel()
{
return yAxisColumn.getLabel();
}
}
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