comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java @ 3739:0edc05642fa4

Add new artifact service for the gauge overview flys-artifacts/trunk@5416 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Mon, 10 Sep 2012 08:23:08 +0000
parents
children a33df17ac9bb
comparison
equal deleted inserted replaced
3738:34da25796c21 3739:0edc05642fa4
1 package de.intevation.flys.artifacts.services;
2
3 import java.math.BigDecimal;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10
11 import de.intevation.artifacts.CallMeta;
12 import de.intevation.artifacts.GlobalContext;
13 import de.intevation.artifacts.common.ArtifactNamespaceContext;
14 import de.intevation.artifacts.common.utils.XMLUtils;
15
16 import de.intevation.flys.artifacts.model.RiverFactory;
17 import de.intevation.flys.model.Gauge;
18 import de.intevation.flys.model.MinMaxWQ;
19 import de.intevation.flys.model.Range;
20 import de.intevation.flys.model.River;
21
22 /**
23 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
24 */
25 public class GaugeOverviewInfoService extends FLYSService {
26
27 private static final Logger logger = Logger.getLogger(
28 GaugeOverviewInfoService.class);
29
30 public static final String RIVER_XPATH = "/art:river/text()";
31
32 @Override
33 public Document doProcess(
34 Document data,
35 GlobalContext globalContext,
36 CallMeta callMeta
37 ) {
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
61 Element r = ec.create("river");
62 ec.addAttr(r, "name", river.getName(), true);
63 ec.addAttr(r, "start", Double.toString(minmax[0]), true);
64 ec.addAttr(r, "end", Double.toString(minmax[1]), true);
65 ec.addAttr(r, "wstunit", river.getWstUnit().getName(), true);
66 ec.addAttr(r, "kmup", Boolean.toString(river.getKmUp()), true);
67 //TODO
68 /* ec.addAttr(r, "qmin", , true); */
69 /* ec.addAttr(r, "qmax", , true); */
70
71 Element egs = ec.create("gauges");
72
73 List<Gauge> gauges = river.getGauges();
74 logger.debug("Loaded gauges: " + gauges);
75 for (Gauge gauge: river.getGauges()) {
76 Element eg = ec.create("gauge");
77 String name = gauge.getName();
78 if (name != null) {
79 ec.addAttr(eg, "name", gauge.getName(), true);
80 }
81
82 Range range = gauge.getRange();
83 if (range != null) {
84 double min = range.getA().doubleValue();
85 ec.addAttr(eg, "start", Double.toString(min), true);
86
87 BigDecimal b = range.getB();
88 if (b != null) {
89 double max = range.getB().doubleValue();
90 ec.addAttr(eg, "end", Double.toString(max), true);
91 }
92 }
93 MinMaxWQ minmaxwq = gauge.fetchMaxMinWQ();
94 String minw = getGaugeValue(minmaxwq.getMinW());
95 String maxw = getGaugeValue(minmaxwq.getMaxW());
96 String minq = getGaugeValue(minmaxwq.getMinQ());
97 String maxq = getGaugeValue(minmaxwq.getMaxQ());
98
99 if (minw != null) {
100 ec.addAttr(eg, "minw", minw, true);
101 }
102 if (maxw != null) {
103 ec.addAttr(eg, "maxw", maxw, true);
104 }
105 if (minq != null) {
106 ec.addAttr(eg, "minq", minq, true);
107 }
108 if (maxq != null) {
109 ec.addAttr(eg, "maxq", maxq, true);
110 }
111
112 ec.addAttr(eg, "aeo", Double.toString(gauge.getAeo().doubleValue()), true);
113 ec.addAttr(eg, "datum", Double.toString(gauge.getDatum().doubleValue()), true);
114
115 egs.appendChild(eg);
116 }
117
118 go.appendChild(r);
119 go.appendChild(egs);
120 result.appendChild(go);
121
122 return result;
123 }
124
125 private String getGaugeValue(BigDecimal value) {
126 if (value == null) {
127 return null;
128 }
129 return Double.toString(value.doubleValue());
130 }
131
132 }

http://dive4elements.wald.intevation.org