Mercurial > dive4elements > gnv-client
comparison gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java @ 681:15ac78a91d1b
Removed trailing whitespace.
gnv/trunk@852 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 29 Mar 2010 08:04:15 +0000 |
parents | 4eccd03394ac |
children | d49e8695786c |
comparison
equal
deleted
inserted
replaced
680:ba3370dbc8c5 | 681:15ac78a91d1b |
---|---|
105 | 105 |
106 /** | 106 /** |
107 * Constructor | 107 * Constructor |
108 */ | 108 */ |
109 public DefaultArtifactDatabaseClient() { | 109 public DefaultArtifactDatabaseClient() { |
110 | 110 |
111 } | 111 } |
112 | 112 |
113 /** | 113 /** |
114 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getArtifactFactories() | 114 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getArtifactFactories() |
115 */ | 115 */ |
153 Node artifactFactoryNode = artifactFactories.item(i); | 153 Node artifactFactoryNode = artifactFactories.item(i); |
154 String name = xmlUtils.getStringXPath(artifactFactoryNode, | 154 String name = xmlUtils.getStringXPath(artifactFactoryNode, |
155 "@art:name"); | 155 "@art:name"); |
156 String description = xmlUtils.getStringXPath( | 156 String description = xmlUtils.getStringXPath( |
157 artifactFactoryNode, "@art:description"); | 157 artifactFactoryNode, "@art:description"); |
158 | 158 |
159 NodeList parameterNodeList = xmlUtils.getNodeSetXPath( | 159 NodeList parameterNodeList = xmlUtils.getNodeSetXPath( |
160 artifactFactoryNode, | 160 artifactFactoryNode, |
161 "art:parameter"); | 161 "art:parameter"); |
162 | 162 |
163 if ((parameterNodeList != null && | 163 if ((parameterNodeList != null && |
164 parameterNodeList.getLength() > 0) || | 164 parameterNodeList.getLength() > 0) || |
165 geometry != null){ | 165 geometry != null){ |
166 Collection<String> parameters = | 166 Collection<String> parameters = |
167 new ArrayList<String>(parameterNodeList.getLength()); | 167 new ArrayList<String>(parameterNodeList.getLength()); |
168 for (int j = 0; j < parameterNodeList.getLength(); j++){ | 168 for (int j = 0; j < parameterNodeList.getLength(); j++){ |
169 Element parameterNode = (Element)parameterNodeList.item(j); | 169 Element parameterNode = (Element)parameterNodeList.item(j); |
170 parameters.add(parameterNode.getAttribute("id")); | 170 parameters.add(parameterNode.getAttribute("id")); |
171 } | 171 } |
172 ParametrizedArtifactObject pao = | 172 ParametrizedArtifactObject pao = |
173 new ParametrizedArtifactFactory(name, | 173 new ParametrizedArtifactFactory(name, |
174 description, | 174 description, |
175 server); | 175 server); |
176 pao.addParameters("parameter", parameters); | 176 pao.addParameters("parameter", parameters); |
177 resultValues.add(pao); | 177 resultValues.add(pao); |
178 if (geometry != null){ | 178 if (geometry != null){ |
320 rootNode.appendChild(typeNode); | 320 rootNode.appendChild(typeNode); |
321 | 321 |
322 Element factoryNode = this.createArtifactElement(document, "factory"); | 322 Element factoryNode = this.createArtifactElement(document, "factory"); |
323 factoryNode.setAttribute("name", artifactFactory.getId()); | 323 factoryNode.setAttribute("name", artifactFactory.getId()); |
324 rootNode.appendChild(factoryNode); | 324 rootNode.appendChild(factoryNode); |
325 | 325 |
326 if (artifactFactory instanceof ParametrizedArtifactObject){ | 326 if (artifactFactory instanceof ParametrizedArtifactObject){ |
327 Map<String, Collection<String>> parameterMap = | 327 Map<String, Collection<String>> parameterMap = |
328 ((ParametrizedArtifactObject)artifactFactory).getParameters(); | 328 ((ParametrizedArtifactObject)artifactFactory).getParameters(); |
329 if (parameterMap != null && !parameterMap.isEmpty() ){ | 329 if (parameterMap != null && !parameterMap.isEmpty() ){ |
330 Iterator<String> keyIt = parameterMap.keySet().iterator(); | 330 Iterator<String> keyIt = parameterMap.keySet().iterator(); |
331 while (keyIt.hasNext()){ | 331 while (keyIt.hasNext()){ |
332 String key = keyIt.next(); | 332 String key = keyIt.next(); |
333 Iterator<String> valueIt = parameterMap.get(key).iterator(); | 333 Iterator<String> valueIt = parameterMap.get(key).iterator(); |
334 while (valueIt.hasNext()){ | 334 while (valueIt.hasNext()){ |
335 String value = valueIt.next(); | 335 String value = valueIt.next(); |
336 Element parameterNode = | 336 Element parameterNode = |
337 this.createArtifactElement(document, "parameter"); | 337 this.createArtifactElement(document, "parameter"); |
338 parameterNode.setAttribute("name", key); | 338 parameterNode.setAttribute("name", key); |
339 parameterNode.setAttribute("value", value); | 339 parameterNode.setAttribute("value", value); |
340 factoryNode.appendChild(parameterNode); | 340 factoryNode.appendChild(parameterNode); |
341 } | 341 } |
395 String url = this.getArtifactUrl(artifactFactory, currentArtifact); | 395 String url = this.getArtifactUrl(artifactFactory, currentArtifact); |
396 log.debug("DESCRIBE URL: " + url); | 396 log.debug("DESCRIBE URL: " + url); |
397 Document request = this.createDescribeRequestBody(currentArtifact, | 397 Document request = this.createDescribeRequestBody(currentArtifact, |
398 includeUI); | 398 includeUI); |
399 InputStream describeResult = this.doPostRequest(url, request); | 399 InputStream describeResult = this.doPostRequest(url, request); |
400 | 400 |
401 return this.readDescription(new XMLUtils().readDocument(describeResult), | 401 return this.readDescription(new XMLUtils().readDocument(describeResult), |
402 currentArtifact); | 402 currentArtifact); |
403 } catch (IOException e) { | 403 } catch (IOException e) { |
404 log.error(e, e); | 404 log.error(e, e); |
405 throw new ArtifactDatabaseClientException(e); | 405 throw new ArtifactDatabaseClientException(e); |
406 } | 406 } |
407 } | 407 } |
408 | 408 |
409 | 409 |
410 private Document createDescribeRequestBody(ArtifactObject currentArtifact, | 410 private Document createDescribeRequestBody(ArtifactObject currentArtifact, |
411 boolean includeUI){ | 411 boolean includeUI){ |
412 | 412 |
413 Document document = new XMLUtils().newDocument(); | 413 Document document = new XMLUtils().newDocument(); |
414 Node rootNode = this.createRootNode(document); | 414 Node rootNode = this.createRootNode(document); |
415 | 415 |
416 Element typeNode = this.createArtifactElement(document, "type"); | 416 Element typeNode = this.createArtifactElement(document, "type"); |
417 typeNode.setAttribute("name", "describe"); | 417 typeNode.setAttribute("name", "describe"); |
491 } | 491 } |
492 | 492 |
493 NodeList exportNodes = xmlUtils.getNodeSetXPath( | 493 NodeList exportNodes = xmlUtils.getNodeSetXPath( |
494 outputModeNode, "art:exports/art:export"); | 494 outputModeNode, "art:exports/art:export"); |
495 Map exports = null; | 495 Map exports = null; |
496 | 496 |
497 if (exportNodes != null) { | 497 if (exportNodes != null) { |
498 int size = exportNodes.getLength(); | 498 int size = exportNodes.getLength(); |
499 exports = new HashMap<String, ExportMode>(size); | 499 exports = new HashMap<String, ExportMode>(size); |
500 | 500 |
501 for (int k = 0; k < size; k++) { | 501 for (int k = 0; k < size; k++) { |
566 throws ArtifactDatabaseClientException, ArtifactDatabaseInputException { | 566 throws ArtifactDatabaseClientException, ArtifactDatabaseInputException { |
567 | 567 |
568 try { | 568 try { |
569 // 1 Feed | 569 // 1 Feed |
570 this.doFeed(artifactFactory, currentArtifact, inputParameter); | 570 this.doFeed(artifactFactory, currentArtifact, inputParameter); |
571 | 571 |
572 // 2. Noch einmal Describe um das jetzt zu erreichende Ziel zu ermitteln | 572 // 2. Noch einmal Describe um das jetzt zu erreichende Ziel zu ermitteln |
573 ArtifactDescription ad = getCurrentStepDescription( | 573 ArtifactDescription ad = getCurrentStepDescription( |
574 artifactFactory, | 574 artifactFactory, |
575 new Artifact(currentArtifact.getId(), | 575 new Artifact(currentArtifact.getId(), |
576 currentArtifact.getHash()), | 576 currentArtifact.getHash()), |
577 false | 577 false |
578 ); | 578 ); |
579 | 579 |
580 target = ad.getReachableStates().iterator().next(); | 580 target = ad.getReachableStates().iterator().next(); |
581 | 581 |
582 // 3 Advance | 582 // 3 Advance |
583 doAdvance(artifactFactory, currentArtifact, target); | 583 doAdvance(artifactFactory, currentArtifact, target); |
584 | 584 |
585 // 3 Describe | 585 // 3 Describe |
586 return this.getCurrentStepDescription(artifactFactory, | 586 return this.getCurrentStepDescription(artifactFactory, |
587 currentArtifact,true); | 587 currentArtifact,true); |
588 } catch (IOException e) { | 588 } catch (IOException e) { |
589 log.error(e, e); | 589 log.error(e, e); |
888 ArtifactObject currentArtifact) | 888 ArtifactObject currentArtifact) |
889 throws ArtifactDatabaseClientException | 889 throws ArtifactDatabaseClientException |
890 { | 890 { |
891 log.debug("DefaultArtifactDatabaseClient.calculateStatistics"); | 891 log.debug("DefaultArtifactDatabaseClient.calculateStatistics"); |
892 Collection<ArtifactStatisticsSet> resultValues = null; | 892 Collection<ArtifactStatisticsSet> resultValues = null; |
893 | 893 |
894 try { | 894 try { |
895 String targetName = "statistics"; | 895 String targetName = "statistics"; |
896 String requestUrl = this.getArtifactUrl(artifactFactory, | 896 String requestUrl = this.getArtifactUrl(artifactFactory, |
897 currentArtifact) + "/" + targetName; | 897 currentArtifact) + "/" + targetName; |
898 Document requestBody = this.createOutRequestBody(currentArtifact, | 898 Document requestBody = this.createOutRequestBody(currentArtifact, |
899 targetName, "", "text/xml", null); | 899 targetName, "", "text/xml", null); |
900 XMLUtils xmlUtils = new XMLUtils(); | 900 XMLUtils xmlUtils = new XMLUtils(); |
901 InputStream is = this.doPostRequest(requestUrl, requestBody); | 901 InputStream is = this.doPostRequest(requestUrl, requestBody); |
902 Document resultDocument = xmlUtils.readDocument(is); | 902 Document resultDocument = xmlUtils.readDocument(is); |
903 if (resultDocument != null) { | 903 if (resultDocument != null) { |
904 | 904 |
905 NodeList statisticSetNodes = xmlUtils.getNodeSetXPath(resultDocument, | 905 NodeList statisticSetNodes = xmlUtils.getNodeSetXPath(resultDocument, |
906 "/art:statistics/art:statistic"); | 906 "/art:statistics/art:statistic"); |
907 resultValues = new ArrayList<ArtifactStatisticsSet> | 907 resultValues = new ArrayList<ArtifactStatisticsSet> |
908 (statisticSetNodes.getLength()); | 908 (statisticSetNodes.getLength()); |
909 for (int i = 0; i < statisticSetNodes.getLength(); i++) { | 909 for (int i = 0; i < statisticSetNodes.getLength(); i++) { |
910 Element statisticSetNode = (Element)statisticSetNodes.item(i); | 910 Element statisticSetNode = (Element)statisticSetNodes.item(i); |
911 String name = statisticSetNode.getAttribute("name"); | 911 String name = statisticSetNode.getAttribute("name"); |
912 ArtifactStatisticsSet set = | 912 ArtifactStatisticsSet set = |
913 new DefaultArtifactStatisticsSet(name); | 913 new DefaultArtifactStatisticsSet(name); |
914 NodeList resultNodes = xmlUtils.getNodeSetXPath(statisticSetNode, | 914 NodeList resultNodes = xmlUtils.getNodeSetXPath(statisticSetNode, |
915 "art:statistic-value"); | 915 "art:statistic-value"); |
916 if (resultNodes != null) { | 916 if (resultNodes != null) { |
917 for (int j = 0; j < resultNodes.getLength(); j++) { | 917 for (int j = 0; j < resultNodes.getLength(); j++) { |
951 log.debug("DefaultArtifactDatabaseClient.getArtifactFactories"); | 951 log.debug("DefaultArtifactDatabaseClient.getArtifactFactories"); |
952 Collection<ArtifactObject> resultValues = null; | 952 Collection<ArtifactObject> resultValues = null; |
953 try { | 953 try { |
954 this.initialize(); | 954 this.initialize(); |
955 Iterator<String> it = artifactDatabases.iterator(); | 955 Iterator<String> it = artifactDatabases.iterator(); |
956 Document requestBody = this.createMetaDataRequestBody(mapServices, | 956 Document requestBody = this.createMetaDataRequestBody(mapServices, |
957 geometry, | 957 geometry, |
958 srs); | 958 srs); |
959 while (it.hasNext()) { | 959 while (it.hasNext()) { |
960 String server = it.next(); | 960 String server = it.next(); |
961 String url = server + "/service/metadata/"; | 961 String url = server + "/service/metadata/"; |
962 log.debug(url); | 962 log.debug(url); |
963 | 963 |
964 InputStream resultStream = this.doPostRequest(url, requestBody); | 964 InputStream resultStream = this.doPostRequest(url, requestBody); |
965 resultValues = this.parseMetaDataResult(resultStream, server,geometry); | 965 resultValues = this.parseMetaDataResult(resultStream, server,geometry); |
966 } | 966 } |
967 } catch (IOException e) { | 967 } catch (IOException e) { |
968 log.error(e,e); | 968 log.error(e,e); |
969 } | 969 } |
970 return resultValues; | 970 return resultValues; |
971 } | 971 } |
972 | 972 |
973 private Collection<ArtifactObject> parseMetaDataResult( | 973 private Collection<ArtifactObject> parseMetaDataResult( |
974 InputStream inputStream, | 974 InputStream inputStream, |
975 String server, | 975 String server, |
976 String geometry) | 976 String geometry) |
977 throws ArtifactDatabaseClientException, ArtifactDatabaseInputException { | 977 throws ArtifactDatabaseClientException, ArtifactDatabaseInputException { |
978 XMLUtils xmlUtils = new XMLUtils(); | 978 XMLUtils xmlUtils = new XMLUtils(); |
979 Document document = xmlUtils.readDocument(inputStream); | 979 Document document = xmlUtils.readDocument(inputStream); |
980 this.check4ExceptionReport(document); | 980 this.check4ExceptionReport(document); |
981 return this.getArtifactFactories(document, server,geometry); | 981 return this.getArtifactFactories(document, server,geometry); |
982 } | 982 } |
983 | 983 |
984 private Document createMetaDataRequestBody(Collection<MapService> mapServices, | 984 private Document createMetaDataRequestBody(Collection<MapService> mapServices, |
985 String geometry, | 985 String geometry, |
986 String srs){ | 986 String srs){ |
987 log.debug("DefaultArtifactDatabaseClient.createMetaDataRequestBody"); | 987 log.debug("DefaultArtifactDatabaseClient.createMetaDataRequestBody"); |
988 Document document = new XMLUtils().newDocument(); | 988 Document document = new XMLUtils().newDocument(); |
989 Node rootNode = this.createArtifactElement(document, "GetMetaData"); | 989 Node rootNode = this.createArtifactElement(document, "GetMetaData"); |
990 document.appendChild(rootNode); | 990 document.appendChild(rootNode); |
991 | 991 |
992 Element locationNode = this.createArtifactElement(document, "location"); | 992 Element locationNode = this.createArtifactElement(document, "location"); |
993 locationNode.setAttribute("srs", srs); | 993 locationNode.setAttribute("srs", srs); |
994 locationNode.appendChild(document.createTextNode(geometry)); | 994 locationNode.appendChild(document.createTextNode(geometry)); |
995 rootNode.appendChild(locationNode); | 995 rootNode.appendChild(locationNode); |
996 | 996 |
997 Element mapServicesNode = this.createArtifactElement(document, | 997 Element mapServicesNode = this.createArtifactElement(document, |
998 "mapservices"); | 998 "mapservices"); |
999 Iterator<MapService> it = mapServices.iterator(); | 999 Iterator<MapService> it = mapServices.iterator(); |
1000 while (it.hasNext()){ | 1000 while (it.hasNext()){ |
1001 MapService mapService = it.next(); | 1001 MapService mapService = it.next(); |