view backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/CollisionKmLineImport.java @ 9657:a79881a892c9

Importer (s/u-info) extensions: depth-evolution: corrected directory name Bezug_aktueller_GlW, detecting and logging of wrong units, then cancelling, various checks of the plausibility of the meta data year values and cancelling in case of errors, detecting and logging missing change values, skipping those lines
author mschaefer
date Mon, 23 Mar 2020 15:26:50 +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.Date;
import java.util.List;

import org.dive4elements.river.importer.common.AbstractKmLineImport;
import org.dive4elements.river.model.sinfo.Collision;
import org.dive4elements.river.model.sinfo.CollisionValue;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 * Imported collision event of a river station.
 *
 * @author Matthias Schäfer
 *
 */
public class CollisionKmLineImport extends AbstractKmLineImport<Collision, CollisionValue> {

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

    private final CollisionTypeImport collisionType;

    private final Date eventDate;

    private final String gaugeName;

    private final double gaugeW;


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

    public CollisionKmLineImport(final Double km, final CollisionTypeImport collisionType, final Date eventDate, final String gaugeName, final double gaugeW) {
        super(km.doubleValue());
        this.collisionType = collisionType;
        this.eventDate = eventDate;
        this.gaugeName = gaugeName;
        this.gaugeW = gaugeW;
    }


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

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


    @Override
    protected CollisionValue createValueItem(final Collision parent) {
        return new CollisionValue(parent, this.station, this.collisionType.getPeer(), this.eventDate, this.gaugeName, this.gaugeW);
    }
}

http://dive4elements.wald.intevation.org