view backend/src/main/java/org/dive4elements/river/importer/ImportElevationModel.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 a275ddf7a3a1
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.apache.log4j.Logger;
import org.dive4elements.river.model.ElevationModel;
import org.hibernate.Query;
import org.hibernate.Session;


public class ImportElevationModel {

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

    protected String name;

    protected ImportUnit unit;

    protected ElevationModel peer;


    public ImportElevationModel(final String name, final ImportUnit unit) {
        this.name = name;
        this.unit = unit;
    }


    public void storeDependencies() {
        final ElevationModel model = getPeer();
    }

    public ElevationModel getPeer() {
        if (this.unit == null) {
            log.warn("No elevation model specified.");
            return null;
        }
        if (this.peer != null)
            return this.peer;

        final Session session = ImporterSession.getInstance().getDatabaseSession();
        final Query query = session.createQuery("FROM ElevationModel WHERE (trim(name)=:name) AND (unit=:unit)");
        query.setParameter("name", this.name);
        query.setParameter("unit", this.unit.getPeer());
        final List<ElevationModel> models = query.list();

        if (models.isEmpty()) {
            log.info("Create new ElevationModel DB instance.");

            this.peer = new ElevationModel(this.name, this.unit.getPeer());
            session.save(this.peer);
        }
        else {
            this.peer = models.get(0);
        }
        return this.peer;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org