annotate flys-client/src/main/java/de/intevation/flys/client/server/FeedServiceImpl.java @ 1275:ca2d5bcf67a3

Bugfix: #111 Reset the values of WQ range mode if single mode is selected and the other way arround. flys-client/trunk@2851 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 28 Sep 2011 09:26:36 +0000
parents 3d379e6b9a5f
children ab8eb2f544f2
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.Data;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19 import de.intevation.flys.client.shared.model.DataItem;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
20 import de.intevation.flys.client.client.services.FeedService;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21
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 * This interface provides a method that bundles the artifact specific
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24 * operation FEED.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25 */
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26 public class FeedServiceImpl
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
27 extends RemoteServiceServlet
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28 implements FeedService
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29 {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30 /** 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
31 public static final String XPATH_RESULT = "/art:result/@art:type";
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33 /** 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
34 public static final String XPATH_RESULT_MSG = "/art:result/text()";
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36 /** A constant that marks errors.*/
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
37 public static final String OPERATION_FAILURE = "FAILURE";
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
38
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
39 /** 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
40 * new data.*/
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41 public static final String ERROR_FEED_DATA = "error_feed_data";
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
42
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 * This method triggers the FEED operation.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46 *
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 * @param url The url of the artifact server.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48 * @param artifact The artifact that needs to be fed.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49 * @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
50 * are used for the FEED operation.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
51 *
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
52 * @return a new artifact parsed from the description of FEED.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
53 */
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
54 public Artifact feed(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
55 String url,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
56 String locale,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
57 Artifact artifact,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
58 Data[] data)
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
59 throws ServerException
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
60 {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
61 System.out.println("StepForwardServiceImpl.feed");
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
62
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
63 Document feed = ClientProtocolUtils.newFeedDocument(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
64 artifact.getUuid(),
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
65 artifact.getHash(),
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
66 createKVP(data));
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
67
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
68 HttpClient client = new HttpClientImpl(url, locale);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
69
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
70 try {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
71 Document description = (Document) client.feed(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
72 new de.intevation.artifacts.httpclient.objects.Artifact(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
73 artifact.getUuid(),
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
74 artifact.getHash()),
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
75 feed,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
76 new DocumentResponseHandler());
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
77
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
78 if (description == null) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
79 System.err.println("StepForwardService.feed() - FAILED");
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
80 throw new ServerException(ERROR_FEED_DATA);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
81 }
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 String result = XMLUtils.xpathString(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
84 description,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
85 XPATH_RESULT,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
86 ArtifactNamespaceContext.INSTANCE);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
87
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
88 if (result == null || !result.equals(OPERATION_FAILURE)) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
89 System.out.println("StepForwardService.feed() - SUCCESS");
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
90 return (Artifact) new FLYSArtifactCreator().create(description);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
91 }
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
92 else if (result != null && result.equals(OPERATION_FAILURE)) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
93 String msg = XMLUtils.xpathString(
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
94 description,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
95 XPATH_RESULT_MSG,
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
96 ArtifactNamespaceContext.INSTANCE);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
97 throw new ServerException(msg);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
98 }
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 catch (ConnectionException ce) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
101 System.err.println(ce.getLocalizedMessage());
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
102 }
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 System.err.println("StepForwardService.feed() - FAILED");
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
105 throw new ServerException(ERROR_FEED_DATA);
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
106 }
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 * 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
111 * 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
112 *
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
113 * @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
114 *
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
115 * @return a string array that contains key/value pairs.
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
116 */
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
117 protected String[][] createKVP(Data[] data) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
118 String[][] kvp = new String[data.length][];
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
119
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
120 int i = 0;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
121
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
122 for (Data d: data) {
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
123 DataItem[] items = d.getItems();
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
124 String key = d.getLabel();
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
125 String value = items[0].getStringValue();
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
126
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
127 kvp[i++] = new String[] { key, value };
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
128 }
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 return kvp;
aa83a6a864b4 Added FeedService Implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
131 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org