Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/UINFOArtifact.java @ 9506:8b7bf26b8782
Predefined artifact for standard vegetation zones.
Some minor adaptions.
author | gernotbelger |
---|---|
date | Fri, 28 Sep 2018 13:44:12 +0200 |
parents | b6e595f1696f |
children | ee6508687e3f |
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 | |
9506
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9426
diff
changeset
|
50 public static final String FIELD_VEGZONES = "vegzones"; |
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9426
diff
changeset
|
51 |
9036 | 52 static { |
53 // Active/deactivate facets. | |
9316
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
54 // BEWARE: we can only define one activity for "uinfo", so we use the artifact |
9036 | 55 // as place for this |
9039 | 56 FacetActivity.Registry.getInstance().register(ARTIFACT_NAME, new FacetActivity() { |
57 @Override | |
58 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
|
59 |
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
60 final String name = facet.getName(); |
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
61 |
9368
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_LINE_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_MNWMW_RAW.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_RANK.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_FILTERED.equals(name)) |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
69 return Boolean.FALSE; |
6f7e92c16050
Fixed U-Info salix mw calculation, added filtered themes, own y axis, warning report
mschaefer
parents:
9316
diff
changeset
|
70 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
|
71 return Boolean.FALSE; |
72b3270e1568
U-Info salix line with regional and supraregional scenario calculation and chart display
mschaefer
parents:
9039
diff
changeset
|
72 |
9039 | 73 return null; |
74 } | |
75 }); | |
9036 | 76 } |
77 | |
78 /** | |
79 * Default constructor, because it's serializable. | |
80 */ | |
81 public UINFOArtifact() { | |
82 } | |
83 | |
84 /** | |
85 * Returns the name of the concrete artifact. | |
86 * | |
87 * @return the name of the concrete artifact. | |
88 */ | |
89 @Override | |
90 public String getName() { | |
91 return ARTIFACT_NAME; | |
92 } | |
93 | |
94 public UinfoCalcMode getCalculationMode() { | |
95 | |
96 final String calc = getDataAsString(FIELD_MODE); | |
97 if (calc == null) { | |
98 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); | |
99 } | |
100 | |
101 try { | |
102 return UinfoCalcMode.valueOf(StringUtils.trimToEmpty(calc).toLowerCase()); | |
103 } | |
104 catch (final Exception e) { | |
105 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE, e); | |
106 } | |
107 } | |
108 | |
109 public String getRiver() { | |
110 return getDataAsString(FIELD_RIVER); | |
111 } | |
9426
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
112 |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
113 @Override |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
114 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
|
115 final double nextKm, |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
116 final double prevKm, |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
117 final CallContext context) { |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
118 |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
119 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
|
120 final Object data = res.getData(); |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
121 if (data instanceof SalixLineCalculationResults) |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
122 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
|
123 |
b6e595f1696f
Activated cross section output mode for salix line and implemented some themes preliminary.
gernotbelger
parents:
9368
diff
changeset
|
124 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
|
125 } |
8996 | 126 } |