annotate 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
rev   line source
3739
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.services;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
2
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
3 import java.math.BigDecimal;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
4 import java.util.List;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
5
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
6 import org.apache.log4j.Logger;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
7
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
8 import org.w3c.dom.Document;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
9 import org.w3c.dom.Element;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
10
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.CallMeta;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.GlobalContext;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
13 import de.intevation.artifacts.common.ArtifactNamespaceContext;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.common.utils.XMLUtils;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
15
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.artifacts.model.RiverFactory;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.model.Gauge;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
18 import de.intevation.flys.model.MinMaxWQ;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19 import de.intevation.flys.model.Range;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
20 import de.intevation.flys.model.River;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
21
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
22 /**
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
23 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
24 */
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
25 public class GaugeOverviewInfoService extends FLYSService {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
26
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
27 private static final Logger logger = Logger.getLogger(
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
28 GaugeOverviewInfoService.class);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
29
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
30 public static final String RIVER_XPATH = "/art:river/text()";
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
31
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
32 @Override
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
33 public Document doProcess(
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
34 Document data,
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
35 GlobalContext globalContext,
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
36 CallMeta callMeta
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
37 ) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
38 logger.debug("GaugeOverviewInfoService.process");
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
39
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
40 String riverstr = XMLUtils.xpathString(
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
41 data, RIVER_XPATH, ArtifactNamespaceContext.INSTANCE);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
42
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
43 River river = RiverFactory.getRiver(riverstr);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
44
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
45 Document result = XMLUtils.newDocument();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
46
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
47 if (river == null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
48 logger.warn("No river with name " + riverstr + " found.");
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
49 return result;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
50 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
51
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
52 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
53 result,
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
54 ArtifactNamespaceContext.NAMESPACE_URI,
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
55 ArtifactNamespaceContext.NAMESPACE_PREFIX);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
56
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
57 Element go = ec.create("gauge-info");
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
58
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
59 double[] minmax = river.determineMinMaxDistance();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
60
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
61 Element r = ec.create("river");
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
62 ec.addAttr(r, "name", river.getName(), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
63 ec.addAttr(r, "start", Double.toString(minmax[0]), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
64 ec.addAttr(r, "end", Double.toString(minmax[1]), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
65 ec.addAttr(r, "wstunit", river.getWstUnit().getName(), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
66 ec.addAttr(r, "kmup", Boolean.toString(river.getKmUp()), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
67 //TODO
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
68 /* ec.addAttr(r, "qmin", , true); */
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
69 /* ec.addAttr(r, "qmax", , true); */
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
70
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
71 Element egs = ec.create("gauges");
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
72
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
73 List<Gauge> gauges = river.getGauges();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
74 logger.debug("Loaded gauges: " + gauges);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
75 for (Gauge gauge: river.getGauges()) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
76 Element eg = ec.create("gauge");
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
77 String name = gauge.getName();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
78 if (name != null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
79 ec.addAttr(eg, "name", gauge.getName(), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
80 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
81
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
82 Range range = gauge.getRange();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
83 if (range != null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
84 double min = range.getA().doubleValue();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
85 ec.addAttr(eg, "start", Double.toString(min), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
86
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
87 BigDecimal b = range.getB();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
88 if (b != null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
89 double max = range.getB().doubleValue();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
90 ec.addAttr(eg, "end", Double.toString(max), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
91 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
92 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
93 MinMaxWQ minmaxwq = gauge.fetchMaxMinWQ();
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
94 String minw = getGaugeValue(minmaxwq.getMinW());
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
95 String maxw = getGaugeValue(minmaxwq.getMaxW());
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
96 String minq = getGaugeValue(minmaxwq.getMinQ());
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
97 String maxq = getGaugeValue(minmaxwq.getMaxQ());
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
98
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
99 if (minw != null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
100 ec.addAttr(eg, "minw", minw, true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
101 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
102 if (maxw != null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
103 ec.addAttr(eg, "maxw", maxw, true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
104 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
105 if (minq != null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
106 ec.addAttr(eg, "minq", minq, true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
107 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
108 if (maxq != null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
109 ec.addAttr(eg, "maxq", maxq, true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
110 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
111
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
112 ec.addAttr(eg, "aeo", Double.toString(gauge.getAeo().doubleValue()), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
113 ec.addAttr(eg, "datum", Double.toString(gauge.getDatum().doubleValue()), true);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
114
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
115 egs.appendChild(eg);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
116 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
117
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
118 go.appendChild(r);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
119 go.appendChild(egs);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
120 result.appendChild(go);
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
121
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
122 return result;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
123 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
124
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
125 private String getGaugeValue(BigDecimal value) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
126 if (value == null) {
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
127 return null;
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
128 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
129 return Double.toString(value.doubleValue());
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
130 }
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
131
0edc05642fa4 Add new artifact service for the gauge overview
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
132 }

http://dive4elements.wald.intevation.org