bjoern@4246: package de.intevation.flys.artifacts.services;
bjoern@4246:
bjoern@4246: import java.math.BigDecimal;
bjoern@4289: import java.text.DateFormat;
bjoern@4289: import java.util.Date;
bjoern@4246: import java.util.List;
bjoern@4289: import java.util.Locale;
bjoern@4246:
bjoern@4246: import org.apache.log4j.Logger;
bjoern@4246:
bjoern@4246: import org.w3c.dom.Document;
bjoern@4246: import org.w3c.dom.Element;
bjoern@4246:
bjoern@4246: import de.intevation.artifacts.CallMeta;
bjoern@4246: import de.intevation.artifacts.GlobalContext;
bjoern@4246:
bjoern@4246: import de.intevation.flys.model.MeasurementStation;
bjoern@4324: import de.intevation.flys.model.Gauge;
bjoern@4246: import de.intevation.flys.model.Range;
bjoern@4246: import de.intevation.flys.model.River;
bjoern@4289: import de.intevation.flys.model.TimeInterval;
bjoern@4246:
bjoern@4246: /**
bjoern@4246: * @author Björn Ricks
bjoern@4246: */
bjoern@4247: public class MeasurementStationInfoService extends RiverInfoService {
bjoern@4246:
bjoern@4246: private static final Logger logger = Logger.getLogger(
bjoern@4264: MeasurementStationInfoService.class);
bjoern@4246:
bjoern@4289: public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance(
bjoern@4289: DateFormat.SHORT, Locale.GERMANY);
bjoern@4289:
bjoern@4246: @Override
bjoern@4246: public Document doProcess(
bjoern@4246: Document data,
bjoern@4246: GlobalContext globalContext,
bjoern@4246: CallMeta callMeta
bjoern@4246: ) {
bjoern@4247: Document result = super.doProcess(data, globalContext, callMeta);
bjoern@4246:
bjoern@4246: Element egs = ec.create("measurement-stations");
bjoern@4246:
bjoern@4246: List mstations = river.getMeasurementStations();
bjoern@4246:
bjoern@4246: if (logger.isDebugEnabled()) {
bjoern@4246: logger.debug("Loaded stations: " + mstations);
bjoern@4246: }
bjoern@4246:
bjoern@4246: for (MeasurementStation mstation: mstations) {
bjoern@4246: Element eg = ec.create("measurement-station");
bjoern@4246:
bjoern@4246: String name = mstation.getName();
bjoern@4246: if (name != null) {
bjoern@4246: ec.addAttr(eg, "name", name, true);
bjoern@4246: }
bjoern@4246:
bjoern@4263: Integer id = mstation.getId();
bjoern@4263: if (id != null) {
bjoern@4263: ec.addAttr(eg, "id", Integer.toString(id), true);
bjoern@4263: }
bjoern@4263:
bjoern@4246: String type = mstation.getMeasurementType();
bjoern@4246: if (type != null) {
bjoern@4246: ec.addAttr(eg, "type", type, true);
bjoern@4246: }
bjoern@4246:
bjoern@4246: String riverside = mstation.getRiverside();
bjoern@4246: if (riverside != null) {
bjoern@4246: ec.addAttr(eg, "riverside", riverside, true);
bjoern@4246: }
bjoern@4246:
bjoern@4246: Double station = mstation.getStation();
bjoern@4246: if (station != null) {
bjoern@4246: ec.addAttr(eg, "station", Double.toString(station), true);
bjoern@4246: }
bjoern@4246:
bjoern@4246: Range range = mstation.getRange();
bjoern@4246: if (range != null) {
bjoern@4246: BigDecimal a = range.getA();
bjoern@4246: if (a != null) {
bjoern@4246: ec.addAttr(eg, "start", getStringValue(a), true);
bjoern@4246: }
bjoern@4246:
bjoern@4246: BigDecimal b = range.getB();
bjoern@4246: if (b != null) {
bjoern@4246: ec.addAttr(eg, "end", getStringValue(b), true);
bjoern@4246: }
bjoern@4246: }
bjoern@4246:
bjoern@4263: String moperator = mstation.getOperator();
bjoern@4263: if (moperator != null) {
bjoern@4263: ec.addAttr(eg, "operator", moperator, true);
bjoern@4263: }
bjoern@4263:
bjoern@4289: TimeInterval tinterval = mstation.getObservationTimerange();
bjoern@4289: if (tinterval != null) {
bjoern@4289: Date tstart = tinterval.getStartTime();
bjoern@4289: if (tstart != null) {
bjoern@4289: ec.addAttr(eg, "starttime", DATE_FORMAT.format(tstart),
bjoern@4289: true);
bjoern@4289: }
bjoern@4289: Date tstop = tinterval.getStopTime();
bjoern@4289: if (tstop != null) {
bjoern@4289: ec.addAttr(eg, "stoptime", DATE_FORMAT.format(tstop),
bjoern@4289: true);
bjoern@4289: }
bjoern@4289: }
bjoern@4289:
bjoern@4324: Gauge gauge = mstation.getGauge();
bjoern@4324: String gaugename = gauge.getName();
bjoern@4324:
bjoern@4324: if (gaugename != null) {
bjoern@4324: Element egauge = ec.create("gauge");
bjoern@4324: ec.addAttr(egauge, "name", gaugename, true);
bjoern@4324: eg.appendChild(egauge);
bjoern@4324: }
bjoern@4324:
bjoern@4246: egs.appendChild(eg);
bjoern@4246: }
bjoern@4246:
bjoern@4247: this.riverele.appendChild(egs);
bjoern@4246:
bjoern@4246: return result;
bjoern@4246: }
bjoern@4246:
bjoern@4246: }