Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
8995:8c3e5682cb60 | 8996:fb9430250899 |
---|---|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.uinfo; | |
11 | |
12 import org.apache.commons.lang.StringUtils; | |
13 import org.dive4elements.artifactdatabase.state.Facet; | |
14 import org.dive4elements.artifactdatabase.state.FacetActivity; | |
15 import org.dive4elements.artifacts.Artifact; | |
16 import org.dive4elements.river.artifacts.D4EArtifact; | |
17 | |
18 /** | |
19 * The default SINFO artifact. | |
20 * | |
21 * @author Gernot Belger | |
22 */ | |
23 public class UINFOArtifact extends D4EArtifact { | |
24 | |
25 private static final long serialVersionUID = 1L; | |
26 | |
27 /** Error message that is thrown if no mode has been chosen. */ | |
28 private static final String ERROR_NO_CALCULATION_MODE = "error_feed_no_calculation_mode"; | |
29 | |
30 /** | |
31 * Error message that is thrown if an invalid calculation mode has been chosen. | |
32 */ | |
33 private static final String ERROR_INVALID_CALCULATION_MODE = "error_feed_invalid_calculation_mode"; | |
34 | |
35 /** The name of the artifact. */ | |
36 private static final String ARTIFACT_NAME = "uinfo"; | |
37 | |
38 private static final String FIELD_RIVER = "river"; | |
39 | |
40 private static final String FIELD_MODE = "calculation_mode"; | |
41 | |
42 static { | |
43 // Active/deactivate facets. | |
44 // BEWARE: we can only define one activity for "sinfo", so we use the artifact | |
45 // as place for this | |
46 FacetActivity.Registry.getInstance().register(ARTIFACT_NAME, new FacetActivity() { | |
47 @Override | |
48 public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String output) { | |
49 return null; | |
50 } | |
51 }); | |
52 } | |
53 | |
54 /** | |
55 * Default constructor, because it's serializable. | |
56 */ | |
57 public UINFOArtifact() { | |
58 } | |
59 | |
60 /** | |
61 * Returns the name of the concrete artifact. | |
62 * | |
63 * @return the name of the concrete artifact. | |
64 */ | |
65 @Override | |
66 public String getName() { | |
67 return ARTIFACT_NAME; | |
68 } | |
69 | |
70 public UinfoCalcMode getCalculationMode() { | |
71 | |
72 final String calc = getDataAsString(FIELD_MODE); | |
73 if (calc == null) { | |
74 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); | |
75 } | |
76 | |
77 try { | |
78 return UinfoCalcMode.valueOf(StringUtils.trimToEmpty(calc).toLowerCase()); | |
79 } catch (final Exception e) { | |
80 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE, e); | |
81 } | |
82 } | |
83 | |
84 public String getRiver() { | |
85 return getDataAsString(FIELD_RIVER); | |
86 } | |
87 } |