Search in sources :

Example 11 with NoSuchRuleInRecipeException

use of org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException in project stanbol by apache.

the class RulesResource method getRule.

/**
     * Get a recipe from the rule base (that is the ontology that contains the rules and the recipe). <br/>
     * If the second parameter is not null then the method returns the rule in the recipe identified by that
     * parameter. <br/>
     * 
     * curl -v -X GET http://localhost:8080/kres/rule/http
     * ://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentRule
     * 
     * @param uri
     *            {A string contains the IRI full name of the rule.}
     * @return Return: <br/>
     *         200 The rule is retrieved (import declarations point to KReS Services) <br/>
     *         404 The rule does not exists in the manager <br/>
     *         500 Some error occurred
     * 
     */
@GET
@Path("/recipe/{recipe:.+}")
@Produces(value = { KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.RDF_JSON, KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL, MediaType.TEXT_PLAIN })
public Response getRule(@PathParam("recipe") String recipeID, @QueryParam("rule") String ruleID, @Context HttpHeaders headers) {
    Recipe recipe;
    Rule rule;
    ResponseBuilder responseBuilder;
    try {
        URI uri = new URI(recipeID);
        if (uri.getScheme() == null) {
            recipeID = "urn:" + recipeID;
            log.info("The recipe ID is a URI without scheme. The ID is set to " + recipeID);
        }
        recipe = ruleStore.getRecipe(new IRI(recipeID));
        if (ruleID != null && !ruleID.isEmpty()) {
            rule = ruleStore.getRule(recipe, new IRI(ruleID));
            RuleList ruleList = new RuleList();
            ruleList.add(rule);
            recipe = new RecipeImpl(recipe.getRecipeID(), recipe.getRecipeDescription(), ruleList);
        }
        responseBuilder = Response.ok(recipe);
    } catch (NoSuchRecipeException e) {
        log.error(e.getMessage(), e);
        responseBuilder = Response.status(Status.NOT_FOUND);
    } 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);
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
        responseBuilder = Response.status(Status.NOT_ACCEPTABLE);
    }
    //        addCORSOrigin(servletContext, responseBuilder, headers);
    return responseBuilder.build();
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RuleList(org.apache.stanbol.rules.base.api.util.RuleList) NoSuchRuleInRecipeException(org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException) Recipe(org.apache.stanbol.rules.base.api.Recipe) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) Rule(org.apache.stanbol.rules.base.api.Rule) URISyntaxException(java.net.URISyntaxException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NoSuchRuleInRecipeException (org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException)11 IRI (org.apache.clerezza.commons.rdf.IRI)9 Recipe (org.apache.stanbol.rules.base.api.Recipe)9 Rule (org.apache.stanbol.rules.base.api.Rule)9 NoSuchRecipeException (org.apache.stanbol.rules.base.api.NoSuchRecipeException)5 RecipeConstructionException (org.apache.stanbol.rules.base.api.RecipeConstructionException)5 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 Path (javax.ws.rs.Path)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Graph (org.apache.clerezza.commons.rdf.Graph)2 Literal (org.apache.clerezza.commons.rdf.Literal)2 ParseException (org.apache.clerezza.rdf.core.sparql.ParseException)2 ResultSet (org.apache.clerezza.rdf.core.sparql.ResultSet)2 SolutionMapping (org.apache.clerezza.rdf.core.sparql.SolutionMapping)2 SelectQuery (org.apache.clerezza.rdf.core.sparql.query.SelectQuery)2 UnionGraph (org.apache.clerezza.rdf.utils.UnionGraph)2