view backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java @ 8975:a0a0a7f912ab

Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
author mschaefer
date Tue, 03 Apr 2018 10:40:57 +0200
parents 5e38e2924c07
children 392bbcd8a88b
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.importer;

import java.util.List;

import org.apache.log4j.Logger;
import org.dive4elements.river.model.BedHeight;
import org.dive4elements.river.model.BedHeightValue;
import org.hibernate.Query;
import org.hibernate.Session;


public class ImportBedHeightValue {

    private static final Logger log = Logger.getLogger(ImportBedHeightValue.class);


    protected ImportBedHeight bedHeight;

    protected Double station;
    protected Double height;
    protected Double uncertainty;
    protected Double dataGap;
    protected Double soundingWidth;
    protected Double minHeight;
    protected Double maxHeight;

    protected BedHeightValue peer;


    public ImportBedHeightValue(final ImportBedHeight bedHeight, final Double station, final Double height, final Double uncertainty, final Double dataGap,
            final Double soundingWidth, final Double minHeight, final Double maxHeight) {
        this.bedHeight     = bedHeight;
        this.station       = station;
        this.height        = height;
        this.uncertainty   = uncertainty;
        this.dataGap       = dataGap;
        this.soundingWidth = soundingWidth;
        this.minHeight = minHeight;
        this.maxHeight = maxHeight;
    }


    public void storeDependencies(final BedHeight bedHeight) {
        getPeer(bedHeight);
    }


    /**
     * Add this value to database or return database bound Value, assuring
     * that the BedHeight exists in db already.
     */
    public BedHeightValue getPeer(final BedHeight bedHeight) {
        if (this.peer != null)
            return this.peer;

        final Session session = ImporterSession.getInstance().getDatabaseSession();
        final Query query = session.createQuery("FROM BedHeightValue WHERE (bedHeight=:bedHeight)"
                + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))");
        query.setParameter("bedHeight", bedHeight);
        query.setParameter("station", this.station);
        final List<BedHeightValue> values = query.list();
        if (values.isEmpty()) {
            this.peer = new BedHeightValue(bedHeight, this.station, this.height, this.uncertainty, this.dataGap, this.soundingWidth,
                    this.minHeight, this.maxHeight);
            session.save(this.peer);
        } else {
            this.peer = values.get(0);
        }
        return this.peer;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org