# HG changeset patch
# User gernotbelger
# Date 1527586544 -7200
# Node ID 07d51fd4864c42277e6a482793950ec6225b513f
# Parent e68d4a10c308a99477cda24f7396691aa10bf77a
Added metadata subtitle to all chart export
diff -r e68d4a10c308 -r 07d51fd4864c artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java Tue May 29 11:35:44 2018 +0200
@@ -0,0 +1,77 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.exports;
+
+import javax.xml.xpath.XPathConstants;
+
+import org.dive4elements.artifacts.ArtifactNamespaceContext;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RangeAccess;
+import org.dive4elements.river.artifacts.access.RiverAccess;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.title.TextTitle;
+import org.w3c.dom.Document;
+
+/**
+ * @author Gernot Belger
+ */
+// FIXME: this class is intended to contain all duplicate code from ChartGenerator and ChartGenerator2; who will clean
+// up this mess...?
+abstract class AbstractChartGenerator implements OutGenerator {
+ private static final String XPATH_CHART_EXPORT = "/art:action/art:attributes/art:export/@art:value";
+
+ // TODO: move real code here
+ protected abstract D4EArtifact getArtifact();
+
+ /** The CallContext object. */
+ // TODO: move real code here
+ protected abstract CallContext getContext();
+
+ /** The document of the incoming out() request. */
+ // TODO: move real code here
+ protected abstract Document getRequest();
+
+ /**
+ * Adds a metadata sub-title to the chart if it gets exported
+ */
+ protected final void addMetadataSubtitle(final JFreeChart chart) {
+ if (isExport()) {
+ final String text = ChartExportHelper.createMetadataSubtitle(getArtifact(), getContext(), getRiverName());
+ chart.addSubtitle(new TextTitle(text));
+ }
+ }
+
+ /**
+ * This method returns the export flag specified in the request document
+ * or false if no export is specified in request.
+ */
+ protected final boolean isExport() {
+ final Boolean export = (Boolean) XMLUtils.xpath(getRequest(), XPATH_CHART_EXPORT, XPathConstants.BOOLEAN, ArtifactNamespaceContext.INSTANCE);
+
+ return export == null ? false : export;
+ }
+
+ protected final String getRiverName() {
+ return new RiverAccess(getArtifact()).getRiver().getName();
+ }
+
+ protected final String getRiverUnit() {
+ return new RiverAccess(getArtifact()).getRiver().getWstUnit().getName();
+ }
+
+ protected final double[] getRange() {
+ final D4EArtifact flys = getArtifact();
+
+ final RangeAccess rangeAccess = new RangeAccess(flys);
+ return rangeAccess.getKmRange();
+ }
+}
\ No newline at end of file
diff -r e68d4a10c308 -r 07d51fd4864c artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java Tue May 29 11:02:56 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java Tue May 29 11:35:44 2018 +0200
@@ -80,7 +80,7 @@
*
* @author Ingo Weinzierl
*/
-public abstract class ChartGenerator implements OutGenerator {
+public abstract class ChartGenerator extends AbstractChartGenerator {
private static Logger log = Logger.getLogger(ChartGenerator.class);
@@ -149,10 +149,26 @@
* Default constructor that initializes internal data structures.
*/
public ChartGenerator() {
- datasets = new TreeMap();
+ datasets = new TreeMap<>();
+ }
+
+ @Override
+ protected final D4EArtifact getArtifact() {
+ // FIXME: should already made sure when this member is set
+ return (D4EArtifact) this.master;
}
@Override
+ protected final CallContext getContext() {
+ return this.context;
+ }
+
+ @Override
+ protected final Document getRequest() {
+ return this.request;
+ }
+
+ @Override
public void setup(Object config) {
log.debug("ChartGenerator.setup");
}
@@ -1123,24 +1139,6 @@
return Resources.getMsg(context.getMeta(), key, def, args);
}
-
- protected String getRiverName() {
- return new RiverAccess((D4EArtifact)master).getRiver().getName();
- }
-
- protected String getRiverUnit() {
- return new RiverAccess((D4EArtifact)master).getRiver()
- .getWstUnit().getName();
- }
-
- protected double[] getRange() {
- D4EArtifact flys = (D4EArtifact) master;
-
- RangeAccess rangeAccess = new RangeAccess(flys);
- return rangeAccess.getKmRange();
- }
-
-
/**
* Returns the size of a chart export as array which has been specified by
* the incoming request document.
@@ -1197,7 +1195,6 @@
: format;
}
-
/**
* Returns the X-Axis range as String array from request document.
* If the (x|y)range elements are not found in request document, return
diff -r e68d4a10c308 -r 07d51fd4864c artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java Tue May 29 11:02:56 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java Tue May 29 11:35:44 2018 +0200
@@ -80,7 +80,8 @@
* It should provide some basic things that equal in all chart types.
*
*/
-public abstract class ChartGenerator2 implements OutGenerator {
+// FIXME: copy/paste of ChartGenerator with LOTS of duplicate code... move duplicates to AbstractChartGenrator!
+public abstract class ChartGenerator2 extends AbstractChartGenerator {
private static Logger log = Logger.getLogger(ChartGenerator2.class);
@@ -146,8 +147,24 @@
* Default constructor that initializes internal data structures.
*/
public ChartGenerator2() {
- datasets = new TreeMap();
- yAnnotations = new TreeMap();
+ datasets = new TreeMap<>();
+ yAnnotations = new TreeMap<>();
+ }
+
+ @Override
+ protected final D4EArtifact getArtifact() {
+ // FIXME: should already made sure when this member is set
+ return (D4EArtifact) this.master;
+ }
+
+ @Override
+ protected final CallContext getContext() {
+ return this.context;
+ }
+
+ @Override
+ protected final Document getRequest() {
+ return this.request;
}
/**
@@ -263,7 +280,7 @@
chart.addSubtitle(new TextTitle(subtitle));
}
}
-
+
/**
* Generate chart.
*/
@@ -1091,23 +1108,6 @@
return Resources.getMsg(context.getMeta(), key, def, args);
}
-
- protected String getRiverName() {
- D4EArtifact flys = (D4EArtifact) master;
-
- River river = RiverUtils.getRiver(flys);
- return (river != null) ? river.getName() : "";
- }
-
-
- protected double[] getRange() {
- D4EArtifact flys = (D4EArtifact) master;
-
- RangeAccess rangeAccess = new RangeAccess(flys);
- return rangeAccess.getKmRange();
- }
-
-
/**
* Returns the size of a chart export as array which has been specified by
* the incoming request document.
@@ -1164,7 +1164,6 @@
: format;
}
-
/**
* Returns the X-Axis range as String array from request document.
* If the (x|y)range elements are not found in request document, return
diff -r e68d4a10c308 -r 07d51fd4864c artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Tue May 29 11:02:56 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Tue May 29 11:35:44 2018 +0200
@@ -197,6 +197,7 @@
chart.setBackgroundPaint(Color.WHITE);
plot.setBackgroundPaint(Color.WHITE);
addSubtitles(chart);
+ addMetadataSubtitle(chart);
adjustPlot(plot);
//debugAxis(plot);
diff -r e68d4a10c308 -r 07d51fd4864c artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java Tue May 29 11:02:56 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java Tue May 29 11:35:44 2018 +0200
@@ -114,6 +114,7 @@
plot.setBackgroundPaint(Color.WHITE);
addSubtitles(chart);
+ addMetadataSubtitle( chart );
adjustPlot(plot);
addDatasets(plot);
adjustAxes(plot);
diff -r e68d4a10c308 -r 07d51fd4864c artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.java Tue May 29 11:02:56 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/XYChartGenerator.java Tue May 29 11:35:44 2018 +0200
@@ -122,6 +122,7 @@
chart.setBackgroundPaint(Color.WHITE);
plot.setBackgroundPaint(Color.WHITE);
addSubtitles(chart);
+ addMetadataSubtitle(chart);
adjustPlot(plot);
//debugAxis(plot);
diff -r e68d4a10c308 -r 07d51fd4864c artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties Tue May 29 11:02:56 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties Tue May 29 11:35:44 2018 +0200
@@ -1121,4 +1121,6 @@
common.client.ui.selection = Selection
common.client.ui.from = from
-common.client.ui.to = to
\ No newline at end of file
+common.client.ui.to = to
+
+chart.subtitle.metadata = FLYS-Version: {0} - Bearbeiter: {1} - Datum der Erstellung: {2} - Gew\u00e4sser: {3}
\ No newline at end of file
diff -r e68d4a10c308 -r 07d51fd4864c artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties Tue May 29 11:02:56 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties Tue May 29 11:35:44 2018 +0200
@@ -1121,4 +1121,6 @@
common.client.ui.selection = Auswahl
common.client.ui.from = von
-common.client.ui.to = bis
\ No newline at end of file
+common.client.ui.to = bis
+
+chart.subtitle.metadata = FLYS-Version: {0} - Bearbeiter: {1} - Datum der Erstellung: {2} - Gew\u00e4sser: {3}
\ No newline at end of file
diff -r e68d4a10c308 -r 07d51fd4864c gwt-client/src/main/java/org/dive4elements/river/client/server/ChartOutputServiceImpl.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ChartOutputServiceImpl.java Tue May 29 11:02:56 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ChartOutputServiceImpl.java Tue May 29 11:35:44 2018 +0200
@@ -44,6 +44,7 @@
/** Handle a get, collectionOut. */
+ @Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
log.info("ChartOutputServiceImpl.doGet");
@@ -79,13 +80,9 @@
}
- protected Map prepareChartAttributes(
- HttpServletRequest req
- ) {
+ private Map prepareChartAttributes( final HttpServletRequest req ) {
Map attr = new HashMap();
- Map params = req.getParameterMap();
-
attr.put("width", req.getParameter("width"));
attr.put("height", req.getParameter("height"));
attr.put("minx", req.getParameter("minx"));
@@ -93,6 +90,7 @@
attr.put("miny", req.getParameter("miny"));
attr.put("maxy", req.getParameter("maxy"));
attr.put("format", req.getParameter("format"));
+ attr.put("export", req.getParameter("export"));
attr.put("km", req.getParameter("currentKm"));
if (log.isDebugEnabled()) {
diff -r e68d4a10c308 -r 07d51fd4864c gwt-client/src/main/java/org/dive4elements/river/client/server/ChartServiceHelper.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ChartServiceHelper.java Tue May 29 11:02:56 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ChartServiceHelper.java Tue May 29 11:35:44 2018 +0200
@@ -62,6 +62,7 @@
appendChartSize(req, attributes, ec);
appendFormat(req, attributes, ec);
+ appendExport(req, attributes, ec);
appendXRange(req, attributes, ec);
appendYRange(req, attributes, ec);
appendCurrentKm(req, attributes, ec);
@@ -174,7 +175,7 @@
* @param doc The attribute document used to adjust chart settings.
* @param ec The ElementCreator that might be used to create new Elements.
*/
- protected static void appendFormat(
+ private static void appendFormat(
Map req,
Element attributes,
ElementCreator ec
@@ -193,6 +194,26 @@
attributes.appendChild(format);
}
+ /**
+ * This method extracts the export string from request object and appends
+ * those format - if existing - to the attribute document used to adjust
+ * the chart settings.
+ *
+ * @param req The request object that might contain the chart export flag.
+ * @param doc The attribute document used to adjust chart settings.
+ * @param ec The ElementCreator that might be used to create new Elements.
+ */
+ private static void appendExport( final Map req, final Element attributes, final ElementCreator ec ) {
+
+ final String exportStr = req.get("export");
+ if (exportStr == null || exportStr.isEmpty())
+ return;
+
+ final Element format = ec.create("export");
+ ec.addAttr(format, "value", exportStr, true);
+
+ attributes.appendChild(format);
+ }
/**
* This method extracts the current km for the chart from request object and