Search in sources :

Example 1 with RecipeEliminationException

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;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) RecipeEliminationException(org.apache.stanbol.rules.base.api.RecipeEliminationException) UnionGraph(org.apache.clerezza.rdf.utils.UnionGraph) Graph(org.apache.clerezza.commons.rdf.Graph) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) NoSuchEntityException(org.apache.clerezza.rdf.core.access.NoSuchEntityException)

Example 2 with RecipeEliminationException

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();
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RecipeEliminationException(org.apache.stanbol.rules.base.api.RecipeEliminationException) NoSuchRuleInRecipeException(org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException) Recipe(org.apache.stanbol.rules.base.api.Recipe) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) URISyntaxException(java.net.URISyntaxException) Rule(org.apache.stanbol.rules.base.api.Rule) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 3 with RecipeEliminationException

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);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RecipeEliminationException(org.apache.stanbol.rules.base.api.RecipeEliminationException) Recipe(org.apache.stanbol.rules.base.api.Recipe) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException) Deactivate(org.apache.felix.scr.annotations.Deactivate)

Aggregations

IRI (org.apache.clerezza.commons.rdf.IRI)3 RecipeEliminationException (org.apache.stanbol.rules.base.api.RecipeEliminationException)3 NoSuchRecipeException (org.apache.stanbol.rules.base.api.NoSuchRecipeException)2 Recipe (org.apache.stanbol.rules.base.api.Recipe)2 RecipeConstructionException (org.apache.stanbol.rules.base.api.RecipeConstructionException)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 Graph (org.apache.clerezza.commons.rdf.Graph)1 Triple (org.apache.clerezza.commons.rdf.Triple)1 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)1 NoSuchEntityException (org.apache.clerezza.rdf.core.access.NoSuchEntityException)1 UnionGraph (org.apache.clerezza.rdf.utils.UnionGraph)1 Deactivate (org.apache.felix.scr.annotations.Deactivate)1 NoSuchRuleInRecipeException (org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException)1 Rule (org.apache.stanbol.rules.base.api.Rule)1