Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/UINFOArtifact.java @ 8996:fb9430250899
Work on uinfo
author | gernotbelger |
---|---|
date | Thu, 12 Apr 2018 19:13:39 +0200 |
parents | |
children | c265c9fc915c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/UINFOArtifact.java Thu Apr 12 19:13:39 2018 +0200 @@ -0,0 +1,87 @@ +/* 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.uinfo; + +import org.apache.commons.lang.StringUtils; +import org.dive4elements.artifactdatabase.state.Facet; +import org.dive4elements.artifactdatabase.state.FacetActivity; +import org.dive4elements.artifacts.Artifact; +import org.dive4elements.river.artifacts.D4EArtifact; + +/** + * The default SINFO artifact. + * + * @author Gernot Belger + */ +public class UINFOArtifact 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 = "uinfo"; + + private static final String FIELD_RIVER = "river"; + + private static final String FIELD_MODE = "calculation_mode"; + + static { + // Active/deactivate facets. + // BEWARE: we can only define one activity for "sinfo", so we use the artifact + // as place for this + FacetActivity.Registry.getInstance().register(ARTIFACT_NAME, new FacetActivity() { + @Override + public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String output) { + return null; + } + }); + } + + /** + * Default constructor, because it's serializable. + */ + public UINFOArtifact() { + } + + /** + * Returns the name of the concrete artifact. + * + * @return the name of the concrete artifact. + */ + @Override + public String getName() { + return ARTIFACT_NAME; + } + + public UinfoCalcMode getCalculationMode() { + + final String calc = getDataAsString(FIELD_MODE); + if (calc == null) { + throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); + } + + try { + return UinfoCalcMode.valueOf(StringUtils.trimToEmpty(calc).toLowerCase()); + } catch (final Exception e) { + throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE, e); + } + } + + public String getRiver() { + return getDataAsString(FIELD_RIVER); + } +} \ No newline at end of file