use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class ClerezzaRuleStore method listRecipes.
@Override
public RecipeList listRecipes() throws NoSuchRecipeException, RecipeConstructionException {
RecipeList recipeList = new RecipeList();
for (IRI recipeID : recipes) {
Recipe recipe;
try {
recipe = getRecipe(recipeID);
} catch (NoSuchRecipeException e) {
throw e;
} catch (RecipeConstructionException e) {
throw e;
}
recipeList.add(recipe);
}
log.info("The Clerezza rule store contains {} recipes", recipeList.size());
return recipeList;
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class ClerezzaRuleStore method findRecipesByDescription.
@Override
public RecipeList findRecipesByDescription(String term) {
String sparql = "SELECT ?recipe " + "WHERE { ?recipe a " + Symbols.Recipe.toString() + " . " + "?recipe " + Symbols.description + " ?description . " + "FILTER (regex(?description, \"" + term + "\", \"i\"))" + "}";
Graph tripleCollection = tcManager.getGraph(new IRI(recipeIndexLocation));
RecipeList matchingRecipes = new RecipeList();
try {
SelectQuery query = (SelectQuery) QueryParser.getInstance().parse(sparql);
ResultSet resultSet = tcManager.executeSparqlQuery(query, tripleCollection);
while (resultSet.hasNext()) {
SolutionMapping solutionMapping = resultSet.next();
IRI recipeID = (IRI) solutionMapping.get("recipe");
try {
Recipe recipe = getRecipe(recipeID);
log.info("Found recipe {}.", recipeID.toString());
matchingRecipes.add(recipe);
log.info("Found {} matching recipes.", matchingRecipes.size());
} catch (NoSuchRecipeException e) {
// in this case go on in the iteration by fetching other matching recipes
} catch (RecipeConstructionException e) {
// in this case go on in the iteration by fetching other matching recipes
}
}
} catch (ParseException e) {
log.error("The sparql query contains errors: ", e);
}
return matchingRecipes;
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class ClerezzaRuleStore method findRulesByName.
@Override
public RuleList findRulesByName(String term) {
String sparql = "SELECT ?recipe ?rule ?description " + "WHERE { " + "?recipe " + Symbols.hasRule + " ?rule . " + "?rule " + Symbols.ruleName + " ?name . " + "?rule " + Symbols.description + " ?description . " + "FILTER (regex(?name, \"" + term + "\", \"i\"))" + "}";
List<IRI> recipeIDs = listRecipeIDs();
Graph[] tripleCollections = new Graph[recipeIDs.size()];
for (int i = 0; i < tripleCollections.length; i++) {
tripleCollections[i] = tcManager.getGraph(recipeIDs.get(i));
}
UnionGraph unionGraph = new UnionGraph(tripleCollections);
RuleList matchingRules = new RuleList();
try {
SelectQuery query = (SelectQuery) QueryParser.getInstance().parse(sparql);
ResultSet resultSet = tcManager.executeSparqlQuery(query, unionGraph);
while (resultSet.hasNext()) {
SolutionMapping solutionMapping = resultSet.next();
IRI recipeID = (IRI) solutionMapping.get("recipe");
IRI ruleID = (IRI) solutionMapping.get("rule");
Literal description = (Literal) solutionMapping.get("description");
try {
Recipe recipe = getRecipe(recipeID);
Rule rule = new RecipeRule(recipe, getRule(recipe, ruleID));
if (description != null) {
rule.setDescription(description.getLexicalForm());
}
matchingRules.add(rule);
} catch (NoSuchRecipeException e) {
// in this case go on in the iteration by fetching other matching recipes
} catch (RecipeConstructionException e) {
// in this case go on in the iteration by fetching other matching recipes
} catch (NoSuchRuleInRecipeException e) {
// in this case go on in the iteration by fetching other matching recipes
}
}
} catch (ParseException e) {
log.error("The sparql query contains errors: ", e);
}
return matchingRules;
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class ClerezzaRuleStore method removeRecipe.
@Override
public boolean removeRecipe(IRI recipeID) throws RecipeEliminationException {
// remove the recipe from the TcManager
try {
tcManager.deleteGraph(recipeID);
} catch (NoSuchEntityException e) {
throw new RecipeEliminationException(e);
}
Graph recipeIndexGraph = tcManager.getGraph(new IRI(recipeIndexLocation));
Triple triple = new TripleImpl(recipeID, RDF.type, Symbols.Recipe);
recipeIndexGraph.remove(triple);
// System.out.println("Recipes: " +recipes.size());
// remove the recipe ID from in-memory list
recipes.remove(recipeID);
return true;
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class UserResource method store.
// **********************************
// ****** ADD PERMISSION TO USER ****
// **********************************
// **************************************
// ****** REMOVE PERMISSION FROM USER ***
// **************************************
// ************************************
// ****** ADD PERMISSION TO ROLE ******
// ************************************
// **************************************
// ****** REMOVE PERMISSION FROM ROLE ***
// **************************************
// //////////////////////////////////////////////////////////////
/**
* Pushes user data into system graph
*
* @param userNode
* @param uriInfo
* @param currentUserName
* @param newUserName
* @param fullName
* @param email
* @param password
* @param roles
* @param permissions
* @return
*/
private Response store(GraphNode userNode, UriInfo uriInfo, String currentUserName, String newUserName, String fullName, String email, String password, List<String> roles, List<String> permissions) {
if (newUserName != null && !newUserName.equals("")) {
changeLiteral(userNode, PLATFORM.userName, newUserName);
}
if (fullName != null && !fullName.equals("")) {
changeLiteral(userNode, FOAF.name, fullName);
}
if (password != null && !password.equals("")) {
String passwordSha1 = PasswordUtil.convertPassword(password);
changeLiteral(userNode, PERMISSION.passwordSha1, passwordSha1);
}
if (email != null && !email.equals("")) {
changeResource(userNode, FOAF.mbox, new IRI("mailto:" + email));
}
BlankNodeOrIRI userResource = (BlankNodeOrIRI) userNode.getNode();
if (roles != null) {
clearRoles(userResource);
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
try {
for (int i = 0; i < roles.size(); i++) {
roles.set(i, roles.get(i).trim());
if (!roles.get(i).equals("")) {
addRole(userNode, roles.get(i));
}
}
} finally {
writeLock.unlock();
}
}
if (permissions != null) {
clearPermissions(userResource);
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
try {
for (int i = 0; i < permissions.size(); i++) {
permissions.set(i, permissions.get(i).trim());
if (!permissions.get(i).equals("")) {
addPermission(userNode, permissions.get(i));
}
}
} finally {
writeLock.unlock();
}
}
URI pageUri = uriInfo.getBaseUriBuilder().path("system/console/usermanagement").build();
// header Cache-control: no-cache, just in case intermediaries are
// holding onto old stuff
CacheControl cc = new CacheControl();
cc.setNoCache(true);
// the jax-rs things available
return Response.seeOther(pageUri).cacheControl(cc).build();
}
Aggregations