Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/UserCollectionsServiceImpl.java @ 290:a6f56ed9238b
Tagged RELEASE 2.3 of flys-client.
flys-client/tags/2.3@1930 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 17 May 2011 07:51:26 +0000 |
parents | 924da6695800 |
children | 53ad6dd2cb2b |
rev | line source |
---|---|
96
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.Date; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import javax.xml.xpath.XPathConstants; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.w3c.dom.Document; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.w3c.dom.Node; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.w3c.dom.NodeList; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifacts.common.utils.XMLUtils; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifacts.httpclient.http.HttpClient; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.client.shared.model.Collection; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.flys.client.shared.model.DefaultCollection; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.flys.client.client.services.UserCollectionsService; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 /** |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 * This service returns a list of collections owned by a specified user. |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 * <b>NOTE:</b> The Collections returned by this service provide no information |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 * about the CollectionItems or OutputModes of the Collection. You need to fetch |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 * these information explicitly using another service. |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 * |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 */ |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 public class UserCollectionsServiceImpl |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 extends RemoteServiceServlet |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 implements UserCollectionsService |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
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:
96
diff
changeset
|
39 public Collection[] getUserCollections( |
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:
96
diff
changeset
|
40 String serverUrl, |
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:
96
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:
96
diff
changeset
|
42 String userid) |
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:
96
diff
changeset
|
43 { |
96
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 System.out.println("UserCollectionsServiceImpl.getUserCollections"); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
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:
96
diff
changeset
|
46 HttpClient client = new HttpClientImpl(serverUrl, locale); |
96
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 try { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 Document result = client.listUserCollections(userid); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 NodeList list = (NodeList) XMLUtils.xpath( |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 result, |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 "/art:artifact-collections/art:artifact-collection", |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 XPathConstants.NODESET, |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 ArtifactNamespaceContext.INSTANCE); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 if (list == null || list.getLength() == 0) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 System.out.println("No collection found for user: " + userid); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 return null; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 int num = list.getLength(); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 List<Collection> all = new ArrayList<Collection>(num); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 for (int i = 0; i < num; i++) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 Collection c = createCollection(list.item(i)); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 if (c != null) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 all.add(c); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 System.out.println("User has " + all.size() + " collections."); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 return (Collection[]) all.toArray(new Collection[all.size()]); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 catch (ConnectionException ce) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 System.err.println(ce.getLocalizedMessage()); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 System.err.println("No user collections found."); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 return null; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 /** |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 * Extracts a SimpleCollection from <i>node</i>. |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 * |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 * @param node Contains information about a collection. |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 * |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 * @return a list of Simplecollections. |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 */ |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 protected Collection createCollection(Node node) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 String creationStr = XMLUtils.xpathString( |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 node, "@art:creation", ArtifactNamespaceContext.INSTANCE); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 String name = XMLUtils.xpathString( |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 node, "@art:name", ArtifactNamespaceContext.INSTANCE); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 String uuid = XMLUtils.xpathString( |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 node, "@art:uuid", ArtifactNamespaceContext.INSTANCE); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 if (uuid != null) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 long time = Long.parseLong(creationStr); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 return new DefaultCollection(uuid, name, new Date(time)); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 System.err.println("Found an invalid Collection."); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 return null; |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |