comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java @ 3193:2f922be407ea

Moved common code of the *Artifacts into FLYSArtifact. flys-artifacts/trunk@4809 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 27 Jun 2012 13:45:55 +0000
parents b60751cfdd6c
children b888c5eb65b3
comparison
equal deleted inserted replaced
3192:cd309f8597f6 3193:2f922be407ea
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2 2
3 import de.intevation.artifactdatabase.ProtocolUtils;
4
5 import de.intevation.artifactdatabase.state.Output;
6 import de.intevation.artifactdatabase.state.State;
7 import de.intevation.artifactdatabase.state.StateEngine;
8
9 import de.intevation.artifactdatabase.transition.TransitionEngine;
10
11 import de.intevation.artifacts.CallContext;
12 import de.intevation.artifacts.Message;
13
14 import de.intevation.artifacts.common.ArtifactNamespaceContext;
15
16 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
17
18 import de.intevation.artifacts.common.utils.XMLUtils;
19
20 import de.intevation.flys.artifacts.context.FLYSContext;
21
22 import de.intevation.flys.artifacts.model.CalculationMessage;
23 import de.intevation.flys.artifacts.model.FacetTypes; 3 import de.intevation.flys.artifacts.model.FacetTypes;
24 4
25 import de.intevation.flys.artifacts.states.DefaultState;
26 import de.intevation.flys.artifacts.states.SoundingsSelect; 5 import de.intevation.flys.artifacts.states.SoundingsSelect;
27 6
28 import de.intevation.flys.utils.FLYSUtils; 7 import de.intevation.flys.utils.FLYSUtils;
29 8
30 import gnu.trove.TIntArrayList; 9 import gnu.trove.TIntArrayList;
31 10
32 import java.util.LinkedList;
33 import java.util.List;
34
35 import org.apache.log4j.Logger; 11 import org.apache.log4j.Logger;
36
37 import org.w3c.dom.Document;
38 import org.w3c.dom.Element;
39 import org.w3c.dom.Node;
40 12
41 /** 13 /**
42 * The default MINFO artifact. 14 * The default MINFO artifact.
43 * 15 *
44 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 16 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
61 * The default constructor. 33 * The default constructor.
62 */ 34 */
63 public MINFOArtifact() { 35 public MINFOArtifact() {
64 } 36 }
65 37
66
67 /**
68 * This method returns a description of this artifact.
69 *
70 * @param data Some data.
71 * @param context The CallContext.
72 *
73 * @return the description of this artifact.
74 */
75 public Document describe(Document data, CallContext context) {
76 logger.debug("Describe: the current state is: " + getCurrentStateId());
77
78 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
79 StateEngine stateEngine = (StateEngine) flysContext.get(
80 FLYSContext.STATE_ENGINE_KEY);
81
82 TransitionEngine transitionEngine = (TransitionEngine) flysContext.get(
83 FLYSContext.TRANSITION_ENGINE_KEY);
84
85 List<State> reachable = transitionEngine.getReachableStates(
86 this, getCurrentState(context), stateEngine);
87
88 Document description = XMLUtils.newDocument();
89 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
90 description,
91 ArtifactNamespaceContext.NAMESPACE_URI,
92 ArtifactNamespaceContext.NAMESPACE_PREFIX);
93
94 Element root = ProtocolUtils.createRootNode(creator);
95 description.appendChild(root);
96
97 State current = getCurrentState(context);
98
99 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
100 ProtocolUtils.appendState(creator, root, current);
101 ProtocolUtils.appendReachableStates(creator, root, reachable);
102
103 appendBackgroundActivity(creator, root, context);
104
105 Element name = ProtocolUtils.createArtNode(
106 creator, "name",
107 new String[] { "value" },
108 new String[] { getName() });
109
110 Element ui = ProtocolUtils.createArtNode(
111 creator, "ui", null, null);
112
113 Element staticUI = ProtocolUtils.createArtNode(
114 creator, "static", null, null);
115
116 Element outs = ProtocolUtils.createArtNode(
117 creator, "outputmodes", null, null);
118 appendOutputModes(description, outs, context, identifier());
119
120 appendStaticUI(description, staticUI, context, identifier());
121
122 Element dynamic = current.describe(
123 this,
124 description,
125 root,
126 context,
127 identifier());
128
129 if (dynamic != null) {
130 ui.appendChild(dynamic);
131 }
132
133 ui.appendChild(staticUI);
134
135 root.appendChild(name);
136 root.appendChild(ui);
137 root.appendChild(outs);
138
139 return description;
140 }
141
142
143 /** 38 /**
144 * Returns the name of the concrete artifact. 39 * Returns the name of the concrete artifact.
145 * 40 *
146 * @return the name of the concrete artifact. 41 * @return the name of the concrete artifact.
147 */ 42 */
43 @Override
148 public String getName() { 44 public String getName() {
149 return ARTIFACT_NAME; 45 return ARTIFACT_NAME;
150 } 46 }
151
152
153 protected static void appendBackgroundActivity(
154 ElementCreator cr,
155 Element root,
156 CallContext context
157 ) {
158 Element inBackground = cr.create("background-processing");
159 root.appendChild(inBackground);
160
161 cr.addAttr(
162 inBackground,
163 "value",
164 String.valueOf(context.isInBackground()),
165 true);
166
167 LinkedList<Message> messages = context.getBackgroundMessages();
168
169 if (messages == null) {
170 return;
171 }
172
173 CalculationMessage message = (CalculationMessage) messages.getLast();
174 cr.addAttr(
175 inBackground,
176 "steps",
177 String.valueOf(message.getSteps()),
178 true);
179
180 cr.addAttr(
181 inBackground,
182 "currentStep",
183 String.valueOf(message.getCurrentStep()),
184 true);
185
186 inBackground.setTextContent(message.getMessage());
187 }
188
189
190 /**
191 * Append output mode nodes to a document.
192 */
193 protected void appendOutputModes(
194 Document doc,
195 Element outs,
196 CallContext context,
197 String uuid)
198 {
199 List<Output> generated = getOutputs(context);
200 logger.debug("This Artifact has " + generated.size() + " Outputs.");
201
202 ProtocolUtils.appendOutputModes(doc, outs, generated);
203 }
204
205
206 /**
207 * This method appends the static data - that has already been inserted by
208 * the user - to the static node of the DESCRIBE document.
209 *
210 * @param doc The document.
211 * @param ui The root node.
212 * @param context The CallContext.
213 * @param uuid The identifier of the artifact.
214 */
215 protected void appendStaticUI(
216 Document doc,
217 Node ui,
218 CallContext context,
219 String uuid)
220 {
221 List<String> stateIds = getPreviousStateIds();
222
223 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
224 StateEngine engine = (StateEngine) flysContext.get(
225 FLYSContext.STATE_ENGINE_KEY);
226
227 for (String stateId: stateIds) {
228 logger.debug("Append static data for state: " + stateId);
229 DefaultState state = (DefaultState) engine.getState(stateId);
230
231 ui.appendChild(state.describeStatic(this, doc, ui, context, uuid));
232 }
233 }
234
235
236 /**
237 * Determines Facets initial disposition regarding activity (think of
238 * selection in Client ThemeList GUI). This will be checked one time
239 * when the facet enters a collections describe document.
240 *
241 * @param facetName name of the facet.
242 * @param index index of the facet.
243 * @return 0 if not active
244 */
245 @Override
246 public int getInitialFacetActivity(String outputName, String facetName, int index) {
247 logger.warn("MINFOArtifact.getInitialFacetActivity: not implemented!");
248 return 1;
249 }
250
251 47
252 public int[] getMainChannels() { 48 public int[] getMainChannels() {
253 String data = getDataAsString("main.channel"); 49 String data = getDataAsString("main.channel");
254 50
255 if (data == null) { 51 if (data == null) {

http://dive4elements.wald.intevation.org