Search in sources :

Example 11 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class UserResource method storeRoleFormHandler.

/**
     * Update role details - adds triples as appropriate to system graph
     *
     */
@POST
@Path("store-role")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response storeRoleFormHandler(@Context UriInfo uriInfo, @FormParam("roleName") String roleName, @FormParam("comment") String comment, @FormParam("permissions") List<String> permissions) {
    GraphNode roleNode = null;
    if (roleName != null) {
        // 
        roleName = roleName.trim();
    }
    if (roleName != null && !roleName.equals("")) {
        roleNode = getRole(roleName);
        if (roleNode != null) {
            return storeRole(roleNode, uriInfo, roleName, comment, permissions);
        }
    }
    roleNode = createRole(roleName, comment);
    return storeRole(roleNode, uriInfo, roleName, comment, permissions);
}
Also used : GraphNode(org.apache.clerezza.rdf.utils.GraphNode) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 12 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class UserResource method addClassToPermissions.

/**
     * a kludge - initially the permissions aren't expressed as instances of
     * Permission class, this adds the relevant triples
     */
private void addClassToPermissions() {
    Iterator<Triple> permissionTriples = systemGraph.filter(null, PERMISSION.hasPermission, null);
    ArrayList<GraphNode> buffer = new ArrayList<GraphNode>();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
        while (permissionTriples.hasNext()) {
            Triple triple = permissionTriples.next();
            RDFTerm permissionResource = triple.getObject();
            buffer.add(new GraphNode(permissionResource, systemGraph));
        }
    } finally {
        readLock.unlock();
    }
    Lock writeLock = systemGraph.getLock().writeLock();
    writeLock.lock();
    try {
        for (int i = 0; i < buffer.size(); i++) {
            buffer.get(i).addProperty(RDF.type, PERMISSION.Permission);
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) ArrayList(java.util.ArrayList) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) Lock(java.util.concurrent.locks.Lock)

Example 13 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class UserResource method getUserRolesGraph.

/**
     * Provides a graph containing Role triples associated with a given user
     *
     * @param userName
     * @return roles graph
     */
private Graph getUserRolesGraph(String userName) {
    GraphNode userNode = getUser(userName);
    Iterator<RDFTerm> functionIterator = userNode.getObjects(SIOC.has_function);
    SimpleGraph rolesGraph = new SimpleGraph();
    while (functionIterator.hasNext()) {
        GraphNode functionNode = new GraphNode(functionIterator.next(), systemGraph);
        Iterator<Triple> roleIterator = systemGraph.filter((BlankNodeOrIRI) functionNode.getNode(), RDF.type, PERMISSION.Role);
        // needs lock?
        while (roleIterator.hasNext()) {
            Triple roleTriple = roleIterator.next();
            // rolesGraph.add(roleTriple);
            BlankNodeOrIRI roleNode = roleTriple.getSubject();
            SimpleGraph detailsGraph = new SimpleGraph(systemGraph.filter(roleNode, null, null));
            rolesGraph.addAll(detailsGraph);
        }
    }
    return rolesGraph;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm)

Example 14 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class UserResource method addRole.

/**
     * Add a role to a given user in system graph
     *
     * @param userNode node corresponding to user
     * @param roleName name of the role
     * @return user node
     */
private GraphNode addRole(GraphNode userNode, String roleName) {
    // is this thing already around? (will be a bnode)
    GraphNode roleNode = getTitleNode(roleName);
    // otherwise make a new one as a named node
    if (roleNode == null) {
        IRI roleIRI = new IRI(rolesBase + roleName);
        roleNode = new GraphNode(roleIRI, systemGraph);
        roleNode.addProperty(RDF.type, PERMISSION.Role);
        roleNode.addProperty(DC.title, new PlainLiteralImpl(roleName));
        userNode.addProperty(SIOC.has_function, roleIRI);
    } else {
        userNode.addProperty(SIOC.has_function, roleNode.getNode());
    }
    return userNode;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) GraphNode(org.apache.clerezza.rdf.utils.GraphNode)

Example 15 with GraphNode

use of org.apache.clerezza.rdf.utils.GraphNode in project stanbol by apache.

the class UserResource method getNamedRole.

/*
     * returns an existing user node from the graph.
     */
private GraphNode getNamedRole(String roleName) {
    GraphNode roleNode = null;
    Iterator<Triple> roleIterator = systemGraph.filter(null, RDF.type, PERMISSION.Role);
    //new PlainLiteralImpl(userName));
    if (!roleIterator.hasNext()) {
        return null;
    }
    ArrayList<Triple> tripleBuffer = new ArrayList<Triple>();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
        while (roleIterator.hasNext()) {
            BlankNodeOrIRI role = roleIterator.next().getSubject();
            Iterator<Triple> roleNameTriples = systemGraph.filter(role, DC.title, null);
            while (roleNameTriples.hasNext()) {
                Literal roleLiteral = (Literal) roleNameTriples.next().getObject();
                if (roleName.equals(roleLiteral.getLexicalForm())) {
                    roleNode = new GraphNode(role, systemGraph);
                    break;
                }
            }
            if (roleNode != null) {
                break;
            }
        }
    } finally {
        readLock.unlock();
    }
    return roleNode;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) Literal(org.apache.clerezza.commons.rdf.Literal) ArrayList(java.util.ArrayList) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) Lock(java.util.concurrent.locks.Lock)

Aggregations

GraphNode (org.apache.clerezza.rdf.utils.GraphNode)20 Triple (org.apache.clerezza.commons.rdf.Triple)8 IRI (org.apache.clerezza.commons.rdf.IRI)6 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)6 HashSet (java.util.HashSet)5 Lock (java.util.concurrent.locks.Lock)5 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)5 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)5 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)4 Graph (org.apache.clerezza.commons.rdf.Graph)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)3 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)3 Literal (org.apache.clerezza.commons.rdf.Literal)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1