Search in sources :

Example 1 with Multimap

use of org.apache.jena.ext.com.google.common.collect.Multimap in project jena by apache.

the class AssemblerSecurityRegistry method parseStruct.

/**
 * Format:: access:entry [ :user "user2"; :graphs (<http://host/graphname3> ) ]
 */
private void parseStruct(Multimap<String, Node> map, Resource root, Resource r) {
    if (!GraphUtils.exactlyOneProperty(r, VocabSecurity.pUser))
        throw new AssemblerException(root, "Expected exactly one access:user property for " + r);
    if (!GraphUtils.exactlyOneProperty(r, VocabSecurity.pGraphs))
        throw new AssemblerException(root, "Expected exactly one access:graphs property for " + r);
    String user = GraphUtils.getStringValue(r, VocabSecurity.pUser);
    r.listProperties(VocabSecurity.pGraphs).mapWith(s -> s.getObject()).forEachRemaining(x -> {
        List<Node> graphs = new ArrayList<>();
        if (x.isURIResource()) {
            // System.out.printf("S: user %s : access : %s\n", user, x.asNode());
            graphs.add(x.asNode());
        } else {
            // List?
            RDFList list = x.as(RDFList.class);
            list.iterator().forEachRemaining(rn -> {
                graphs.add(rn.asNode());
            });
        }
        accessEntries(root, map, user, graphs);
    });
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Assembler(org.apache.jena.assembler.Assembler) Collection(java.util.Collection) RDFList(org.apache.jena.rdf.model.RDFList) NodeFmtLib(org.apache.jena.riot.out.NodeFmtLib) Set(java.util.Set) Multimap(org.apache.jena.ext.com.google.common.collect.Multimap) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Collectors(java.util.stream.Collectors) Mode(org.apache.jena.assembler.Mode) ArrayList(java.util.ArrayList) RDFNode(org.apache.jena.rdf.model.RDFNode) List(java.util.List) ArrayListMultimap(org.apache.jena.ext.com.google.common.collect.ArrayListMultimap) GraphList(org.apache.jena.sparql.util.graph.GraphList) Util(org.apache.jena.rdf.model.impl.Util) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) Resource(org.apache.jena.rdf.model.Resource) GraphUtils(org.apache.jena.sparql.util.graph.GraphUtils) Log(org.apache.jena.atlas.logging.Log) GNode(org.apache.jena.sparql.util.graph.GNode) AssemblerBase(org.apache.jena.assembler.assemblers.AssemblerBase) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) RDFList(org.apache.jena.rdf.model.RDFList) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) GNode(org.apache.jena.sparql.util.graph.GNode) ArrayList(java.util.ArrayList)

Example 2 with Multimap

use of org.apache.jena.ext.com.google.common.collect.Multimap in project jena by apache.

the class AssemblerSecurityRegistry method accessEntries.

private void accessEntries(Resource root, Multimap<String, Node> map, String user, List<Node> _graphs) {
    // Convert string names for graphs to URIs.
    Set<Node> graphs = _graphs.stream().map(n -> graphLabel(n, root)).collect(Collectors.toSet());
    if (graphs.contains(SecurityContext.allGraphs)) {
        map.removeAll(user);
        map.put(user, SecurityContext.allGraphs);
        return;
    }
    if (graphs.contains(SecurityContext.allNamedGraphs)) {
        boolean dft = dftPresent(graphs);
        Node x = SecurityContext.allNamedGraphs;
        if (dft)
            // Put in "*" instead.
            x = SecurityContext.allGraphs;
        map.removeAll(user);
        map.put(user, x);
        return;
    }
    if (SKIP_ALLGRAPH) {
        if (graphs.contains(SecurityContext.allGraphs)) {
            Log.warn(this, "Graph name '" + SecurityContext.allGraphsStr + "' not supported yet");
            graphs.remove(SecurityContext.allGraphs);
        }
        if (graphs.contains(SecurityContext.allNamedGraphs)) {
            Log.warn(this, "Graph name '" + SecurityContext.allNamedGraphsStr + "' not supported yet");
            graphs.remove(SecurityContext.allNamedGraphs);
        }
    }
    map.putAll(user, graphs);
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Assembler(org.apache.jena.assembler.Assembler) Collection(java.util.Collection) RDFList(org.apache.jena.rdf.model.RDFList) NodeFmtLib(org.apache.jena.riot.out.NodeFmtLib) Set(java.util.Set) Multimap(org.apache.jena.ext.com.google.common.collect.Multimap) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Collectors(java.util.stream.Collectors) Mode(org.apache.jena.assembler.Mode) ArrayList(java.util.ArrayList) RDFNode(org.apache.jena.rdf.model.RDFNode) List(java.util.List) ArrayListMultimap(org.apache.jena.ext.com.google.common.collect.ArrayListMultimap) GraphList(org.apache.jena.sparql.util.graph.GraphList) Util(org.apache.jena.rdf.model.impl.Util) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) Resource(org.apache.jena.rdf.model.Resource) GraphUtils(org.apache.jena.sparql.util.graph.GraphUtils) Log(org.apache.jena.atlas.logging.Log) GNode(org.apache.jena.sparql.util.graph.GNode) AssemblerBase(org.apache.jena.assembler.assemblers.AssemblerBase) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) GNode(org.apache.jena.sparql.util.graph.GNode)

Aggregations

ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Assembler (org.apache.jena.assembler.Assembler)2 Mode (org.apache.jena.assembler.Mode)2 AssemblerBase (org.apache.jena.assembler.assemblers.AssemblerBase)2 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 Log (org.apache.jena.atlas.logging.Log)2 ArrayListMultimap (org.apache.jena.ext.com.google.common.collect.ArrayListMultimap)2 Multimap (org.apache.jena.ext.com.google.common.collect.Multimap)2 Node (org.apache.jena.graph.Node)2 RDFList (org.apache.jena.rdf.model.RDFList)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 Resource (org.apache.jena.rdf.model.Resource)2 StmtIterator (org.apache.jena.rdf.model.StmtIterator)2 Util (org.apache.jena.rdf.model.impl.Util)2 NodeFmtLib (org.apache.jena.riot.out.NodeFmtLib)2 Quad (org.apache.jena.sparql.core.Quad)2