Mercurial > dive4elements > river
changeset 9405:34cd4faf43f4
minMax queries
author | gernotbelger |
---|---|
date | Wed, 15 Aug 2018 14:34:23 +0200 |
parents | bc9a45d2b1fa |
children | 55e3b1a8aa06 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java backend/src/main/java/org/dive4elements/river/model/sinfo/DailyDischargeValue.java |
diffstat | 2 files changed, 17 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Wed Aug 15 13:59:09 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Wed Aug 15 14:34:23 2018 +0200 @@ -25,6 +25,7 @@ import org.dive4elements.river.model.Gauge; import org.dive4elements.river.model.River; import org.dive4elements.river.model.sinfo.DailyDischargeValue; +import org.dive4elements.river.model.sinfo.DailyDischargeValue.MinMax; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -92,18 +93,15 @@ for (final Gauge gauge : gauges) { - final List<DailyDischargeValue> qdvsGlobal = DailyDischargeValue.getGlobalMinMax(gauge); - if (qdvsGlobal == null) { - + final Date minGlobalForGauge = DailyDischargeValue.getGlobalMinMax(gauge, MinMax.min); + final Date maxGlobalForGauge = DailyDischargeValue.getGlobalMinMax(gauge, MinMax.max); + if (minGlobalForGauge == null || maxGlobalForGauge == null) { // der Fall, dass nur eins von beiden null ist, kann eigentlich nciht vorkommen 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;
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/DailyDischargeValue.java Wed Aug 15 13:59:09 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/DailyDischargeValue.java Wed Aug 15 14:34:23 2018 +0200 @@ -11,7 +11,6 @@ package org.dive4elements.river.model.sinfo; import java.io.Serializable; -import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -50,6 +49,10 @@ DAY, DISCHARGE; } + public enum MinMax { + min, max + } + /***** FIELDS *****/ private static final long serialVersionUID = -6192738825193230784L; @@ -139,22 +142,17 @@ /** * Selects from the database the daily discharge, puts the first and the last into a List (min, max day) */ - public static List<DailyDischargeValue> getGlobalMinMax(final Gauge gauge) { + + public static Date getGlobalMinMax(final Gauge gauge, final MinMax minmax) { final Session session = SessionHolder.HOLDER.get(); - final Query query = session - .createQuery("SELECT v" + " FROM DailyDischargeValue AS v JOIN v.dailyDischarge AS s" + " WHERE (s.gauge.id=:gaugeid) ORDER BY day"); + final Query query = session.createQuery( + "SELECT " + minmax.toString() + "(v.day) " + " FROM DailyDischargeValue AS v JOIN v.dailyDischarge AS s" + " WHERE (s.gauge.id=:gaugeid)"); query.setParameter("gaugeid", gauge.getId()); - return minMaxFromDbResultHelper(query.list()); + final List<Date> list = query.list(); + if (list != null && list.size() == 1) { + return list.get(0); + } + return null; } - private static List<DailyDischargeValue> minMaxFromDbResultHelper(final List<DailyDischargeValue> values) { - if (values != null && values.size() > 1) { - final List<DailyDischargeValue> newList = new ArrayList<>(); - newList.add(values.get(0)); - newList.add(values.get(values.size() - 1)); - return newList; - } - return null; - - } }