comparison gwt-client/src/main/java/org/dive4elements/river/client/server/ModuleServiceImpl.java @ 8870:c26fb37899ca

Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui. Also using now the localization info from the server instead of localizing the modules again on the client side.
author gernotbelger
date Wed, 07 Feb 2018 11:59:13 +0100
parents 5e38e2924c07
children
comparison
equal deleted inserted replaced
8869:20b85ea3b524 8870:c26fb37899ca
40 40
41 public static final String ERROR_NO_MODULES_FOUND = 41 public static final String ERROR_NO_MODULES_FOUND =
42 "error_no_module_found"; 42 "error_no_module_found";
43 43
44 @Override 44 @Override
45 public Module[] list(String locale) throws ServerException { 45 public Module[] list(final String locale) throws ServerException {
46 User user = this.getUser(); 46 final User user = this.getUser();
47 47
48 log.info("ModuleService.list"); 48 log.info("ModuleService.list");
49 49
50 String url = getServletContext().getInitParameter("server-url"); 50 final String url = getServletContext().getInitParameter("server-url");
51 51
52 // create dummy xml 52 // create dummy xml
53 Document doc = XMLUtils.newDocument(); 53 final Document doc = XMLUtils.newDocument();
54 54
55 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( 55 final XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
56 doc, 56 doc,
57 ArtifactNamespaceContext.NAMESPACE_URI, 57 ArtifactNamespaceContext.NAMESPACE_URI,
58 ArtifactNamespaceContext.NAMESPACE_PREFIX); 58 ArtifactNamespaceContext.NAMESPACE_PREFIX);
59 59
60 Element dummy = ec.create("modules"); 60 final Element dummy = ec.create("modules");
61 doc.appendChild(dummy); 61 doc.appendChild(dummy);
62 62
63 HttpClient client = new HttpClientImpl(url, locale); 63 final HttpClient client = new HttpClientImpl(url, locale);
64 try { 64 try {
65 Document result = client.callService(url, "modules", doc); 65 final Document result = client.callService(url, "modules", doc);
66 66
67 NodeList list = (NodeList) XMLUtils.xpath( 67 final NodeList list = (NodeList) XMLUtils.xpath(
68 result, 68 result,
69 XPATH_MODULES, 69 XPATH_MODULES,
70 XPathConstants.NODESET, 70 XPathConstants.NODESET,
71 ArtifactNamespaceContext.INSTANCE); 71 ArtifactNamespaceContext.INSTANCE);
72 72
74 log.warn("No modules found."); 74 log.warn("No modules found.");
75 75
76 throw new ServerException(ERROR_NO_MODULES_FOUND); 76 throw new ServerException(ERROR_NO_MODULES_FOUND);
77 } 77 }
78 78
79 int num = list.getLength(); 79 final int num = list.getLength();
80 80
81 List<Module> modules = new ArrayList<Module>(list.getLength()); 81 final List<Module> modules = new ArrayList<Module>(list.getLength());
82 for(int i =0; i < num; i++) { 82 for(int i =0; i < num; i++) {
83 Element em = (Element)list.item(i); 83 final Element em = (Element)list.item(i);
84 String name = em.getAttributeNS( 84 final String name = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "name");
85 ArtifactNamespaceContext.NAMESPACE_URI, "name"); 85 final String localname = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "localname");
86 String localname = em.getAttributeNS( 86 final String strselected = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "selected");
87 ArtifactNamespaceContext.NAMESPACE_URI, "localname"); 87 boolean selected = Boolean.parseBoolean(strselected);
88 String strselected = em.getAttributeNS( 88 final String group = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "groupId");
89 ArtifactNamespaceContext.NAMESPACE_URI, "selected"); 89 final String groupLabel = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "groupLabel");
90 boolean selected = strselected == null ? false : 90
91 strselected.equalsIgnoreCase("true"); 91 final NodeList rivers = em.getChildNodes();
92 NodeList rivers = em.getChildNodes(); 92 final List<String> riverUuids = new ArrayList<String>(rivers.getLength());
93 List<String> riverUuids = new ArrayList<String>();
94 for (int j = 0; j < rivers.getLength(); j++) { 93 for (int j = 0; j < rivers.getLength(); j++) {
95 Element re = (Element)rivers.item(j); 94 final Element re = (Element)rivers.item(j);
96 riverUuids.add(re.getAttribute("uuid")); 95 riverUuids.add(re.getAttribute("uuid"));
97 } 96 }
98 log.debug("Found module " + name + " " + localname); 97 log.debug("Found module " + name + " " + localname);
99 if (user == null || user.canUseFeature("module:" + name)) { 98 if (user == null || user.canUseFeature("module:" + name)) {
100 modules.add(new DefaultModule( 99 modules.add(new DefaultModule(name, localname, selected, group, groupLabel, riverUuids));
101 name, localname, selected, riverUuids));
102 } 100 }
103 } 101 }
104 return modules.toArray(new Module[modules.size()]); 102 return modules.toArray(new Module[modules.size()]);
105 } 103 }
106 catch (ConnectionException ce) { 104 catch (ConnectionException ce) {

http://dive4elements.wald.intevation.org