Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/BedHeightsArtifact.java @ 8961:8a1c6e2ad48b
Implemented datacage for min/max bedheights.
Allow to add min/max bed heights as themes to charts.
author | gernotbelger |
---|---|
date | Wed, 28 Mar 2018 14:35:01 +0200 |
parents | 5e38e2924c07 |
children | 45f1ad66560e |
comparison
equal
deleted
inserted
replaced
8960:66ce19d2c5f1 | 8961:8a1c6e2ad48b |
---|---|
10 | 10 |
11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
12 import java.util.List; | 12 import java.util.List; |
13 | 13 |
14 import org.apache.log4j.Logger; | 14 import org.apache.log4j.Logger; |
15 import org.w3c.dom.Document; | |
16 | |
17 import org.dive4elements.artifactdatabase.state.DefaultOutput; | 15 import org.dive4elements.artifactdatabase.state.DefaultOutput; |
18 import org.dive4elements.artifactdatabase.state.Facet; | 16 import org.dive4elements.artifactdatabase.state.Facet; |
19 import org.dive4elements.artifactdatabase.state.FacetActivity; | 17 import org.dive4elements.artifactdatabase.state.FacetActivity; |
18 import org.dive4elements.artifacts.Artifact; | |
20 import org.dive4elements.artifacts.ArtifactFactory; | 19 import org.dive4elements.artifacts.ArtifactFactory; |
21 import org.dive4elements.artifacts.Artifact; | |
22 import org.dive4elements.artifacts.CallMeta; | 20 import org.dive4elements.artifacts.CallMeta; |
23 import org.dive4elements.artifacts.common.utils.XMLUtils; | 21 import org.dive4elements.artifacts.common.utils.XMLUtils; |
24 import org.dive4elements.river.artifacts.model.FacetTypes; | 22 import org.dive4elements.river.artifacts.model.FacetTypes; |
25 import org.dive4elements.river.artifacts.model.minfo.BedHeightFacet; | 23 import org.dive4elements.river.artifacts.model.minfo.BedHeightFacet; |
26 import org.dive4elements.river.artifacts.model.minfo.BedHeightFactory; | 24 import org.dive4elements.river.artifacts.model.minfo.BedHeightMinMaxFacet; |
25 import org.dive4elements.river.artifacts.model.minfo.BedHeightMinMaxFacet.BedHeightValueType; | |
27 import org.dive4elements.river.artifacts.model.minfo.BedHeightSoundingWidthFacet; | 26 import org.dive4elements.river.artifacts.model.minfo.BedHeightSoundingWidthFacet; |
27 import org.dive4elements.river.artifacts.resources.Resources; | |
28 import org.dive4elements.river.artifacts.states.StaticState; | 28 import org.dive4elements.river.artifacts.states.StaticState; |
29 import org.dive4elements.river.exports.process.BedHeightProcessor; | |
30 import org.w3c.dom.Document; | |
29 | 31 |
30 import org.dive4elements.river.artifacts.resources.Resources; | 32 public class BedHeightsArtifact extends AbstractStaticStateArtifact implements FacetTypes { |
31 | |
32 public class BedHeightsArtifact | |
33 extends AbstractStaticStateArtifact | |
34 implements FacetTypes | |
35 { | |
36 /** The log for this class. */ | 33 /** The log for this class. */ |
37 private static Logger log = | 34 private static Logger log = Logger.getLogger(BedHeightsArtifact.class); |
38 Logger.getLogger(BedHeightsArtifact.class); | |
39 | 35 |
40 /** Artifact name. */ | 36 /** Artifact name. */ |
41 private static final String NAME = "bedheights"; | 37 private static final String NAME = "bedheights"; |
42 | 38 |
43 static { | 39 static { |
44 // TODO: Move to configuration. | 40 // TODO: Move to configuration. |
45 FacetActivity.Registry.getInstance() | 41 FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE); |
46 .register(NAME, FacetActivity.INACTIVE); | |
47 } | 42 } |
48 | 43 |
49 public static final String STATIC_STATE_NAME = | 44 public static final String STATIC_STATE_NAME = "state.additional_bedheights.static"; |
50 "state.additional_bedheights.static"; | |
51 | 45 |
52 /** Data Item name to know whether we are Heighmarks and receive | 46 /** |
53 * some data slightly different. */ | 47 * Data Item name to know whether we are Heighmarks and receive |
54 public static final String DATA_HEIGHT_TYPE = | 48 * some data slightly different. |
55 "height_marks"; | 49 */ |
50 public static final String DATA_HEIGHT_TYPE = "height_marks"; | |
56 | 51 |
57 /** | 52 /** |
58 * Trivial Constructor. | 53 * Trivial Constructor. |
59 */ | 54 */ |
60 public BedHeightsArtifact() { | 55 public BedHeightsArtifact() { |
68 | 63 |
69 /** | 64 /** |
70 * Gets called from factory, to set things up. | 65 * Gets called from factory, to set things up. |
71 */ | 66 */ |
72 @Override | 67 @Override |
73 public void setup( | 68 public void setup(final String identifier, final ArtifactFactory factory, final Object context, final CallMeta callMeta, final Document data, |
74 String identifier, | 69 final List<Class> loadFacets) { |
75 ArtifactFactory factory, | |
76 Object context, | |
77 CallMeta callMeta, | |
78 Document data, | |
79 List<Class> loadFacets) | |
80 { | |
81 log.debug("BedHeightsArtifact.setup"); | 70 log.debug("BedHeightsArtifact.setup"); |
82 | 71 |
83 if (log.isDebugEnabled()) { | 72 if (log.isDebugEnabled()) { |
84 log.debug(XMLUtils.toString(data)); | 73 log.debug(XMLUtils.toString(data)); |
85 } | 74 } |
86 | 75 |
87 String code = getDatacageIDValue(data); | 76 final String code = getDatacageIDValue(data); |
88 | 77 |
89 if (code != null) { | 78 createFacets(callMeta, code); |
90 String [] parts = code.split("-"); | |
91 | 79 |
92 if (parts.length >= 3) { | 80 super.setup(identifier, factory, context, callMeta, data, loadFacets); |
93 // The setting is a bit complicated: | 81 } |
94 // This artifact can spawn epoch type bedheight facets, | |
95 // 'singlevalue'/singleyear bedheight facets or | |
96 // sounding-width facets. The type is indicated by | |
97 // the ids-param which comes from datacage. | |
98 | 82 |
99 String name = parts[0]; | 83 private void createFacets(final CallMeta callMeta, final String code) { |
100 String type = parts[1]; | 84 if (code == null) |
101 String facetType = BEDHEIGHT; | 85 return; |
102 if (type.equals("soundings")) { | |
103 type = "singlevalues"; | |
104 facetType = BEDHEIGHT_SOUNDING_WIDTH; | |
105 } | |
106 addStringData("height_id", parts[2]); | |
107 addStringData("type", type); | |
108 String btype = type; | |
109 int hId = Integer.parseInt(parts[2]); | |
110 | 86 |
111 if (type.equals("singlevalues")) { | 87 final String[] parts = code.split("-", 5); |
112 btype = "single"; | 88 if (parts.length < 5) { |
113 } | 89 log.error("Invalid datacage ID '" + code + "'"); |
90 return; | |
91 } | |
114 | 92 |
115 String bedHName = BedHeightFactory.getHeightName(btype, hId); | 93 // String name = parts[0]; |
116 | 94 |
117 Facet facet = null; | 95 // type may only be 'single' or 'soundings' |
118 if (facetType.equals(BEDHEIGHT_SOUNDING_WIDTH)) { | 96 final String type = parts[1]; |
119 bedHName = Resources.getMsg( | |
120 callMeta, | |
121 "facet.bedheight.sounding_width", | |
122 new Object[] { bedHName }); | |
123 facet = new BedHeightSoundingWidthFacet( | |
124 facetType, bedHName); | |
125 } | |
126 else { | |
127 facet = new BedHeightFacet(facetType, bedHName); | |
128 } | |
129 | 97 |
98 final String heightId = parts[2]; | |
99 // final int hId = Integer.parseInt(heightId); | |
130 | 100 |
131 ArrayList<Facet> facets = new ArrayList<Facet>(1); | 101 // final String year = parts[3]; |
132 facets.add(facet); | 102 final String bedHName = parts[4]; |
133 | 103 |
134 addFacets(STATIC_STATE_NAME, facets); | 104 addStringData("height_id", heightId); |
135 } | 105 if (type.equals("soundings")) |
136 else { | 106 addStringData("type", "singlevalues"); |
137 log.error("Invalid datacage ID '" + code + "'"); | 107 else |
138 } | 108 addStringData("type", type); |
139 } | 109 |
140 super.setup(identifier, factory, context, callMeta, data, loadFacets); | 110 final ArrayList<Facet> facets = new ArrayList<>(1); |
111 | |
112 if ("soundings".equals(type)) { | |
113 final String description = Resources.getMsg(callMeta, "facet.bedheight.sounding_width", new Object[] { bedHName }); | |
114 facets.add(new BedHeightSoundingWidthFacet(BEDHEIGHT_SOUNDING_WIDTH, description)); | |
115 } else if ("single".equals(type)) | |
116 facets.add(new BedHeightFacet(BEDHEIGHT, bedHName)); | |
117 else if ("singleMin".equals(type)) | |
118 facets.add(new BedHeightMinMaxFacet(BedHeightProcessor.FACET_BED_HEIGHTS_MIN, bedHName, BedHeightValueType.min)); | |
119 else if ("singleMax".equals(type)) | |
120 facets.add(new BedHeightMinMaxFacet(BedHeightProcessor.FACET_BED_HEIGHTS_MAX, bedHName, BedHeightValueType.max)); | |
121 | |
122 addFacets(STATIC_STATE_NAME, facets); | |
141 } | 123 } |
142 | 124 |
143 @Override | 125 @Override |
144 protected void initStaticState() { | 126 protected void initStaticState() { |
145 | 127 |
146 log.debug("initStaticState " + getName() + " " + identifier()); | 128 log.debug("initStaticState " + getName() + " " + identifier()); |
147 | 129 |
148 StaticState state = new StaticState(STATIC_STATE_NAME); | 130 final StaticState state = new StaticState(STATIC_STATE_NAME); |
149 DefaultOutput output = new DefaultOutput( | 131 final DefaultOutput output = new DefaultOutput("general", "general", "image/png", "chart"); |
150 "general", | |
151 "general", | |
152 "image/png", | |
153 "chart"); | |
154 | 132 |
155 List<Facet> facets = getFacets(STATIC_STATE_NAME); | 133 final List<Facet> facets = getFacets(STATIC_STATE_NAME); |
156 output.addFacets(facets); | 134 output.addFacets(facets); |
157 state.addOutput(output); | 135 state.addOutput(output); |
158 | 136 |
159 setStaticState(state); | 137 setStaticState(state); |
160 } | 138 } |
161 | 139 |
162 @Override | 140 @Override |
163 protected void initialize( | 141 protected void initialize(final Artifact artifact, final Object context, final CallMeta meta) { |
164 Artifact artifact, | |
165 Object context, | |
166 CallMeta meta | |
167 ) { | |
168 // do not clone facets, etc. from master artifact | 142 // do not clone facets, etc. from master artifact |
169 | 143 |
170 log.debug("initialize"); | 144 log.debug("initialize"); |
171 importData((D4EArtifact)artifact, "river"); | 145 importData((D4EArtifact) artifact, "river"); |
172 importData((D4EArtifact)artifact, "ld_from"); | 146 importData((D4EArtifact) artifact, "ld_from"); |
173 importData((D4EArtifact)artifact, "ld_to"); | 147 importData((D4EArtifact) artifact, "ld_to"); |
174 | 148 |
175 log.debug("ld_from " + getDataAsString("ld_from")); | 149 log.debug("ld_from " + getDataAsString("ld_from")); |
176 log.debug("ld_to " + getDataAsString("ld_to")); | 150 log.debug("ld_to " + getDataAsString("ld_to")); |
177 } | 151 } |
178 } | 152 } |
179 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |