use of org.apache.stanbol.rules.base.api.RecipeConstructionException 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();
}
Aggregations