Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeInfoService.java @ 2592:26cd4dfafdf1
Removed useless imports.
flys-artifacts/trunk@4149 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 16 Mar 2012 07:07:32 +0000 |
parents | 2966787b5188 |
children | e96bf6c47c12 |
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"); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 String gaugeNumber = XMLUtils.xpathString( |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 data, GAUGE_XPATH, ArtifactNamespaceContext.INSTANCE); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 if(gaugeNumber == null || |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 (gaugeNumber = gaugeNumber.trim()).length() == 0) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 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
|
53 return XMLUtils.newDocument(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 } |
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 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
|
57 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 long gn; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 try { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 gn = Long.parseLong(gaugeNumber); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 catch (NumberFormatException nfe) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 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
|
64 return XMLUtils.newDocument(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 } |
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 Gauge gauge = Gauge.getGaugeByOfficialNumber(gn); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 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
|
70 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 return buildDocument(gauge); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 } |
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 protected Document buildDocument(Gauge gauge) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 Document result = XMLUtils.newDocument(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 List<DischargeTable> tables =gauge.getDischargeTables(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 Element all = result.createElement("discharges"); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 for (DischargeTable dt: tables) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 Element discharge = result.createElement("discharge"); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 discharge.setAttribute("description", dt.getDescription()); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 // Get time interval. |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 TimeInterval ti = dt.getTimeInterval(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 Date startTime = ti.getStartTime(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 Date stopTime = ti.getStopTime(); |
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 the year for start end end date. |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
91 int startYear; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
92 int stopYear; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 Calendar c = new GregorianCalendar(); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 if (startTime != null) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 c.setTime(startTime); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 startYear = c.get(Calendar.YEAR); |
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 else { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 startYear = -1; |
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 (stopTime != null) { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
102 c.setTime(stopTime); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 stopYear = c.get(Calendar.YEAR); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 else { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 stopYear = -1; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
107 } |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
109 discharge.setAttribute("start", String.valueOf(startYear)); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
110 discharge.setAttribute("end", String.valueOf(stopYear)); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 all.appendChild(discharge); |
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 result.appendChild(all); |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
115 return result; |
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 } |