# HG changeset patch # User Ingo Weinzierl # Date 1350555228 -7200 # Node ID 7d4480c0e68ebc0e228b46bdc0538adf73f3fec7 # Parent 9fd17cb690475fdac04110b7d7e19505c780df9f 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. diff -r 9fd17cb69047 -r 7d4480c0e68e flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeInfoService.java --- 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 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); diff -r 9fd17cb69047 -r 7d4480c0e68e flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java --- 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 { 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 :