annotate gwt-client/src/main/java/org/dive4elements/river/client/server/ModuleServiceImpl.java @ 9709:b74f817435fe

comment removed
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Wed, 27 Jan 2021 11:47:38 +0100
parents c26fb37899ca
children
rev   line source
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5993
ea9eef426962 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5861
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5993
ea9eef426962 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5861
diff changeset
6 * documentation coming with Dive4Elements River for details.
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
9 package org.dive4elements.river.client.server;
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
10
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
11 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
12 import org.dive4elements.artifacts.common.utils.XMLUtils;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
13 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
14 import org.dive4elements.artifacts.httpclient.http.HttpClient;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
15 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
16 import org.dive4elements.river.client.client.services.ModuleService;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
17 import org.dive4elements.river.client.server.auth.User;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
18 import org.dive4elements.river.client.shared.exceptions.ServerException;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
19 import org.dive4elements.river.client.shared.model.DefaultModule;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
20 import org.dive4elements.river.client.shared.model.Module;
3540
98fac4872ae6 Add missing imports and fix package declaration of RemoteServiceServlet
Christian Lins <christian.lins@intevation.de>
parents: 3535
diff changeset
21
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
22 import java.util.ArrayList;
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
23 import java.util.List;
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
24
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
25 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
26
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
27 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
28 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
29 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
30 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
31
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
32 public class ModuleServiceImpl
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
33 extends RemoteServiceServlet
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
34 implements ModuleService
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
35 {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7761
diff changeset
36 private static final Logger log =
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
37 Logger.getLogger(ModuleServiceImpl.class);
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
38
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
39 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
40
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
41 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
42 "error_no_module_found";
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
43
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
44 @Override
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
45 public Module[] list(final String locale) throws ServerException {
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
46 final User user = this.getUser();
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
47
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7761
diff changeset
48 log.info("ModuleService.list");
3515
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
49
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
50 final String url = getServletContext().getInitParameter("server-url");
3529
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 // create dummy xml
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
53 final Document doc = XMLUtils.newDocument();
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
54
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
55 final XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
56 doc,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
57 ArtifactNamespaceContext.NAMESPACE_URI,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
58 ArtifactNamespaceContext.NAMESPACE_PREFIX);
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
59
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
60 final Element dummy = ec.create("modules");
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
61 doc.appendChild(dummy);
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
62
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
63 final HttpClient client = new HttpClientImpl(url, locale);
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
64 try {
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
65 final Document result = client.callService(url, "modules", doc);
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
66
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
67 final NodeList list = (NodeList) XMLUtils.xpath(
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
68 result,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
69 XPATH_MODULES,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
70 XPathConstants.NODESET,
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
71 ArtifactNamespaceContext.INSTANCE);
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 if (list == null) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7761
diff changeset
74 log.warn("No modules found.");
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
75
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
76 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
77 }
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
78
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
79 final int num = list.getLength();
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
80
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
81 final List<Module> modules = new ArrayList<Module>(list.getLength());
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
82 for(int i =0; i < num; i++) {
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
83 final Element em = (Element)list.item(i);
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
84 final String name = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "name");
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
85 final String localname = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "localname");
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
86 final String strselected = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "selected");
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
87 boolean selected = Boolean.parseBoolean(strselected);
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
88 final String group = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "groupId");
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
89 final String groupLabel = em.getAttributeNS(ArtifactNamespaceContext.NAMESPACE_URI, "groupLabel");
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
90
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
91 final NodeList rivers = em.getChildNodes();
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
92 final List<String> riverUuids = new ArrayList<String>(rivers.getLength());
7761
350a7cf09fbc Load modules with supported rivers and rivers with model_uuid.
Raimund Renkert <rrenkert@intevation.de>
parents: 5993
diff changeset
93 for (int j = 0; j < rivers.getLength(); j++) {
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
94 final Element re = (Element)rivers.item(j);
7761
350a7cf09fbc Load modules with supported rivers and rivers with model_uuid.
Raimund Renkert <rrenkert@intevation.de>
parents: 5993
diff changeset
95 riverUuids.add(re.getAttribute("uuid"));
350a7cf09fbc Load modules with supported rivers and rivers with model_uuid.
Raimund Renkert <rrenkert@intevation.de>
parents: 5993
diff changeset
96 }
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7761
diff changeset
97 log.debug("Found module " + name + " " + localname);
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
98 if (user == null || user.canUseFeature("module:" + name)) {
8870
c26fb37899ca Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui.
gernotbelger
parents: 8856
diff changeset
99 modules.add(new DefaultModule(name, localname, selected, group, groupLabel, riverUuids));
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
100 }
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
101 }
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
102 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
103 }
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
104 catch (ConnectionException ce) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7761
diff changeset
105 log.error(ce, ce);
3529
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
106 }
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
107
72d2ec6a471e Load the list of modules from the flys artifact server
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3519
diff changeset
108 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
109 }
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
110 }
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
111
70c0942156ad Add service to list available modules for a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :

http://dive4elements.wald.intevation.org