view flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java @ 4287:82c1e911dd71

Add start and end time of an observation on a measurement station Add start and end time of an observation on a measurement station to the MeasurementStation classes.
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 29 Oct 2012 09:54:31 +0100
parents 31c017420502
children 3fffd7d5d67d
line wrap: on
line source
package de.intevation.flys.artifacts.services;

import java.math.BigDecimal;
import java.util.List;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import de.intevation.artifacts.CallMeta;
import de.intevation.artifacts.GlobalContext;
import de.intevation.artifacts.common.ArtifactNamespaceContext;
import de.intevation.artifacts.common.utils.XMLUtils;

import de.intevation.flys.artifacts.model.RiverFactory;
import de.intevation.flys.model.MeasurementStation;
import de.intevation.flys.model.Range;
import de.intevation.flys.model.River;

/**
 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
 */
public class MeasurementStationInfoService extends RiverInfoService {

    private static final Logger logger = Logger.getLogger(
            MeasurementStationInfoService.class);

    @Override
    public Document doProcess(
        Document      data,
        GlobalContext globalContext,
        CallMeta      callMeta
    ) {
        Document result = super.doProcess(data, globalContext, callMeta);

        Element egs = ec.create("measurement-stations");

        List<MeasurementStation> mstations = river.getMeasurementStations();

        if (logger.isDebugEnabled()) {
            logger.debug("Loaded stations: " + mstations);
        }

        for (MeasurementStation mstation: mstations) {
            Element eg = ec.create("measurement-station");

            String name = mstation.getName();
            if (name != null) {
                ec.addAttr(eg, "name", name, true);
            }

            Integer id = mstation.getId();
            if (id != null) {
                ec.addAttr(eg, "id", Integer.toString(id), true);
            }

            String type = mstation.getMeasurementType();
            if (type != null) {
                ec.addAttr(eg, "type", type, true);
            }

            String riverside = mstation.getRiverside();
            if (riverside != null) {
                ec.addAttr(eg, "riverside", riverside, true);
            }

            Double station = mstation.getStation();
            if (station != null) {
                ec.addAttr(eg, "station", Double.toString(station), true);
            }

            Range range = mstation.getRange();
            if (range != null) {
                BigDecimal a = range.getA();
                if (a != null) {
                    ec.addAttr(eg, "start", getStringValue(a), true);
                }

                BigDecimal b = range.getB();
                if (b != null) {
                    ec.addAttr(eg, "end", getStringValue(b), true);
                }
            }

            String moperator = mstation.getOperator();
            if (moperator != null) {
                ec.addAttr(eg, "operator", moperator, true);
            }

            egs.appendChild(eg);
        }

        this.riverele.appendChild(egs);

        return result;
    }

}

http://dive4elements.wald.intevation.org