annotate flys-client/src/main/java/de/intevation/flys/client/server/ModuleServiceImpl.java @ 3842:44c1beb78ad1

Move GaugeTree to its own java file flys-client/trunk@5557 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 21 Sep 2012 13:44:56 +0000
parents b0c1d9e06a69
children
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.server.auth.User;
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.shared.exceptions.ServerException;
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.model.DefaultModule;
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.Module;
98fac4872ae6 Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents: 3535
diff changeset
13
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
14 import java.util.ArrayList;
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
15 import java.util.List;
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
16
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
17 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
18
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19 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
20 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
21 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
22 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
23
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
24 public class ModuleServiceImpl
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
25 extends RemoteServiceServlet
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
26 implements ModuleService
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
27 {
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
28 private static final Logger logger =
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
29 Logger.getLogger(ModuleServiceImpl.class);
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
30
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
31 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
32
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
33 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
34 "error_no_module_found";
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
35
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
36 @Override
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
37 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
38 User user = this.getUser();
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
39
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
40 logger.info("ModuleService.list");
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
41
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
42 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
43
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
44 // create dummy xml
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
45 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
46
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
47 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
48 doc,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
49 ArtifactNamespaceContext.NAMESPACE_URI,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
50 ArtifactNamespaceContext.NAMESPACE_PREFIX);
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
51
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
52 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
53 doc.appendChild(dummy);
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
54
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
55 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
56 try {
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
57 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
58
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
59 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
60 result,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
61 XPATH_MODULES,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
62 XPathConstants.NODESET,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
63 ArtifactNamespaceContext.INSTANCE);
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
64
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
65 if (list == null) {
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
66 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
67
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
68 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
69 }
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
70
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
71 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
72
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83 strselected.equalsIgnoreCase("true");
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
84 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
85 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
86 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
87 }
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 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
90 }
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
91 catch (ConnectionException ce) {
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
92 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
93 }
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 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
96 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :

http://dive4elements.wald.intevation.org