view backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/FlowDepthKmLineImport.java @ 9656:31549fdfaf4f

Importer (s/u-info) extensions: flow-depth: uniform formatting of from-to series names, warning instead of cancelling in case of missing column values, detecting, logging and skipping columns with wrong unit, better counting of inserted/updated values for each column
author mschaefer
date Mon, 23 Mar 2020 15:21:39 +0100
parents 50416a0df385
children
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * 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.importer.sinfo.importitem;

import java.util.List;

import org.dive4elements.river.importer.common.AbstractKmLineImport;
import org.dive4elements.river.model.sinfo.FlowDepthColumn;
import org.dive4elements.river.model.sinfo.FlowDepthValue;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 * Imported flow depth value of a river station.
 *
 * @author Matthias Schäfer
 *
 */
public class FlowDepthKmLineImport extends AbstractKmLineImport<FlowDepthColumn, FlowDepthValue> {

    /***** FIELDS *****/

    /**
     * Flow depth in m
     */
    private final double depth;


    /***** CONSTRUCTOR *****/

    public FlowDepthKmLineImport(final Double km, final double depth) {
        super(km.doubleValue());
        this.depth = depth;
    }


    /***** METHODS *****/

    @Override
    protected FlowDepthValue queryValueItem(final Session session, final FlowDepthColumn parent) {
        final Query query = session.createQuery("FROM FlowDepthValue WHERE (flowDepthColumn=:parent)"
                + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))");
        query.setParameter("parent", parent);
        query.setParameter("station", this.station);
        final List rows = query.list();
        if (!rows.isEmpty())
            return (FlowDepthValue) rows.get(0);
        else
            return null;
    }


    @Override
    protected FlowDepthValue createValueItem(final FlowDepthColumn parent) {
        return new FlowDepthValue(parent, this.station, this.depth);
    }
}

http://dive4elements.wald.intevation.org