use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.
the class RefactorResource method applyRefactoringFromRuleFile.
/**
* The apply mode allows the client to compose a recipe, by mean of string containg the rules, and apply
* it "on the fly" to the graph in input.
*
* @param recipe
* String
* @param input
* InputStream
* @return a Response containing the transformed graph
*/
@POST
@Path("/applyfile")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(value = { TURTLE, RDF_XML, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, RDF_JSON, X_TURTLE })
public Response applyRefactoringFromRuleFile(MultiPartBody data, @Context HttpHeaders headers) {
InputStream recipeStream = null;
InputStream input = null;
if (data.getFormFileParameterValues("recipe") != null) {
recipeStream = new ByteArrayInputStream(data.getFormFileParameterValues("recipe")[0].getContent());
}
if (data.getFormFileParameterValues("input") != null) {
input = new ByteArrayInputStream(data.getFormFileParameterValues("input")[0].getContent());
}
if (recipeStream == null || input == null) {
throw new WebApplicationException(BAD_REQUEST);
}
ResponseBuilder rb;
OWLOntology output = null;
try {
output = doRefactoring(input, RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/refactor/", recipeStream));
} catch (OWLOntologyCreationException e1) {
throw new WebApplicationException(e1, INTERNAL_SERVER_ERROR);
} catch (RefactoringException e1) {
throw new WebApplicationException(e1, INTERNAL_SERVER_ERROR);
}
if (output != null) {
rb = Response.ok(output);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null)
rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
} else
rb = Response.status(NOT_FOUND);
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.
the class RefactorResource method performRefactoring.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(value = { TURTLE, RDF_XML, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, RDF_JSON, X_TURTLE })
public Response performRefactoring(MultiPartBody data, @Context HttpHeaders headers) {
String recipe = null;
InputStream input = null;
if (data.getTextParameterValues("recipe") != null) {
recipe = data.getTextParameterValues("recipe")[0];
}
if (data.getFormFileParameterValues("input") != null) {
input = new ByteArrayInputStream(data.getFormFileParameterValues("input")[0].getContent());
}
if (recipe == null || input == null) {
throw new WebApplicationException(BAD_REQUEST);
}
// Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
ResponseBuilder rb;
Recipe rcp;
try {
URI uri = new URI(recipe);
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);
}
IRI recipeID = new IRI(recipe);
rcp = ruleStore.getRecipe(recipeID);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology inputOntology = manager.loadOntologyFromOntologyDocument(input);
Graph tripleCollection = refactorer.graphRefactoring(OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(inputOntology), rcp);
OWLOntology outputOntology = OWLAPIToClerezzaConverter.clerezzaGraphToOWLOntology(tripleCollection);
rb = Response.ok(outputOntology);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null)
rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
} catch (NoSuchRecipeException e) {
rb = Response.status(NOT_FOUND);
log.error(e.getMessage(), e);
} catch (RecipeConstructionException e) {
rb = Response.status(NO_CONTENT);
log.error(e.getMessage(), e);
} catch (OWLOntologyCreationException e) {
rb = Response.status(PRECONDITION_FAILED);
log.error(e.getMessage(), e);
} catch (RefactoringException e) {
rb = Response.status(INTERNAL_SERVER_ERROR);
log.error(e.getMessage(), e);
} catch (URISyntaxException e) {
rb = Response.status(NOT_ACCEPTABLE);
log.error(e.getMessage(), e);
}
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.
the class RulesResource method showRecipe.
@GET
@Path("/recipe/{recipe:.+}")
@Produces(value = { MediaType.TEXT_HTML })
public Response showRecipe(@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(new Viewable("rules", new RulesPrettyPrintResource(uriInfo, 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();
}
use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.
the class RulesResource method addRulesToRecipe.
/**
* Add rules to a recipe. An optional description can be provided to the rules.
*
* @param recipe
* {A string contains the IRI of the recipe to be added}
* @param rules
* {A string contains the rules in Stanbol syntax}
* @param description
* {A string contains a description of the rule}
* @param headers
* {The {@link HttpHeaders}
* @return Return: <br/>
* 200 The recipe has been added<br/>
* 409 The recipe has not been added<br/>
* 500 Some error occurred
*/
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(value = { KRFormat.TEXT_PLAIN, KRFormat.RDF_JSON })
@Path("/recipe/{recipe:.+}")
public Response addRulesToRecipe(@PathParam(value = "recipe") String recipe, MultiPartBody data, @Context HttpHeaders headers) {
String description = null;
InputStream rules = null;
if (data.getTextParameterValues("description") != null) {
description = data.getTextParameterValues("description")[0];
}
if (data.getFormFileParameterValues("rules") != null) {
rules = new ByteArrayInputStream(data.getFormFileParameterValues("rules")[0].getContent());
}
if (recipe == null || rules == null || description == null) {
throw new WebApplicationException(BAD_REQUEST);
}
ResponseBuilder responseBuilder;
Recipe rcp;
try {
URI uri = new URI(recipe);
if (uri.getScheme() == null) {
recipe = "urn:" + recipe;
log.info("The recipe ID is a URI without scheme. The ID is set to " + recipe);
}
rcp = ruleStore.getRecipe(new IRI(recipe));
ruleStore.addRulesToRecipe(rcp, rules, description);
responseBuilder = Response.ok();
} 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.INTERNAL_SERVER_ERROR);
} catch (URISyntaxException e) {
log.error(e.getMessage(), e);
responseBuilder = Response.status(Status.NOT_ACCEPTABLE);
}
// addCORSOrigin(servletContext, responseBuilder, headers);
return responseBuilder.build();
}
use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.
the class SiteManagerRootResource method getSitesPage.
@GET
@Produces(MediaType.TEXT_HTML)
public Response getSitesPage(@Context HttpHeaders headers) {
ResponseBuilder rb = Response.ok(new Viewable("index", this));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
Aggregations