Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeInfoService.java @ 4637:3ab9ec5ca02f
Added methods to set single values.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 04 Dec 2012 15:38:21 +0100 |
parents | 5b8919ef601d |
children |
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 |
4173
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
3 import java.util.Collections; |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 import java.util.Date; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 import org.apache.log4j.Logger; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 import org.w3c.dom.Document; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import org.w3c.dom.Element; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.artifacts.CallMeta; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifacts.GlobalContext; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 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
|
16 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
|
17 |
4173
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
18 import de.intevation.flys.artifacts.model.DischargeTables; |
2276
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 |
4433
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4432
diff
changeset
|
79 List<DischargeTable> tables =gauge.getDischargeTables(); |
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4432
diff
changeset
|
80 Collections.sort(tables); |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 Element all = result.createElement("discharges"); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 for (DischargeTable dt: tables) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 Element discharge = result.createElement("discharge"); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 discharge.setAttribute("description", dt.getDescription()); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 // Get time interval. |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 TimeInterval ti = dt.getTimeInterval(); |
2598
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
89 |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
90 if (ti == null) { |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
91 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
|
92 continue; |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
93 } |
e96bf6c47c12
Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2276
diff
changeset
|
94 |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 Date startTime = ti.getStartTime(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 Date stopTime = ti.getStopTime(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 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
|
99 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
|
100 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 else { |
4173
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
102 continue; |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 } |
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
|
104 |
4173
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
105 if (stopTime != null && dt.getKind() != DischargeTables.MASTER) { |
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
|
106 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
|
107 } |
4173
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
108 else if (dt.getKind() == DischargeTables.MASTER) { |
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
109 long now = System.currentTimeMillis(); |
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
110 discharge.setAttribute("end", String.valueOf(now)); |
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
111 } |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 else { |
4173
7d4480c0e68e
Allow users to select the current relevant discharge table in historical discharge table calculattion.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4115
diff
changeset
|
113 continue; |
2276
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 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
116 all.appendChild(discharge); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
118 result.appendChild(all); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
119 return result; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
120 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
121 } |
3083
4bd3d8bbb60c
Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2598
diff
changeset
|
122 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |