# HG changeset patch
# User gernotbelger
# Date 1534334349 -7200
# Node ID bc9a45d2b1faad50c99d83768a556e6a3a3fa0b4
# Parent e2da9c8a7c577359a5301c1d1869dd586506cc3f
common time range for gauges incl. error messages
diff -r e2da9c8a7c57 -r bc9a45d2b1fa artifacts/src/main/java/org/dive4elements/river/artifacts/services/AbstractDynamicMainValuesService.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/AbstractDynamicMainValuesService.java Wed Aug 15 13:59:09 2018 +0200
@@ -0,0 +1,96 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * 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.artifacts.services;
+
+import java.util.Date;
+import java.util.List;
+
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.artifacts.GlobalContext;
+import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.river.model.Gauge;
+import org.dive4elements.river.model.MainValue;
+import org.dive4elements.river.model.River;
+import org.w3c.dom.Document;
+
+/**
+ * This service returns the main values of a river's gauge based on the start
+ * and end point of the river.
+ *
+ * @author Ingo Weinzierl
+ */
+abstract public class AbstractDynamicMainValuesService extends AbstractMainValuesService {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Document doProcess(final Document data, final GlobalContext context, final CallMeta callMeta) {
+ try {
+
+ final River river = getRequestedRiver(data, "/art:mainvalues/art:river/text()");
+ final Gauge gauge = getRequestedGauge(data, river);
+ final Date startTime = getRequestedStartDate(data, "/art:mainvalues/art:startDate/text()");
+ final Date endTime = getRequestedEndDate(data, "/art:mainvalues/art:endDate/text()");
+
+ final List mainValues = getMainValues(river, gauge, startTime, endTime);
+
+ return buildDocument(river, gauge, mainValues, context);
+ }
+ catch (final MainValuesServiceException e) {
+ // e.printStackTrace();
+ return error(e.getMessage());
+ }
+ catch (final Exception e) {
+ e.printStackTrace();
+ return error(e.getMessage());
+ }
+ }
+
+ public static final Date getRequestedStartDate(final Document data, final String XPATH_END_YEAR) throws MainValuesServiceException {
+
+ final String startStr = XMLUtils.xpathString(data, XPATH_END_YEAR, ArtifactNamespaceContext.INSTANCE);
+
+ if (startStr == null)
+ throw new MainValuesServiceException("no start date");
+
+ try {
+ return new Date(Long.parseLong(startStr));
+ // FIXME: timezone? probably must match timezone of database
+ }
+ catch (final NumberFormatException e) {
+ e.printStackTrace();
+ throw new MainValuesServiceException("invalid start date");
+ }
+ }
+
+ public static final Date getRequestedEndDate(final Document data, final String XPATH_END_DATE) throws MainValuesServiceException {
+
+ final String endStr = XMLUtils.xpathString(data, XPATH_END_DATE, ArtifactNamespaceContext.INSTANCE);
+
+ if (endStr == null)
+ throw new MainValuesServiceException("no end date");
+
+ try {
+ return new Date(Long.parseLong(endStr));
+ // FIXME: timezone? probably must match timezone of database
+ }
+ catch (final NumberFormatException e) {
+ e.printStackTrace();
+ throw new MainValuesServiceException("invalid end date");
+ }
+ }
+
+ /**
+ * Computes a gauge's main values for a period of time based on its daily discharges stored in the database
+ */
+ protected abstract List getMainValues(final River river, final Gauge gauge, final Date startTime, final Date endTime)
+ throws MainValuesServiceException;
+
+}
\ No newline at end of file
diff -r e2da9c8a7c57 -r bc9a45d2b1fa artifacts/src/main/java/org/dive4elements/river/artifacts/services/AbstractMainValuesService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/AbstractMainValuesService.java Wed Aug 15 13:22:00 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/AbstractMainValuesService.java Wed Aug 15 13:59:09 2018 +0200
@@ -47,7 +47,6 @@
private static Logger log = Logger.getLogger(AbstractMainValuesService.class);
/** XPath that points to the river definition of the incoming request. */
- private static final String XPATH_RIVER = "/art:mainvalues/art:river/text()";
/** XPath that points to the start definition of the incoming request. */
private static final String XPATH_START = "/art:mainvalues/art:start/text()";
@@ -70,7 +69,7 @@
*
* @return the River object.
*/
- protected final River getRequestedRiver(final Document data) throws MainValuesServiceException {
+ protected static final River getRequestedRiver(final Document data, final String XPATH_RIVER) throws MainValuesServiceException {
log.debug("MainValuesService.getRequestedRiver");
String riverStr = XMLUtils.xpathString(data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE);
@@ -81,7 +80,7 @@
throw new MainValuesServiceException("no river found.");
}
- protected final Gauge getRequestedGauge(final Document data, final River river) throws MainValuesServiceException {
+ protected static final Gauge getRequestedGauge(final Document data, final River river) throws MainValuesServiceException {
final double[] minmax = getRequestedStartEnd(data, river);
final Gauge gauge = river.determineRefGauge(minmax, CMP.compare(minmax[0], minmax[1]) != 0);
@@ -105,7 +104,7 @@
*
* @return the start and end point.
*/
- private double[] getRequestedStartEnd(final Document data, final River river) {
+ public static double[] getRequestedStartEnd(final Document data, final River river) {
log.debug("MainValuesService.getStartEnd");
final String startStr = XMLUtils.xpathString(data, XPATH_START, ArtifactNamespaceContext.INSTANCE);
@@ -165,7 +164,7 @@
* @param context
* The context object.
*/
- private void appendMetaInformation(final Document doc, final Element root, final River river, final Gauge gauge, final Object context) {
+ static void appendMetaInformation(final Document doc, final Element root, final River river, final Gauge gauge, final Object context) {
log.debug("MainValuesService.appendMetaInformation");
final ElementCreator cr = new ElementCreator(doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);
diff -r e2da9c8a7c57 -r bc9a45d2b1fa artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java Wed Aug 15 13:22:00 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesService.java Wed Aug 15 13:59:09 2018 +0200
@@ -16,11 +16,7 @@
import java.util.Date;
import java.util.List;
-import org.dive4elements.artifacts.CallMeta;
-import org.dive4elements.artifacts.GlobalContext;
-import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
import org.dive4elements.artifacts.common.utils.DateUtils;
-import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.dive4elements.river.backend.SessionHolder;
import org.dive4elements.river.model.Gauge;
import org.dive4elements.river.model.MainValue;
@@ -34,7 +30,6 @@
import org.dive4elements.river.model.sinfo.DailyDischargeValue.OrderByField;
import org.dive4elements.river.utils.DoubleUtil;
import org.hibernate.Session;
-import org.w3c.dom.Document;
import gnu.trove.TDoubleArrayList;
@@ -44,80 +39,14 @@
*
* @author Ingo Weinzierl
*/
-public class DynamicMainValuesService extends AbstractMainValuesService {
+public class DynamicMainValuesService extends AbstractDynamicMainValuesService {
private static final long serialVersionUID = 1L;
- private static final String XPATH_START_YEAR = "/art:mainvalues/art:startYear/text()";
-
- private static final String XPATH_END_YEAR = "/art:mainvalues/art:endYear/text()";
-
- @Override
- public Document doProcess(final Document data, final GlobalContext context, final CallMeta callMeta) {
- try {
-
- final River river = getRequestedRiver(data);
- final Gauge gauge = getRequestedGauge(data, river);
- final Date startTime = getRequestedStartYear(data);
- final Date endTime = getRequestedEndYear(data);
-
- final List mainValues = getMainValues(river, gauge, startTime, endTime);
-
- return buildDocument(river, gauge, mainValues, context);
- }
- catch (final MainValuesServiceException e) {
- // e.printStackTrace();
- return error(e.getMessage());
- }
- catch (final Exception e) {
- e.printStackTrace();
- return error(e.getMessage());
- }
- }
-
- private Date getRequestedStartYear(final Document data) throws MainValuesServiceException {
-
- final String startStr = XMLUtils.xpathString(data, XPATH_START_YEAR, ArtifactNamespaceContext.INSTANCE);
-
- if (startStr == null)
- throw new MainValuesServiceException("no start year");
-
- try {
- final int year = Integer.parseInt(startStr);
- final Calendar cal = Calendar.getInstance();
- cal.clear();
- cal.set(year, 0, 1);
- return cal.getTime();
- }
- catch (final NumberFormatException e) {
- e.printStackTrace();
- throw new MainValuesServiceException("invalid start year");
- }
- }
-
- private Date getRequestedEndYear(final Document data) throws MainValuesServiceException {
-
- final String endStr = XMLUtils.xpathString(data, XPATH_END_YEAR, ArtifactNamespaceContext.INSTANCE);
-
- if (endStr == null)
- throw new MainValuesServiceException("no end year");
-
- try {
- final int year = Integer.parseInt(endStr);
- final Calendar cal = Calendar.getInstance();
- cal.clear();
- cal.set(year, 11, 31);
- return cal.getTime();
- }
- catch (final NumberFormatException e) {
- e.printStackTrace();
- throw new MainValuesServiceException("invalid end year");
- }
- }
-
/**
* Computes a gauge's main values for a period of time based on its daily discharges stored in the database
*/
+ @Override
protected List getMainValues(final River river, final Gauge gauge, final Date startTime, final Date endTime) throws MainValuesServiceException {
final List mainValues = new ArrayList<>();
@@ -135,7 +64,7 @@
final List qdvs = DailyDischargeValue.getValues(gauge, startTime, endTime, OrderByField.DAY);
if (qdvs.isEmpty())
throw new MainValuesServiceException("no daily discharge values for gauge " + gauge.getName() + " in the requested time period");
- // return; // TODO Fehlermeldung
+ // return;
// Build yearly aggregates
final TDoubleArrayList mnqs = new TDoubleArrayList();
@@ -152,8 +81,7 @@
mqcnt++;
if (i == qdvs.size() - 1)
mqs.set(j, mqs.get(j) / mqcnt);
- }
- else {
+ } else {
// Complete mq aggregation
if (mqcnt >= 1) {
mqs.set(j, mqs.get(j) / mqcnt);
diff -r e2da9c8a7c57 -r bc9a45d2b1fa artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Wed Aug 15 13:59:09 2018 +0200
@@ -0,0 +1,269 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * 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.artifacts.services;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.xml.xpath.XPathConstants;
+
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.artifacts.GlobalContext;
+import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.services.AbstractMainValuesService.MainValuesServiceException;
+import org.dive4elements.river.model.Gauge;
+import org.dive4elements.river.model.River;
+import org.dive4elements.river.model.sinfo.DailyDischargeValue;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * This service returns the main values of a river's gauge based on the start
+ * and end point of the river.
+ *
+ * @author Ingo Weinzierl
+ */
+public class DynamicMainValuesTimeRangeDeterminationService extends D4EService {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final String ROOT_NODE = "dynamic-mainvalues-input";
+
+ private static final Long DATE_DELTA_ERROR_MSG = (long) (60 * 60 * 24 * 1000);
+
+ public static final class ServiceException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public ServiceException(final String message) {
+ super(message);
+ }
+ }
+
+ /**
+ * Computes a gauge's main values for a period of time based on its daily discharges stored in the database
+ *
+ * @throws Exception
+ */
+
+ private static class GaugeInfoResult {
+ private final String globalErrorMsg;
+ private final List gaugeInfos;
+
+ private GaugeInfoResult(final List gaugeInfos, final String globalErrorMsg) {
+ this.gaugeInfos = gaugeInfos;
+ this.globalErrorMsg = globalErrorMsg;
+ }
+
+ private static class GaugeInfo {
+ private final String errorMsg;
+ private final Gauge gauge;
+ private final Date startdate;
+ private final Date enddate;
+
+ public GaugeInfo(final String errorMsg, final Gauge gauge, final Date startdate, final Date enddate) {
+ this.errorMsg = errorMsg;
+ this.gauge = gauge;
+ this.startdate = startdate;
+ this.enddate = enddate;
+ }
+ }
+ }
+
+ private GaugeInfoResult getCommonTimeRangeForGauges(final List gauges, final Date startTime, final Date endTime, final CallMeta meta)
+ throws ServiceException {
+
+ // Query the gauge's daily Q values
+ final List gaugeResults = new ArrayList<>();
+ Date min = startTime;
+ Date max = endTime;
+
+ for (final Gauge gauge : gauges) {
+
+ final List qdvsGlobal = DailyDischargeValue.getGlobalMinMax(gauge);
+ if (qdvsGlobal == null) {
+
+ gaugeResults.add(new GaugeInfoResult.GaugeInfo(getMsg(meta, "bundu.wst_no_data_at_all"), gauge, null, null));
+ // TODO : wenn der Workflow abgebrochen werden soll, GlobalErrorMsg setzen, dass mind. ein Pegel überhaupt keine Daten
+ // hat (der Mechnismus auf Client-Seite ist schon implementiert)
+
+ continue;
+ }
+ assert qdvsGlobal.size() == 2;
+ final Date minGlobalForGauge = qdvsGlobal.get(0).getDay();
+ final Date maxGlobalForGauge = qdvsGlobal.get(1).getDay();
+
+ if (minGlobalForGauge.getTime() > startTime.getTime())
+ min = minGlobalForGauge;
+
+ if (maxGlobalForGauge.getTime() < endTime.getTime())
+ max = maxGlobalForGauge;
+
+ String errormsg = null;
+ if ((maxGlobalForGauge.getTime() < endTime.getTime()) || (minGlobalForGauge.getTime() > startTime.getTime()))
+ errormsg = makeDoesNotCoverErrorMsg(minGlobalForGauge, maxGlobalForGauge, meta);
+
+ gaugeResults.add(new GaugeInfoResult.GaugeInfo(errormsg, gauge, min, max));
+ }
+
+ // common Range and correct errorMsg
+ final List gaugeResultsSecondTurn = new ArrayList<>();
+ for (final GaugeInfoResult.GaugeInfo gi : gaugeResults) {
+ gaugeResultsSecondTurn
+ .add(new GaugeInfoResult.GaugeInfo(gi.errorMsg, gi.gauge, gi.startdate != null ? min : null, gi.enddate != null ? max : null));
+ }
+ final String globalErrorMsg = (min.getTime() > max.getTime()) ? getMsg(meta, "bundu.wst.gauge_timeranges_disjoint") : "";
+ final GaugeInfoResult result = new GaugeInfoResult(gaugeResultsSecondTurn, globalErrorMsg);
+
+ return result;
+ }
+
+ private String makeDoesNotCoverErrorMsg(final Date start, final Date end, final CallMeta meta) {
+ final Calendar cal = Calendar.getInstance();
+ cal.setTime(start);
+ final String startyear = String.valueOf(cal.get(Calendar.YEAR));
+ cal.setTime(end);
+ final String endyear = String.valueOf(cal.get(Calendar.YEAR));
+ return Resources.getMsg(meta, "bundu.wst.range_does_not_cover", new Object[] { startyear, endyear });
+ }
+
+ @Override
+ public Document doProcess(final Document data, final GlobalContext context, final CallMeta callMeta) {
+ try {
+ final River river = AbstractMainValuesService.getRequestedRiver(data, "/art:" + this.ROOT_NODE + "/art:river/text()");
+ final List gauges = getRequestedGauges(data, river, callMeta);
+ final Date start = getRequestedStartYear(data, "/art:" + this.ROOT_NODE + "/art:startYear/text()");
+ final Date end = getRequestedEndYear(data, "/art:" + this.ROOT_NODE + "/art:endYear/text()");
+
+ final GaugeInfoResult result = getCommonTimeRangeForGauges(gauges, start, end, callMeta);
+
+ return buildDocument(result, context, callMeta);
+ }
+ catch (final ServiceException | MainValuesServiceException e) {
+ e.printStackTrace();
+ return AbstractMainValuesService.error(e.getMessage());
+ }
+ }
+
+ public static final Date getRequestedEndYear(final Document data, final String XPATH_END_YEAR) throws MainValuesServiceException {
+
+ final String endStr = XMLUtils.xpathString(data, XPATH_END_YEAR, ArtifactNamespaceContext.INSTANCE);
+
+ if (endStr == null)
+ throw new MainValuesServiceException("no end year"); // should not happen
+
+ try {
+ final int year = Integer.parseInt(endStr);
+
+ // FIXME: timezone? probably must match timezone of database
+ final Calendar cal = Calendar.getInstance();
+ cal.clear();
+ cal.set(year, 11, 31);
+ return cal.getTime();
+ }
+ catch (final NumberFormatException e) {
+ e.printStackTrace();
+ throw new MainValuesServiceException("invalid end year"); // should not happen
+ }
+ }
+
+ public static final Date getRequestedStartYear(final Document data, final String XPATH_START_YEAR) throws MainValuesServiceException {
+
+ final String startStr = XMLUtils.xpathString(data, XPATH_START_YEAR, ArtifactNamespaceContext.INSTANCE);
+
+ if (startStr == null)
+ throw new MainValuesServiceException("no start year");// should not happen
+
+ try {
+ final int year = Integer.parseInt(startStr);
+
+ // FIXME: timezone? probably must match timezone of database
+ final Calendar cal = Calendar.getInstance();
+ cal.clear();
+ cal.set(year, 0, 1);
+ return cal.getTime();
+ }
+ catch (final NumberFormatException e) {
+ e.printStackTrace();
+ throw new MainValuesServiceException("invalid start year"); // should not happen
+ }
+ }
+
+ private Document buildDocument(final GaugeInfoResult result, final GlobalContext context, final CallMeta meta) {
+
+ final Document doc = XMLUtils.newDocument();
+
+ final ElementCreator cr = new ElementCreator(doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+ final Element rootEl = cr.create(ROOT_NODE);
+
+ doc.appendChild(rootEl);
+
+ final Element globalErrElement = cr.create("global-error-msg");
+ globalErrElement.setTextContent(result.globalErrorMsg);
+ rootEl.appendChild(globalErrElement);
+
+ final List values = result.gaugeInfos;
+
+ for (final GaugeInfoResult.GaugeInfo gauge : values) {
+ final Element gaugeElement = cr.create("gauge");
+ cr.addAttr(gaugeElement, "name", gauge.gauge.getName());
+ if (gauge.startdate != null)
+ cr.addAttr(gaugeElement, "date-from", String.valueOf(gauge.startdate.getTime()));
+
+ if (gauge.enddate != null)
+ cr.addAttr(gaugeElement, "date-to", String.valueOf(gauge.enddate.getTime()));
+
+ if (gauge.errorMsg != null)
+ cr.addAttr(gaugeElement, "error-message", gauge.errorMsg);
+
+ rootEl.appendChild(gaugeElement);
+ }
+
+ return doc;
+
+ }
+
+ final Element buildElement(final ElementCreator cr, final String type, final Date date) {
+ final Element el = cr.create(type);
+ cr.addAttr(el, "value", String.valueOf(date.getTime()));
+ return el;
+ }
+
+ private static final List getRequestedGauges(final Document data, final River river, final CallMeta meta) throws ServiceException {
+
+ final NodeList gaugeNodes = data.getElementsByTagNameNS(ArtifactNamespaceContext.NAMESPACE_URI, "gauge");
+
+ final List gauges = new ArrayList<>();
+
+ for (int i = 0; i < gaugeNodes.getLength(); i++) {
+ final Element gaugeElt = (Element) gaugeNodes.item(i);
+
+ final String gaugeName = (String) XMLUtils.xpath(gaugeElt, "text()", XPathConstants.STRING);
+ final Gauge gauge = Gauge.getGaugeByNameAndRiver(gaugeName, river);
+ if (gauge != null)
+ gauges.add(gauge);
+ else {
+ throw new ServiceException("bundu_wst_error_reading_gauges");
+ }
+ }
+
+ return gauges;
+ }
+
+ private static String getMsg(final CallMeta meta, final String key) {
+ return Resources.getMsg(meta, key);
+ }
+}
\ No newline at end of file
diff -r e2da9c8a7c57 -r bc9a45d2b1fa artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java Wed Aug 15 13:22:00 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java Wed Aug 15 13:59:09 2018 +0200
@@ -34,7 +34,7 @@
@Override
public Document doProcess(final Document data, final GlobalContext context, final CallMeta callMeta) {
try {
- final River river = getRequestedRiver(data);
+ final River river = getRequestedRiver(data, "/art:mainvalues/art:river/text()");
final Gauge gauge = getRequestedGauge(data, river);
final List mainValues = getMainValues(river, gauge);
diff -r e2da9c8a7c57 -r bc9a45d2b1fa artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationCalculation.java Wed Aug 15 13:22:00 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationCalculation.java Wed Aug 15 13:59:09 2018 +0200
@@ -20,7 +20,7 @@
import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils;
import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
-import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZone;
+import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZoneServerClientXChange;
import org.dive4elements.river.model.River;
/**
@@ -50,7 +50,7 @@
final String url = indurax.getWMSUrl();
final Integer year = indurax.getYear(); // null bei year -> Integer
final String zonesRaw = indurax.getVegZones();
- final List zones = VegetationZone.parse(zonesRaw);
+ final List zones = VegetationZoneServerClientXChange.parse(zonesRaw);
final String scenarioUrl = indurax.getWMSScenarioUrl();
final String scenarioStr = String.valueOf(indurax.getDwspl());
diff -r e2da9c8a7c57 -r bc9a45d2b1fa artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties Wed Aug 15 13:22:00 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties Wed Aug 15 13:59:09 2018 +0200
@@ -1294,6 +1294,10 @@
bundu.wst.export.csv.meta.header.bezugswst = Bezugswasserstand
bundu.wst.export.pdf.meta.header.bezugswst = Bezugs-wasserstand
+bundu.wst_no_data_at_all = Es liegt keine Abflussganglinie vor.
+bundu.wst.range_does_not_cover = Die Abflussganglinie ({0}-{1}) deckt nicht den Bezugszeitraum ab.
+bundu.wst.error_reading_gauges = Fehler beim Abruf des Pegels aus der Datenbank.
+bundu.wst.gauge_timeranges_disjoint = Der Bezugszeitraum konnte nicht auf die vorhandenen Abflusswerte eingeschr\u00e4nkt werden.
common.client.ui.selection = Selection
common.client.ui.from = from
diff -r e2da9c8a7c57 -r bc9a45d2b1fa artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties Wed Aug 15 13:22:00 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties Wed Aug 15 13:59:09 2018 +0200
@@ -1294,7 +1294,11 @@
bundu.wst.export.csv.meta.header.bezugswst = Bezugswasserstand
bundu.wst.export.pdf.meta.header.bezugswst = Bezugs-wasserstand
-
+bundu.wst_no_data_at_all = Es liegt keine Abflussganglinie vor.
+bundu.wst.range_does_not_cover = Die Abflussganglinie ({0}-{1}) deckt nicht den Bezugszeitraum ab.
+bundu.wst.error_reading_gauges = Fehler beim Abruf des Pegels aus der Datenbank.
+bundu.wst.gauge_timeranges_disjoint = Der Bezugszeitraum konnte nicht auf die vorhandenen Abflusswerte eingeschr\u00e4nkt werden.
+
common.client.ui.selection = Auswahl
common.client.ui.from = von
common.client.ui.to = bis
diff -r e2da9c8a7c57 -r bc9a45d2b1fa backend/src/main/java/org/dive4elements/river/model/Gauge.java
--- a/backend/src/main/java/org/dive4elements/river/model/Gauge.java Wed Aug 15 13:22:00 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/Gauge.java Wed Aug 15 13:59:09 2018 +0200
@@ -8,48 +8,42 @@
package org.dive4elements.river.model;
+import java.io.Serializable;
import java.math.BigDecimal;
-
-import java.io.Serializable;
-
import java.util.List;
+import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Column;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
-import javax.persistence.GenerationType;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToOne;
-import javax.persistence.OneToMany;
-
-import org.hibernate.Session;
-import org.hibernate.Query;
+import javax.persistence.Table;
import org.apache.log4j.Logger;
-
import org.dive4elements.river.backend.SessionHolder;
+import org.hibernate.Query;
+import org.hibernate.Session;
/** Database-mapped Gauge with all info about it. */
@Entity
@Table(name = "gauges")
-public class Gauge
-implements Serializable, Comparable
-{
+public class Gauge implements Serializable, Comparable {
private static final Logger log = Logger.getLogger(Gauge.class);
public static final int MASTER_DISCHARGE_TABLE = 0;
- private Integer id;
- private String name;
- private River river;
+ private Integer id;
+ private String name;
+ private River river;
private BigDecimal station;
private BigDecimal aeo;
private BigDecimal datum;
- private Long officialNumber;
- private Range range;
+ private Long officialNumber;
+ private Range range;
private List dischargeTables;
@@ -59,247 +53,226 @@
public Gauge() {
}
- public Gauge(
- String name,
- River river,
- BigDecimal station,
- BigDecimal aeo,
- BigDecimal datum,
- Long officialNumber,
- Range range
- ) {
- this.name = name;
- this.river = river;
- this.station = station;
- this.aeo = aeo;
- this.datum = datum;
- this.officialNumber = officialNumber;
- this.range = range;
+ public Gauge(final String name, final River river, final BigDecimal station, final BigDecimal aeo, final BigDecimal datum, final Long officialNumber,
+ final Range range) {
+ this.name = name;
+ this.river = river;
+ this.station = station;
+ this.aeo = aeo;
+ this.datum = datum;
+ this.officialNumber = officialNumber;
+ this.range = range;
}
@Id
- @SequenceGenerator(
- name = "SEQUENCE_GAUGES_ID_SEQ",
- sequenceName = "GAUGES_ID_SEQ",
- allocationSize = 1)
- @GeneratedValue(
- strategy = GenerationType.SEQUENCE,
- generator = "SEQUENCE_GAUGES_ID_SEQ")
+ @SequenceGenerator(name = "SEQUENCE_GAUGES_ID_SEQ", sequenceName = "GAUGES_ID_SEQ", allocationSize = 1)
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_GAUGES_ID_SEQ")
@Column(name = "id")
public Integer getId() {
- return id;
+ return this.id;
}
- public void setId(Integer id) {
+ public void setId(final Integer id) {
this.id = id;
}
@OneToOne
- @JoinColumn(name = "river_id" )
+ @JoinColumn(name = "river_id")
public River getRiver() {
- return river;
+ return this.river;
}
- public void setRiver(River river) {
+ public void setRiver(final River river) {
this.river = river;
}
@Column(name = "name")
public String getName() {
- return name;
+ return this.name;
}
- public void setName(String name) {
+ public void setName(final String name) {
this.name = name;
}
@Column(name = "station") // FIXME: type mapping needed
public BigDecimal getStation() {
- return station;
+ return this.station;
}
- public void setStation(BigDecimal station) {
+ public void setStation(final BigDecimal station) {
this.station = station;
}
@Column(name = "aeo") // FIXME: type mapping needed
public BigDecimal getAeo() {
- return aeo;
+ return this.aeo;
}
- public void setAeo(BigDecimal aeo) {
+ public void setAeo(final BigDecimal aeo) {
this.aeo = aeo;
}
@Column(name = "datum") // FIXME: type mapping needed
public BigDecimal getDatum() {
- return datum;
+ return this.datum;
}
- public void setDatum(BigDecimal datum) {
+ public void setDatum(final BigDecimal datum) {
this.datum = datum;
}
@Column(name = "official_number")
public Long getOfficialNumber() {
- return officialNumber;
+ return this.officialNumber;
}
- public void setOfficialNumber(Long officialNumber) {
+ public void setOfficialNumber(final Long officialNumber) {
this.officialNumber = officialNumber;
}
@OneToOne
- @JoinColumn(name = "range_id" )
+ @JoinColumn(name = "range_id")
public Range getRange() {
- return range;
+ return this.range;
}
- public void setRange(Range range) {
+ public void setRange(final Range range) {
this.range = range;
}
@OneToMany
@JoinColumn(name = "gauge_id")
public List getDischargeTables() {
- return dischargeTables;
+ return this.dischargeTables;
}
- public void setDischargeTables(List dischargeTables) {
+ public void setDischargeTables(final List dischargeTables) {
this.dischargeTables = dischargeTables;
}
-
/**
* Returns min and max W values of this gauge.
*
* @return the min and max W value of this gauge [min,max].
*/
public double[] determineMinMaxW() {
- Session session = SessionHolder.HOLDER.get();
+ final Session session = SessionHolder.HOLDER.get();
- DischargeTable dischargeTable = fetchMasterDischargeTable();
+ final DischargeTable dischargeTable = fetchMasterDischargeTable();
if (dischargeTable == null) {
return null;
}
- Query query = session.createQuery(
- "select min(w) as min, max(w) as max from DischargeTableValue " +
- "where table_id =:table");
+ final Query query = session.createQuery("select min(w) as min, max(w) as max from DischargeTableValue " + "where table_id =:table");
query.setParameter("table", dischargeTable.getId());
- List> results = query.list();
+ final List> results = query.list();
if (results.isEmpty()) {
log.error("No values in discharge table found.");
return null;
}
- Object[] result = (Object[])results.get(0);
+ final Object[] result = (Object[]) results.get(0);
- BigDecimal a = (BigDecimal)result[0];
- BigDecimal b = (BigDecimal)result[1];
+ final BigDecimal a = (BigDecimal) result[0];
+ final BigDecimal b = (BigDecimal) result[1];
- return a != null && b != null
- ? new double [] { a.doubleValue(), b.doubleValue() }
- : null;
+ return a != null && b != null ? new double[] { a.doubleValue(), b.doubleValue() } : null;
}
@OneToMany
@JoinColumn(name = "gauge_id")
public List getMainValues() {
- return mainValues;
+ return this.mainValues;
}
- public void setMainValues(List mainValues) {
+ public void setMainValues(final List mainValues) {
this.mainValues = mainValues;
}
- public static Gauge getGaugeByOfficialNumber(long number) {
- Session session = SessionHolder.HOLDER.get();
+ public static Gauge getGaugeByOfficialNumber(final long number) {
+ final Session session = SessionHolder.HOLDER.get();
- Query query = session.createQuery(
- "from Gauge where officialNumber=:number");
+ final Query query = session.createQuery("from Gauge where officialNumber=:number");
query.setParameter("number", number);
- List results = query.list();
+ final List results = query.list();
return results.isEmpty() ? null : results.get(0);
}
- public static Gauge getGaugeByOfficialNumber(
- long number,
- String river_name
- ) {
- Session session = SessionHolder.HOLDER.get();
+ public static Gauge getGaugeByOfficialNumber(final long number, final String river_name) {
+ final Session session = SessionHolder.HOLDER.get();
- Query query = session.createQuery(
- "from Gauge as gau " +
- "where gau.officialNumber=:number and gau.river.name=:river_name");
+ final Query query = session.createQuery("from Gauge as gau " + "where gau.officialNumber=:number and gau.river.name=:river_name");
query.setParameter("number", number);
query.setParameter("river_name", river_name);
- List results = query.list();
+ final List results = query.list();
return results.isEmpty() ? null : results.get(0);
}
+ public static Gauge getGaugeByNameAndRiver(final String gauge_name, final River river) {
+ final Session session = SessionHolder.HOLDER.get();
+
+ final Query query = session.createQuery("from Gauge as gau " + "where gau.name=:name and gau.river=:river");
+
+ query.setParameter("name", gauge_name);
+ query.setParameter("river", river);
+
+ final List results = query.list();
+
+ return results.isEmpty() ? null : results.get(0);
+ }
public DischargeTable fetchMasterDischargeTable() {
- Session session = SessionHolder.HOLDER.get();
+ final Session session = SessionHolder.HOLDER.get();
- Query query = session.createQuery(
- "from DischargeTable " +
- "where kind = 0 " +
- "and gauge = :gauge");
+ final Query query = session.createQuery("from DischargeTable " + "where kind = 0 " + "and gauge = :gauge");
query.setParameter("gauge", this);
- List