view backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/FlowDepthColumnSeriesImport.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 31549fdfaf4f
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.io.File;
import java.util.List;

import org.apache.log4j.Logger;
import org.dive4elements.river.importer.common.AbstractSeriesImport;
import org.dive4elements.river.model.River;
import org.dive4elements.river.model.sinfo.FlowDepthColumn;
import org.dive4elements.river.model.sinfo.FlowDepthValue;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 * Imported flow depth data series of a river
 *
 * @author Matthias Schäfer
 *
 */
public class FlowDepthColumnSeriesImport extends AbstractSeriesImport<FlowDepthColumn, FlowDepthValue, FlowDepthKmLineImport> {

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

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

    private int year;

    private String sounding_info;

    private String evaluation_by;

    private final FlowDepthSeriesImport parent;

    private final String colName;

    private final File relativeFilePath;


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

    public FlowDepthColumnSeriesImport(final String filename) {
        this(filename, null, null, null);
    }

    public FlowDepthColumnSeriesImport(final String filename, final FlowDepthSeriesImport parent, final String colName, final File relativeFilePath) {
        super(filename);
        this.parent = parent;
        final String[] items = (colName == null) ? new String[] {} : colName.split("\\-");
        if (items.length == 2)
            this.colName = items[0].trim() + " - " + items[1].trim();
        else
            this.colName = colName;
        this.relativeFilePath = relativeFilePath;
    }


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

    public int getYear() {
        return this.year;
    }

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

    public String getSounding_info() {
        return this.sounding_info;
    }

    public void setSounding_info(final String sounding_info) {
        this.sounding_info = sounding_info;
    }

    public String getEvaluation_by() {
        return this.evaluation_by;
    }

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

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

    private List<FlowDepthColumn> querySeriesItem(final Session session, final River river) {
        final Query query = session.createQuery("FROM FlowDepthColumn WHERE flowDepth=:parent AND lower(name)=:colname");
        query.setParameter("parent", this.parent.getPeer(river));
        query.setParameter("colname", this.colName.toLowerCase());
        return query.list();
    }

    @Override
    public List<FlowDepthColumn> querySeriesItem(final Session session, final River river, final boolean doQueryParent) {
        final Query query = session.createQuery("FROM FlowDepthColumn c INNER JOIN c.flowDepth s"
                + " WHERE s.river=:river AND lower(s.filename)=:filename AND lower(c.name)=:colname");
        query.setParameter("river", river);
        query.setParameter("filename", this.filename.toLowerCase());
        query.setParameter("colname", this.colName.toLowerCase());
        return query.list();
    }

    @Override
    public FlowDepthColumn createSeriesItem(final River river) {
        return new FlowDepthColumn(this.parent.getPeer(river), this.colName);
    }

    @Override
    protected void logStoreInfo() {
        getLog().info(String.format("Store series column '%s':;'%s'", this.colName, this.relativeFilePath));
    }
}

http://dive4elements.wald.intevation.org