Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/UserCollectionsServiceImpl.java @ 100:95b30a5d6350
Bugfix: A collection view just creates a single time a new collection - even if we step back to a previous state and go forward afterwards.
flys-client/trunk@1614 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 30 Mar 2011 07:40:53 +0000 |
parents | 261a2ee7d9bb |
children | 924da6695800 |
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 { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 public Collection[] getUserCollections(String serverUrl, String userid) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 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
|
41 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 HttpClient client = new HttpClientImpl(serverUrl); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 try { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 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
|
46 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 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
|
48 result, |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 "/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
|
50 XPathConstants.NODESET, |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 ArtifactNamespaceContext.INSTANCE); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 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
|
54 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
|
55 return null; |
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 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 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
|
59 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 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
|
61 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 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
|
63 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
|
64 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 if (c != null) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 all.add(c); |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 } |
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 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 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
|
71 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 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
|
73 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 catch (ConnectionException ce) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 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
|
76 } |
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 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
|
79 return null; |
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 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 /** |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 * 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
|
85 * |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 * @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
|
87 * |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 * @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
|
89 */ |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 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
|
95 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
|
96 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 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
|
98 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
|
99 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 if (uuid != null) { |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 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
|
102 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
|
103 } |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 |
261a2ee7d9bb
Added a service that returns the collections of a specified user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 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
|
106 return null; |
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |