annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeInfoService.java @ 3394:f091f2f55f88

Partial implementation of bandwidths for curves (issue720). flys-artifacts/trunk@5024 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 17 Jul 2012 18:31:34 +0000
parents 4bd3d8bbb60c
children 0cc2c3d89a9d
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) {
2598
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2276
diff changeset
82 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
83 continue;
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2276
diff changeset
84 }
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2276
diff changeset
85
2276
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 Element discharge = result.createElement("discharge");
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 discharge.setAttribute("description", dt.getDescription());
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 // Get time interval.
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 TimeInterval ti = dt.getTimeInterval();
2598
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2276
diff changeset
91
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2276
diff changeset
92 if (ti == null) {
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2276
diff changeset
93 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
94 continue;
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2276
diff changeset
95 }
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2276
diff changeset
96
2276
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 Date startTime = ti.getStartTime();
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 Date stopTime = ti.getStopTime();
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100 // 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
101 int startYear;
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 int stopYear;
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 Calendar c = new GregorianCalendar();
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 if (startTime != null) {
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 c.setTime(startTime);
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 startYear = c.get(Calendar.YEAR);
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 else {
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 startYear = -1;
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 if (stopTime != null) {
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 c.setTime(stopTime);
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 stopYear = c.get(Calendar.YEAR);
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 else {
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116 stopYear = -1;
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
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119 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
120 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
121
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
122 all.appendChild(discharge);
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123 }
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 result.appendChild(all);
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125 return result;
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 }
2966787b5188 Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 }
3083
4bd3d8bbb60c Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2598
diff changeset
128 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org