# HG changeset patch
# User gernotbelger
# Date 1538403680 -7200
# Node ID b188255f08b317f0aee7e89cd893820eb8c16fea
# Parent ec2ebbc49fbcd27fd175341979d55e3bb6a7e129
Allow to filter datacage entries by module-roles of current user.
Hide Sinfo, Uinfo and Minfo branches if user does not have those modules.
diff -r ec2ebbc49fbc -r b188255f08b3 artifacts/doc/conf/meta-data.xml
--- a/artifacts/doc/conf/meta-data.xml Mon Oct 01 16:21:16 2018 +0200
+++ b/artifacts/doc/conf/meta-data.xml Mon Oct 01 16:21:20 2018 +0200
@@ -290,14 +290,14 @@
-
+
-
+
@@ -1355,7 +1355,7 @@
-
+
@@ -1688,7 +1688,7 @@
-
+
@@ -1701,7 +1701,7 @@
-
+
@@ -1714,7 +1714,7 @@
-
+
@@ -1731,7 +1731,7 @@
-
+
diff -r ec2ebbc49fbc -r b188255f08b3 gwt-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java Mon Oct 01 16:21:16 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java Mon Oct 01 16:21:20 2018 +0200
@@ -8,105 +8,148 @@
package org.dive4elements.river.client.server;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import java.util.Iterator;
+import java.util.List;
import org.apache.log4j.Logger;
-
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-
import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
-
import org.dive4elements.artifacts.common.utils.XMLUtils;
-
-import org.dive4elements.river.client.shared.exceptions.ServerException;
-
-import org.dive4elements.river.client.client.services.MetaDataService;
-
import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException;
-
import org.dive4elements.artifacts.httpclient.http.HttpClient;
import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
-
+import org.dive4elements.river.client.client.services.MetaDataService;
+import org.dive4elements.river.client.server.auth.User;
+import org.dive4elements.river.client.server.meta.Converter;
+import org.dive4elements.river.client.shared.exceptions.ServerException;
import org.dive4elements.river.client.shared.model.AttrList;
import org.dive4elements.river.client.shared.model.DataCageNode;
import org.dive4elements.river.client.shared.model.DataCageTree;
-
-import org.dive4elements.river.client.server.meta.Converter;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* Service that returns certain meta-data from the backends data, polished to
* inclusion into current project.
*/
-public class MetaDataServiceImpl
-extends RemoteServiceServlet
-implements MetaDataService, DataCageTree.Visitor
-{
- /** Our very own log. */
- private static final Logger log =
- Logger.getLogger(MetaDataServiceImpl.class);
+public class MetaDataServiceImpl extends RemoteServiceServlet implements MetaDataService {
- public static final String ERROR_NO_META_DATA_FOUND =
- "error_no_meta_data_found";
-
+ private static final long serialVersionUID = 1L;
- @Override
- public boolean accept(DataCageNode node) {
- AttrList al = node.getAttributes();
- return al != null && al.hasAttribute("factory");
+ /** Our very own log. */
+ private static final Logger log = Logger.getLogger(MetaDataServiceImpl.class);
+
+ private static final String ERROR_NO_META_DATA_FOUND = "error_no_meta_data_found";
+
+ private static final class Prune {
+ private final User user;
+
+ public Prune(final User user) {
+ this.user = user;
+ }
+
+ void execute(final DataCageTree tree) {
+
+ final DataCageNode root = tree.getRoot();
+
+ if (root == null || !root.hasChildren())
+ return;
+
+ recursivePrune(root);
+ }
+
+ private boolean recursivePrune(final DataCageNode node) {
+
+ /* filter by user - features */
+ if (!acceptUserFeatures(node))
+ return false;
+
+ /* recursively check all leafs, we only accepts real ones that have a factory */
+ if (!node.hasChildren())
+ return acceptLeaf(node);
+
+ final List children = node.getChildren();
+
+ for (final Iterator iterator = children.iterator(); iterator.hasNext();) {
+ final DataCageNode dataCageNode = iterator.next();
+
+ if (!recursivePrune(dataCageNode))
+ iterator.remove();
+ }
+
+ return !children.isEmpty();
+ }
+
+ private boolean acceptUserFeatures(final DataCageNode node) {
+ final AttrList al = node.getAttributes();
+ if (al == null)
+ return true;
+
+ final String module = al.getValue("module");
+ if (module == null)
+ return true;
+
+ if (this.user == null || this.user.canUseFeature("module:" + module))
+ return true;
+
+ return false;
+ }
+
+ private boolean acceptLeaf(final DataCageNode node) {
+ final AttrList al = node.getAttributes();
+ if (al == null)
+ return false;
+
+ return al.hasAttribute("factory");
+ }
}
/**
- * @param locale needed for i18n.
- * @param artifactId ID of masterartifact (can be null)
- * @param userId can be null
- * @param outs can be null
- * @param parameters can be null or parameters like
- * "load-system:true;key:value"
+ * @param locale
+ * needed for i18n.
+ * @param artifactId
+ * ID of masterartifact (can be null)
+ * @param userId
+ * can be null
+ * @param outs
+ * can be null
+ * @param parameters
+ * can be null or parameters like
+ * "load-system:true;key:value"
*/
@Override
- public DataCageTree getMetaData(
- String locale,
- String artifactId,
- String userId,
- String outs,
- String parameters
- ) throws ServerException
- {
+ public DataCageTree getMetaData(final String locale, final String artifactId, final String userId, final String outs, final String parameters)
+ throws ServerException {
log.info("MetaDataService.getMetaData");
// Create the query document.
- String url = getServletContext().getInitParameter("server-url");
-
- Document doc = XMLUtils.newDocument();
+ final String url = getServletContext().getInitParameter("server-url");
- XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
- doc,
- ArtifactNamespaceContext.NAMESPACE_URI,
- ArtifactNamespaceContext.NAMESPACE_PREFIX);
+ final Document doc = XMLUtils.newDocument();
- Element meta = ec.create("meta");
+ final XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+ final Element meta = ec.create("meta");
if (artifactId != null) {
- Element artifactEl = ec.create("artifact-id");
+ final Element artifactEl = ec.create("artifact-id");
artifactEl.setAttribute("value", artifactId);
meta.appendChild(artifactEl);
}
if (userId != null) {
- Element userEl = ec.create("user-id");
+ final Element userEl = ec.create("user-id");
userEl.setAttribute("value", userId);
meta.appendChild(userEl);
}
if (outs != null) {
- Element outsEl = ec.create("outs");
+ final Element outsEl = ec.create("outs");
outsEl.setAttribute("value", outs);
meta.appendChild(outsEl);
}
if (parameters != null) {
- Element paramsEl = ec.create("parameters");
+ final Element paramsEl = ec.create("parameters");
paramsEl.setAttribute("value", parameters);
meta.appendChild(paramsEl);
}
@@ -114,20 +157,22 @@
doc.appendChild(meta);
// Fire.
- HttpClient client = new HttpClientImpl(url, locale);
+ final HttpClient client = new HttpClientImpl(url, locale);
try {
- Converter converter = new Converter();
- DataCageTree tree = converter.convert(
- client.callService(url, "metadata", doc));
- tree.prune(this);
+ final User user = getUser();
+
+ final Converter converter = new Converter();
+ final DataCageTree tree = converter.convert(client.callService(url, "metadata", doc));
+
+ new Prune(user).execute(tree);
+
return tree;
}
- catch (ConnectionException ce) {
+ catch (final ConnectionException ce) {
ce.printStackTrace();
}
throw new ServerException(ERROR_NO_META_DATA_FOUND);
}
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file
diff -r ec2ebbc49fbc -r b188255f08b3 gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java Mon Oct 01 16:21:16 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java Mon Oct 01 16:21:20 2018 +0200
@@ -9,53 +9,29 @@
package org.dive4elements.river.client.shared.model;
import java.io.Serializable;
-import java.util.List;
-public class DataCageTree implements Serializable
-{
+public class DataCageTree implements Serializable {
+
+ private static final long serialVersionUID = 1L;
public interface Visitor {
boolean accept(DataCageNode node);
- } // interface
+ }
- protected DataCageNode root;
+ private DataCageNode root;
public DataCageTree() {
}
- public DataCageTree(DataCageNode root) {
+ public DataCageTree(final DataCageNode root) {
this.root = root;
}
- public void setRoot(DataCageNode root) {
+ public void setRoot(final DataCageNode root) {
this.root = root;
}
public DataCageNode getRoot() {
- return root;
+ return this.root;
}
-
-
- protected boolean recursivePrune(DataCageNode node, Visitor visitor) {
- if (!node.hasChildren()) {
- return visitor.accept(node);
- }
-
- List children = node.getChildren();
-
- for (int i = children.size()-1; i >= 0; --i) {
- if (!recursivePrune(children.get(i), visitor)) {
- children.remove(i);
- }
- }
-
- return !children.isEmpty();
- }
-
- public boolean prune(Visitor visitor) {
- return root == null || !root.hasChildren()
- ? true
- : recursivePrune(root, visitor);
- }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file