annotate flys-client/src/main/java/de/intevation/flys/client/server/GetArtifactServiceImpl.java @ 275:8264b02091ef

ISSUE-56 Display download buttons to export the computed data. flys-client/trunk@1901 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 11 May 2011 14:29:35 +0000
parents 924da6695800
children ab8eb2f544f2
rev   line source
221
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import org.w3c.dom.Document;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import de.intevation.artifacts.common.ArtifactNamespaceContext;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import de.intevation.artifacts.common.utils.XMLUtils;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.httpclient.http.HttpClient;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.client.shared.exceptions.ServerException;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.client.shared.model.Artifact;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import de.intevation.flys.client.client.services.GetArtifactService;
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 /**
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 * This service provides a method that returns an artifact based on its
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 * identifier.
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 *
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 */
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 public class GetArtifactServiceImpl
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 extends RemoteServiceServlet
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 implements GetArtifactService
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 {
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 public static final String ERROR_DESCRIBE_ARTIFACT =
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 "error_describe_artifact";
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 public static final String XPATH_RESULT = "/art:result/text()";
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 public static final String OPERATION_FAILURE = "FAILED";
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
229
924da6695800 Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 221
diff changeset
39 public Artifact getArtifact(
924da6695800 Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 221
diff changeset
40 String url,
924da6695800 Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 221
diff changeset
41 String locale,
924da6695800 Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 221
diff changeset
42 String uuid,
924da6695800 Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 221
diff changeset
43 String hash)
221
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 throws ServerException
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 {
229
924da6695800 Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 221
diff changeset
46 System.out.println("GetArtifactServiceImpl.getArtifact");
924da6695800 Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 221
diff changeset
47
221
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 Document describe = ClientProtocolUtils.newDescribeDocument(
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 uuid, hash, true);
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
229
924da6695800 Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 221
diff changeset
51 HttpClient client = new HttpClientImpl(url, locale);
221
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 try {
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 Document description = (Document) client.describe(
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 new de.intevation.artifacts.httpclient.objects.Artifact(
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 uuid, hash),
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 describe,
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 new DocumentResponseHandler());
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 if (description == null) {
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 throw new ServerException(ERROR_DESCRIBE_ARTIFACT);
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 }
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 String result = XMLUtils.xpathString(
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 description,
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 XPATH_RESULT,
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 ArtifactNamespaceContext.INSTANCE);
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 if (result == null || !result.equals(OPERATION_FAILURE)) {
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 return (Artifact) new FLYSArtifactCreator().create(description);
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 }
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 }
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 catch (ConnectionException ce) {
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 System.err.println(ce.getLocalizedMessage());
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 }
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 throw new ServerException(ERROR_DESCRIBE_ARTIFACT);
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 }
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 }
f03c34bec364 Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org