Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/ModuleServiceImpl.java @ 3543:14774fb42054
Issue 808.
Updated wq input in winfo module.
flys-client/trunk@5356 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 04 Sep 2012 12:10:01 +0000 |
parents | 98fac4872ae6 |
children | fed914a42a10 |
rev | line source |
---|---|
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
2 |
3540
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
3 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
4 import de.intevation.artifacts.common.utils.XMLUtils; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
5 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
6 import de.intevation.artifacts.httpclient.http.HttpClient; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
7 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
8 import de.intevation.flys.client.client.services.ModuleService; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
9 import de.intevation.flys.client.client.services.RemoteServiceServlet; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
10 import de.intevation.flys.client.server.auth.User; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
11 import de.intevation.flys.client.shared.exceptions.ServerException; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
12 import de.intevation.flys.client.shared.model.DefaultModule; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
13 import de.intevation.flys.client.shared.model.Module; |
98fac4872ae6
Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents:
3535
diff
changeset
|
14 |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 import java.util.ArrayList; |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 import java.util.List; |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
17 |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
18 import javax.xml.xpath.XPathConstants; |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
19 |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
20 import org.apache.log4j.Logger; |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
21 import org.w3c.dom.Document; |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
22 import org.w3c.dom.Element; |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
23 import org.w3c.dom.NodeList; |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
24 |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
25 public class ModuleServiceImpl |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
26 extends RemoteServiceServlet |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 implements ModuleService |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
28 { |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 private static final Logger logger = |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
30 Logger.getLogger(ModuleServiceImpl.class); |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
31 |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
32 public static final String XPATH_MODULES = "/art:modules/art:module"; |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
34 public static final String ERROR_NO_MODULES_FOUND = |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
35 "error_no_module_found"; |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
36 |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 @Override |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
38 public Module[] list(String locale) throws ServerException { |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
39 User user = this.getUser(); |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
41 logger.info("ModuleService.list"); |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
42 |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
43 String url = getServletContext().getInitParameter("server-url"); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
44 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
45 // create dummy xml |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
46 Document doc = XMLUtils.newDocument(); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
47 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
48 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
49 doc, |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
50 ArtifactNamespaceContext.NAMESPACE_URI, |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
51 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
52 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
53 Element dummy = ec.create("modules"); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
54 doc.appendChild(dummy); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
55 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
56 HttpClient client = new HttpClientImpl(url, locale); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
57 try { |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
58 Document result = client.callService(url, "modules", doc); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
59 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
60 NodeList list = (NodeList) XMLUtils.xpath( |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
61 result, |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
62 XPATH_MODULES, |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
63 XPathConstants.NODESET, |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
64 ArtifactNamespaceContext.INSTANCE); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
65 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
66 if (list == null) { |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
67 logger.warn("No modules found."); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
68 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
69 throw new ServerException(ERROR_NO_MODULES_FOUND); |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
70 } |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
71 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
72 int num = list.getLength(); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
73 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
74 List<Module> modules = new ArrayList<Module>(list.getLength()); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
75 for(int i =0; i < num; i++) { |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
76 Element em = (Element)list.item(i); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
77 String name = em.getAttributeNS( |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
78 ArtifactNamespaceContext.NAMESPACE_URI, "name"); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
79 String localname = em.getAttributeNS( |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
80 ArtifactNamespaceContext.NAMESPACE_URI, "localname"); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
81 String strselected = em.getAttributeNS( |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
82 ArtifactNamespaceContext.NAMESPACE_URI, "selected"); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
83 boolean selected = strselected == null ? false : |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
84 strselected.equalsIgnoreCase("true"); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
85 logger.debug("Found module " + name + " " + localname); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
86 if (user == null || user.canUseFeature("module:" + name)) { |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
87 modules.add(new DefaultModule(name, localname, selected)); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
88 } |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
89 } |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
90 return modules.toArray(new Module[modules.size()]); |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
91 } |
3529
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
92 catch (ConnectionException ce) { |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
93 logger.error(ce, ce); |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
94 } |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
95 |
72d2ec6a471e
Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3519
diff
changeset
|
96 throw new ServerException(ERROR_NO_MODULES_FOUND); |
3515
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
97 } |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
98 } |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
99 |
70c0942156ad
Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 : |