comparison artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java @ 6482:b07cfc319781

Official lines: Use river id instead of river name to be more precise when finding out which main values has a official line.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 27 Jun 2013 18:14:49 +0200
parents 4c791a458305
children 81d5939ec064
comparison
equal deleted inserted replaced
6480:d19a0ffb9ccf 6482:b07cfc319781
204 cr.addAttr(rootEl, "name", "mainvalues"); 204 cr.addAttr(rootEl, "name", "mainvalues");
205 205
206 doc.appendChild(rootEl); 206 doc.appendChild(rootEl);
207 207
208 appendMetaInformation(doc, rootEl, river, gauge, context); 208 appendMetaInformation(doc, rootEl, river, gauge, context);
209 appendMainValues(doc, rootEl, mainValues, river.getName(), context); 209 appendMainValues(doc, rootEl, mainValues, river.getId(), context);
210 210
211 return doc; 211 return doc;
212 } 212 }
213 213
214 214
250 root.appendChild(gaugeEl); 250 root.appendChild(gaugeEl);
251 } 251 }
252 252
253 253
254 /** Checks i a main value has an official associated, */ 254 /** Checks i a main value has an official associated, */
255 protected static boolean hasOfficialLine(NamedMainValue nmv, String river) { 255 protected static boolean hasOfficialLine(NamedMainValue nmv, Integer riverId) {
256 for (OfficialLine ol: nmv.getOfficialLines()) { 256 for (OfficialLine ol: nmv.getOfficialLines()) {
257 if (river.equals(ol.getWstColumn().getWst().getRiver().getName())) { 257 if (ol.getWstColumn().getWst().getRiver().getId().equals(riverId)) {
258 return true; 258 return true;
259 } 259 }
260 } 260 }
261 return false; 261 return false;
262 } 262 }
264 264
265 protected void appendMainValues( 265 protected void appendMainValues(
266 Document doc, 266 Document doc,
267 Element root, 267 Element root,
268 List<MainValue> mainValues, 268 List<MainValue> mainValues,
269 String river, 269 Integer riverId,
270 Object context) 270 Object context)
271 { 271 {
272 logger.debug("MainValuesService.appendMainValues"); 272 logger.debug("MainValuesService.appendMainValues");
273 273
274 ElementCreator cr = new ElementCreator( 274 ElementCreator cr = new ElementCreator(
277 ArtifactNamespaceContext.NAMESPACE_PREFIX); 277 ArtifactNamespaceContext.NAMESPACE_PREFIX);
278 278
279 Element list = cr.create("mainvalues"); 279 Element list = cr.create("mainvalues");
280 280
281 for (MainValue mainValue: mainValues) { 281 for (MainValue mainValue: mainValues) {
282 Element newEl = buildMainValueElement(doc, mainValue, river, context); 282 Element newEl = buildMainValueElement(doc, mainValue, riverId, context);
283 283
284 if (newEl != null) { 284 if (newEl != null) {
285 list.appendChild(newEl); 285 list.appendChild(newEl);
286 } 286 }
287 } 287 }
301 * @return a mainvalue element. 301 * @return a mainvalue element.
302 */ 302 */
303 protected Element buildMainValueElement( 303 protected Element buildMainValueElement(
304 Document doc, 304 Document doc,
305 MainValue mainValue, 305 MainValue mainValue,
306 String river, 306 Integer riverId,
307 Object context) 307 Object context)
308 { 308 {
309 ElementCreator cr = new ElementCreator( 309 ElementCreator cr = new ElementCreator(
310 doc, 310 doc,
311 ArtifactNamespaceContext.NAMESPACE_URI, 311 ArtifactNamespaceContext.NAMESPACE_URI,
318 318
319 cr.addAttr(el, "value", mainValue.getValue().toString()); 319 cr.addAttr(el, "value", mainValue.getValue().toString());
320 cr.addAttr(el, "name", namedMainValue.getName()); 320 cr.addAttr(el, "name", namedMainValue.getName());
321 cr.addAttr(el, "type", mainValueType.getName()); 321 cr.addAttr(el, "type", mainValueType.getName());
322 322
323 if (hasOfficialLine(namedMainValue, river)) { 323 if (hasOfficialLine(namedMainValue, riverId)) {
324 cr.addAttr(el, "official", "true"); 324 cr.addAttr(el, "official", "true");
325 } 325 }
326 326
327 327
328 return el; 328 return el;

http://dive4elements.wald.intevation.org