private Response removeNotificationSubscription(PluginUnsubscribeRequest body) { NotificationUnsubscribeRequest notificationUnsubscribeRequest = new NotificationUnsubscribeRequest(ImmutableSet.of(body.getSubscriptionId())); Request notificationRequest = Request.newBuilder() .withBody(notificationUnsubscribeRequest) .withSingleReply(false) .build(); notificationRequest.setReplyTo(body.getTopicName()); return notificationUnsubscribeRequestHandler.handle(notificationRequest); }
private void validate(PluginUnsubscribeRequest request) { Assert.notNull(request, "Request body is null"); Assert.notNull(request.getSubscriptionId(), "Subscription id not provided"); }
@Transactional public CompletableFuture<Response> delete(PluginVO existingPlugin) { pluginService.delete(existingPlugin.getId()); CompletableFuture<com.devicehive.shim.api.Response> future = new CompletableFuture<>(); if (existingPlugin.getSubscriptionId() != null) { PluginUnsubscribeRequest request = new PluginUnsubscribeRequest(existingPlugin.getSubscriptionId(), existingPlugin.getTopicName()); rpcClient.call(Request.newBuilder() .withBody(request) .build(), new ResponseConsumer(future)); return future.thenApply(response -> ResponseFactory.response(NO_CONTENT)); } else { return CompletableFuture.completedFuture(ResponseFactory.response(NO_CONTENT)); } }
@Override public Response handle(Request request) { PluginUnsubscribeRequest body = (PluginUnsubscribeRequest) request.getBody(); validate(body); removeCommandSubscription(body); removeNotificationSubscription(body); return Response.newBuilder() .withBody(new PluginUnsubscribeResponse(body.getSubscriptionId())) .withLast(false) .withCorrelationId(request.getCorrelationId()) .buildSuccess(); }
request = new PluginUnsubscribeRequest(existingPlugin.getSubscriptionId(), existingPlugin.getTopicName()); existingPlugin.setSubscriptionId(null);
private Response removeCommandSubscription(PluginUnsubscribeRequest body) { CommandUnsubscribeRequest commandUnsubscribeRequest = new CommandUnsubscribeRequest(ImmutableSet.of(body.getSubscriptionId())); Request commandRequest = Request.newBuilder() .withBody(commandUnsubscribeRequest) .withSingleReply(false) .build(); commandRequest.setReplyTo(body.getTopicName()); return commandUnsubscribeRequestHandler.handle(commandRequest); }