Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java @ 4837:9e25c7523485
Fixed calculation of effective width in MINFO SQ relation.
* Get all (including empty datasets) from db.
* Filter empty datasets when processing data of the same date.
* Added debug outputs.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 23 Jan 2013 11:14:41 +0100 |
parents | 3937c6a85db4 |
children | 5d99cd6e146a |
rev | line source |
---|---|
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.services; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
2 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
3 import java.math.BigDecimal; |
4289
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
4 import java.text.DateFormat; |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
5 import java.util.Date; |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
6 import java.util.List; |
4289
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
7 import java.util.Locale; |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
8 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
9 import org.apache.log4j.Logger; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
10 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 import org.w3c.dom.Document; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
12 import org.w3c.dom.Element; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
13 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.CallMeta; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifacts.GlobalContext; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.flys.model.MeasurementStation; |
4324
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
18 import de.intevation.flys.model.Gauge; |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.flys.model.Range; |
4289
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
20 import de.intevation.flys.model.TimeInterval; |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
21 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
22 /** |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
23 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
24 */ |
4247
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4246
diff
changeset
|
25 public class MeasurementStationInfoService extends RiverInfoService { |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
26 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 private static final Logger logger = Logger.getLogger( |
4264
31c017420502
Use correct class for logger in MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4263
diff
changeset
|
28 MeasurementStationInfoService.class); |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 |
4289
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
30 public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
31 DateFormat.SHORT, Locale.GERMANY); |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
32 |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 @Override |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
34 public Document doProcess( |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
35 Document data, |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
36 GlobalContext globalContext, |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 CallMeta callMeta |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
38 ) { |
4247
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4246
diff
changeset
|
39 Document result = super.doProcess(data, globalContext, callMeta); |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
41 Element egs = ec.create("measurement-stations"); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
42 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
43 List<MeasurementStation> mstations = river.getMeasurementStations(); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
44 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
45 if (logger.isDebugEnabled()) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
46 logger.debug("Loaded stations: " + mstations); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
47 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
48 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
49 for (MeasurementStation mstation: mstations) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
50 Element eg = ec.create("measurement-station"); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
51 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
52 String name = mstation.getName(); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
53 if (name != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
54 ec.addAttr(eg, "name", name, true); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
55 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
56 |
4263
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
57 Integer id = mstation.getId(); |
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
58 if (id != null) { |
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
59 ec.addAttr(eg, "id", Integer.toString(id), true); |
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
60 } |
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
61 |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
62 String type = mstation.getMeasurementType(); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
63 if (type != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
64 ec.addAttr(eg, "type", type, true); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
65 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
66 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
67 String riverside = mstation.getRiverside(); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
68 if (riverside != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
69 ec.addAttr(eg, "riverside", riverside, true); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
70 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
71 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
72 Double station = mstation.getStation(); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
73 if (station != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
74 ec.addAttr(eg, "station", Double.toString(station), true); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
75 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
76 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
77 Range range = mstation.getRange(); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
78 if (range != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
79 BigDecimal a = range.getA(); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
80 if (a != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
81 ec.addAttr(eg, "start", getStringValue(a), true); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
82 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
83 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
84 BigDecimal b = range.getB(); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
85 if (b != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
86 ec.addAttr(eg, "end", getStringValue(b), true); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
87 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
88 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
89 |
4263
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
90 String moperator = mstation.getOperator(); |
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
91 if (moperator != null) { |
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
92 ec.addAttr(eg, "operator", moperator, true); |
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
93 } |
6abc8507e3c8
Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4247
diff
changeset
|
94 |
4289
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
95 TimeInterval tinterval = mstation.getObservationTimerange(); |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
96 if (tinterval != null) { |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
97 Date tstart = tinterval.getStartTime(); |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
98 if (tstart != null) { |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
99 ec.addAttr(eg, "starttime", DATE_FORMAT.format(tstart), |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
100 true); |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
101 } |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
102 Date tstop = tinterval.getStopTime(); |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
103 if (tstop != null) { |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
104 ec.addAttr(eg, "stoptime", DATE_FORMAT.format(tstop), |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
105 true); |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
106 } |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
107 } |
3fffd7d5d67d
Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4264
diff
changeset
|
108 |
4324
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
109 Gauge gauge = mstation.getGauge(); |
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
110 String gaugename = gauge.getName(); |
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
111 |
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
112 if (gaugename != null) { |
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
113 Element egauge = ec.create("gauge"); |
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
114 ec.addAttr(egauge, "name", gaugename, true); |
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
115 eg.appendChild(egauge); |
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
116 } |
4980659b2f22
Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4289
diff
changeset
|
117 |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
118 egs.appendChild(eg); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
119 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
120 |
4247
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4246
diff
changeset
|
121 this.riverele.appendChild(egs); |
4246
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
122 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
123 return result; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
124 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
125 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
126 } |