Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/FLYSArtifactCreator.java @ 9071:a561b882436d
create module bundu (Betrieb & Unterhaltung)
incl. original Fixierungsanalyse+Ausgelagerte Wasserspiegellage
author | gernotbelger |
---|---|
date | Wed, 16 May 2018 11:08:56 +0200 |
parents | 8c3e5682cb60 |
children | 02739b8c010d |
comparison
equal
deleted
inserted
replaced
9070:611a523fc42f | 9071:a561b882436d |
---|---|
11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
12 import java.util.List; | 12 import java.util.List; |
13 | 13 |
14 import javax.xml.xpath.XPathConstants; | 14 import javax.xml.xpath.XPathConstants; |
15 | 15 |
16 import org.w3c.dom.Document; | |
17 import org.w3c.dom.Element; | |
18 import org.w3c.dom.NodeList; | |
19 | |
20 import org.apache.log4j.Logger; | 16 import org.apache.log4j.Logger; |
21 | 17 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; |
22 import org.dive4elements.artifacts.common.utils.XMLUtils; | 18 import org.dive4elements.artifacts.common.utils.XMLUtils; |
23 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; | |
24 | |
25 import org.dive4elements.artifacts.httpclient.utils.ArtifactCreator; | 19 import org.dive4elements.artifacts.httpclient.utils.ArtifactCreator; |
26 | |
27 import org.dive4elements.river.client.shared.model.Artifact; | 20 import org.dive4elements.river.client.shared.model.Artifact; |
28 import org.dive4elements.river.client.shared.model.CalculationMessage; | 21 import org.dive4elements.river.client.shared.model.CalculationMessage; |
29 import org.dive4elements.river.client.shared.model.ChartArtifact; | 22 import org.dive4elements.river.client.shared.model.ChartArtifact; |
30 import org.dive4elements.river.client.shared.model.DefaultArtifact; | 23 import org.dive4elements.river.client.shared.model.DefaultArtifact; |
31 import org.dive4elements.river.client.shared.model.FixAnalysisArtifact; | 24 import org.dive4elements.river.client.shared.model.FixAnalysisArtifact; |
32 import org.dive4elements.river.client.shared.model.GaugeDischargeCurveArtifact; | 25 import org.dive4elements.river.client.shared.model.GaugeDischargeCurveArtifact; |
26 import org.dive4elements.river.client.shared.model.MINFOArtifact; | |
33 import org.dive4elements.river.client.shared.model.MapArtifact; | 27 import org.dive4elements.river.client.shared.model.MapArtifact; |
34 import org.dive4elements.river.client.shared.model.SINFOArtifact; | 28 import org.dive4elements.river.client.shared.model.SINFOArtifact; |
35 import org.dive4elements.river.client.shared.model.MINFOArtifact; | |
36 import org.dive4elements.river.client.shared.model.StaticSQRelationArtifact; | 29 import org.dive4elements.river.client.shared.model.StaticSQRelationArtifact; |
37 import org.dive4elements.river.client.shared.model.UINFOArtifact; | 30 import org.dive4elements.river.client.shared.model.UINFOArtifact; |
38 import org.dive4elements.river.client.shared.model.WINFOArtifact; | 31 import org.dive4elements.river.client.shared.model.WINFOArtifact; |
39 | 32 import org.w3c.dom.Document; |
33 import org.w3c.dom.Element; | |
34 import org.w3c.dom.NodeList; | |
40 | 35 |
41 /** | 36 /** |
42 * An implementation of an {@link ArtifactCreator}. This class uses the document | 37 * An implementation of an {@link ArtifactCreator}. This class uses the document |
43 * that is returned by the artifact server to parse important information (like | 38 * that is returned by the artifact server to parse important information (like |
44 * uuid, hash) and returns a new {@link Artifact} instance. | 39 * uuid, hash) and returns a new {@link Artifact} instance. |
45 * | 40 * |
46 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 41 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
47 */ | 42 */ |
48 public class FLYSArtifactCreator implements ArtifactCreator { | 43 public class FLYSArtifactCreator implements ArtifactCreator { |
49 | 44 |
50 private static final Logger log = | 45 private static final Logger log = Logger.getLogger(FLYSArtifactCreator.class); |
51 Logger.getLogger(FLYSArtifactCreator.class); | 46 |
52 | 47 /** The XPath to the artifact's uuid. */ |
53 | |
54 /** The XPath to the artifact's uuid.*/ | |
55 public static final String XPATH_UUID = "/art:result/art:uuid/@art:value"; | 48 public static final String XPATH_UUID = "/art:result/art:uuid/@art:value"; |
56 | 49 |
57 /** The XPath to the artifact's hash value.*/ | 50 /** The XPath to the artifact's hash value. */ |
58 public static final String XPATH_HASH = "/art:result/art:hash/@art:value"; | 51 public static final String XPATH_HASH = "/art:result/art:hash/@art:value"; |
59 | 52 |
60 /** The XPath to the artifact's name value.*/ | 53 /** The XPath to the artifact's name value. */ |
61 public static final String XPATH_NAME = "/art:result/art:name/@art:value"; | 54 public static final String XPATH_NAME = "/art:result/art:name/@art:value"; |
62 | 55 |
63 /** The XPath to the value that determines if the artifact is processing in | 56 /** |
64 * background.*/ | 57 * The XPath to the value that determines if the artifact is processing in |
65 public static final String XPATH_BACKGROUND_VALUE = | 58 * background. |
66 "/art:result/art:background-processing/@art:value"; | 59 */ |
67 | 60 public static final String XPATH_BACKGROUND_VALUE = "/art:result/art:background-processing/@art:value"; |
68 /** The XPath that points to the (if existing) background messages.*/ | 61 |
69 public static final String XPATH_BACKGROUND = | 62 /** The XPath that points to the (if existing) background messages. */ |
70 "/art:result/art:background-processing"; | 63 public static final String XPATH_BACKGROUND = "/art:result/art:background-processing"; |
71 | |
72 | 64 |
73 /** | 65 /** |
74 * Creates a new instance of an {@link ArtifactCreator}. | 66 * Creates a new instance of an {@link ArtifactCreator}. |
75 */ | 67 */ |
76 public FLYSArtifactCreator() { | 68 public FLYSArtifactCreator() { |
77 } | 69 } |
78 | |
79 | 70 |
80 /** | 71 /** |
81 * This concreate implementation returns an instance of {@link Artifact} | 72 * This concreate implementation returns an instance of {@link Artifact} |
82 * that is used in the FLYS GWT Client code. | 73 * that is used in the FLYS GWT Client code. |
83 * | 74 * |
84 * @param doc A document that describes the artifact that has been created | 75 * @param doc |
85 * in the artifact server. | 76 * A document that describes the artifact that has been created |
77 * in the artifact server. | |
86 * | 78 * |
87 * @return an instance if {@link Artifact}. | 79 * @return an instance if {@link Artifact}. |
88 */ | 80 */ |
89 public Object create(Document doc) { | 81 @Override |
90 Artifact artifact = extractArtifact(doc); | 82 public Object create(final Document doc) { |
91 artifact.setArtifactDescription( | 83 final Artifact artifact = extractArtifact(doc); |
92 ArtifactDescriptionFactory.createArtifactDescription(doc)); | 84 artifact.setArtifactDescription(ArtifactDescriptionFactory.createArtifactDescription(doc)); |
93 | 85 |
94 return artifact; | 86 return artifact; |
95 } | 87 } |
96 | |
97 | 88 |
98 /** | 89 /** |
99 * This method extracts the UUID und HASH information of the returned | 90 * This method extracts the UUID und HASH information of the returned |
100 * artifact document. | 91 * artifact document. |
101 * | 92 * |
102 * @param doc The result of the CREATE operation. | 93 * @param doc |
94 * The result of the CREATE operation. | |
103 * | 95 * |
104 * @return an instance of an {@link Artifact}. | 96 * @return an instance of an {@link Artifact}. |
105 */ | 97 */ |
106 protected Artifact extractArtifact(Document doc) { | 98 protected Artifact extractArtifact(final Document doc) { |
107 log.debug("FLYSArtifactCreator - extractArtifact()"); | 99 log.debug("FLYSArtifactCreator - extractArtifact()"); |
108 | 100 |
109 String uuid = XMLUtils.xpathString( | 101 final String uuid = XMLUtils.xpathString(doc, XPATH_UUID, ArtifactNamespaceContext.INSTANCE); |
110 doc, XPATH_UUID, ArtifactNamespaceContext.INSTANCE); | 102 |
111 | 103 final String hash = XMLUtils.xpathString(doc, XPATH_HASH, ArtifactNamespaceContext.INSTANCE); |
112 String hash = XMLUtils.xpathString( | 104 |
113 doc, XPATH_HASH, ArtifactNamespaceContext.INSTANCE); | 105 String name = XMLUtils.xpathString(doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE); |
114 | 106 |
115 String name = XMLUtils.xpathString( | 107 final String backgroundStr = XMLUtils.xpathString(doc, XPATH_BACKGROUND_VALUE, ArtifactNamespaceContext.INSTANCE); |
116 doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE); | |
117 | |
118 String backgroundStr = XMLUtils.xpathString( | |
119 doc, XPATH_BACKGROUND_VALUE, ArtifactNamespaceContext.INSTANCE); | |
120 | 108 |
121 boolean background = false; | 109 boolean background = false; |
122 if (backgroundStr != null && backgroundStr.length() > 0) { | 110 if (backgroundStr != null && backgroundStr.length() > 0) { |
123 background = Boolean.valueOf(backgroundStr); | 111 background = Boolean.valueOf(backgroundStr); |
124 } | 112 } |
125 | 113 |
126 List<CalculationMessage> msg = parseBackgroundMessages(doc); | 114 final List<CalculationMessage> msg = parseBackgroundMessages(doc); |
127 | 115 |
128 log.debug("NEW Artifact UUID: " + uuid); | 116 log.debug("NEW Artifact UUID: " + uuid); |
129 log.debug("NEW Artifact HASH: " + hash); | 117 log.debug("NEW Artifact HASH: " + hash); |
130 log.debug("NEW Artifact NAME: " + name); | 118 log.debug("NEW Artifact NAME: " + name); |
131 log.debug("NEW Artifact IN BACKGROUND: " + background); | 119 log.debug("NEW Artifact IN BACKGROUND: " + background); |
134 return new DefaultArtifact(uuid, hash, background, msg); | 122 return new DefaultArtifact(uuid, hash, background, msg); |
135 } | 123 } |
136 | 124 |
137 name = name.trim(); | 125 name = name.trim(); |
138 | 126 |
139 // FIXME: why do we have a super sophisticated artifact-framework if, in the end, module dependent stuff is still switched manually.... | 127 // FIXME: why do we have a super sophisticated artifact-framework if, in the end, module dependent stuff is still |
128 // switched manually.... | |
140 if (name.equals("winfo")) { | 129 if (name.equals("winfo")) { |
141 log.debug("+++++ NEW WINFO ARTIFACT."); | 130 log.debug("+++++ NEW WINFO ARTIFACT."); |
142 return new WINFOArtifact(uuid, hash, background, msg); | 131 return new WINFOArtifact(uuid, hash, background, msg); |
143 } | 132 } |
144 | 133 |
145 if (name.equals("new_map")) { | 134 if (name.equals("new_map")) { |
146 log.debug("+++++ NEW MAP ARTIFACT."); | 135 log.debug("+++++ NEW MAP ARTIFACT."); |
147 return new MapArtifact(uuid, hash, background, msg); | 136 return new MapArtifact(uuid, hash, background, msg); |
148 } | 137 } |
149 | 138 |
150 if (name.equals("new_chart")) { | 139 if (name.equals("new_chart")) { |
151 log.debug("+++++ NEW CHART ARTIFACT."); | 140 log.debug("+++++ NEW CHART ARTIFACT."); |
152 return new ChartArtifact(uuid, hash, background, msg); | 141 return new ChartArtifact(uuid, hash, background, msg); |
153 } | 142 } |
154 | 143 |
155 if (name.equals("minfo")) { | 144 if (name.equals("minfo")) { |
156 log.debug("+++++ NEW MINFO ARTIFACT."); | 145 log.debug("+++++ NEW MINFO ARTIFACT."); |
157 return new MINFOArtifact(uuid, hash, background, msg); | 146 return new MINFOArtifact(uuid, hash, background, msg); |
158 } | 147 } |
159 | 148 |
160 if (name.equals("fixanalysis")) { | 149 if (name.equals("fixanalysis")) { |
161 log.debug("+++++ NEW FIXANALYSIS ARTIFACT."); | 150 log.debug("+++++ NEW FIXANALYSIS ARTIFACT."); |
162 return new FixAnalysisArtifact(uuid, hash, background, msg); | 151 return new FixAnalysisArtifact(uuid, hash, background, msg); |
163 } | 152 } |
164 | 153 |
165 if (name.equals("gaugedischargecurve")) { | 154 if (name.equals("gaugedischargecurve")) { |
166 log.debug("+++++ NEW GAUGEDISCHARGECURVE ARTIFACT."); | 155 log.debug("+++++ NEW GAUGEDISCHARGECURVE ARTIFACT."); |
167 return new GaugeDischargeCurveArtifact(uuid, hash, background, msg); | 156 return new GaugeDischargeCurveArtifact(uuid, hash, background, msg); |
168 } | 157 } |
169 | 158 |
170 if (name.equals("staticsqrelation")) { | 159 if (name.equals("staticsqrelation")) { |
171 log.debug("+++++ STATICSQRELATION ARTIFACT."); | 160 log.debug("+++++ STATICSQRELATION ARTIFACT."); |
172 return new StaticSQRelationArtifact(uuid, hash, background, msg); | 161 return new StaticSQRelationArtifact(uuid, hash, background, msg); |
173 } | 162 } |
174 | 163 |
176 log.debug("+++++ NEW SINFO ARTIFACT."); | 165 log.debug("+++++ NEW SINFO ARTIFACT."); |
177 return new SINFOArtifact(uuid, hash, background, msg); | 166 return new SINFOArtifact(uuid, hash, background, msg); |
178 } | 167 } |
179 | 168 |
180 if (name.equals("uinfo")) { | 169 if (name.equals("uinfo")) { |
181 log.debug("+++++ NEW UINFO ARTIFACT."); | 170 log.debug("+++++ NEW UINFO ARTIFACT."); |
182 return new UINFOArtifact(uuid, hash, background, msg); | 171 return new UINFOArtifact(uuid, hash, background, msg); |
183 } | 172 } |
184 | 173 if (name.equals("bundu")) { |
174 log.debug("+++++ NEW BUNDU ARTIFACT."); | |
175 return new UINFOArtifact(uuid, hash, background, msg); | |
176 } | |
185 return new DefaultArtifact(uuid, hash, background, msg); | 177 return new DefaultArtifact(uuid, hash, background, msg); |
186 } | 178 } |
187 | 179 |
188 | 180 public static List<CalculationMessage> parseBackgroundMessages(final Document d) { |
189 public static List<CalculationMessage> parseBackgroundMessages(Document d) { | 181 final NodeList list = (NodeList) XMLUtils.xpath(d, XPATH_BACKGROUND, XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE); |
190 NodeList list = (NodeList) XMLUtils.xpath( | 182 |
191 d, XPATH_BACKGROUND, XPathConstants.NODESET, | 183 final int len = list != null ? list.getLength() : 0; |
192 ArtifactNamespaceContext.INSTANCE); | |
193 | |
194 int len = list != null ? list.getLength() : 0; | |
195 | 184 |
196 log.debug("Found " + len + " background messages."); | 185 log.debug("Found " + len + " background messages."); |
197 | 186 |
198 List<CalculationMessage> res = new ArrayList<CalculationMessage>(len); | 187 final List<CalculationMessage> res = new ArrayList<CalculationMessage>(len); |
199 | 188 |
200 for (int i = 0; i < len; i++) { | 189 for (int i = 0; i < len; i++) { |
201 CalculationMessage msg = parseBackgroundMessage( | 190 final CalculationMessage msg = parseBackgroundMessage((Element) list.item(i)); |
202 (Element) list.item(i)); | |
203 | 191 |
204 if (msg != null) { | 192 if (msg != null) { |
205 res.add(msg); | 193 res.add(msg); |
206 } | 194 } |
207 } | 195 } |
208 | 196 |
209 return res; | 197 return res; |
210 } | 198 } |
211 | 199 |
212 | 200 public static CalculationMessage parseBackgroundMessage(final Element e) { |
213 public static CalculationMessage parseBackgroundMessage(Element e) { | 201 final String steps = e.getAttribute("art:steps"); |
214 String steps = e.getAttribute("art:steps"); | 202 final String currentStep = e.getAttribute("art:currentStep"); |
215 String currentStep = e.getAttribute("art:currentStep"); | 203 final String message = e.getTextContent(); |
216 String message = e.getTextContent(); | 204 |
217 | 205 final int lenCurStep = currentStep != null ? currentStep.length() : 0; |
218 int lenCurStep = currentStep != null ? currentStep.length() : 0; | 206 final int lenSteps = steps != null ? steps.length() : 0; |
219 int lenSteps = steps != null ? steps.length() : 0; | 207 final int lenMessage = message != null ? message.length() : 0; |
220 int lenMessage = message != null ? message.length() : 0; | |
221 | 208 |
222 if (lenSteps > 0 && lenMessage > 0 && lenCurStep > 0) { | 209 if (lenSteps > 0 && lenMessage > 0 && lenCurStep > 0) { |
223 try { | 210 try { |
224 return new CalculationMessage( | 211 return new CalculationMessage(Integer.parseInt(steps), Integer.parseInt(currentStep), message); |
225 Integer.parseInt(steps), | |
226 Integer.parseInt(currentStep), | |
227 message); | |
228 | 212 |
229 } | 213 } |
230 catch (NumberFormatException nfe) { | 214 catch (final NumberFormatException nfe) { |
231 nfe.printStackTrace(); | 215 nfe.printStackTrace(); |
232 } | 216 } |
233 } | 217 } |
234 | 218 |
235 return null; | 219 return null; |