8996
|
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; |
9039
|
13 import org.dive4elements.artifactdatabase.state.Facet; |
8996
|
14 import org.dive4elements.artifactdatabase.state.FacetActivity; |
9039
|
15 import org.dive4elements.artifacts.Artifact; |
8996
|
16 import org.dive4elements.river.artifacts.D4EArtifact; |
|
17 |
|
18 /** |
9036
|
19 * The default UINFO artifact. |
8996
|
20 * |
|
21 * @author Gernot Belger |
|
22 */ |
|
23 public class UINFOArtifact extends D4EArtifact { |
|
24 |
9036
|
25 private static final long serialVersionUID = 1L; |
8996
|
26 |
9036
|
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"; |
8996
|
29 |
9036
|
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"; |
8996
|
34 |
9036
|
35 /** The name of the artifact. */ |
|
36 private static final String ARTIFACT_NAME = "uinfo"; |
8996
|
37 |
9036
|
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 |
9039
|
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 }); |
9036
|
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 } |
|
80 catch (final Exception e) { |
|
81 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE, e); |
|
82 } |
|
83 } |
|
84 |
|
85 public String getRiver() { |
|
86 return getDataAsString(FIELD_RIVER); |
|
87 } |
8996
|
88 } |