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);
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations