@GET @Produces(TEXT_HTML) public Response getHtmlInfo(@PathParam("id") String sessionId, @Context HttpHeaders headers) { ResponseBuilder rb; session = sesMgr.getSession(sessionId); if (session == null) rb = Response.status(NOT_FOUND); else rb = Response.ok(new Viewable("index", this)); rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8"); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
@POST public Response createSessionWithAutomaticId(@Context UriInfo uriInfo, @Context HttpHeaders headers) { Session s; try { s = sessionManager.createSession(); } catch (SessionLimitException e) { throw new WebApplicationException(e, FORBIDDEN); } String uri = uriInfo.getRequestUri().toString(); while (uri.endsWith("/")) uri = uri.substring(0, uri.length() - 1); uri += "/" + s.getID(); ResponseBuilder rb = Response.created(URI.create(uri)); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
/** * Destroys the session and unmanages its ontologies (which are also lost unless stored). * * @param sessionId * the session identifier * @param uriInfo * @param headers * @return {@link Status#OK} if the deletion was successful, {@link Status#NOT_FOUND} if there is no such * session at all. */ @DELETE public Response deleteSession(@PathParam("id") String sessionId, // @Context UriInfo uriInfo, @Context HttpHeaders headers) { session = sesMgr.getSession(sessionId); if (session == null) return Response.status(NOT_FOUND).build(); sesMgr.destroySession(sessionId); session = null; ResponseBuilder rb = Response.ok(); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
public Set<Session> getSessions() { Set<Session> result = new HashSet<Session>(); for (String id : sessionManager.getRegisteredSessionIDs()) result.add(sessionManager.getSession(id)); return result; }
session = sessionManager.createSession(); } catch (SessionLimitException e1) { throw new EngineException( sessionManager.destroySession(session.getID());
@GET @Produces(value = {RDF_XML, OWL_XML, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON, N3, N_TRIPLE, TEXT_PLAIN}) public Response listSessions(@Context UriInfo uriInfo, @Context HttpHeaders headers) { OWLOntologyManager ontMgr = OWLManager.createOWLOntologyManager(); OWLDataFactory df = ontMgr.getOWLDataFactory(); OWLClass cSession = df.getOWLClass(IRI.create("http://stanbol.apache.org/ontologies/meta/Session")); OWLOntology o; try { o = ontMgr.createOntology(IRI.create(uriInfo.getRequestUri())); List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); for (String id : sessionManager.getRegisteredSessionIDs()) { IRI sessionid = IRI.create(sessionManager.getDefaultNamespace() + sessionManager.getID() + "/" + id); OWLNamedIndividual ind = df.getOWLNamedIndividual(sessionid); changes.add(new AddAxiom(o, df.getOWLClassAssertionAxiom(cSession, ind))); } ontMgr.applyChanges(changes); } catch (OWLOntologyCreationException e) { throw new WebApplicationException(e, INTERNAL_SERVER_ERROR); } ResponseBuilder rb = Response.ok(o); MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null); if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
@Override public Set<String> run() { Set<String> handles = new HashSet<String>(); if (onManager != null) { for (Scope scope : onManager.getRegisteredScopes()) { if (scope.getCoreSpace().hasOntology(ontologyId) || scope.getCustomSpace().hasOntology(ontologyId)) { handles.add(scope.getID()); } } } if (sessionManager != null) { for (String sesId : sessionManager.getRegisteredSessionIDs()) { if (sessionManager.getSession(sesId).hasOntology(ontologyId)) { handles.add(sesId); } } } return handles; } });
@GET @Produces(value = {APPLICATION_JSON, N3, N_TRIPLE, RDF_JSON}) public Response asOntologyGraph(@PathParam(value = "id") String sessionId, @PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context HttpHeaders headers) { session = sesMgr.getSession(sessionId); if (session == null) return Response.status(NOT_FOUND).build(); IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/"); // Export to Clerezza ImmutableGraph, which can be rendered as JSON-LD. ResponseBuilder rb = Response.ok(session.export(ImmutableGraph.class, merge, prefix)); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
for (String sesId : sessionManager.getRegisteredSessionIDs()) { if (sessionManager.getSession(sesId).hasOntology(key)) { handles.add(sessionManager.getSession(sesId));
/** * Used to create an OntoNet session with a specified identifier. * * @param sessionId * the identifier of the session to be created. * @param uriInfo * @param headers * @return {@link Status#OK} if the creation was successful, or {@link Status#CONFLICT} if a session with * that ID already exists. */ @PUT public Response createSession(@PathParam("id") String sessionId, // @Context UriInfo uriInfo, @Context HttpHeaders headers) { try { session = sesMgr.createSession(sessionId); } catch (DuplicateSessionIDException e) { throw new WebApplicationException(e, CONFLICT); } catch (SessionLimitException e) { throw new WebApplicationException(e, FORBIDDEN); } ResponseBuilder rb = Response.created(uriInfo.getRequestUri()); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
@GET @Produces(value = {MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN}) public Response asOntologyOWL(@PathParam(value = "id") String sessionId, @PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context HttpHeaders headers) { session = sesMgr.getSession(sessionId); if (session == null) return Response.status(NOT_FOUND).build(); IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/"); // Export to OWLOntology, the only to support OWL formats. ResponseBuilder rb = Response.ok(session.export(OWLOntology.class, merge, prefix)); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
@GET @Produces(value = {RDF_XML, TURTLE, X_TURTLE}) public Response asOntologyMixed(@PathParam(value = "id") String sessionId, @PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context HttpHeaders headers) { session = sesMgr.getSession(sessionId); if (session == null) return Response.status(NOT_FOUND).build(); ResponseBuilder rb; IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/"); // Export smaller graphs to OWLOntology due to the more human-readable rendering. if (merge) rb = Response.ok(session.export(ImmutableGraph.class, merge, prefix)); else rb = Response.ok(session.export(OWLOntology.class, merge, prefix)); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
@POST @Produces({WILDCARD}) public Response emptyPost(@PathParam("id") String sessionId, @Context HttpHeaders headers) { log.debug(" post(no data)"); session = sesMgr.getSession(sessionId); for (Scope sc : getAllScopes()) { // First remove appended scopes not in the list String scid = sc.getID(); if (getAppendedScopes().contains(scid)) { session.detachScope(scid); log.info("Removed scope \"{]\".", scid); } } ResponseBuilder rb = Response.ok(); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
/** * Gets the ontology with the given identifier in its version managed by the session. * * @param sessionId * the session identifier. * @param ontologyId * the ontology identifier. * @param uriInfo * @param headers * @return the requested managed ontology, or {@link Status#NOT_FOUND} if either the sessionn does not * exist, or the if the ontology either does not exist or is not managed. */ @GET @Path(value = "/{ontologyId:.+}") @Produces(value = {APPLICATION_JSON, N3, N_TRIPLE, RDF_JSON}) public Response managedOntologyGetGraph(@PathParam("id") String sessionId, @PathParam("ontologyId") String ontologyId, @DefaultValue("false") @QueryParam("merge") boolean merge, // @Context UriInfo uriInfo, @Context HttpHeaders headers) { session = sesMgr.getSession(sessionId); if (session == null) return Response.status(NOT_FOUND).build(); IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/"); ImmutableGraph o = session.getOntology(OntologyUtils.decode(ontologyId), ImmutableGraph.class, merge, prefix); ResponseBuilder rb = (o != null) ? Response.ok(o) : Response.status(NOT_FOUND); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
/** * Tells the session that it should manage the ontology obtained by dereferencing the supplied IRI.<br> * <br> * Note that the PUT method cannot be used, as it is not possible to predict what ID the ontology will * have until it is parsed. * * @param content * the ontology physical IRI * @return {@link Status#OK} if the addition was successful, {@link Status#NOT_FOUND} if there is no such * session at all, {@link Status#FORBIDDEN} if the session is locked or cannot modified for some * other reason, {@link Status#INTERNAL_SERVER_ERROR} if some other error occurs. */ @POST @Consumes(value = MediaType.TEXT_PLAIN) public Response manageOntology(String iri, @PathParam("id") String sessionId, @Context HttpHeaders headers) { session = sesMgr.getSession(sessionId); if (session == null) return Response.status(NOT_FOUND).build(); try { session.addOntology(new RootOntologySource(IRI.create(iri))); } catch (UnmodifiableOntologyCollectorException e) { throw new WebApplicationException(e, FORBIDDEN); } catch (OWLOntologyCreationException e) { throw new WebApplicationException(e, INTERNAL_SERVER_ERROR); } ResponseBuilder rb = Response.ok(); // addCORSOrigin(servletContext, rb, headers); return rb.build(); }
session = sesMgr.getSession(sessionId); if (session == null) return Response.status(NOT_FOUND).build(); IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
ResponseBuilder rb; session = sesMgr.getSession(sessionId); if (session == null) rb = Response.status(NOT_FOUND); else {
session = sesMgr.getSession(sessionId); if (session == null) rb = Response.status(NOT_FOUND); else {
session = sessionManager.getSession(sessionId);
ResponseBuilder rb; session = sesMgr.getSession(sessionId); String mt = headers.getMediaType().toString(); if (session == null) rb = Response.status(NOT_FOUND); // Always check session first