Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeInfoService.java @ 4116:4ffeccc5b5a1
Initial GUI and state for per-segment Q-input for extreme valua analysis.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 12 Oct 2012 15:07:01 +0200 |
parents | 0cc2c3d89a9d |
children | 7d4480c0e68e |
rev | line source |
---|---|
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.services; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 import java.util.List; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 import java.util.Date; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 import java.util.Calendar; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 import java.util.GregorianCalendar; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 import org.apache.log4j.Logger; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import org.w3c.dom.Document; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 import org.w3c.dom.Element; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifacts.CallMeta; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.GlobalContext; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.artifacts.common.utils.XMLUtils; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.flys.model.Gauge; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.flys.model.DischargeTable; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.flys.model.TimeInterval; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 /** |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 * This service provides information about discharges at a defined gauge. |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 * |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 */ |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 public class DischargeInfoService extends FLYSService { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 /** The logger used in this service. */ |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 private static Logger logger = Logger.getLogger(DischargeInfoService.class); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 public static final String GAUGE_XPATH = "/art:gauge/text()"; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 public DischargeInfoService() { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 @Override |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 public Document doProcess( |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 Document data, |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 GlobalContext globalContext, |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 CallMeta callMeta |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 ) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 logger.debug("DischargeInfoService.process"); |
4115
0cc2c3d89a9d
#900 Added complete start and end date to the discharge info service and display on in the client side.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
46 logger.debug(XMLUtils.toString(data)); |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 String gaugeNumber = XMLUtils.xpathString( |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 data, GAUGE_XPATH, ArtifactNamespaceContext.INSTANCE); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 if(gaugeNumber == null || |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 (gaugeNumber = gaugeNumber.trim()).length() == 0) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 logger.warn("No gauge specified. Cannot return discharge info."); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 return XMLUtils.newDocument(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 logger.debug("Getting discharge for gauge: " + gaugeNumber); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 long gn; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 try { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 gn = Long.parseLong(gaugeNumber); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 catch (NumberFormatException nfe) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 logger.warn("Invalid gauge number. Cannot return discharg info."); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 return XMLUtils.newDocument(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 Gauge gauge = Gauge.getGaugeByOfficialNumber(gn); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 logger.debug("Found gauge: " + gauge.getName()); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 return buildDocument(gauge); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 protected Document buildDocument(Gauge gauge) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 Document result = XMLUtils.newDocument(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 List<DischargeTable> tables =gauge.getDischargeTables(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 Element all = result.createElement("discharges"); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 for (DischargeTable dt: tables) { |
2598
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
83 if (dt.getKind() == Gauge.MASTER_DISCHARGE_TABLE) { |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
84 continue; |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
85 } |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
86 |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 Element discharge = result.createElement("discharge"); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 discharge.setAttribute("description", dt.getDescription()); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
89 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
90 // Get time interval. |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
91 TimeInterval ti = dt.getTimeInterval(); |
2598
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
92 |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
93 if (ti == null) { |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
94 logger.warn("DischargeTable has no TimeInterval set!"); |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
95 continue; |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
96 } |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
97 |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 Date startTime = ti.getStartTime(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 Date stopTime = ti.getStopTime(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 if (startTime != null) { |
4115
0cc2c3d89a9d
#900 Added complete start and end date to the discharge info service and display on in the client side.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
102 discharge.setAttribute("start", String.valueOf(startTime.getTime())); |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 else { |
4115
0cc2c3d89a9d
#900 Added complete start and end date to the discharge info service and display on in the client side.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
105 discharge.setAttribute("start", "-1"); |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 } |
4115
0cc2c3d89a9d
#900 Added complete start and end date to the discharge info service and display on in the client side.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
107 |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 if (stopTime != null) { |
4115
0cc2c3d89a9d
#900 Added complete start and end date to the discharge info service and display on in the client side.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
109 discharge.setAttribute("end", String.valueOf(stopTime.getTime())); |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
110 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 else { |
4115
0cc2c3d89a9d
#900 Added complete start and end date to the discharge info service and display on in the client side.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
112 discharge.setAttribute("end", "-1"); |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
114 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
115 all.appendChild(discharge); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
116 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 result.appendChild(all); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
118 return result; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
119 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
120 } |
3083
4bd3d8bbb60c
Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2598
diff
changeset
|
121 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |