Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/RiverInfoService.java @ 5753:6f166b8b5eda
Rework layout for issue 767
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 18 Apr 2013 10:43:23 +0200 |
parents | 5da024c2af62 |
children |
rev | line source |
---|---|
4247
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.services; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
2 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
3 import java.math.BigDecimal; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
4 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
5 import org.apache.log4j.Logger; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
6 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Document; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.Element; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
9 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.artifacts.CallMeta; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.GlobalContext; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifacts.common.utils.XMLUtils; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
14 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.flys.artifacts.model.RiverFactory; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.flys.model.River; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
17 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
18 /** |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
19 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
20 */ |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
21 public class RiverInfoService extends FLYSService { |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
22 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
23 private static final Logger logger = Logger.getLogger( |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
24 RiverInfoService.class); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
25 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
26 protected static final String RIVER_XPATH = "/art:river/text()"; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
28 protected XMLUtils.ElementCreator ec; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 protected River river; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
30 protected Element riverele; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
31 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
32 protected Document doProcess( |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 Document data, |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
34 GlobalContext globalContext, |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
35 CallMeta callMeta |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
36 ) { |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 String rivername = XMLUtils.xpathString( |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
38 data, RIVER_XPATH, ArtifactNamespaceContext.INSTANCE); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
39 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 river = RiverFactory.getRiver(rivername); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
41 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
42 Document result = XMLUtils.newDocument(); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
43 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
44 if (river == null) { |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
45 logger.warn("No river with name " + rivername + " found."); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
46 return null; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
47 } |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
48 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
49 ec = new XMLUtils.ElementCreator( |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
50 result, |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
51 ArtifactNamespaceContext.NAMESPACE_URI, |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
52 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
53 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
54 riverele = ec.create("river-info"); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
55 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
56 double[] minmax = river.determineMinMaxDistance(); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
57 double[] minmaxq = river.determineMinMaxQ(); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
58 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
59 Element r = ec.create("river"); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
60 ec.addAttr(r, "name", river.getName(), true); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
61 ec.addAttr(r, "start", Double.toString(minmax[0]), true); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
62 ec.addAttr(r, "end", Double.toString(minmax[1]), true); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
63 ec.addAttr(r, "wstunit", river.getWstUnit().getName(), true); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
64 ec.addAttr(r, "kmup", Boolean.toString(river.getKmUp()), true); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
65 ec.addAttr(r, "minq", Double.toString(minmaxq[0]), true); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
66 ec.addAttr(r, "maxq", Double.toString(minmaxq[1]), true); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
67 ec.addAttr(r, "official", Long.toString(river.getOfficialNumber()), |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
68 true); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
69 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
70 riverele.appendChild(r); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
71 result.appendChild(riverele); |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
72 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
73 return result; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
74 } |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
75 |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
76 /** |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
77 * Returns a Double as String from a BigDecimal value. |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
78 * |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
79 * If value is null an empty String is returned. |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
80 */ |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
81 protected static String getStringValue(BigDecimal value) { |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
82 return value != null |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
83 ? Double.toString(value.doubleValue()) : ""; |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
84 } |
5da024c2af62
Refactor GaugeOverviewInfoService and MeasurementStationInfoService
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
85 } |