annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java @ 5694:8508ee487893

SedimentLoadYearSelect: Add validation to have second year later than first.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 15 Apr 2013 10:55:08 +0200
parents 57f802db5c5a
children
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;
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
18 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
19 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
20
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 * @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
23 */
4247
5da024c2af62 Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4246
diff changeset
24 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
25
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
26 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
27 MeasurementStationInfoService.class);
4246
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
28
4289
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
29 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
30 DateFormat.SHORT, Locale.GERMANY);
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
31
4246
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
32 @Override
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
33 public Document doProcess(
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
34 Document data,
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
35 GlobalContext globalContext,
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
36 CallMeta callMeta
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
37 ) {
4247
5da024c2af62 Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4246
diff changeset
38 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
39
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
40 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
41
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
42 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
43
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
44 if (logger.isDebugEnabled()) {
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
45 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
46 }
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 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
49 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
50
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
51 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
52 if (name != null) {
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
53 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
54 }
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
55
4263
6abc8507e3c8 Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4247
diff changeset
56 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
57 if (id != null) {
6abc8507e3c8 Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4247
diff changeset
58 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
59 }
6abc8507e3c8 Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4247
diff changeset
60
4246
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
61 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
62 if (type != null) {
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
63 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
64 }
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 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
67 if (riverside != null) {
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
68 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
69 }
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 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
72 if (station != null) {
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
73 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
74 }
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 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
77 if (range != null) {
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
78 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
79 if (a != null) {
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
80 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
81 }
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 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
84 if (b != null) {
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
85 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
86 }
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
4263
6abc8507e3c8 Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4247
diff changeset
89 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
90 if (moperator != null) {
6abc8507e3c8 Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4247
diff changeset
91 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
92 }
6abc8507e3c8 Add operator and station id to the artifact xml
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4247
diff changeset
93
4289
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
94 TimeInterval tinterval = mstation.getObservationTimerange();
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
95 if (tinterval != null) {
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
96 Date tstart = tinterval.getStartTime();
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
97 if (tstart != null) {
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
98 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
99 true);
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
100 }
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
101 Date tstop = tinterval.getStopTime();
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
102 if (tstop != null) {
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
103 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
104 true);
3fffd7d5d67d Add observation TimeInteval to the artifact MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4264
diff changeset
105 }
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
5497
5d99cd6e146a Use gauge name instead of gauge to fill 'messstelleninfo'.
Raimund Renkert <rrenkert@intevation.de>
parents: 4382
diff changeset
108 String gaugename= mstation.getGaugeName();
4324
4980659b2f22 Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4289
diff changeset
109
4980659b2f22 Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4289
diff changeset
110 if (gaugename != null) {
4980659b2f22 Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4289
diff changeset
111 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
112 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
113 eg.appendChild(egauge);
4980659b2f22 Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4289
diff changeset
114 }
4980659b2f22 Add gauge name to the measurement station xml response
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4289
diff changeset
115
4246
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
116 egs.appendChild(eg);
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
117 }
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
118
4247
5da024c2af62 Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4246
diff changeset
119 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
120
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
121 return result;
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
cac0878b4a92 Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
124 }

http://dive4elements.wald.intevation.org