Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java Wed Oct 24 15:57:48 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java Wed Oct 24 16:36:59 2012 +0200 @@ -21,53 +21,18 @@ /** * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> */ -public class MeasurementStationInfoService extends FLYSService { +public class MeasurementStationInfoService extends RiverInfoService { private static final Logger logger = Logger.getLogger( GaugeOverviewInfoService.class); - public static final String RIVER_XPATH = "/art:river/text()"; - @Override public Document doProcess( Document data, GlobalContext globalContext, CallMeta callMeta ) { - logger.debug("MeasurementStationInfoService.process"); - - String riverstr = XMLUtils.xpathString( - data, RIVER_XPATH, ArtifactNamespaceContext.INSTANCE); - - River river = RiverFactory.getRiver(riverstr); - - Document result = XMLUtils.newDocument(); - - if (river == null) { - logger.warn("No river with name " + riverstr + " found."); - return result; - } - - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - result, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element go = ec.create("masurement-station-info"); - - double[] minmax = river.determineMinMaxDistance(); - double[] minmaxq = river.determineMinMaxQ(); - - Element r = ec.create("river"); - ec.addAttr(r, "name", river.getName(), true); - ec.addAttr(r, "start", Double.toString(minmax[0]), true); - ec.addAttr(r, "end", Double.toString(minmax[1]), true); - ec.addAttr(r, "wstunit", river.getWstUnit().getName(), true); - ec.addAttr(r, "kmup", Boolean.toString(river.getKmUp()), true); - ec.addAttr(r, "minq", Double.toString(minmaxq[0]), true); - ec.addAttr(r, "maxq", Double.toString(minmaxq[1]), true); - ec.addAttr(r, "official", Long.toString(river.getOfficialNumber()), - true); + Document result = super.doProcess(data, globalContext, callMeta); Element egs = ec.create("measurement-stations"); @@ -116,20 +81,9 @@ egs.appendChild(eg); } - go.appendChild(r); - go.appendChild(egs); - result.appendChild(go); + this.riverele.appendChild(egs); return result; } - /** - * Returns a Double as String from a BigDecimal value. - * - * If value is null an empty String is returned. - */ - private static String getStringValue(BigDecimal value) { - return value != null - ? Double.toString(value.doubleValue()) : ""; - } }