view backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/FlowDepthColumnParser.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.parsers;

import java.io.File;

import org.apache.log4j.Logger;
import org.dive4elements.river.importer.ImportRiver;
import org.dive4elements.river.importer.common.AbstractParser;
import org.dive4elements.river.importer.common.ParsingState;
import org.dive4elements.river.importer.sinfo.importitem.FlowDepthColumnSeriesImport;
import org.dive4elements.river.importer.sinfo.importitem.FlowDepthKmLineImport;
import org.dive4elements.river.importer.sinfo.importitem.FlowDepthSeriesImport;
import org.dive4elements.river.model.sinfo.FlowDepthColumn;
import org.dive4elements.river.model.sinfo.FlowDepthValue;

/**
 * Reads and parses a column of a flow depth file
 *
 * @author Matthias Schäfer
 *
 */
public class FlowDepthColumnParser extends AbstractParser<FlowDepthColumn, FlowDepthValue, FlowDepthKmLineImport, FlowDepthColumnSeriesImport> {

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

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

    private final FlowDepthSeriesImport parent;

    private final int colIndex;

    private final String colName;


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

    public FlowDepthColumnParser(final File importPath, final File rootRelativePath, final ImportRiver river, final FlowDepthSeriesImport parent,
            final int colIndex, final String colName) {
        super(importPath, rootRelativePath, river);
        this.parent = parent;
        this.colIndex = colIndex;
        this.colName = colName;
    }


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

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

    @Override
    protected void logStartInfo() {
        getLog().info(String.format("Start parsing column %d '%s':;'%s'", this.colIndex + 1, this.colName, this.rootRelativePath));
    }

    @Override
    protected boolean handleMetaOther() {
        this.headerParsingState = ParsingState.IGNORE;
        return false;
    }

    @Override
    protected FlowDepthColumnSeriesImport createSeriesImport(final String filename) {
        return new FlowDepthColumnSeriesImport(filename, this.parent, this.colName, this.rootRelativePath);
    }

    @Override
    protected FlowDepthKmLineImport createKmLineImport(final Double km, final String[] values) {
        final Number value = parseDoubleCheckNull(values, this.colIndex);
        if ((value == null) || Double.isNaN(value.doubleValue())) {
            logLineWarning("Column %d: " + INVALID_VALUE_ERROR_FORMAT, this.colIndex + 1, "depth");
            return null;
        }
        return new FlowDepthKmLineImport(km, value.doubleValue());
    }
}

http://dive4elements.wald.intevation.org