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