view artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsJRDataSource.java @ 8755:30b1ddadf275

(issue1801) Unify reference gauge finding code The basic way as described in the method comment of the determineRefGauge method is now used in the WINFOArtifact, MainValuesService and RiverUtils.getGauge method. RiverUtils.getGauge previously just returned the first gauge found. While this is now a behavior change I believe that it is always more correct then the undeterministic behavior of the previous implmenentation.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 24 Jun 2015 14:07:26 +0200
parents e4606eae8ea5
children 0a5239a1e46e
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.model;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.log4j.Logger;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;


/**
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class WKmsJRDataSource implements JRDataSource
{
    /** The log used in this exporter.*/
    private static Logger log = Logger.getLogger(WKmsJRDataSource.class);

    /**
     *
     */
    private ArrayList<String[]> data;
    private HashMap<String, String> metaData;

    private int index = -1;

    /**
     *
     */
    public WKmsJRDataSource()
    {
        data = new ArrayList<String[]>();
        metaData = new HashMap<String, String>();
    }


    /**
     *
     */
    public void addData(String[] data) {
        this.data.add(data);
    }


    /**
     *
     */
    public void addMetaData(String key, String value) {
        this.metaData.put(key, value);
    }


    /**
     *
     */
    public boolean next() throws JRException
    {
        index++;

        return (index < data.size());
    }


    /**
     *
     */
    public Object getFieldValue(JRField field) throws JRException
    {
        Object value = "";
        String fieldName = field.getName();
        if ("river".equals(fieldName)) {
            value = metaData.get("river");
        }
        else if ("date".equals(fieldName)) {
            value = metaData.get("date");
        }
        else if ("range".equals(fieldName)) {
            value = metaData.get("range");
        }
        else if ("gauge".equals(fieldName)) {
            value = metaData.get("gauge");
        }
        else if ("datum".equals(fieldName)) {
            value = metaData.get("datum");
        }
        else if ("calculation".equals(fieldName)) {
            value = metaData.get("calculation");
        }
        else if ("differences".equals(fieldName)) {
            value = metaData.get("differences");
        }
        else if ("wUnit".equals(fieldName)) {
            value = metaData.get("wUnit");
        }
        else if ("valid_since".equals(fieldName)) {
            value = metaData.get("valid_since");
        }
        else if ("km".equals(fieldName)) {
            value = data.get(index)[0];
        }
        else if ("W".equals(fieldName)) {
            value = data.get(index)[1];
        }
        else if ("Q".equals(fieldName)) {
            value = data.get(index)[2];
        }
        else if ("description".equals(fieldName)) {
            value = data.get(index)[3];
        }
        else if ("location".equals(fieldName)) {
            value = data.get(index)[4];
        }
        else if ("gaugename".equals(fieldName)) {
            value = data.get(index)[5];
        }
        else if ("day".equals(fieldName)) {
            value = data.get(index)[6];
        }
        return value;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org