comparison 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
comparison
equal deleted inserted replaced
4246:cac0878b4a92 4247:5da024c2af62
19 import de.intevation.flys.model.River; 19 import de.intevation.flys.model.River;
20 20
21 /** 21 /**
22 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> 22 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
23 */ 23 */
24 public class MeasurementStationInfoService extends FLYSService { 24 public class MeasurementStationInfoService extends RiverInfoService {
25 25
26 private static final Logger logger = Logger.getLogger( 26 private static final Logger logger = Logger.getLogger(
27 GaugeOverviewInfoService.class); 27 GaugeOverviewInfoService.class);
28
29 public static final String RIVER_XPATH = "/art:river/text()";
30 28
31 @Override 29 @Override
32 public Document doProcess( 30 public Document doProcess(
33 Document data, 31 Document data,
34 GlobalContext globalContext, 32 GlobalContext globalContext,
35 CallMeta callMeta 33 CallMeta callMeta
36 ) { 34 ) {
37 logger.debug("MeasurementStationInfoService.process"); 35 Document result = super.doProcess(data, globalContext, callMeta);
38
39 String riverstr = XMLUtils.xpathString(
40 data, RIVER_XPATH, ArtifactNamespaceContext.INSTANCE);
41
42 River river = RiverFactory.getRiver(riverstr);
43
44 Document result = XMLUtils.newDocument();
45
46 if (river == null) {
47 logger.warn("No river with name " + riverstr + " found.");
48 return result;
49 }
50
51 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
52 result,
53 ArtifactNamespaceContext.NAMESPACE_URI,
54 ArtifactNamespaceContext.NAMESPACE_PREFIX);
55
56 Element go = ec.create("masurement-station-info");
57
58 double[] minmax = river.determineMinMaxDistance();
59 double[] minmaxq = river.determineMinMaxQ();
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 ec.addAttr(r, "minq", Double.toString(minmaxq[0]), true);
68 ec.addAttr(r, "maxq", Double.toString(minmaxq[1]), true);
69 ec.addAttr(r, "official", Long.toString(river.getOfficialNumber()),
70 true);
71 36
72 Element egs = ec.create("measurement-stations"); 37 Element egs = ec.create("measurement-stations");
73 38
74 List<MeasurementStation> mstations = river.getMeasurementStations(); 39 List<MeasurementStation> mstations = river.getMeasurementStations();
75 40
114 } 79 }
115 80
116 egs.appendChild(eg); 81 egs.appendChild(eg);
117 } 82 }
118 83
119 go.appendChild(r); 84 this.riverele.appendChild(egs);
120 go.appendChild(egs);
121 result.appendChild(go);
122 85
123 return result; 86 return result;
124 } 87 }
125 88
126 /**
127 * Returns a Double as String from a BigDecimal value.
128 *
129 * If value is null an empty String is returned.
130 */
131 private static String getStringValue(BigDecimal value) {
132 return value != null
133 ? Double.toString(value.doubleValue()) : "";
134 }
135 } 89 }

http://dive4elements.wald.intevation.org