view flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents 5da024c2af62
children b0173cdbbe51
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.Gauge;
import de.intevation.flys.model.MinMaxWQ;
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 GaugeOverviewInfoService extends RiverInfoService {

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

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

        logger.debug("GaugeOverviewInfoService.process");

        Element egs = ec.create("gauges");

        List<Gauge> gauges = river.getGauges();

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

        for (Gauge gauge: river.getGauges()) {
            Element eg = ec.create("gauge");

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

            String aeo = getStringValue(gauge.getAeo());
            if (aeo != null) {
                ec.addAttr(eg, "aeo", aeo, true);
            }

            String datum = getStringValue(gauge.getDatum());
            if (datum != null) {
                ec.addAttr(eg, "datum", datum, true);
            }

            Range range = gauge.getRange();
            if (range != null) {
                BigDecimal a = range.getA();
                if (a != null) {
                    double min = a.doubleValue();
                    ec.addAttr(eg, "start", Double.toString(min), true);
                }

                BigDecimal b = range.getB();
                if (b != null) {
                    double max = range.getB().doubleValue();
                    ec.addAttr(eg, "end", Double.toString(max), true);
                }
            }
            MinMaxWQ minmaxwq = gauge.fetchMaxMinWQ();
            String minw = getStringValue(minmaxwq.getMinW());
            String maxw = getStringValue(minmaxwq.getMaxW());
            String minq = getStringValue(minmaxwq.getMinQ());
            String maxq = getStringValue(minmaxwq.getMaxQ());

            if (minw != null) {
                ec.addAttr(eg, "minw", minw, true);
            }
            if (maxw != null) {
                ec.addAttr(eg, "maxw", maxw, true);
            }
            if (minq != null) {
                ec.addAttr(eg, "minq", minq, true);
            }
            if (maxq != null) {
                ec.addAttr(eg, "maxq", maxq, true);
            }

            String station = getStringValue(gauge.getStation());
            if (station != null) {
                ec.addAttr(eg, "station", station, true);
            }

            Long official = gauge.getOfficialNumber();
            if (official != null) {
                ec.addAttr(eg, "official", official.toString(), true);
            }

            egs.appendChild(eg);
        }

        riverele.appendChild(egs);

        return result;
    }
}

http://dive4elements.wald.intevation.org