view backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadLSValue.java @ 9650:a2a42a6bac6b

Importer (s/u-info) extensions: outer try/catch for parse and log of line no, catching parsing exception if not enough value fields, parsing error and warning log messages with line number, detecting and rejecting duplicate data series, better differentiation between error and warning log messages
author mschaefer
date Mon, 23 Mar 2020 14:57:03 +0100
parents 392bbcd8a88b
children
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.dive4elements.river.importer.common.StoreMode;
import org.dive4elements.river.model.SedimentLoadLS;
import org.dive4elements.river.model.SedimentLoadLSValue;
import org.hibernate.Query;
import org.hibernate.Session;


public class ImportSedimentLoadLSValue {

    private final Double station;
    private final Double value;

    private SedimentLoadLSValue peer;


    public ImportSedimentLoadLSValue(final Double station, final Double value) {
        this.station = station;
        this.value   = value;
    }


    public void storeDependencies(final SedimentLoadLS sedimentLoadLS, final StoreMode parentStoreMode) {
        getPeer(sedimentLoadLS, parentStoreMode);
    }


    public SedimentLoadLSValue getPeer(final SedimentLoadLS sedimentLoadLS, final StoreMode parentStoreMode) {
        if (this.peer == null) {
            List<SedimentLoadLSValue> values;
            final Session session = ImporterSession.getInstance().getDatabaseSession();
            if (parentStoreMode == StoreMode.INSERT)
                values = null;
            else {
                final Query query = session.createQuery(
                        "from SedimentLoadLSValue where " +
                                "   sedimentLoadLS=:sedimentLoadLS and " +
                                "   station=:station and " +
                                "   value=:value"
                        );
                query.setParameter("sedimentLoadLS", sedimentLoadLS);
                query.setParameter("station", this.station);
                query.setParameter("value", this.value);
                values = query.list();
            }
            if ((values == null) || values.isEmpty()) {
                this.peer = new SedimentLoadLSValue(sedimentLoadLS, this.station, this.value);
                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