annotate flys-client/src/main/java/de/intevation/flys/client/server/FeedServiceImpl.java @ 851:aa83a6a864b4

Added FeedService Implementation. flys-client/trunk@2636 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 02 Sep 2011 12:48:25 +0000
parents
children 3d379e6b9a5f
rev   line source
851
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
2
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
3 import org.w3c.dom.Document;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
4
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
5 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
6
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
7 import de.intevation.artifacts.common.ArtifactNamespaceContext;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
8 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
9 import de.intevation.artifacts.common.utils.XMLUtils;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.httpclient.http.HttpClient;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
13 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.client.shared.exceptions.ServerException;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.client.shared.model.Artifact;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
18 import de.intevation.flys.client.shared.model.ArtifactDescription;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19 import de.intevation.flys.client.shared.model.Data;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
20 import de.intevation.flys.client.shared.model.DataItem;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21 import de.intevation.flys.client.client.services.FeedService;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
22
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23 /**
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24 * This interface provides a method that bundles the artifact specific
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25 * operation FEED.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26 */
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
27 public class FeedServiceImpl
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28 extends RemoteServiceServlet
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29 implements FeedService
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30 {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
31 /** XPath that points to the result type of a feed or advance operation.*/
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32 public static final String XPATH_RESULT = "/art:result/@art:type";
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34 /** XPath that points to the result type of a feed or advance operation.*/
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35 public static final String XPATH_RESULT_MSG = "/art:result/text()";
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
37 /** A constant that marks errors.*/
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
38 public static final String OPERATION_FAILURE = "FAILURE";
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
39
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
40 /** The error message key that is thrown if an error occured while feeding
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41 * new data.*/
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
42 public static final String ERROR_FEED_DATA = "error_feed_data";
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
45 /**
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46 * This method triggers the FEED operation.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 *
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48 * @param url The url of the artifact server.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49 * @param artifact The artifact that needs to be fed.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
50 * @param data An array of Data objects that contain the information that
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
51 * are used for the FEED operation.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
52 *
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
53 * @return a new artifact parsed from the description of FEED.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
54 */
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
55 public Artifact feed(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
56 String url,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
57 String locale,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
58 Artifact artifact,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
59 Data[] data)
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
60 throws ServerException
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
61 {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
62 System.out.println("StepForwardServiceImpl.feed");
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
63
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
64 Document feed = ClientProtocolUtils.newFeedDocument(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
65 artifact.getUuid(),
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
66 artifact.getHash(),
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
67 createKVP(data));
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
68
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
69 HttpClient client = new HttpClientImpl(url, locale);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
70
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
71 try {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
72 Document description = (Document) client.feed(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
73 new de.intevation.artifacts.httpclient.objects.Artifact(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
74 artifact.getUuid(),
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
75 artifact.getHash()),
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
76 feed,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
77 new DocumentResponseHandler());
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
78
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
79 if (description == null) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
80 System.err.println("StepForwardService.feed() - FAILED");
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
81 throw new ServerException(ERROR_FEED_DATA);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
82 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
83
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
84 String result = XMLUtils.xpathString(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
85 description,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
86 XPATH_RESULT,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
87 ArtifactNamespaceContext.INSTANCE);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
88
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
89 if (result == null || !result.equals(OPERATION_FAILURE)) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
90 System.out.println("StepForwardService.feed() - SUCCESS");
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
91 return (Artifact) new FLYSArtifactCreator().create(description);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
92 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
93 else if (result != null && result.equals(OPERATION_FAILURE)) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
94 String msg = XMLUtils.xpathString(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
95 description,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
96 XPATH_RESULT_MSG,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
97 ArtifactNamespaceContext.INSTANCE);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
98 throw new ServerException(msg);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
99 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
100 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
101 catch (ConnectionException ce) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
102 System.err.println(ce.getLocalizedMessage());
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
103 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
104
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
105 System.err.println("StepForwardService.feed() - FAILED");
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
106 throw new ServerException(ERROR_FEED_DATA);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
107 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
108
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
109
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
110 /**
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
111 * This method creates an array of key/value pairs from an array of Data
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
112 * objects. The string array is used as parameter for the feed() operation.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
113 *
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
114 * @param data The data that should be transformed into the string array.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
115 *
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
116 * @return a string array that contains key/value pairs.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
117 */
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
118 protected String[][] createKVP(Data[] data) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
119 String[][] kvp = new String[data.length][];
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
120
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
121 int i = 0;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
122
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
123 for (Data d: data) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
124 DataItem[] items = d.getItems();
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
125 String key = d.getLabel();
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
126 String value = items[0].getStringValue();
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
127
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
128 kvp[i++] = new String[] { key, value };
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
129 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
130
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
131 return kvp;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
132 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
133 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
134 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org