view artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java @ 9404:bc9a45d2b1fa

common time range for gauges incl. error messages
author gernotbelger
date Wed, 15 Aug 2018 13:59:09 +0200
parents 82c67b859aa7
children
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts.services;

import java.util.List;

import org.apache.log4j.Logger;
import org.dive4elements.artifacts.CallMeta;
import org.dive4elements.artifacts.GlobalContext;
import org.dive4elements.river.model.Gauge;
import org.dive4elements.river.model.MainValue;
import org.dive4elements.river.model.River;
import org.w3c.dom.Document;

/**
 * This service returns the main values of a river's gauge based on the start
 * and end point of the river.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class MainValuesService extends AbstractMainValuesService {

    private static final long serialVersionUID = 1L;

    /** The log that is used by this service. */
    private static Logger log = Logger.getLogger(MainValuesService.class);

    @Override
    public Document doProcess(final Document data, final GlobalContext context, final CallMeta callMeta) {
        try {
            final River river = getRequestedRiver(data, "/art:mainvalues/art:river/text()");
            final Gauge gauge = getRequestedGauge(data, river);

            final List<MainValue> mainValues = getMainValues(river, gauge);

            return buildDocument(river, gauge, mainValues, context);
        }
        catch (final MainValuesServiceException e) {
            e.printStackTrace();
            return error(e.getMessage());
        }
    }

    /**
     * This method creates the result document that includes the main values of
     * the specified <i>gauge</i>.
     *
     * @param river
     *            The river.
     * @param gauge
     *            The gauge.
     *
     * @return a document that includes the main values of the specified river
     *         at the specified gauge.
     */
    protected List<MainValue> getMainValues(final River river, final Gauge gauge) {

        if (log.isDebugEnabled()) {
            log.debug("MainValuesService.buildMainValues");
            log.debug("River: " + river.getName());
            log.debug("Gauge: " + gauge.getName());
        }

        final List<MainValue> mainValues = gauge.getMainValues();

        if (log.isDebugEnabled()) {
            log.debug(mainValues.size() + " main values found.");
        }

        return mainValues;
    }
}

http://dive4elements.wald.intevation.org