diff 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
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ModuleServiceImpl.java	Wed Feb 07 11:52:04 2018 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ModuleServiceImpl.java	Wed Feb 07 11:59:13 2018 +0100
@@ -42,29 +42,29 @@
         "error_no_module_found";
 
     @Override
-    public Module[] list(String locale) throws ServerException {
-        User user = this.getUser();
+    public Module[] list(final String locale) throws ServerException {
+        final User user = this.getUser();
 
         log.info("ModuleService.list");
 
-        String url = getServletContext().getInitParameter("server-url");
+        final String url = getServletContext().getInitParameter("server-url");
 
         // create dummy xml
-        Document doc = XMLUtils.newDocument();
+        final Document doc = XMLUtils.newDocument();
 
-        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+        final XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
             doc,
             ArtifactNamespaceContext.NAMESPACE_URI,
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
-        Element dummy = ec.create("modules");
+        final Element dummy = ec.create("modules");
         doc.appendChild(dummy);
 
-        HttpClient client = new HttpClientImpl(url, locale);
+        final HttpClient client = new HttpClientImpl(url, locale);
         try {
-            Document result = client.callService(url, "modules", doc);
+            final Document result = client.callService(url, "modules", doc);
 
-            NodeList list = (NodeList) XMLUtils.xpath(
+            final NodeList list = (NodeList) XMLUtils.xpath(
                 result,
                 XPATH_MODULES,
                 XPathConstants.NODESET,
@@ -76,29 +76,27 @@
                 throw new ServerException(ERROR_NO_MODULES_FOUND);
             }
 
-            int num = list.getLength();
+            final int num = list.getLength();
 
-            List<Module> modules = new ArrayList<Module>(list.getLength());
+            final List<Module> modules = new ArrayList<Module>(list.getLength());
             for(int i =0; i < num; i++) {
-                Element em = (Element)list.item(i);
-                String name = em.getAttributeNS(
-                        ArtifactNamespaceContext.NAMESPACE_URI, "name");
-                String localname = em.getAttributeNS(
-                        ArtifactNamespaceContext.NAMESPACE_URI, "localname");
-                String strselected = em.getAttributeNS(
-                        ArtifactNamespaceContext.NAMESPACE_URI, "selected");
-                boolean selected = strselected == null ? false :
-                        strselected.equalsIgnoreCase("true");
-                NodeList rivers = em.getChildNodes();
-                List<String> riverUuids = new ArrayList<String>();
+                final Element em = (Element)list.item(i);
+                final String name = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "name");
+                final String localname = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "localname");
+                final String strselected = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "selected");
+                boolean selected = Boolean.parseBoolean(strselected); 
+                final String group = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "groupId");
+                final String groupLabel = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "groupLabel");
+
+                final NodeList rivers = em.getChildNodes();
+                final List<String> riverUuids = new ArrayList<String>(rivers.getLength());
                 for (int j = 0; j < rivers.getLength(); j++) {
-                    Element re = (Element)rivers.item(j);
+                    final Element re = (Element)rivers.item(j);
                     riverUuids.add(re.getAttribute("uuid"));
                 }
                 log.debug("Found module " + name + " " + localname);
                 if (user == null || user.canUseFeature("module:" + name)) {
-                    modules.add(new DefaultModule(
-                            name, localname, selected, riverUuids));
+                    modules.add(new DefaultModule(name, localname, selected, group, groupLabel, riverUuids));
                 }
             }
             return modules.toArray(new Module[modules.size()]);

http://dive4elements.wald.intevation.org