Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/UINFOArtifact.java @ 9036:c265c9fc915c
work on u-info/s-info states
author | gernotbelger |
---|---|
date | Mon, 30 Apr 2018 18:03:02 +0200 |
parents | fb9430250899 |
children | 13b5b515c61f |
comparison
equal
deleted
inserted
replaced
9034:8aa7d9eaaa21 | 9036:c265c9fc915c |
---|---|
8 * documentation coming with Dive4Elements River for details. | 8 * documentation coming with Dive4Elements River for details. |
9 */ | 9 */ |
10 package org.dive4elements.river.artifacts.uinfo; | 10 package org.dive4elements.river.artifacts.uinfo; |
11 | 11 |
12 import org.apache.commons.lang.StringUtils; | 12 import org.apache.commons.lang.StringUtils; |
13 import org.dive4elements.artifactdatabase.state.Facet; | |
14 import org.dive4elements.artifactdatabase.state.FacetActivity; | 13 import org.dive4elements.artifactdatabase.state.FacetActivity; |
15 import org.dive4elements.artifacts.Artifact; | |
16 import org.dive4elements.river.artifacts.D4EArtifact; | 14 import org.dive4elements.river.artifacts.D4EArtifact; |
17 | 15 |
18 /** | 16 /** |
19 * The default SINFO artifact. | 17 * The default UINFO artifact. |
20 * | 18 * |
21 * @author Gernot Belger | 19 * @author Gernot Belger |
22 */ | 20 */ |
23 public class UINFOArtifact extends D4EArtifact { | 21 public class UINFOArtifact extends D4EArtifact { |
24 | 22 |
25 private static final long serialVersionUID = 1L; | 23 private static final long serialVersionUID = 1L; |
26 | 24 |
27 /** Error message that is thrown if no mode has been chosen. */ | 25 /** 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"; | 26 private static final String ERROR_NO_CALCULATION_MODE = "error_feed_no_calculation_mode"; |
29 | 27 |
30 /** | 28 /** |
31 * Error message that is thrown if an invalid calculation mode has been chosen. | 29 * Error message that is thrown if an invalid calculation mode has been chosen. |
32 */ | 30 */ |
33 private static final String ERROR_INVALID_CALCULATION_MODE = "error_feed_invalid_calculation_mode"; | 31 private static final String ERROR_INVALID_CALCULATION_MODE = "error_feed_invalid_calculation_mode"; |
34 | 32 |
35 /** The name of the artifact. */ | 33 /** The name of the artifact. */ |
36 private static final String ARTIFACT_NAME = "uinfo"; | 34 private static final String ARTIFACT_NAME = "uinfo"; |
37 | 35 |
38 private static final String FIELD_RIVER = "river"; | 36 private static final String FIELD_RIVER = "river"; |
39 | 37 |
40 private static final String FIELD_MODE = "calculation_mode"; | 38 private static final String FIELD_MODE = "calculation_mode"; |
41 | 39 |
42 static { | 40 static { |
43 // Active/deactivate facets. | 41 // Active/deactivate facets. |
44 // BEWARE: we can only define one activity for "sinfo", so we use the artifact | 42 // BEWARE: we can only define one activity for "sinfo", so we use the artifact |
45 // as place for this | 43 // as place for this |
46 FacetActivity.Registry.getInstance().register(ARTIFACT_NAME, new FacetActivity() { | 44 FacetActivity.Registry.getInstance().register(ARTIFACT_NAME, (artifact, facet, output) -> null); |
47 @Override | 45 } |
48 public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String output) { | |
49 return null; | |
50 } | |
51 }); | |
52 } | |
53 | 46 |
54 /** | 47 /** |
55 * Default constructor, because it's serializable. | 48 * Default constructor, because it's serializable. |
56 */ | 49 */ |
57 public UINFOArtifact() { | 50 public UINFOArtifact() { |
58 } | 51 } |
59 | 52 |
60 /** | 53 /** |
61 * Returns the name of the concrete artifact. | 54 * Returns the name of the concrete artifact. |
62 * | 55 * |
63 * @return the name of the concrete artifact. | 56 * @return the name of the concrete artifact. |
64 */ | 57 */ |
65 @Override | 58 @Override |
66 public String getName() { | 59 public String getName() { |
67 return ARTIFACT_NAME; | 60 return ARTIFACT_NAME; |
68 } | 61 } |
69 | 62 |
70 public UinfoCalcMode getCalculationMode() { | 63 public UinfoCalcMode getCalculationMode() { |
71 | 64 |
72 final String calc = getDataAsString(FIELD_MODE); | 65 final String calc = getDataAsString(FIELD_MODE); |
73 if (calc == null) { | 66 if (calc == null) { |
74 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); | 67 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); |
75 } | 68 } |
76 | 69 |
77 try { | 70 try { |
78 return UinfoCalcMode.valueOf(StringUtils.trimToEmpty(calc).toLowerCase()); | 71 return UinfoCalcMode.valueOf(StringUtils.trimToEmpty(calc).toLowerCase()); |
79 } catch (final Exception e) { | 72 } |
80 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE, e); | 73 catch (final Exception e) { |
81 } | 74 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE, e); |
82 } | 75 } |
76 } | |
83 | 77 |
84 public String getRiver() { | 78 public String getRiver() { |
85 return getDataAsString(FIELD_RIVER); | 79 return getDataAsString(FIELD_RIVER); |
86 } | 80 } |
87 } | 81 } |