private List<org.streampipes.model.ApplicationLink> generateAppLinks() { List<NamedStreamPipesEntity> allElements = new ArrayList<>(); List<org.streampipes.model.ApplicationLink> allApplicationLinks = new ArrayList<>(); allElements.addAll(getPipelineElementRdfStorage() .getAllSEPAs().stream().map(e -> new DataProcessorDescription(e)).collect(Collectors.toList())); allElements.addAll(getPipelineElementRdfStorage() .getAllSECs().stream().map(e -> new DataSinkDescription(e)).collect(Collectors.toList())); allElements.addAll(getPipelineElementRdfStorage() .getAllSEPs().stream().map(e -> new DataSourceDescription(e)).collect(Collectors.toList())); allElements.stream().forEach(e -> allApplicationLinks.addAll(removeDuplicates(allApplicationLinks, e.getApplicationLinks()))); return allApplicationLinks; }
@Override public boolean storeSEPA(DataProcessorDescription sepa) { boolean success = sesameStorage.storeSEPA(sepa); initializeSEPAStorage(); return success; }
@Override protected void update(String username) { storageApi.update(elementDescription); } }
@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()); }
private void initializeSEPStorage() { inMemorySEPStorage.clear(); List<DataSourceDescription> seps = sesameStorage.getAllSEPs(); seps.forEach(sep -> inMemorySEPStorage.put(sep.getElementId(), sep)); seps.forEach(sep -> sep.getSpDataStreams().forEach(eventStream -> inMemoryEventStreamStorage.put(eventStream.getElementId(), eventStream))); }
@POST @Path("/update") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) public Response directUpdate(@PathParam("username") String username, @FormDataParam("config") String config, @FormDataParam("model") String model) { DeploymentConfiguration deploymentConfig = fromJson(config); boolean success; if (deploymentConfig.getElementType().equals("Sepa")) { DataProcessorDescription sepa = GsonSerializer.getGsonWithIds().fromJson(model, DataProcessorDescription.class); success = StorageManager.INSTANCE.getStorageAPI().deleteSEPA(sepa.getElementId()); StorageManager.INSTANCE.getStorageAPI().storeSEPA(sepa); } else { DataSinkDescription sec = new DataSinkDescription(GsonSerializer.getGsonWithIds().fromJson(model, DataSinkDescription.class)); success = StorageManager.INSTANCE.getStorageAPI().update(sec); } if (success) return ok(Notifications.success("Element description updated.")); else return ok(Notifications.error("Could not update element description.")); }
private void initializeSEPAStorage() { inMemorySEPAStorage.clear(); List<DataProcessorDescription> sepas = sesameStorage.getAllSEPAs(); sepas.forEach(sepa -> inMemorySEPAStorage.put(sepa.getElementId(), sepa)); }
private void initializeSECStorage() { inMemorySECStorage.clear(); List<DataSinkDescription> secs = sesameStorage.getAllSECs(); secs.forEach(sec -> inMemorySECStorage.put(sec.getElementId(), sec)); }
public void prepareMonitoring() { StorageManager.INSTANCE.getStorageAPI().getAllSEPAs().forEach(s -> addJob(new SepaMonitoringJob(s))); StorageManager.INSTANCE.getStorageAPI().getAllSECs().forEach(s -> addJob(new SecMonitoringJob(s))); //TODO: add seps StorageManager.INSTANCE.getStorageAPI().getAllSECs().forEach(s -> currentJobs.add(new SecMonitoringJob(s))); } }
@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())); } } }
@Override protected StorageState store(String username, boolean publicElement) { StorageState storageState = StorageState.STORED; if (!storageApi.exists(elementDescription)) storageApi.storeSEPA(elementDescription); else storageState = StorageState.ALREADY_IN_SESAME; if (!(userService.getOwnSepaUris(username).contains(elementDescription.getUri()))) userService.addOwnSepa(username, elementDescription.getUri(), publicElement); else storageState = StorageState.ALREADY_IN_SESAME_AND_USER_DB; return storageState; }
private DataProcessorDescription getProcessor(String id) throws URISyntaxException { return getStorage() .getSEPAById(id); }
private DataSinkDescription getSink(String id) throws URISyntaxException { return getStorage() .getSECById(id); }
@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().deleteOwnSepa(username, elementUri); getPipelineElementRdfStorage().deleteSEPA(getPipelineElementRdfStorage().getSEPAById(elementUri)); } catch (URISyntaxException e) { return constructErrorMessage(Notifications.create(NotificationType.STORAGE_ERROR, e.getMessage())); } return constructSuccessMessage(NotificationType.STORAGE_SUCCESS.uiNotification()); }
@Override public boolean deleteSEP(String rdfId) { boolean success = sesameStorage.deleteSEP(rdfId); initializeSEPStorage(); return success; }
@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()); }
@Override public boolean deleteSEC(String rdfId) { boolean success = sesameStorage.deleteSEC(rdfId); initializeSECStorage(); return success; }
@Override public boolean deleteSEPA(DataProcessorDescription sepa) { boolean success = sesameStorage.deleteSEPA(sepa); initializeSEPAStorage(); return success; }
private void initializeSEPStorage() { inMemorySEPStorage.clear(); List<DataSourceDescription> seps = sesameStorage.getAllSEPs(); seps.forEach(sep -> inMemorySEPStorage.put(sep.getElementId(), sep)); seps.forEach(sep -> sep.getSpDataStreams().forEach(eventStream -> inMemoryEventStreamStorage.put(eventStream.getElementId(), eventStream))); }