Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/ModuleServiceImpl.java @ 3529:72d2ec6a471e
Load the list of modules from the flys artifact server
flys-client/trunk@5332 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 31 Aug 2012 13:24:50 +0000 |
parents | f9ef72f4c6d5 |
children | 75a3a41a6e51 |
comparison
equal
deleted
inserted
replaced
3528:b5825159250e | 3529:72d2ec6a471e |
---|---|
1 package de.intevation.flys.client.server; | 1 package de.intevation.flys.client.server; |
2 | 2 |
3 import java.util.ArrayList; | 3 import java.util.ArrayList; |
4 import java.util.List; | 4 import java.util.List; |
5 | 5 |
6 import javax.xml.xpath.XPathConstants; | |
7 | |
6 import org.apache.log4j.Logger; | 8 import org.apache.log4j.Logger; |
9 | |
10 import org.w3c.dom.Document; | |
11 import org.w3c.dom.Element; | |
12 import org.w3c.dom.NodeList; | |
13 | |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
15 import de.intevation.artifacts.common.utils.XMLUtils; | |
16 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; | |
17 import de.intevation.artifacts.httpclient.http.HttpClient; | |
18 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | |
7 | 19 |
8 import de.intevation.flys.client.client.FLYSConstants; | 20 import de.intevation.flys.client.client.FLYSConstants; |
9 import de.intevation.flys.client.client.services.ModuleService; | 21 import de.intevation.flys.client.client.services.ModuleService; |
10 import de.intevation.flys.client.server.auth.User; | 22 import de.intevation.flys.client.server.auth.User; |
23 import de.intevation.flys.client.shared.exceptions.ServerException; | |
11 import de.intevation.flys.client.shared.model.DefaultModule; | 24 import de.intevation.flys.client.shared.model.DefaultModule; |
12 import de.intevation.flys.client.shared.model.Module; | 25 import de.intevation.flys.client.shared.model.Module; |
13 | 26 |
14 public class ModuleServiceImpl | 27 public class ModuleServiceImpl |
15 extends RemoteServiceServlet | 28 extends RemoteServiceServlet |
16 implements ModuleService | 29 implements ModuleService |
17 { | 30 { |
18 private static final Logger logger = | 31 private static final Logger logger = |
19 Logger.getLogger(ModuleServiceImpl.class); | 32 Logger.getLogger(ModuleServiceImpl.class); |
20 | 33 |
21 /** Constant value for the WINFO plugin.*/ | 34 public static final String XPATH_MODULES = "/art:modules/art:module"; |
22 public static final String FIELD_PLUGIN_WINFO = "winfo"; | |
23 | 35 |
24 /** Constant value for the MINFO plugin.*/ | 36 public static final String ERROR_NO_MODULES_FOUND = |
25 public static final String FIELD_PLUGIN_MINFO = "minfo"; | 37 "error_no_module_found"; |
26 | |
27 /** Constant value for the MAP plugin.*/ | |
28 public static final String FIELD_PLUGIN_MAP = "new_map"; | |
29 | |
30 /** Constant value for the CHART plugin.*/ | |
31 public static final String FIELD_PLUGIN_CHART = "new_chart"; | |
32 | |
33 /** Constant value for the FIX plugin.*/ | |
34 public static final String FIELD_PLUGIN_FIX = "fixanalysis"; | |
35 | 38 |
36 @Override | 39 @Override |
37 public Module[] list(String locale) { | 40 public Module[] list(String locale) throws ServerException { |
38 User user = this.getUser(); | 41 User user = this.getUser(); |
39 | 42 |
40 //TODO load modules from artifactserver | 43 logger.info("ModuleService.list"); |
41 Module[] available = { | |
42 new DefaultModule(FIELD_PLUGIN_WINFO, "WINFO"), | |
43 new DefaultModule(FIELD_PLUGIN_MINFO, "MINFO"), | |
44 new DefaultModule(FIELD_PLUGIN_CHART, "Neues Diargamm"), | |
45 new DefaultModule(FIELD_PLUGIN_FIX, "Fixierungsanalyse"), | |
46 new DefaultModule(FIELD_PLUGIN_MAP, "Neue Karte"), | |
47 }; | |
48 | 44 |
49 List<Module> modules = new ArrayList<Module>(available.length); | 45 String url = getServletContext().getInitParameter("server-url"); |
50 for(Module module : available) { | 46 |
51 if (user == null || user.canUseFeature("module:" + module.getName())) { | 47 // create dummy xml |
52 modules.add(module); | 48 Document doc = XMLUtils.newDocument(); |
49 | |
50 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
51 doc, | |
52 ArtifactNamespaceContext.NAMESPACE_URI, | |
53 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
54 | |
55 Element dummy = ec.create("modules"); | |
56 doc.appendChild(dummy); | |
57 | |
58 HttpClient client = new HttpClientImpl(url, locale); | |
59 try { | |
60 Document result = client.callService(url, "modules", doc); | |
61 | |
62 NodeList list = (NodeList) XMLUtils.xpath( | |
63 result, | |
64 XPATH_MODULES, | |
65 XPathConstants.NODESET, | |
66 ArtifactNamespaceContext.INSTANCE); | |
67 | |
68 if (list == null) { | |
69 logger.warn("No modules found."); | |
70 | |
71 throw new ServerException(ERROR_NO_MODULES_FOUND); | |
53 } | 72 } |
73 | |
74 int num = list.getLength(); | |
75 | |
76 List<Module> modules = new ArrayList<Module>(list.getLength()); | |
77 for(int i =0; i < num; i++) { | |
78 Element em = (Element)list.item(i); | |
79 String name = em.getAttributeNS( | |
80 ArtifactNamespaceContext.NAMESPACE_URI, "name"); | |
81 String localname = em.getAttributeNS( | |
82 ArtifactNamespaceContext.NAMESPACE_URI, "localname"); | |
83 String strselected = em.getAttributeNS( | |
84 ArtifactNamespaceContext.NAMESPACE_URI, "selected"); | |
85 boolean selected = strselected == null ? false : | |
86 strselected.equalsIgnoreCase("true"); | |
87 logger.debug("Found module " + name + " " + localname); | |
88 if (user == null || user.canUseFeature("module:" + name)) { | |
89 modules.add(new DefaultModule(name, localname, selected)); | |
90 } | |
91 } | |
92 return modules.toArray(new Module[modules.size()]); | |
54 } | 93 } |
55 return modules.toArray(new Module[modules.size()]); | 94 catch (ConnectionException ce) { |
95 logger.error(ce, ce); | |
96 } | |
97 | |
98 throw new ServerException(ERROR_NO_MODULES_FOUND); | |
56 } | 99 } |
57 } | 100 } |
58 | 101 |
59 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 : | 102 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 : |