teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5863: * Software engineering by Intevation GmbH
teichmann@5863: *
teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5994: * documentation coming with Dive4Elements River for details.
teichmann@5863: */
teichmann@5863:
teichmann@5831: package org.dive4elements.river.artifacts.services;
ingo@331:
ingo@331: import java.util.List;
ingo@331:
ingo@331: import org.apache.log4j.Logger;
teichmann@5831: import org.dive4elements.artifacts.CallMeta;
teichmann@5831: import org.dive4elements.artifacts.GlobalContext;
teichmann@5831: import org.dive4elements.river.model.Gauge;
teichmann@5831: import org.dive4elements.river.model.MainValue;
teichmann@5831: import org.dive4elements.river.model.River;
gernotbelger@9288: import org.w3c.dom.Document;
ingo@331:
ingo@331: /**
ingo@331: * This service returns the main values of a river's gauge based on the start
ingo@331: * and end point of the river.
ingo@331: *
ingo@331: * @author Ingo Weinzierl
ingo@331: */
gernotbelger@9288: public class MainValuesService extends AbstractMainValuesService {
ingo@331:
gernotbelger@9288: private static final long serialVersionUID = 1L;
felix@7555:
gernotbelger@9288: /** The log that is used by this service. */
gernotbelger@9288: private static Logger log = Logger.getLogger(MainValuesService.class);
ingo@331:
sascha@966: @Override
gernotbelger@9288: public Document doProcess(final Document data, final GlobalContext context, final CallMeta callMeta) {
gernotbelger@9288: try {
gernotbelger@9404: final River river = getRequestedRiver(data, "/art:mainvalues/art:river/text()");
gernotbelger@9288: final Gauge gauge = getRequestedGauge(data, river);
ingo@331:
gernotbelger@9288: final List mainValues = getMainValues(river, gauge);
ingo@331:
gernotbelger@9288: return buildDocument(river, gauge, mainValues, context);
sascha@3728: }
gernotbelger@9288: catch (final MainValuesServiceException e) {
gernotbelger@9288: e.printStackTrace();
gernotbelger@9288: return error(e.getMessage());
ingo@331: }
ingo@331: }
ingo@331:
ingo@331: /**
ingo@331: * This method creates the result document that includes the main values of
ingo@331: * the specified gauge.
ingo@331: *
gernotbelger@9288: * @param river
gernotbelger@9288: * The river.
gernotbelger@9288: * @param gauge
gernotbelger@9288: * The gauge.
ingo@331: *
ingo@331: * @return a document that includes the main values of the specified river
gernotbelger@9288: * at the specified gauge.
ingo@331: */
gernotbelger@9288: protected List getMainValues(final River river, final Gauge gauge) {
sascha@3728:
teichmann@8202: if (log.isDebugEnabled()) {
teichmann@8202: log.debug("MainValuesService.buildMainValues");
teichmann@8202: log.debug("River: " + river.getName());
teichmann@8202: log.debug("Gauge: " + gauge.getName());
ingo@331: }
ingo@331:
gernotbelger@9288: final List mainValues = gauge.getMainValues();
ingo@331:
teichmann@8202: if (log.isDebugEnabled()) {
teichmann@8202: log.debug(mainValues.size() + " main values found.");
ingo@331: }
ingo@1631:
ingo@1631: return mainValues;
ingo@331: }
gernotbelger@9288: }