use of org.apache.stanbol.rules.refactor.api.RefactoringException 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 org.apache.stanbol.rules.refactor.api.RefactoringException in project stanbol by apache.
the class RefactorResource method performRefactoringLazyCreateGraph.
@GET
public Response performRefactoringLazyCreateGraph(@QueryParam("recipe") String recipe, @QueryParam("input-graph") String inputGraph, @QueryParam("output-graph") String outputGraph, @Context HttpHeaders headers) {
log.info("recipe: {}", recipe);
log.info("input-graph: {}", inputGraph);
log.info("output-graph: {}", outputGraph);
IRI recipeID = new IRI(recipe);
IRI inputGraphID = new IRI(inputGraph);
IRI outputGraphID = new IRI(outputGraph);
// Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
ResponseBuilder responseBuilder = null;
try {
refactorer.graphRefactoring(outputGraphID, inputGraphID, recipeID);
responseBuilder = Response.ok();
} catch (RefactoringException e) {
// refactoring exceptions are re-thrown
log.error(e.getMessage(), e);
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
} catch (NoSuchRecipeException e) {
log.error(e.getMessage(), e);
responseBuilder = Response.status(NOT_FOUND);
}
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null)
responseBuilder.header(HttpHeaders.CONTENT_TYPE, mediaType);
// addCORSOrigin(servletContext, responseBuilder, headers);
return responseBuilder.build();
}
use of org.apache.stanbol.rules.refactor.api.RefactoringException in project stanbol by apache.
the class RefactoringTest method persistentRefactoringTest.
@Test
public void persistentRefactoringTest() throws Exception {
try {
refactorer.graphRefactoring(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/refactoredGraph"), new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/graph"), new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/recipeA"));
Graph tc = tcm.getGraph(new IRI("http://incubator.apache.com/stanbol/rules/refactor/test/refactoredGraph"));
Assert.assertNotNull(tc);
} catch (RefactoringException e) {
fail("Error while refactoring.");
}
}
use of org.apache.stanbol.rules.refactor.api.RefactoringException in project stanbol by apache.
the class RefactorerImpl method graphRefactoring.
@SuppressWarnings("unchecked")
@Override
public void graphRefactoring(IRI refactoredOntologyID, IRI datasetID, IRI recipeID) throws RefactoringException, NoSuchRecipeException {
Recipe recipe;
try {
try {
recipe = ruleStore.getRecipe(recipeID);
RuleAdapter ruleAdapter = ruleAdapterManager.getAdapter(recipe, ConstructQuery.class);
List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe, ConstructQuery.class);
Graph mGraph = tcManager.createGraph(refactoredOntologyID);
for (ConstructQuery constructQuery : constructQueries) {
mGraph.addAll(this.sparqlConstruct(constructQuery, datasetID));
}
} catch (RecipeConstructionException e) {
throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
} catch (UnavailableRuleObjectException e) {
throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
} catch (UnsupportedTypeForExportException e) {
throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
} catch (RuleAtomCallExeption e) {
throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
}
} catch (NoSuchRecipeException e1) {
log.error("No Such recipe in the Rule Store", e1);
throw e1;
}
}
use of org.apache.stanbol.rules.refactor.api.RefactoringException 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();
}
Aggregations