private CommandSearchResponse searchSingleCommandByDeviceAndId(long id, String deviceId, boolean returnUpdated) { final CommandSearchResponse commandSearchResponse = new CommandSearchResponse(); final List<DeviceCommand> commands = hazelcastService.find(id, deviceId, returnUpdated, DeviceCommand.class) .map(Collections::singletonList) .orElse(Collections.emptyList()); commandSearchResponse.setCommands(commands); return commandSearchResponse; }
public CompletableFuture<Optional<DeviceCommand>> findOne(Long id, String deviceId, boolean returnUpdated) { CommandSearchRequest searchRequest = new CommandSearchRequest(); searchRequest.setId(id); searchRequest.setDeviceIds(Collections.singleton(deviceId)); searchRequest.setReturnUpdated(returnUpdated); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder() .withBody(searchRequest) .build(), new ResponseConsumer(future)); return future.thenApply(r -> r.getBody().cast(CommandSearchResponse.class).getCommands().stream().findFirst()); }
public CompletableFuture<List<DeviceCommand>> find(Collection<String> deviceIds, Collection<String> names, Date timestampSt, Date timestampEnd, String status, String sortField, String sortOrder, Integer take, Integer skip) { CommandSearchRequest searchRequest = new CommandSearchRequest(); searchRequest.setDeviceIds(Sets.newHashSet(deviceIds)); if (names != null) { searchRequest.setNames(Sets.newHashSet(names)); } searchRequest.setTimestampStart(timestampSt); searchRequest.setTimestampEnd(timestampEnd); searchRequest.setStatus(status); searchRequest.setSortField(sortField); searchRequest.setSortOrder(sortOrder); searchRequest.setTake(take); searchRequest.setSkip(skip); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder() .withBody(searchRequest) .withPartitionKey(searchRequest.getDeviceId()) .build(), new ResponseConsumer(future)); // CompletableFuture<Response> => CompletableFuture<List<DeviceCommand>> return future.thenApply(v -> v.getBody().cast(CommandSearchResponse.class).getCommands()); }
private CommandSearchResponse searchMultipleCommands(CommandSearchRequest searchRequest) { final CommandSearchResponse commandSearchResponse = new CommandSearchResponse(); final Collection<DeviceCommand> commands = hazelcastService.find( searchRequest.getDeviceIds(), searchRequest.getNames(), getTotal(searchRequest.getSkip(), searchRequest.getTake()), searchRequest.getTimestampStart(), searchRequest.getTimestampEnd(), searchRequest.isReturnUpdated(), searchRequest.getStatus(), DeviceCommand.class); final Comparator<DeviceCommand> comparator = buildDeviceCommandComparator(searchRequest.getSortField()); String sortOrder = searchRequest.getSortOrder(); final Boolean reverse = sortOrder == null ? null : "desc".equalsIgnoreCase(sortOrder); final List<DeviceCommand> sortedDeviceCommands = orderAndLimit(new ArrayList<>(commands), comparator, reverse, searchRequest.getSkip(), searchRequest.getTake()); commandSearchResponse.setCommands(new ArrayList<>(sortedDeviceCommands)); return commandSearchResponse; }