Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java @ 4247:5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Refactor RiverInfoService out of GaugeOverviewInfoService and
MeasurementStationInfoService to share common code of both classes in a base
class.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 24 Oct 2012 16:36:59 +0200 |
parents | cac0878b4a92 |
children | 6abc8507e3c8 |
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; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
5 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
6 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
|
7 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
8 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
|
9 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
|
10 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 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
|
12 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
|
13 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
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.common.utils.XMLUtils; |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.flys.artifacts.model.RiverFactory; |
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; |
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.River; |
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( |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 GaugeOverviewInfoService.class); |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
28 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 @Override |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
30 public Document doProcess( |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
31 Document data, |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
32 GlobalContext globalContext, |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 CallMeta callMeta |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
34 ) { |
4247
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4246
diff
changeset
|
35 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
|
36 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 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
|
38 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
39 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
|
40 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
41 if (logger.isDebugEnabled()) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
42 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
|
43 } |
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 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
|
46 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
|
47 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
48 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
|
49 if (name != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
50 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
|
51 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
52 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
53 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
|
54 if (type != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
55 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
|
56 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
57 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
58 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
|
59 if (riverside != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
60 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
|
61 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
62 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
63 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
|
64 if (station != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
65 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
|
66 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
67 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
68 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
|
69 if (range != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
70 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
|
71 if (a != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
72 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
|
73 } |
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 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
|
76 if (b != null) { |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
77 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
|
78 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
79 } |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
80 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
81 egs.appendChild(eg); |
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 |
4247
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4246
diff
changeset
|
84 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
|
85 |
cac0878b4a92
Add a service to return measurement stations of a river
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
86 return result; |
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 } |