Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/UINFOArtifact.java @ 9426:b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
author | gernotbelger |
---|---|
date | Fri, 17 Aug 2018 15:31:16 +0200 |
parents | 6f7e92c16050 |
children | 8b7bf26b8782 |
rev | line source |
---|---|
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 | |
9426
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
12 import java.io.Serializable; |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
13 |
8996 | 14 import org.apache.commons.lang.StringUtils; |
9039 | 15 import org.dive4elements.artifactdatabase.state.Facet; |
8996 | 16 import org.dive4elements.artifactdatabase.state.FacetActivity; |
9039 | 17 import org.dive4elements.artifacts.Artifact; |
9426
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
18 import org.dive4elements.artifacts.CallContext; |
8996 | 19 import org.dive4elements.river.artifacts.D4EArtifact; |
9426
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
20 import org.dive4elements.river.artifacts.WaterLineArtifact; |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
21 import org.dive4elements.river.artifacts.model.CalculationResult; |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
22 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
23 import org.dive4elements.river.artifacts.uinfo.salix.SalixLineCalculationResults; |
9316
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
24 import org.dive4elements.river.artifacts.uinfo.salix.SalixLineProcessor; |
8996 | 25 |
26 /** | |
9036 | 27 * The default UINFO artifact. |
8996 | 28 * |
29 * @author Gernot Belger | |
30 */ | |
9426
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
31 public class UINFOArtifact extends D4EArtifact implements WaterLineArtifact { |
8996 | 32 |
9036 | 33 private static final long serialVersionUID = 1L; |
8996 | 34 |
9036 | 35 /** Error message that is thrown if no mode has been chosen. */ |
36 private static final String ERROR_NO_CALCULATION_MODE = "error_feed_no_calculation_mode"; | |
8996 | 37 |
9036 | 38 /** |
39 * Error message that is thrown if an invalid calculation mode has been chosen. | |
40 */ | |
41 private static final String ERROR_INVALID_CALCULATION_MODE = "error_feed_invalid_calculation_mode"; | |
8996 | 42 |
9036 | 43 /** The name of the artifact. */ |
44 private static final String ARTIFACT_NAME = "uinfo"; | |
8996 | 45 |
9036 | 46 private static final String FIELD_RIVER = "river"; |
47 | |
48 private static final String FIELD_MODE = "calculation_mode"; | |
49 | |
50 static { | |
51 // Active/deactivate facets. | |
9316
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
52 // BEWARE: we can only define one activity for "uinfo", so we use the artifact |
9036 | 53 // as place for this |
9039 | 54 FacetActivity.Registry.getInstance().register(ARTIFACT_NAME, new FacetActivity() { |
55 @Override | |
56 public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String output) { | |
9316
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
57 |
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
58 final String name = facet.getName(); |
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
59 |
9368
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
60 if (SalixLineProcessor.FACET_SALIX_LINE_RAW.equals(name)) |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
61 return Boolean.FALSE; |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
62 if (SalixLineProcessor.FACET_SALIX_MNWMW_RAW.equals(name)) |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
63 return Boolean.FALSE; |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
64 if (SalixLineProcessor.FACET_SALIX_RANK.equals(name)) |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
65 return Boolean.FALSE; |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
66 if (SalixLineProcessor.FACET_SALIX_SCENARIO_FILTERED.equals(name)) |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
67 return Boolean.FALSE; |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
68 if (SalixLineProcessor.FACET_SALIX_SCENARIO_RAW.equals(name)) |
9316
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
69 return Boolean.FALSE; |
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
70 |
9039 | 71 return null; |
72 } | |
73 }); | |
9036 | 74 } |
75 | |
76 /** | |
77 * Default constructor, because it's serializable. | |
78 */ | |
79 public UINFOArtifact() { | |
80 } | |
81 | |
82 /** | |
83 * Returns the name of the concrete artifact. | |
84 * | |
85 * @return the name of the concrete artifact. | |
86 */ | |
87 @Override | |
88 public String getName() { | |
89 return ARTIFACT_NAME; | |
90 } | |
91 | |
92 public UinfoCalcMode getCalculationMode() { | |
93 | |
94 final String calc = getDataAsString(FIELD_MODE); | |
95 if (calc == null) { | |
96 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); | |
97 } | |
98 | |
99 try { | |
100 return UinfoCalcMode.valueOf(StringUtils.trimToEmpty(calc).toLowerCase()); | |
101 } | |
102 catch (final Exception e) { | |
103 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE, e); | |
104 } | |
105 } | |
106 | |
107 public String getRiver() { | |
108 return getDataAsString(FIELD_RIVER); | |
109 } | |
9426
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
110 |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
111 @Override |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
112 public double getWaterLevel(final ComputeType type, final String hash, final String stateId, final double currentKm, final Serializable waterLineIndex, |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
113 final double nextKm, |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
114 final double prevKm, |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
115 final CallContext context) { |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
116 |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
117 final CalculationResult res = (CalculationResult) this.compute(context, hash, stateId, type, false); |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
118 final Object data = res.getData(); |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
119 if (data instanceof SalixLineCalculationResults) |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
120 return ((SalixLineCalculationResults) data).getCrossSectionLine(currentKm, waterLineIndex, nextKm, prevKm, context); |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
121 |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
122 throw new IllegalStateException("Cross section stuff should only happen for salix line"); |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
123 } |
8996 | 124 } |