use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class ReasoningServiceTaskResource method processBackgroundRequest.
/**
* Process a background request. This service use the Stanbol Commons Jobs API to start a background job.
* Returns 201 on success, with HTTP header Location pointing to the Job resource.
*
* @return
*/
private Response processBackgroundRequest() {
// If parameters is empty it's a bad request...
if (this.parameters.isEmpty()) {
log.error("Cannot start job without input parameters... sending BAD REQUEST");
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
String target = getTarget();
// Setup the input
ReasoningServiceInputManager imngr = prepareInput();
// The service executor
ReasoningServiceExecutor executor = new ReasoningServiceExecutor(tcManager, imngr, getCurrentService(), getCurrentTask(), target, parameters);
String jid = getJobManager().execute(executor);
URI location = URI.create(getPublicBaseUri() + "jobs/" + jid);
this.jobLocation = location.toString();
/**
* If everything went well, we return 201 Created We include the header Location: with the Job URL
*/
Viewable view = new Viewable("created", this);
return Response.created(location).entity(view).build();
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class ReasoningServiceTaskResource method processRealTimeRequest.
/**
* Process a real-time operation. Returns 200 when the process is ready, 500 if some error occurs
*
* @return
*/
private Response processRealTimeRequest() {
// page
if (this.parameters.isEmpty() && file == null) {
log.debug("no parameters no input file, show default index page");
// return Response.ok(new Viewable("index", this)).build();
ResponseBuilder rb = Response.ok(new Viewable("index", this));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
return rb.build();
}
try {
String target = getTarget();
// Setup the input
ReasoningServiceInputManager imngr = prepareInput();
// The service executor
ReasoningServiceExecutor executor = new ReasoningServiceExecutor(tcManager, imngr, getCurrentService(), getCurrentTask(), target, parameters);
ReasoningServiceResult<?> result = executor.call();
return new ResponseTaskBuilder(new ReasoningTaskResult(uriInfo, headers)).build(result);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class ResponseTaskBuilder method buildCheckResponse.
/**
* To build the Response for any CHECK task execution
*
* @param isConsistent
* @return
*/
private Response buildCheckResponse(boolean isConsistent) {
if (isHTML()) {
if (isConsistent) {
log.debug("The input is consistent");
result.setResult("The input is consistent :)");
ResponseBuilder rb = Response.ok(new Viewable("result", result));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
// addCORSOrigin(context, rb, headers);
return rb.build();
/*return Response.ok(
new Viewable("result",
new ReasoningPrettyResultResource(
context, info,
"The input is consistent :)")),
TEXT_HTML).build();*/
} else {
log.debug("The input is not consistent");
ResponseBuilder rb = Response.status(Status.CONFLICT);
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
// addCORSOrigin(context, rb, headers);
result.setResult("The input is NOT consistent :(");
rb.entity(new Viewable("result", result));
return rb.build();
/*return Response
.status(Status.CONFLICT)
.entity(new Viewable("result",
new ReasoningPrettyResultResource(
context, info,
"The input is NOT consistent :(")))
.type(TEXT_HTML).build();*/
}
} else {
if (isConsistent) {
log.debug("The input is consistent");
//return Response.ok("The input is consistent :)").build();
ResponseBuilder rb = Response.ok("The input is consistent :)");
// addCORSOrigin(context, rb, headers);
return rb.build();
} else {
log.debug("The input is not consistent");
//return Response.status(Status.CONFLICT).build();
ResponseBuilder rb = Response.status(Status.CONFLICT);
// addCORSOrigin(context, rb, headers);
return rb.build();
}
}
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class RootResource method performShowOntology.
/**
* Helper method to make sure a ResponseBuilder is created on every conditions, so that it is then
* possible to enable CORS on it afterwards.
*
* @param ontologyId
* @return
*/
protected ResponseBuilder performShowOntology(String ontologyId) {
if (ontologyId == null || ontologyId.isEmpty()) {
return Response.status(BAD_REQUEST);
}
OWLOntologyID key = OntologyUtils.decode(ontologyId);
if (ontologyProvider.listOrphans().contains(key)) {
return Response.status(NO_CONTENT);
}
OWLOntology o = getOWLOntology(ontologyId, false, uriInfo.getRequestUri());
if (o == null) {
return Response.status(NOT_FOUND);
}
// Assemble dependency list
Map<OWLOntologyID, OntologyProvider.Status> deps = new HashMap<OWLOntologyID, OntologyProvider.Status>();
for (OWLOntologyID dep : getDescriptor().getDependencies(key)) {
deps.put(dep, ontologyProvider.getStatus(dep));
}
Set<OntologyCollector> handles = new HashSet<OntologyCollector>();
if (onManager != null) {
for (Scope scope : onManager.getRegisteredScopes()) {
if (scope.getCoreSpace().hasOntology(key)) {
handles.add(scope.getCoreSpace());
}
if (scope.getCustomSpace().hasOntology(key)) {
handles.add(scope.getCustomSpace());
}
}
}
if (sessionManager != null) {
for (String sesId : sessionManager.getRegisteredSessionIDs()) {
if (sessionManager.getSession(sesId).hasOntology(key)) {
handles.add(sessionManager.getSession(sesId));
}
}
}
return Response.ok(new Viewable("ontology", new OntologyStats(uriInfo, key, o, ontologyProvider.listAliases(key), deps, handles)));
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class ScopeResource method managedOntologyShow.
@GET
@Path("/{ontologyId:.+}")
@Produces(TEXT_HTML)
public Response managedOntologyShow(@PathParam("scopeid") String scopeid, @PathParam("ontologyId") String ontologyId, @Context HttpHeaders headers) {
ResponseBuilder rb;
scope = onm.getScope(scopeid);
if (scope == null)
rb = Response.status(NOT_FOUND);
else if (ontologyId == null || ontologyId.isEmpty())
rb = Response.status(BAD_REQUEST);
else if (!ontologyProvider.hasOntology(OntologyUtils.decode(ontologyId)))
rb = Response.status(NOT_FOUND);
else {
IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
OWLOntology o = scope.getCustomSpace().getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
if (o == null)
o = scope.getCoreSpace().getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
if (o == null)
rb = Response.status(NOT_FOUND);
else
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
o.getOWLOntologyManager().saveOntology(o, new ManchesterOWLSyntaxOntologyFormat(), out);
rb = Response.ok(new Viewable("ontology", new OntologyPrettyPrintResource(uriInfo, out, scope)));
} catch (OWLOntologyStorageException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
}
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
Aggregations