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