Mercurial > dive4elements > river
changeset 4173:7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
In addition to this, the discharge tables in the helper panel displayed in the client is ordered in time.
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 18 Oct 2012 12:13:48 +0200 |
parents | 9fd17cb69047 |
children | eaf83d4ae6b1 |
files | flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeInfoService.java flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java |
diffstat | 2 files changed, 71 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeInfoService.java Thu Oct 18 09:53:27 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeInfoService.java Thu Oct 18 12:13:48 2012 +0200 @@ -1,5 +1,6 @@ package de.intevation.flys.artifacts.services; +import java.util.Collections; import java.util.List; import java.util.Date; import java.util.Calendar; @@ -16,6 +17,7 @@ import de.intevation.artifacts.common.ArtifactNamespaceContext; import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.artifacts.model.DischargeTables; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.TimeInterval; @@ -77,13 +79,10 @@ Document result = XMLUtils.newDocument(); List<DischargeTable> tables =gauge.getDischargeTables(); + Collections.sort(tables); Element all = result.createElement("discharges"); for (DischargeTable dt: tables) { - if (dt.getKind() == Gauge.MASTER_DISCHARGE_TABLE) { - continue; - } - Element discharge = result.createElement("discharge"); discharge.setAttribute("description", dt.getDescription()); @@ -102,14 +101,18 @@ discharge.setAttribute("start", String.valueOf(startTime.getTime())); } else { - discharge.setAttribute("start", "-1"); + continue; } - if (stopTime != null) { + if (stopTime != null && dt.getKind() != DischargeTables.MASTER) { discharge.setAttribute("end", String.valueOf(stopTime.getTime())); } + else if (dt.getKind() == DischargeTables.MASTER) { + long now = System.currentTimeMillis(); + discharge.setAttribute("end", String.valueOf(now)); + } else { - discharge.setAttribute("end", "-1"); + continue; } all.appendChild(discharge);
--- a/flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java Thu Oct 18 09:53:27 2012 +0200 +++ b/flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java Thu Oct 18 12:13:48 2012 +0200 @@ -1,25 +1,25 @@ package de.intevation.flys.model; import java.io.Serializable; +import java.util.Date; +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.SequenceGenerator; -import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.OrderBy; -import javax.persistence.JoinColumn; - -import java.util.List; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; @Entity @Table(name = "discharge_tables") public class DischargeTable -implements Serializable +implements Serializable, Comparable<DischargeTable> { private Integer id; private Gauge gauge; @@ -116,5 +116,57 @@ ) { this.dischargeTableValues = dischargeTableValues; } + + @Override + public int compareTo(DischargeTable o) { + if (getKind() == 0 && o.getKind() != 0) { + return 1; + } + + TimeInterval other = o.getTimeInterval(); + + Date otherStartTime = other.getStartTime(); + Date thisStartTime = timeInterval.getStartTime(); + + if (otherStartTime == null) { + return -1; + } + else if (thisStartTime == null) { + return 1; + } + + long otherStart = otherStartTime.getTime(); + long thisStart = thisStartTime.getTime(); + + if (otherStart < thisStart) { + return 1; + } + else if (otherStart > thisStart) { + return -1; + } + + Date otherStopTime = other.getStopTime(); + Date thisStopTime = timeInterval.getStopTime(); + + if (otherStopTime == null) { + return -1; + } + else if (thisStopTime == null) { + return 1; + } + + long otherEnd = otherStopTime.getTime(); + long thisEnd = thisStopTime.getTime(); + + if (otherEnd < thisEnd) { + return 1; + } + else if (otherEnd > thisEnd) { + return -1; + } + else { + return 0; + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :