Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.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 | 5fce1908317f |
children | b0173cdbbe51 |
comparison
equal
deleted
inserted
replaced
4246:cac0878b4a92 | 4247:5da024c2af62 |
---|---|
20 import de.intevation.flys.model.River; | 20 import de.intevation.flys.model.River; |
21 | 21 |
22 /** | 22 /** |
23 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> | 23 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> |
24 */ | 24 */ |
25 public class GaugeOverviewInfoService extends FLYSService { | 25 public class GaugeOverviewInfoService extends RiverInfoService { |
26 | 26 |
27 private static final Logger logger = Logger.getLogger( | 27 private static final Logger logger = Logger.getLogger( |
28 GaugeOverviewInfoService.class); | 28 GaugeOverviewInfoService.class); |
29 | |
30 public static final String RIVER_XPATH = "/art:river/text()"; | |
31 | 29 |
32 @Override | 30 @Override |
33 public Document doProcess( | 31 public Document doProcess( |
34 Document data, | 32 Document data, |
35 GlobalContext globalContext, | 33 GlobalContext globalContext, |
36 CallMeta callMeta | 34 CallMeta callMeta |
37 ) { | 35 ) { |
36 Document result = super.doProcess(data, globalContext, callMeta); | |
37 | |
38 logger.debug("GaugeOverviewInfoService.process"); | 38 logger.debug("GaugeOverviewInfoService.process"); |
39 | |
40 String riverstr = XMLUtils.xpathString( | |
41 data, RIVER_XPATH, ArtifactNamespaceContext.INSTANCE); | |
42 | |
43 River river = RiverFactory.getRiver(riverstr); | |
44 | |
45 Document result = XMLUtils.newDocument(); | |
46 | |
47 if (river == null) { | |
48 logger.warn("No river with name " + riverstr + " found."); | |
49 return result; | |
50 } | |
51 | |
52 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
53 result, | |
54 ArtifactNamespaceContext.NAMESPACE_URI, | |
55 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
56 | |
57 Element go = ec.create("gauge-info"); | |
58 | |
59 double[] minmax = river.determineMinMaxDistance(); | |
60 double[] minmaxq = river.determineMinMaxQ(); | |
61 | |
62 Element r = ec.create("river"); | |
63 ec.addAttr(r, "name", river.getName(), true); | |
64 ec.addAttr(r, "start", Double.toString(minmax[0]), true); | |
65 ec.addAttr(r, "end", Double.toString(minmax[1]), true); | |
66 ec.addAttr(r, "wstunit", river.getWstUnit().getName(), true); | |
67 ec.addAttr(r, "kmup", Boolean.toString(river.getKmUp()), true); | |
68 ec.addAttr(r, "minq", Double.toString(minmaxq[0]), true); | |
69 ec.addAttr(r, "maxq", Double.toString(minmaxq[1]), true); | |
70 ec.addAttr(r, "official", Long.toString(river.getOfficialNumber()), | |
71 true); | |
72 | 39 |
73 Element egs = ec.create("gauges"); | 40 Element egs = ec.create("gauges"); |
74 | 41 |
75 List<Gauge> gauges = river.getGauges(); | 42 List<Gauge> gauges = river.getGauges(); |
76 | 43 |
84 String name = gauge.getName(); | 51 String name = gauge.getName(); |
85 if (name != null) { | 52 if (name != null) { |
86 ec.addAttr(eg, "name", gauge.getName(), true); | 53 ec.addAttr(eg, "name", gauge.getName(), true); |
87 } | 54 } |
88 | 55 |
89 String aeo = getGaugeValue(gauge.getAeo()); | 56 String aeo = getStringValue(gauge.getAeo()); |
90 if (aeo != null) { | 57 if (aeo != null) { |
91 ec.addAttr(eg, "aeo", aeo, true); | 58 ec.addAttr(eg, "aeo", aeo, true); |
92 } | 59 } |
93 | 60 |
94 String datum = getGaugeValue(gauge.getDatum()); | 61 String datum = getStringValue(gauge.getDatum()); |
95 if (datum != null) { | 62 if (datum != null) { |
96 ec.addAttr(eg, "datum", datum, true); | 63 ec.addAttr(eg, "datum", datum, true); |
97 } | 64 } |
98 | 65 |
99 Range range = gauge.getRange(); | 66 Range range = gauge.getRange(); |
109 double max = range.getB().doubleValue(); | 76 double max = range.getB().doubleValue(); |
110 ec.addAttr(eg, "end", Double.toString(max), true); | 77 ec.addAttr(eg, "end", Double.toString(max), true); |
111 } | 78 } |
112 } | 79 } |
113 MinMaxWQ minmaxwq = gauge.fetchMaxMinWQ(); | 80 MinMaxWQ minmaxwq = gauge.fetchMaxMinWQ(); |
114 String minw = getGaugeValue(minmaxwq.getMinW()); | 81 String minw = getStringValue(minmaxwq.getMinW()); |
115 String maxw = getGaugeValue(minmaxwq.getMaxW()); | 82 String maxw = getStringValue(minmaxwq.getMaxW()); |
116 String minq = getGaugeValue(minmaxwq.getMinQ()); | 83 String minq = getStringValue(minmaxwq.getMinQ()); |
117 String maxq = getGaugeValue(minmaxwq.getMaxQ()); | 84 String maxq = getStringValue(minmaxwq.getMaxQ()); |
118 | 85 |
119 if (minw != null) { | 86 if (minw != null) { |
120 ec.addAttr(eg, "minw", minw, true); | 87 ec.addAttr(eg, "minw", minw, true); |
121 } | 88 } |
122 if (maxw != null) { | 89 if (maxw != null) { |
127 } | 94 } |
128 if (maxq != null) { | 95 if (maxq != null) { |
129 ec.addAttr(eg, "maxq", maxq, true); | 96 ec.addAttr(eg, "maxq", maxq, true); |
130 } | 97 } |
131 | 98 |
132 String station = getGaugeValue(gauge.getStation()); | 99 String station = getStringValue(gauge.getStation()); |
133 if (station != null) { | 100 if (station != null) { |
134 ec.addAttr(eg, "station", station, true); | 101 ec.addAttr(eg, "station", station, true); |
135 } | 102 } |
136 | 103 |
137 Long official = gauge.getOfficialNumber(); | 104 Long official = gauge.getOfficialNumber(); |
140 } | 107 } |
141 | 108 |
142 egs.appendChild(eg); | 109 egs.appendChild(eg); |
143 } | 110 } |
144 | 111 |
145 go.appendChild(r); | 112 riverele.appendChild(egs); |
146 go.appendChild(egs); | |
147 result.appendChild(go); | |
148 | 113 |
149 return result; | 114 return result; |
150 } | 115 } |
151 | |
152 /** | |
153 * Returns a Double from a BigDecimal value or null if value is null | |
154 */ | |
155 private static String getGaugeValue(BigDecimal value) { | |
156 return value != null | |
157 ? Double.toString(value.doubleValue()) | |
158 : ""; | |
159 } | |
160 } | 116 } |