comparison gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java @ 157:013d47662161

Switched the Communication for Describe-Calls to the artifact-database from get to post. Added the possibility to tell the artifact-database that the ui should not be delivered in describe-responses. gnv/trunk@285 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 05 Nov 2009 14:53:24 +0000
parents d6b82c585f1f
children 5570d9b3282f
comparison
equal deleted inserted replaced
156:aa5197b3f930 157:013d47662161
322 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getCurrentStepDescription(de.intevation.gnv.artifactdatabase.objects.ArtifactFactory, 322 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getCurrentStepDescription(de.intevation.gnv.artifactdatabase.objects.ArtifactFactory,
323 * de.intevation.gnv.artifactdatabase.objects.ArtifactObject) 323 * de.intevation.gnv.artifactdatabase.objects.ArtifactObject)
324 */ 324 */
325 public ArtifactDescription getCurrentStepDescription( 325 public ArtifactDescription getCurrentStepDescription(
326 ArtifactObject artifactFactory, 326 ArtifactObject artifactFactory,
327 ArtifactObject currentArtifact) 327 ArtifactObject currentArtifact,
328 throws ArtifactDatabaseClientException { 328 boolean includeUI)
329 throws ArtifactDatabaseClientException {
329 try { 330 try {
330 String url = this.getArtifactUrl(artifactFactory, currentArtifact); 331 String url = this.getArtifactUrl(artifactFactory, currentArtifact);
331 Document result = this.doGetRequest(url); 332 Document request = this.createDescribeRequestBody(currentArtifact,
332 return this.readDescription(result, currentArtifact); 333 includeUI);
334 InputStream describeResult = this.doPostRequest(url, request);
335
336 return this.readDescription(new XMLUtils().readDocument(describeResult),
337 currentArtifact);
333 } catch (IOException e) { 338 } catch (IOException e) {
334 log.error(e, e); 339 log.error(e, e);
335 throw new ArtifactDatabaseClientException(e); 340 throw new ArtifactDatabaseClientException(e);
336 } 341 }
342 }
343
344
345 private Document createDescribeRequestBody(ArtifactObject currentArtifact,
346 boolean includeUI){
347
348 Document document = new XMLUtils().newDocument();
349 Node rootNode = this.createRootNode(document);
350
351 Element typeNode = this.createArtifactElement(document, "type");
352 typeNode.setAttribute("name", "describe");
353 rootNode.appendChild(typeNode);
354
355 Element uuidNode = this.createArtifactElement(document, "uuid");
356 uuidNode.setAttribute("value", currentArtifact.getId());
357 rootNode.appendChild(uuidNode);
358
359 Element hashNode = this.createArtifactElement(document, "hash");
360 hashNode.setAttribute("value", currentArtifact.getHash());
361 rootNode.appendChild(hashNode);
362 Element includeUINode = this.createArtifactElement(document, "include-ui");
363 includeUINode.appendChild(document.createTextNode(""+includeUI));
364 rootNode.appendChild(includeUINode);
365 return document;
337 } 366 }
338 367
339 /** 368 /**
340 * @param artifactFactory 369 * @param artifactFactory
341 * @param currentArtifact 370 * @param currentArtifact
452 throws ArtifactDatabaseClientException { 481 throws ArtifactDatabaseClientException {
453 482
454 try { 483 try {
455 // 1 Feed 484 // 1 Feed
456 this.doFeed(artifactFactory, currentArtifact, inputParameter); 485 this.doFeed(artifactFactory, currentArtifact, inputParameter);
457 // 2 Advance 486
487 // 2. Noch einmal Describe um das jetzt zu erreichende Ziel zu ermitteln
488 ArtifactDescription ad = this.getCurrentStepDescription(artifactFactory,
489 new Artifact(currentArtifact.getId(),
490 currentArtifact.getHash()),
491 false);
492 target = ad.getReachableStates().iterator().next();
493
494 // 3 Advance
458 String url = this.getArtifactUrl(artifactFactory, currentArtifact); 495 String url = this.getArtifactUrl(artifactFactory, currentArtifact);
459 Document advanceDocument = this.createAdvanceRequestBody( 496 Document advanceDocument = this.createAdvanceRequestBody(
460 currentArtifact, target); 497 currentArtifact, target);
461 InputStream advanceResult = this 498 InputStream advanceResult = this
462 .doPostRequest(url, advanceDocument); 499 .doPostRequest(url, advanceDocument);
463 this.check4ExceptionReport(new XMLUtils() 500 this.check4ExceptionReport(new XMLUtils()
464 .readDocument(advanceResult)); 501 .readDocument(advanceResult));
465 // 3 Describe 502 // 3 Describe
466 return this.getCurrentStepDescription(artifactFactory, 503 return this.getCurrentStepDescription(artifactFactory,
467 currentArtifact); 504 currentArtifact,true);
468 } catch (IOException e) { 505 } catch (IOException e) {
469 log.error(e, e); 506 log.error(e, e);
470 throw new ArtifactDatabaseClientException(e); 507 throw new ArtifactDatabaseClientException(e);
471 } 508 }
472 } 509 }

http://dive4elements.wald.intevation.org