public static NotificationSearchRequest createNotificationSearchRequest(JsonObject request) { NotificationSearchRequest notificationSearchRequest = new GsonBuilder() .registerTypeAdapter(Date.class, new TimestampAdapter()) .excludeFieldsWithModifiers(Modifier.PROTECTED) .create() .fromJson(request, NotificationSearchRequest.class); notificationSearchRequest.setTake(Optional.ofNullable(notificationSearchRequest.getTake()).orElse(DEFAULT_TAKE)); notificationSearchRequest.setSkip(Optional.ofNullable(notificationSearchRequest.getSkip()).orElse(DEFAULT_SKIP)); if (CollectionUtils.isEmpty(notificationSearchRequest.getDeviceIds())) { Optional.ofNullable(request.get(DEVICE_ID)).map(JsonElement::getAsString).ifPresent(deviceId -> { notificationSearchRequest.setDeviceIds(Collections.singleton(deviceId)); }); } if (CollectionUtils.isEmpty(notificationSearchRequest.getNames())) { Optional.ofNullable(request.get(NOTIFICATION)).map(JsonElement::getAsString).ifPresent(notification -> { notificationSearchRequest.setNames(Collections.singleton(notification)); }); } return notificationSearchRequest; }
private NotificationSearchResponse searchMultipleNotifications(NotificationSearchRequest searchRequest) { //TODO [rafa] has response is quite bad, instead we should separate command and reply into two separate collections. final Collection<DeviceNotification> notifications = hazelcastService.find( searchRequest.getDeviceIds(), searchRequest.getNames(), getTotal(searchRequest.getSkip(), searchRequest.getTake()), searchRequest.getTimestampStart(), searchRequest.getTimestampEnd(), false, null, DeviceNotification.class); final Comparator<DeviceNotification> comparator = buildDeviceNotificationComparator(searchRequest.getSortField()); String sortOrder = searchRequest.getSortOrder(); final Boolean reverse = sortOrder == null ? null : "desc".equalsIgnoreCase(sortOrder); final List<DeviceNotification> sortedDeviceNotifications = orderAndLimit(new ArrayList<>(notifications), comparator, reverse, searchRequest.getSkip(), searchRequest.getTake()); return new NotificationSearchResponse(new ArrayList<>(sortedDeviceNotifications)); }
public CompletableFuture<List<DeviceNotification>> find(NotificationSearchRequest request) { return find(request.getDeviceIds(), request.getNames(), request.getTimestampStart(), request.getTimestampEnd(), request.getSortField(), request.getSortOrder(), request.getTake(), request.getSkip()); }