view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/SINFOArtifact.java @ 8948:a4f1ac81f26d

Work on SINFO-FlowDepthMinMax. Also rework of result row stuff, in order to reduce abstraction, using result type concept
author gernotbelger
date Wed, 14 Mar 2018 14:10:32 +0100
parents 5d5d482da3e9
children ee5ce13016ed
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.artifacts.sinfo;

import org.apache.commons.lang.StringUtils;
import org.dive4elements.river.artifacts.D4EArtifact;

/**
 * The default SINFO artifact.
 *
 * @author Gernot Belger
 */
public class SINFOArtifact extends D4EArtifact {

    private static final long serialVersionUID = 1L;

    /** Error message that is thrown if no mode has been chosen. */
    private static final String ERROR_NO_CALCULATION_MODE = "error_feed_no_calculation_mode";

    /**
     * Error message that is thrown if an invalid calculation mode has been
     * chosen.
     */
    private static final String ERROR_INVALID_CALCULATION_MODE = "error_feed_invalid_calculation_mode";

    /** The name of the artifact. */
    private static final String ARTIFACT_NAME = "sinfo";

    private static final String FIELD_RIVER = "river";

    private static final String FIELD_MODE = "calculation_mode";

    /**
     * Default constructor, because it's serializable.
     */
    public SINFOArtifact() {
    }

    /**
     * Returns the name of the concrete artifact.
     *
     * @return the name of the concrete artifact.
     */
    @Override
    public String getName() {
        return ARTIFACT_NAME;
    }

    public SinfoCalcMode getCalculationMode() {

        final String calc = getDataAsString(FIELD_MODE);
        if (calc == null) {
            throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE);
        }

        try {
            return SinfoCalcMode.valueOf(StringUtils.trimToEmpty(calc).toLowerCase());
        }
        catch (final Exception e) {
            throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE, e);
        }
    }

    public String getRiver() {
        return getDataAsString(FIELD_RIVER);
    }
}

http://dive4elements.wald.intevation.org