view backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureSeriesImport.java @ 9658:d86c7cb68b41

Importer (s/u-info) extensions: daily discharge: detecting, logging and skipping lines with missing date or q, or duplicate date, detecting wrong column titles and cancelling the import, specific error message if gauge not found
author mschaefer
date Mon, 23 Mar 2020 15:33:40 +0100
parents cedcee24a21a
children 75bd347147ad
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.List;

import org.apache.log4j.Logger;
import org.dive4elements.river.importer.ImportAnnotationType;
import org.dive4elements.river.importer.common.AbstractSeriesImport;
import org.dive4elements.river.model.River;
import org.dive4elements.river.model.sinfo.Infrastructure;
import org.dive4elements.river.model.sinfo.InfrastructureValue;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 * Imported infrastructure data series of a river and a type
 *
 * @author Matthias Schäfer
 *
 */
public class InfrastructureSeriesImport extends AbstractSeriesImport<Infrastructure, InfrastructureValue, InfrastructureKmLineImport> {

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

    private static Logger log = Logger.getLogger(InfrastructureSeriesImport.class);

    private ImportAnnotationType type;

    private ImportAnnotationType group;

    private String provider;

    private String evaluation_by;

    private int year;


    /***** CONSTRUCTORS *****/

    public InfrastructureSeriesImport(final String filename) {
        super(filename);
    }


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

    public void setType(final ImportAnnotationType type) {
        this.type = type;
    }

    public void setGroup(final ImportAnnotationType group) {
        this.group = group;
    }

    public void setProvider(final String provider) {
        this.provider = provider;
    }

    public void setEvaluation_by(final String evaluation_by) {
        this.evaluation_by = evaluation_by;
    }

    public void setYear(final int year) {
        this.year = year;
    }

    @Override
    public Logger getLog() {
        return log;
    }

    @Override
    public List<Infrastructure> querySeriesItem(final Session session, final River river) {
        final Query query = session.createQuery("FROM Infrastructure WHERE river=:river AND lower(filename)=:filename");
        query.setParameter("river", river);
        query.setParameter("filename", this.filename.toLowerCase());
        return query.list();
    }


    @Override
    public Infrastructure createSeriesItem(final River river) {
        return new Infrastructure(river, this.filename, this.kmrange_info, this.notes, this.type.getPeer(), this.group.getPeer(), this.year, this.provider,
                this.evaluation_by);
    }
}

http://dive4elements.wald.intevation.org