Mercurial > dive4elements > gnv-client
annotate gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java @ 34:25fdec8b4c69
Added Global Errorhandling to the GNV-Client
gnv/trunk@170 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 02 Oct 2009 08:38:57 +0000 |
parents | 0f4362d75e9e |
children | 4405f31bbc30 |
rev | line source |
---|---|
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 /** |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 * |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
3 */ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
4 package de.intevation.gnv.artifactdatabase.client; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
5 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
6 import java.io.IOException; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
7 import java.io.InputStream; |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
8 import java.io.OutputStream; |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 import java.util.ArrayList; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 import java.util.Collection; |
30
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
11 import java.util.HashMap; |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 import java.util.Iterator; |
30
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
13 import java.util.Map; |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
14 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 import org.apache.log4j.Logger; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 import org.restlet.Client; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 import org.restlet.data.Method; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 import org.restlet.data.Protocol; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 import org.restlet.data.Request; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 import org.restlet.data.Response; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 import org.restlet.representation.Representation; |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
22 import org.restlet.representation.StringRepresentation; |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 import org.w3c.dom.Document; |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
24 import org.w3c.dom.Element; |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 import org.w3c.dom.Node; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 import org.w3c.dom.NodeList; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 import de.intevation.gnv.artifactdatabase.client.exception.ArtifactDatabaseClientException; |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
29 import de.intevation.gnv.artifactdatabase.objects.Artifact; |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
30 import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 import de.intevation.gnv.artifactdatabase.objects.ArtifactFactory; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; |
32
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
33 import de.intevation.gnv.artifactdatabase.objects.ArtifactStatisticValue; |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
34 import de.intevation.gnv.artifactdatabase.objects.DefaultArtifactStatisticValue; |
30
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
35 import de.intevation.gnv.artifactdatabase.objects.DefaultOutputMode; |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
36 import de.intevation.gnv.artifactdatabase.objects.DefaultOutputParameter; |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
37 import de.intevation.gnv.artifactdatabase.objects.InputParameter; |
30
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
38 import de.intevation.gnv.artifactdatabase.objects.OutputMode; |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
39 import de.intevation.gnv.artifactdatabase.objects.OutputParameter; |
23
b11f941f7eb2
Made ArtifactDatabase URL configurable
Tim Englich <tim.englich@intevation.de>
parents:
19
diff
changeset
|
40 import de.intevation.gnv.propertiesreader.PropertiesReader; |
b11f941f7eb2
Made ArtifactDatabase URL configurable
Tim Englich <tim.englich@intevation.de>
parents:
19
diff
changeset
|
41 import de.intevation.gnv.propertiesreader.PropertiesReaderFactory; |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
42 import de.intevation.gnv.util.XMLUtils; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
43 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
44 /** |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
45 * @author Tim Englich <tim.englich@intevation.de> |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
46 * |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
47 */ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 public class DefaultArtifactDatabaseClient implements ArtifactDatabaseClient { |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 /** |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
50 * The URI of the namespace of the artifacts. |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
51 */ |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
52 public final static String NAMESPACE_URI = "http://www.intevation.de/2009/artifacts"; |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
53 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
54 /** |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
55 * The XML prefix for the artifacts namespace. |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
56 */ |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
57 public final static String NAMESPACE_PREFIX = "art"; |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
58 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
59 /** |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 * the logger, used to log exceptions and additonaly information |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 */ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
62 private static Logger log = Logger.getLogger(DefaultArtifactDatabaseClient.class); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
63 |
25 | 64 /** |
65 * The Databases which could be used | |
66 */ | |
67 private static Collection<String> artifactDatabases = null; | |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
68 |
25 | 69 /** |
70 * Is the Class initialized? | |
71 */ | |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
72 private static boolean initialized = false; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
73 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
74 /** |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
75 * Constructor |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
76 */ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
77 public DefaultArtifactDatabaseClient() { |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
78 super(); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
79 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
80 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
81 /** |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
82 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getArtifactFactories() |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
83 */ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
84 public Collection<ArtifactObject> getArtifactFactories() throws ArtifactDatabaseClientException { |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
85 Collection<ArtifactObject> resultValues = null; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
86 if (!initialized){ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
87 this.initialize(); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
88 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
89 try { |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
90 log.debug("DefaultArtifactDatabaseClient.getArtifactFactories"); |
25 | 91 Iterator<String> it = artifactDatabases.iterator(); |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
92 while (it.hasNext()){ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
93 String server = it.next(); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
94 String url = server+ "/factories"; |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
95 Document document = this.doGetRequest(url); |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
96 if (resultValues == null){ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
97 resultValues = this.getArtifactFactories(document,server); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
98 }else{ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
99 resultValues.addAll(this.getArtifactFactories(document,server)); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
100 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
101 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
102 } catch (IOException e) { |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
103 log.error(e,e); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
104 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
105 return resultValues; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
106 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
107 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
108 private Collection<ArtifactObject> getArtifactFactories(Document document, String server){ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
109 XMLUtils xmlUtils = new XMLUtils(); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
110 NodeList artifactFactories = xmlUtils.getNodeSetXPath(document, "/result/factories/factory"); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
111 Collection<ArtifactObject> resultValues = new ArrayList<ArtifactObject>(artifactFactories.getLength()); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
112 if (artifactFactories != null){ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
113 for (int i = 0; i < artifactFactories.getLength(); i++){ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
114 Node artifactFactoryNode = artifactFactories.item(i); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
115 String name = xmlUtils.getStringXPath(artifactFactoryNode, "@name"); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
116 String description = xmlUtils.getStringXPath(artifactFactoryNode, "@description"); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
117 ArtifactFactory artifactFactory = new ArtifactFactory(name, description, server); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
118 resultValues.add(artifactFactory); |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
119 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
120 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
121 return resultValues; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
122 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
123 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
124 /** |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
125 * @throws IOException |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
126 */ |
25 | 127 private Document doGetRequest(String requestUrl) throws IOException, ArtifactDatabaseClientException { |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
128 return this.doGetRequest(requestUrl, null); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
129 } |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
130 |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
131 /** |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
132 * @throws IOException |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
133 */ |
25 | 134 private Document doGetRequest(String requestUrl, Document requestBody) throws IOException, ArtifactDatabaseClientException { |
135 XMLUtils xmlUtils = new XMLUtils(); | |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
136 Representation output = doGetRequestInternal(requestUrl, requestBody); |
25 | 137 Document document = xmlUtils.readDocument(output.getStream()); |
138 this.check4ExceptionReport(document); | |
139 return document; | |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
140 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
141 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
142 /** |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
143 * @param requestUrl |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
144 * @param requestBody |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
145 * @return |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
146 */ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
147 private Representation doGetRequestInternal(String requestUrl, |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
148 Document requestBody) { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
149 Client client = new Client(Protocol.HTTP); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
150 Request request = new Request(Method.GET, requestUrl); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
151 if (requestBody != null){ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
152 String documentBody = new XMLUtils().writeDocument2String(requestBody); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
153 Representation representation = new StringRepresentation(documentBody); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
154 request.setEntity(representation); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
155 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
156 Response response = client.handle(request); |
25 | 157 // TODO RESPONSESTATUS AUSWERTEN. |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
158 Representation output = response.getEntity(); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
159 return output; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
160 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
161 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
162 /** |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
163 * @throws IOException |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
164 */ |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
165 private InputStream doPostRequest(String requestUrl, Document requestBody) throws IOException { |
34
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
32
diff
changeset
|
166 log.debug("##################################################"); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
32
diff
changeset
|
167 log.debug(new XMLUtils().writeDocument2String(requestBody)); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
32
diff
changeset
|
168 log.debug("##################################################"); |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
169 Client client = new Client(Protocol.HTTP); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
170 Request request = new Request(Method.POST, requestUrl); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
171 String documentBody = new XMLUtils().writeDocument2String(requestBody); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
172 Representation representation = new StringRepresentation(documentBody); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
173 request.setEntity(representation); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
174 Response response = client.handle(request); |
25 | 175 // TODO RESPONSESTATUS AUSWERTEN. |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
176 Representation output = response.getEntity(); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
177 return output.getStream(); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
178 } |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
179 |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
180 private synchronized void initialize(){ |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
181 if (!initialized){ |
23
b11f941f7eb2
Made ArtifactDatabase URL configurable
Tim Englich <tim.englich@intevation.de>
parents:
19
diff
changeset
|
182 PropertiesReader pr = PropertiesReaderFactory.getInstance().getPropertiesReader(); |
b11f941f7eb2
Made ArtifactDatabase URL configurable
Tim Englich <tim.englich@intevation.de>
parents:
19
diff
changeset
|
183 int count = Integer.parseInt(pr.getPropertieValue(ARTIFACTDATABASE_COUNT_ID, "0")); |
25 | 184 artifactDatabases = new ArrayList<String>(count); |
23
b11f941f7eb2
Made ArtifactDatabase URL configurable
Tim Englich <tim.englich@intevation.de>
parents:
19
diff
changeset
|
185 for (int i = 0; i < count ; i++){ |
25 | 186 artifactDatabases.add(pr.getPropertieValue(ARTIFACTDATABASE_URL_ID+"."+(i+1), "N/N")); |
23
b11f941f7eb2
Made ArtifactDatabase URL configurable
Tim Englich <tim.englich@intevation.de>
parents:
19
diff
changeset
|
187 } |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
188 initialized = true; |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
189 } |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
190 |
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
191 } |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
192 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
193 /** |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
194 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#createNewArtifact(de.intevation.gnv.artifactdatabase.objects.ArtifactObject) |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
195 */ |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
196 public ArtifactObject createNewArtifact(ArtifactObject artifactFactory) |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
197 throws ArtifactDatabaseClientException { |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
198 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
199 try { |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
200 Document request = this.createCreateRequestBody(artifactFactory.getId()); |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
201 Document result = doPostRequest(artifactFactory, request, "create"); |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
202 return this.getArtifact(result); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
203 } catch (IOException e) { |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
204 log.error(e,e); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
205 throw new ArtifactDatabaseClientException(e); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
206 } |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
207 } |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
208 |
7
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
209 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
210 private ArtifactObject getArtifact(Document document){ |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
211 XMLUtils xmlUtils = new XMLUtils(); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
212 String uuid = xmlUtils.getStringXPath(document, "/result/uuid/@value"); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
213 String hash = xmlUtils.getStringXPath(document, "/result/hash/@value"); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
214 log.info("NEW Artifact: "+uuid+" / "+hash); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
215 return new Artifact(uuid, hash); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
216 } |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
217 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
218 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
219 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
220 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
221 private Document createCreateRequestBody(String artifactFactoryName){ |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
222 Document document = new XMLUtils().newDocument(); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
223 Node rootNode = this.createRootNode(document); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
224 Element typeNode = this.createArtifactElement(document, "type"); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
225 typeNode.setAttribute("name", "create"); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
226 rootNode.appendChild(typeNode); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
227 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
228 Element factoyNode = this.createArtifactElement(document, "factory"); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
229 factoyNode.setAttribute("name", artifactFactoryName); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
230 rootNode.appendChild(factoyNode); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
231 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
232 return document; |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
233 } |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
234 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
235 private Element createRootNode(Document document){ |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
236 Element rootNode = this.createArtifactElement(document,"action"); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
237 document.appendChild(rootNode); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
238 return rootNode; |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
239 } |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
240 |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
241 /** |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
242 * @param document |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
243 * @return |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
244 */ |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
245 private Element createArtifactElement(Document document, String name) { |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
246 Element node = document.createElementNS(NAMESPACE_URI, name); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
247 node.setPrefix(NAMESPACE_PREFIX); |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
248 return node; |
fe6a64545552
Support for creating an Artifact integrated
Tim Englich <tim.englich@intevation.de>
parents:
2
diff
changeset
|
249 } |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
250 |
25 | 251 /** |
252 * @param artifactFactory | |
253 * @param xmlUtils | |
254 * @param request | |
255 * @throws IOException | |
256 */ | |
257 private Document doPostRequest(ArtifactObject artifactFactory, | |
258 Document request, String suburl) throws IOException, ArtifactDatabaseClientException { | |
259 XMLUtils xmlUtils = new XMLUtils(); | |
260 String url = ((ArtifactFactory)artifactFactory).getDataBaseUrl(); | |
261 InputStream is = this.doPostRequest(url+"/"+suburl, request); | |
262 Document result = xmlUtils.readDocument(is); | |
263 this.check4ExceptionReport(result); | |
264 return result; | |
265 } | |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
266 |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
267 |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
268 /** |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
269 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getCurrentStepDescription(de.intevation.gnv.artifactdatabase.objects.ArtifactFactory, de.intevation.gnv.artifactdatabase.objects.ArtifactObject) |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
270 */ |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
271 public ArtifactDescription getCurrentStepDescription(ArtifactObject artifactFactory, |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
272 ArtifactObject currentArtifact) |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
273 throws ArtifactDatabaseClientException { |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
274 try { |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
275 String url = this.getArtifactUrl(artifactFactory, currentArtifact); |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
276 Document result = this.doGetRequest(url); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
277 return this.readDescription(result,currentArtifact); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
278 } catch (IOException e) { |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
279 log.error(e,e); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
280 throw new ArtifactDatabaseClientException(e); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
281 } |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
282 } |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
283 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
284 /** |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
285 * @param artifactFactory |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
286 * @param currentArtifact |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
287 * @return |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
288 */ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
289 private String getArtifactUrl(ArtifactObject artifactFactory, |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
290 ArtifactObject currentArtifact) { |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
291 String url = ((ArtifactFactory)artifactFactory).getDataBaseUrl()+"/artifact/"+ currentArtifact.getId(); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
292 return url; |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
293 } |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
294 |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
295 private ArtifactDescription readDescription(Document document, ArtifactObject artifact) throws ArtifactDatabaseClientException{ |
25 | 296 // Check if there was an Error or Exception reported from the ArtifactDatabase |
297 this.check4ExceptionReport(document); | |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
298 XMLUtils xmlUtils = new XMLUtils(); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
299 if (artifact instanceof ArtifactDescription){ |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
300 ArtifactDescription ad = (ArtifactDescription)artifact; |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
301 Node uiNode = xmlUtils.getNodeXPath(document, "/result/ui"); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
302 Node outputNode = xmlUtils.getNodeXPath(document, "/result/outputs"); |
30
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
303 |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
304 Map<String, OutputMode> outputModes = null; |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
305 if (outputNode != null){ |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
306 NodeList outputModesNodes = xmlUtils.getNodeSetXPath(outputNode, "output"); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
307 if (outputModesNodes != null){ |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
308 outputModes = new HashMap<String, OutputMode>(outputModesNodes.getLength()); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
309 for (int i = 0; i < outputModesNodes.getLength(); i++){ |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
310 Node outputModeNode = outputModesNodes.item(i); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
311 String name = xmlUtils.getStringXPath(outputModeNode, "@name"); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
312 String mimeType = xmlUtils.getStringXPath(outputModeNode, "@mime-type"); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
313 |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
314 NodeList parameterNodes = xmlUtils.getNodeSetXPath(outputModeNode, "parameter/parameter"); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
315 Collection<OutputParameter> parameter = null; |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
316 if (parameterNodes != null){ |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
317 parameter = new ArrayList<OutputParameter>(parameterNodes.getLength()); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
318 for (int j = 0; j < parameterNodes.getLength(); j++){ |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
319 Node outputParameterNode = parameterNodes.item(j); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
320 parameter.add(new DefaultOutputParameter(xmlUtils.getStringXPath(outputParameterNode,"@name"),xmlUtils.getStringXPath(outputParameterNode,"@value"),xmlUtils.getStringXPath(outputParameterNode,"@name"),xmlUtils.getStringXPath(outputParameterNode,"@type"))); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
321 } |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
322 } |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
323 outputModes.put(name,new DefaultOutputMode(name, mimeType, parameter)); |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
324 } |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
325 |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
326 } |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
327 } |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
328 |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
329 String currentState = xmlUtils.getStringXPath(document, "/result/state/@name"); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
330 NodeList statesList = xmlUtils.getNodeSetXPath(document, "/result/reachable-states/state/@name"); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
331 Collection<String> reachableStates = new ArrayList<String>(statesList.getLength()); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
332 for (int i = 0; i < statesList.getLength(); i++){ |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
333 reachableStates.add(statesList.item(i).getNodeValue()); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
334 } |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
335 |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
336 NodeList inputNodes = xmlUtils.getNodeSetXPath(document, "/result/model/input"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
337 if (inputNodes != null){ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
338 Collection<String> inputParameter = new ArrayList<String>(inputNodes.getLength()); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
339 for (int i = 0; i < inputNodes.getLength(); i++){ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
340 Node inputNode = inputNodes.item(i); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
341 String name = xmlUtils.getStringXPath(inputNode, "@name"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
342 inputParameter.add(name); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
343 } |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
344 ad.setInputParameter(inputParameter); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
345 } |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
346 |
30
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
347 ad.setOutputModes(outputModes); |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
348 ad.setCurrentOut(outputNode); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
349 ad.setCurrentUI(uiNode); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
350 ad.setCurrentState(currentState); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
351 ad.setReachableStates(reachableStates); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
352 return ad; |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
353 }else{ |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
354 log.error("Artifact must be Instance of ArtifactDescription"); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
355 throw new ArtifactDatabaseClientException("Artifact must be Instance of ArtifactDescription"); |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
356 } |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
357 |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
358 |
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
359 } |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
360 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
361 /** |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
362 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#doNextStep(de.intevation.gnv.artifactdatabase.objects.ArtifactObject, de.intevation.gnv.artifactdatabase.objects.ArtifactObject, java.lang.String, java.util.Collection) |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
363 */ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
364 public ArtifactDescription doNextStep(ArtifactObject artifactFactory, |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
365 ArtifactObject currentArtifact, String target, |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
366 Collection<InputParameter> inputParameter) |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
367 throws ArtifactDatabaseClientException { |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
368 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
369 try { |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
370 // 1 Feed |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
371 this.doFeed(artifactFactory, currentArtifact, inputParameter); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
372 // 2 Advance |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
373 String url = this.getArtifactUrl(artifactFactory, currentArtifact); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
374 Document advanceDocument = this.createAdvanceRequestBody(currentArtifact, target); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
375 InputStream advanceResult = this.doPostRequest(url, advanceDocument); |
25 | 376 this.check4ExceptionReport(new XMLUtils().readDocument(advanceResult)); |
377 // 3 Describe | |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
378 return this.getCurrentStepDescription(artifactFactory, currentArtifact); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
379 } catch (IOException e) { |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
380 log.error(e,e); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
381 throw new ArtifactDatabaseClientException(e); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
382 } |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
383 } |
9
a4cb6d175a6e
Support for Initial DescribeCall to ArtifactDatabase implemented
Tim Englich <tim.englich@intevation.de>
parents:
7
diff
changeset
|
384 |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
385 private Document createFeedRequestBody(ArtifactObject currentArtifact, |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
386 Collection<InputParameter> inputParameter){ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
387 Document document = new XMLUtils().newDocument(); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
388 Node rootNode = this.createRootNode(document); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
389 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
390 Element typeNode = this.createArtifactElement(document, "type"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
391 typeNode.setAttribute("name", "feed"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
392 rootNode.appendChild(typeNode); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
393 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
394 Element uuidNode = this.createArtifactElement(document, "uuid"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
395 uuidNode.setAttribute("value", currentArtifact.getId()); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
396 rootNode.appendChild(uuidNode); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
397 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
398 Element hashNode = this.createArtifactElement(document, "hash"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
399 hashNode.setAttribute("value", currentArtifact.getHash()); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
400 rootNode.appendChild(hashNode); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
401 |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
402 Node dataNode = this.createParameterNodes(inputParameter, document, "data"); |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
403 rootNode.appendChild(dataNode); |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
404 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
405 return document; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
406 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
407 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
408 /** |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
409 * @param inputParameter |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
410 * @param document |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
411 * @param rootNode |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
412 */ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
413 private Node createParameterNodes(Collection<InputParameter> inputParameter, Document document, String nodeName) { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
414 Element dataNode = this.createArtifactElement(document, nodeName); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
415 |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
416 if (inputParameter != null){ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
417 Iterator<InputParameter> it = inputParameter.iterator(); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
418 while(it.hasNext()){ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
419 InputParameter ip = it.next(); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
420 String name = ip.getName(); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
421 String[] values = ip.getValues(); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
422 if (values != null){ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
423 for (int i = 0; i < values.length; i++){ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
424 String value = values[i]; |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
425 Element inputNode = this.createArtifactElement(document, "input"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
426 inputNode.setAttribute("name", name); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
427 inputNode.setAttribute("value", value); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
428 dataNode.appendChild(inputNode); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
429 } |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
430 } |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
431 } |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
432 } |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
433 return dataNode; |
12
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
434 } |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
435 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
436 private Document createAdvanceRequestBody(ArtifactObject currentArtifact, String target){ |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
437 Document document = new XMLUtils().newDocument(); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
438 Node rootNode = this.createRootNode(document); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
439 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
440 Element typeNode = this.createArtifactElement(document, "type"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
441 typeNode.setAttribute("name", "advance"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
442 rootNode.appendChild(typeNode); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
443 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
444 Element uuidNode = this.createArtifactElement(document, "uuid"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
445 uuidNode.setAttribute("value", currentArtifact.getId()); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
446 rootNode.appendChild(uuidNode); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
447 |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
448 Element hashNode = this.createArtifactElement(document, "hash"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
449 hashNode.setAttribute("value", currentArtifact.getHash()); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
450 rootNode.appendChild(hashNode); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
451 Element targetNode = this.createArtifactElement(document, "target"); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
452 targetNode.setAttribute("name", target); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
453 rootNode.appendChild(targetNode); |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
454 return document; |
4ebe57b170d3
Integration of moving through the Artifact-States and rendering the UI.
Tim Englich <tim.englich@intevation.de>
parents:
11
diff
changeset
|
455 } |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
456 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
457 /** |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
458 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#doOutput(de.intevation.gnv.artifactdatabase.objects.ArtifactObject, de.intevation.gnv.artifactdatabase.objects.ArtifactObject, java.io.OutputStream, java.lang.String, java.lang.String, java.util.Collection) |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
459 */ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
460 public void doOutput(ArtifactObject artifactFactory, |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
461 ArtifactObject currentArtifact, OutputStream stream, |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
462 String targetName, String mimeType, |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
463 Collection<InputParameter> inputParameter) |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
464 throws ArtifactDatabaseClientException { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
465 try { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
466 XMLUtils xmlUtils = new XMLUtils(); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
467 Document requestBody = this.createOutRequestBody(currentArtifact, targetName, mimeType, inputParameter); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
468 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
469 String requestUrl = this.getArtifactUrl(artifactFactory, currentArtifact)+"/"+targetName; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
470 InputStream is = this.doPostRequest( requestUrl, requestBody); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
471 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
472 byte[] b = new byte[4096]; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
473 int i = -1 ; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
474 while ((i = is.read(b)) > 0) |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
475 { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
476 stream.write(b, 0, i); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
477 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
478 } catch (IOException e) { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
479 log.error(e,e); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
480 throw new ArtifactDatabaseClientException(e); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
481 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
482 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
483 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
484 private Document createOutRequestBody(ArtifactObject currentArtifact, String target, String mimeType, Collection<InputParameter> inputParameter){ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
485 Document document = new XMLUtils().newDocument(); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
486 Node rootNode = this.createRootNode(document); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
487 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
488 Element typeNode = this.createArtifactElement(document, "type"); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
489 typeNode.setAttribute("name", "out"); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
490 rootNode.appendChild(typeNode); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
491 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
492 Element uuidNode = this.createArtifactElement(document, "uuid"); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
493 uuidNode.setAttribute("value", currentArtifact.getId()); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
494 rootNode.appendChild(uuidNode); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
495 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
496 Element hashNode = this.createArtifactElement(document, "hash"); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
497 hashNode.setAttribute("value", currentArtifact.getHash()); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
498 rootNode.appendChild(hashNode); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
499 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
500 Element outNode = this.createArtifactElement(document, "out"); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
501 outNode.setAttribute("name", target); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
502 rootNode.appendChild(outNode); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
503 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
504 Element mimeTypeNode = this.createArtifactElement(document, "out"); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
505 mimeTypeNode.setAttribute("value", mimeType); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
506 outNode.appendChild(mimeTypeNode); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
507 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
508 Node parameterNode = this.createParameterNodes(inputParameter, document, "params"); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
509 outNode.appendChild(parameterNode); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
510 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
511 return document; |
2
5e94403971af
infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
512 } |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
513 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
514 /** |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
515 * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#doFeed(de.intevation.gnv.artifactdatabase.objects.ArtifactObject, de.intevation.gnv.artifactdatabase.objects.ArtifactObject, java.util.Collection) |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
516 */ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
517 public void doFeed(ArtifactObject artifactFactory, |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
518 ArtifactObject currentArtifact, |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
519 Collection<InputParameter> inputParameter) |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
520 throws ArtifactDatabaseClientException { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
521 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
522 try { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
523 Document feedDocument = this.createFeedRequestBody(currentArtifact, inputParameter); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
524 String url = this.getArtifactUrl(artifactFactory, currentArtifact); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
525 InputStream feedResult = this.doPostRequest(url, feedDocument); |
25 | 526 Document feedResultDocument = new XMLUtils().readDocument(feedResult); |
527 this.check4ExceptionReport(feedResultDocument); | |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
528 } catch (IOException e) { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
529 log.error(e,e); |
25 | 530 throw new ArtifactDatabaseClientException(e); |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
531 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
532 } |
25 | 533 |
534 private void check4ExceptionReport(Document document) throws ArtifactDatabaseClientException{ | |
535 | |
536 String message = new XMLUtils().getStringXPath(document,"/exceptionreport/exception"); | |
537 if (message != null){ | |
538 throw new ArtifactDatabaseClientException(message); | |
539 } | |
540 | |
541 } | |
32
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
542 |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
543 public Collection<ArtifactStatisticValue> calculateStatistics( |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
544 ArtifactObject artifactFactory, ArtifactObject currentArtifact) throws ArtifactDatabaseClientException{ |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
545 log.debug("DefaultArtifactDatabaseClient.calculateStatistics") ; |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
546 Collection<ArtifactStatisticValue> result; |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
547 try { |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
548 result = null; |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
549 String targetName = "statistics"; |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
550 String requestUrl = this.getArtifactUrl(artifactFactory, currentArtifact)+"/"+targetName; |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
551 Document requestBody = this.createOutRequestBody(currentArtifact, targetName, "text/xml", null); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
552 XMLUtils xmlUtils = new XMLUtils(); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
553 InputStream is = this.doPostRequest(requestUrl, requestBody); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
554 Document resultDocument = xmlUtils.readDocument(is); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
555 if (resultDocument != null){ |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
556 NodeList resultNodes = xmlUtils.getNodeSetXPath(resultDocument, "/statistic-values/statistic"); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
557 if (resultNodes != null){ |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
558 result = new ArrayList<ArtifactStatisticValue>(resultNodes.getLength()); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
559 for (int i = 0; i < resultNodes.getLength(); i++){ |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
560 Node statisticNode = resultNodes.item(i); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
561 String name = xmlUtils.getStringXPath(statisticNode, "@name"); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
562 String value = xmlUtils.getStringXPath(statisticNode, "@value"); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
563 result.add(new DefaultArtifactStatisticValue(name, value)); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
564 } |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
565 } |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
566 } |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
567 } catch (IOException e) { |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
568 log.error(e,e); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
569 throw new ArtifactDatabaseClientException(e); |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
570 } |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
571 |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
572 return result; |
0f4362d75e9e
Adding StatisticsOutput to the GUI
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
573 } |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
12
diff
changeset
|
574 } |