use of org.apache.stanbol.rules.base.api.RecipeEliminationException 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.stanbol.rules.base.api.RecipeEliminationException in project stanbol by apache.
the class RulesResource method removeRecipe.
/**
* This method allows to delete a recipe or a rule from the store.<br/>
* If the optional rule identifier id provided as second parameter that the rule is deleted. Otherwise it
* is the whole recipe to be deleted.
*
* @param recipe
* {@link String}
* @param rule
* {@link String} - OPTIONAL
* @param headers
* {@link HttpHeaders}
* @return <ul>
* <li>200 - if either the recipe or the rule is deleted</li>
* <li>204 - it is not possible to delete the rule because the internal construction of the recipe
* failed</li>
* <li>404 - the rule does not exist</li>
* <li>412 - the recipe to which the rule belongs does not exist</li>
* <li>500 - if a {@link RecipeEliminationException} exception is thrown</li>
* </ul>
*/
@DELETE
@Path("/recipe/{recipe:.+}")
public Response removeRecipe(@PathParam("recipe") String recipe, @QueryParam("rule") String rule, @Context HttpHeaders headers) {
ResponseBuilder responseBuilder;
boolean stop = false;
URI uri = null;
try {
uri = new URI(recipe);
} catch (URISyntaxException e1) {
log.error(e1.getMessage(), e1);
responseBuilder = Response.status(Status.NOT_ACCEPTABLE);
stop = true;
}
if (!stop) {
if (uri != null && uri.getScheme() == null) {
recipe = "urn:" + recipe;
log.info("The recipe ID is a URI without scheme. The ID is set to " + recipe);
}
log.info("The recipe ID is : " + recipe);
if (rule != null && !rule.isEmpty()) {
Recipe rcp;
try {
rcp = ruleStore.getRecipe(new IRI(recipe));
Rule rl = ruleStore.getRule(rcp, new IRI(rule));
ruleStore.removeRule(rcp, rl);
} catch (NoSuchRecipeException e) {
log.error(e.getMessage(), e);
responseBuilder = Response.status(Status.PRECONDITION_FAILED);
} catch (RecipeConstructionException e) {
log.error(e.getMessage(), e);
responseBuilder = Response.status(Status.NO_CONTENT);
} catch (NoSuchRuleInRecipeException e) {
log.error(e.getMessage(), e);
responseBuilder = Response.status(Status.NOT_FOUND);
}
} else {
try {
ruleStore.removeRecipe(new IRI(recipe));
} catch (RecipeEliminationException e) {
log.error(e.getMessage(), e);
responseBuilder = Response.status(Status.INTERNAL_SERVER_ERROR);
}
}
}
responseBuilder = Response.ok();
// addCORSOrigin(servletContext, responseBuilder, headers);
return responseBuilder.build();
}
use of org.apache.stanbol.rules.base.api.RecipeEliminationException in project stanbol by apache.
the class RefactorEnhancementEngine method deactivate.
@Deactivate
protected void deactivate(ComponentContext context) {
// Deactivation clears all the rules and releases OntoNet resources.
IRI recipeId = new IRI(engineConfiguration.getRecipeId());
try {
// step 1: get all the rules
log.debug("Recipe {} and its associated rules will be removed from the rule store.", recipeId);
Recipe recipe = null;
try {
recipe = ruleStore.getRecipe(recipeId);
} catch (RecipeConstructionException e) {
log.error(e.getMessage());
}
if (recipe != null) {
// step 2: remove the recipe
try {
if (ruleStore.removeRecipe(recipeId)) {
log.debug("Recipe {} has been removed correctly. Note that its rules will be removed separately.", recipeId);
} else
log.error("Recipe {} cannot be removed.", recipeId);
} catch (RecipeEliminationException e) {
log.error(e.getMessage());
}
}
} catch (NoSuchRecipeException ex) {
log.error("The recipe " + engineConfiguration.getRecipeId() + " doesn't exist", ex);
}
// step 3: clear OntoNet resources
scope.getCoreSpace().tearDown();
scope.tearDown();
onManager.deregisterScope(scope);
log.debug("OntoNet resources released : scope {}", scope);
log.info("in " + RefactorEnhancementEngine.class + " deactivate with context " + context);
}
Aggregations