use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.
the class OWLAPIToClerezzaConverterTest method setupClass.
@BeforeClass
public static void setupClass() {
/*
* Set-up the OWL ontology for the test. Simply add the axioms: AndreaNuzzolese isA Person -> class
* assertion axiom EnricoDaga isA Person -> class assertion axiom AndreaNuzzolese knows EnricoDaga ->
* object property assertion axiom
*/
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
try {
ontology = manager.createOntology(org.semanticweb.owlapi.model.IRI.create(ns + "testOntology"));
} catch (OWLOntologyCreationException e) {
log.error(e.getMessage());
}
if (ontology != null) {
OWLClass personClass = factory.getOWLClass(org.semanticweb.owlapi.model.IRI.create(foaf + "Person"));
OWLNamedIndividual andreaNuzzoleseOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "AndreaNuzzolese"));
OWLNamedIndividual enricoDagaOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "EnricoDaga"));
OWLObjectProperty knowsOWL = factory.getOWLObjectProperty(org.semanticweb.owlapi.model.IRI.create(foaf + "knows"));
OWLAxiom axiom = factory.getOWLClassAssertionAxiom(personClass, andreaNuzzoleseOWL);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLClassAssertionAxiom(personClass, enricoDagaOWL);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLObjectPropertyAssertionAxiom(knowsOWL, andreaNuzzoleseOWL, enricoDagaOWL);
manager.addAxiom(ontology, axiom);
}
/*
* Set-up the Clerezza model for the test. As before simply add the triples: AndreaNuzzolese isA
* Person EnricoDaga isA Person AndreaNuzzolese knows EnricoDaga
*/
mGraph = new SimpleGraph();
IRI knowsInClerezza = new IRI(ns + "knows");
IRI rdfType = new IRI(RDF.getURI() + "type");
IRI foafPersonInClerezza = new IRI(foaf + "Person");
BlankNodeOrIRI andreaNuzzoleseInClerezza = new IRI(ns + "AndreaNuzzolese");
BlankNodeOrIRI enricoDagaInClerezza = new IRI(ns + "EnricoDaga");
Triple triple = new TripleImpl(andreaNuzzoleseInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(enricoDagaInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(andreaNuzzoleseInClerezza, knowsInClerezza, enricoDagaInClerezza);
mGraph.add(triple);
}
use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.
the class UserResource method clearPermissions.
// [] a <http://xmlns.com/foaf/0.1/Agent> ;
// <http://clerezza.org/2008/10/permission#hasPermission>
// [ a <http://clerezza.org/2008/10/permission#Permission> ;
// <http://clerezza.org/2008/10/permission#javaPermissionEntry>
// "(java.security.AllPermission \"\" \"\")"
// ] ;
private void clearPermissions(BlankNodeOrIRI subject) {
ArrayList<Triple> buffer = new ArrayList<Triple>();
Lock readLock = systemGraph.getLock().readLock();
readLock.lock();
try {
Iterator<Triple> permissions = systemGraph.filter(subject, PERMISSION.hasPermission, null);
while (permissions.hasNext()) {
Triple permissionTriple = permissions.next();
buffer.add(permissionTriple);
BlankNodeOrIRI permissionNode = (BlankNodeOrIRI) permissionTriple.getObject();
Iterator<Triple> permissionTriples = systemGraph.filter(permissionNode, null, null);
while (permissionTriples.hasNext()) {
buffer.add(permissionTriples.next());
}
}
} finally {
readLock.unlock();
}
systemGraph.removeAll(buffer);
}
use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI 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.commons.rdf.BlankNodeOrIRI 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;
}
use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.
the class UserResource method addUser.
/**
* Endpoint-style user creation takes a little bunch of Turtle e.g. [] a
* foaf:Agent ; cz:userName "Hugo Ball" .
*
* [has test]
*
* @TODO check for password
*
* @param userData
* @return HTTP/1.1 204 No Content
*/
@POST
@Consumes(SupportedFormat.TURTLE)
@Path("add-user")
public Response addUser(@Context UriInfo uriInfo, ImmutableGraph inputGraph) {
Iterator<Triple> agents = inputGraph.filter(null, null, FOAF.Agent);
BlankNodeOrIRI userNode = agents.next().getSubject();
Iterator<Triple> userTriples = inputGraph.filter(userNode, null, null);
String userName = "";
Triple userTriple = null;
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
try {
GraphNode systemUserNode = new GraphNode(userNode, systemGraph);
addRole(systemUserNode, "BasePermissionsRole");
while (userTriples.hasNext()) {
userTriple = userTriples.next();
systemGraph.add(userTriple);
}
userName = ((Literal) userTriple.getObject()).getLexicalForm();
} finally {
writeLock.unlock();
}
UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
URI createdResource = uriBuilder.replacePath("/user-management/users/" + userName).build();
return Response.created(createdResource).build();
}
Aggregations