public Notification getNotification() { return new Notification(type.title(), type.description()); }
public Notification getNotification() { return new Notification(type.title(), type.description()); }
@Path("/{elementUri}/jsonld") @GET @Produces(MediaType.TEXT_PLAIN) @Override public String getAsJsonLd(@PathParam("elementUri") String elementUri) { try { return toJsonLd(getPipelineElementRdfStorage().getSECById(elementUri)); } catch (URISyntaxException e) { return toJson(constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage()))); } }
@Path("/{sourceId}/streams") @GET @Produces(MediaType.APPLICATION_JSON) @GsonWithIds public Response getStreamsBySource(@PathParam("username") String username, @PathParam("sourceId") String sourceId) { try { return ok(new DataSourceDescription(getPipelineElementRdfStorage().getSEPById(sourceId))); } catch (URISyntaxException e) { return constructErrorMessage(new Notification(NotificationType.URIOFFLINE.title(), NotificationType.URIOFFLINE.description(), e.getMessage())); } catch (Exception e) { return constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage())); } }
@Path("/recommend") @POST @Produces(MediaType.APPLICATION_JSON) @GsonWithIds public Response recommend(@PathParam("username") String email, org.streampipes.model.client.pipeline.Pipeline pipeline) { try { return ok(Operations.findRecommendedElements(email, pipeline)); } catch (JsonSyntaxException e) { return constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage())); } catch (NoSuitableSepasAvailableException e) { return constructErrorMessage(new Notification(NotificationType.NO_SEPA_FOUND.title(), NotificationType.NO_SEPA_FOUND.description(), e.getMessage())); } catch (Exception e) { e.printStackTrace(); return constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage())); } }
@PUT @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) public Response updateElement(@PathParam("username") String username, @PathParam("id") String uri) { if (!authorized(username)) { return ok(Notifications.error(NotificationType.UNAUTHORIZED)); } try { uri = URLDecoder.decode(uri, "UTF-8"); String payload = parseURIContent(uri); return ok(Operations.verifyAndUpdateElement(payload, username)); } catch (URISyntaxException | IOException e) { e.printStackTrace(); return constructErrorMessage(new Notification(NotificationType.PARSE_ERROR.title(), NotificationType.PARSE_ERROR.description(), e.getMessage())); } catch (SepaParseException e) { e.printStackTrace(); return constructErrorMessage(new Notification(NotificationType.PARSE_ERROR.title(), NotificationType.PARSE_ERROR.description(), e.getMessage())); } }
public Response stopPipeline(String pipelineId) { try { Pipeline pipeline = getPipelineStorage().getPipeline(pipelineId); PipelineOperationStatus status = Operations.stopPipeline(pipeline); return ok(status); } catch (Exception e) { e.printStackTrace(); return constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage())); } }
@DELETE @Path("/own/{elementUri}") @RequiresAuthentication @Produces(MediaType.APPLICATION_JSON) @GsonWithIds @Override public Response removeOwn(@PathParam("username") String username, @PathParam("elementUri") String elementUri) { try { IPipelineElementDescriptionStorage requestor = getPipelineElementRdfStorage(); getUserService().deleteOwnAction(username, elementUri); requestor.deleteSEC(requestor.getSECById(elementUri)); } catch (URISyntaxException e) { return constructErrorMessage(new Notification(NotificationType.STORAGE_ERROR.title(), NotificationType.STORAGE_ERROR.description(), e.getMessage())); } return constructSuccessMessage(NotificationType.STORAGE_SUCCESS.uiNotification()); }
@DELETE @Path("/own/{elementUri}") @RequiresAuthentication @Produces(MediaType.APPLICATION_JSON) @GsonWithIds @Override public Response removeOwn(@PathParam("username") String username, @PathParam("elementUri") String elementUri) { try { getUserService().deleteOwnSource(username, elementUri); getPipelineElementRdfStorage().deleteSEC(getPipelineElementRdfStorage().getSECById(elementUri)); } catch (URISyntaxException e) { return constructErrorMessage(new Notification(NotificationType.STORAGE_ERROR.title(), NotificationType.STORAGE_ERROR.description(), e.getMessage())); } return constructSuccessMessage(NotificationType.STORAGE_SUCCESS.uiNotification()); }
@Path("/delete") @POST @Produces(MediaType.APPLICATION_JSON) public Response deleteElement(@PathParam("username") String username, @FormParam("uri") String uri) { // URI myUri = uri.getBaseUri(); // String id = myUri.toString() + "v2/adapter/all/" + elementId; UserService userService = getUserService(); IPipelineElementDescriptionStorage requestor = getPipelineElementRdfStorage(); logger.info("User " + username + " deletes element with URI: " + uri + " from triplestore"); try { if (requestor.getSEPById(uri) != null) { requestor.deleteSEP(requestor.getSEPById(uri)); userService.deleteOwnSource(username, uri); } else return constructErrorMessage(new Notification(NotificationType.STORAGE_ERROR.title(), NotificationType.STORAGE_ERROR.description())); } catch (URISyntaxException e) { return constructErrorMessage(new Notification(NotificationType.STORAGE_ERROR.title(), NotificationType.STORAGE_ERROR.description())); } return constructSuccessMessage(NotificationType.STORAGE_SUCCESS.uiNotification()); }
protected <T> String toJsonLd(String rootElementUri, T object) { try { return Utils.asString(new JsonLdTransformer(rootElementUri).toJsonLd(object)); } catch (IllegalAccessException | InvocationTargetException | InvalidRdfException | ClassNotFoundException e) { return toJson(constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage()))); } }
protected <T> String toJsonLd(T object) { try { return Utils.asString(new JsonLdTransformer().toJsonLd(object)); } catch (RDFHandlerException | IllegalArgumentException | IllegalAccessException | SecurityException | InvocationTargetException | ClassNotFoundException | InvalidRdfException e) { return toJson(constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage()))); } }
@Path("/update") @POST @Produces(MediaType.APPLICATION_JSON) @GsonWithIds public Response update(org.streampipes.model.client.pipeline.Pipeline pipeline, @PathParam("username") String username) { try { return ok(Operations.validatePipeline(pipeline, true, username)); } catch (JsonSyntaxException e) { return constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage())); } catch (NoMatchingSchemaException e) { return constructErrorMessage(new Notification(NotificationType.NO_VALID_CONNECTION.title(), NotificationType.NO_VALID_CONNECTION.description(), e.getMessage())); } catch (NoMatchingFormatException e) { return constructErrorMessage(new Notification(NotificationType.NO_MATCHING_FORMAT_CONNECTION.title(), NotificationType.NO_MATCHING_FORMAT_CONNECTION.description(), e.getMessage())); } catch (NoMatchingProtocolException e) { return constructErrorMessage(new Notification(NotificationType.NO_MATCHING_PROTOCOL_CONNECTION.title(), NotificationType.NO_MATCHING_PROTOCOL_CONNECTION.description(), e.getMessage())); } catch (RemoteServerNotAccessibleException e) { return constructErrorMessage(new Notification(NotificationType.REMOTE_SERVER_NOT_ACCESSIBLE.title(), NotificationType.REMOTE_SERVER_NOT_ACCESSIBLE.description(), e.getMessage())); } catch (NoMatchingJsonSchemaException e) { return constructErrorMessage(new Notification(NotificationType.REMOTE_SERVER_NOT_ACCESSIBLE.title(), NotificationType.REMOTE_SERVER_NOT_ACCESSIBLE.description(), e.getMessage())); } catch (InvalidConnectionException e) { return ok(e.getErrorLog()); } catch (Exception e) { e.printStackTrace(); return constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage())); } }
@Path("/{id}") @DELETE @Produces(MediaType.APPLICATION_JSON) public Response deleteElement(@PathParam("username") String username, @PathParam("id") String elementId) { UserService userService = getUserService(); IPipelineElementDescriptionStorage requestor = getPipelineElementRdfStorage(); try { if (requestor.getSEPAById(elementId) != null) { requestor.deleteSEPA(requestor.getSEPAById(elementId)); userService.deleteOwnSepa(username, elementId); } else if (requestor.getSEPById(elementId) != null) { requestor.deleteSEP(requestor.getSEPById(elementId)); userService.deleteOwnSource(username, elementId); } else if (requestor.getSECById(elementId) != null) { requestor.deleteSEC(requestor.getSECById(elementId)); userService.deleteOwnAction(username, elementId); } else { return constructErrorMessage(new Notification(NotificationType.STORAGE_ERROR.title(), NotificationType.STORAGE_ERROR.description())); } } catch (URISyntaxException e) { return constructErrorMessage(new Notification(NotificationType.STORAGE_ERROR.title(), NotificationType.STORAGE_ERROR.description())); } return constructSuccessMessage(NotificationType.STORAGE_SUCCESS.uiNotification()); }
@Path("{id}/jsonld") @GET @Produces(MediaType.TEXT_PLAIN) public Response getActionAsJsonLd(@PathParam("id") String elementId) { IPipelineElementDescriptionStorage requestor = getPipelineElementRdfStorage(); elementId = decode(elementId); try { if (requestor.getSEPAById(elementId) != null) { return ok(toJsonLd(requestor.getSEPAById(elementId))); } else if (requestor.getSEPById(elementId) != null) { return ok(toJsonLd(requestor.getSEPById(elementId))); } else if (requestor.getSECById(elementId) != null) { return ok(toJsonLd(requestor.getSECById(elementId))); } else { return ok(Notifications.create(NotificationType.UNKNOWN_ERROR)); } } catch (URISyntaxException e) { return constructErrorMessage(new Notification(NotificationType.UNKNOWN_ERROR.title(), NotificationType.UNKNOWN_ERROR.description(), e.getMessage())); } } }