view backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/CollisionKmLineImport.java @ 8971:50416a0df385

Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
author mschaefer
date Tue, 03 Apr 2018 10:18:30 +0200
parents
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