Search in sources :

Example 6 with GraphNode

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

the class UserResource method rolesCheckboxes.

/**
     * Provides HTML corresponding to a user's roles
     *
     * all roles are listed with checkboxes, the roles this user has are checked
     *
     * (isn't very pretty but is just a one-off)
     *
     * @param userName the user in question
     * @return HTML checkboxes as HTTP response
     */
@GET
@Path("users/{username}/rolesCheckboxes")
@Produces(MediaType.TEXT_HTML)
public Response rolesCheckboxes(@PathParam("username") String userName) {
    // return new RdfViewable("rolesCheckboxes", getRoleType(), this.getClass());
    StringBuffer html = new StringBuffer();
    Iterator<Triple> allRoleTriples = systemGraph.filter(null, RDF.type, PERMISSION.Role);
    ArrayList<String> allRoleNames = new ArrayList<String>();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
        // pulls out all role names
        while (allRoleTriples.hasNext()) {
            Triple triple = allRoleTriples.next();
            GraphNode roleNode = new GraphNode(triple.getSubject(), systemGraph);
            Iterator<Literal> titlesIterator = roleNode.getLiterals(DC.title);
            while (titlesIterator.hasNext()) {
                allRoleNames.add(titlesIterator.next().getLexicalForm());
            }
        }
    } finally {
        readLock.unlock();
    }
    Graph rolesGraph = getUserRolesGraph(userName);
    ArrayList<String> userRoleNames = new ArrayList<String>();
    Iterator<Triple> userRoleTriples = rolesGraph.filter(null, RDF.type, PERMISSION.Role);
    while (userRoleTriples.hasNext()) {
        Triple triple = userRoleTriples.next();
        GraphNode roleNode = new GraphNode(triple.getSubject(), rolesGraph);
        Iterator<Literal> titlesIterator = roleNode.getLiterals(DC.title);
        while (titlesIterator.hasNext()) {
            userRoleNames.add(titlesIterator.next().getLexicalForm());
        }
    }
    for (int i = 0; i < allRoleNames.size(); i++) {
        String role = allRoleNames.get(i);
        if (role.equals("BasePermissionsRole")) {
            // filter out
            continue;
        }
        if (userRoleNames.contains(role)) {
            html.append("<input class=\"role\" type=\"checkbox\" id=\"").append(role).append("\" name=\"").append(role).append("\" value=\"").append(role).append("\" checked=\"checked\" />");
        } else {
            html.append("<input class=\"role\" type=\"checkbox\" id=\"").append(role).append("\" name=\"").append(role).append("\" value=\"").append(role).append("\" />");
        }
        html.append("<label for=\"").append(role).append("\">").append(role).append("</label>");
        html.append("<br />");
    }
    return Response.ok(html.toString()).build();
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Literal(org.apache.clerezza.commons.rdf.Literal) ArrayList(java.util.ArrayList) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) Lock(java.util.concurrent.locks.Lock) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with GraphNode

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

the class UserResource method createRole.

/**
     * Creates a new role wit the the specified role name
     *
     * @param newUserName
     * @return user node in system graph
     */
private GraphNode createRole(String newRoleName, String comment) {
    BlankNode subject = new BlankNode();
    GraphNode roleNode = new GraphNode(subject, systemGraph);
    roleNode.addProperty(RDF.type, PERMISSION.Role);
    roleNode.addProperty(DC.title, new PlainLiteralImpl(newRoleName));
    roleNode.addProperty(RDFS.comment, new PlainLiteralImpl(comment));
    return roleNode;
}
Also used : PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) BlankNode(org.apache.clerezza.commons.rdf.BlankNode) GraphNode(org.apache.clerezza.rdf.utils.GraphNode)

Example 8 with GraphNode

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

the class UserResource method storeUser.

/**
     * Update user details adds triples as appropriate to system graph
     *
     * @param uriInfo
     * @param currentLogin
     * @param newLogin
     * @param fullName
     * @param email
     * @param password
     * @param roles
     * @param permissions
     * @return
     */
@POST
@Path("store-user")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response storeUser(@Context UriInfo uriInfo, @FormParam("currentLogin") String currentLogin, @FormParam("newLogin") String newLogin, @FormParam("fullName") String fullName, @FormParam("email") String email, @FormParam("password") String password, @FormParam("roles") List<String> roles, @FormParam("permissions") List<String> permissions) {
    GraphNode userNode = null;
    if (currentLogin != null) {
        // 
        currentLogin = currentLogin.trim();
    }
    if (currentLogin != null && !currentLogin.equals("")) {
        userNode = getUser(currentLogin);
        if (userNode != null) {
            return store(userNode, uriInfo, currentLogin, newLogin, fullName, email, password, roles, permissions);
        }
    }
    userNode = createUser(newLogin);
    return store(userNode, uriInfo, newLogin, newLogin, fullName, email, password, roles, 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 9 with GraphNode

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

the class UserResource method addPermission.

// public final static String permissionsBase = "urn:x-localhost/role/";
private GraphNode addPermission(GraphNode subjectNode, String permissionString) {
    if (hasPermission(subjectNode, permissionString)) {
        return subjectNode;
    }
    GraphNode permissionNode = new GraphNode(new BlankNode(), systemGraph);
    permissionNode.addProperty(RDF.type, PERMISSION.Permission);
    // permissionNode.addProperty(DC.title, new PlainLiteralImpl(permissionName));
    subjectNode.addProperty(PERMISSION.hasPermission, permissionNode.getNode());
    permissionNode.addProperty(PERMISSION.javaPermissionEntry, new PlainLiteralImpl(permissionString));
    return subjectNode;
}
Also used : PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) BlankNode(org.apache.clerezza.commons.rdf.BlankNode) GraphNode(org.apache.clerezza.rdf.utils.GraphNode)

Example 10 with GraphNode

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

the class UserResource method getResourcesOfType.

private Set<GraphNode> getResourcesOfType(IRI type) {
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
        final Iterator<Triple> triples = systemGraph.filter(null, RDF.type, type);
        Set<GraphNode> resources = new HashSet<GraphNode>();
        while (triples.hasNext()) {
            resources.add(new GraphNode(triples.next().getSubject(), systemGraph));
        }
        return resources;
    } finally {
        readLock.unlock();
    }
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) Lock(java.util.concurrent.locks.Lock) HashSet(java.util.HashSet)

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