Advertisement
jamescpp

Untitled

Apr 13th, 2020
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.04 KB | None | 0 0
  1.   @Override
  2.   public CompletableFuture<Map<DeviceId, Optional<Map<String, String>>>>
  3.       getMultipleDeviceLastKnownCategoriesInfo(
  4.           Set<UserId> userIds, Set<DeviceId> deviceIds, TracingContext tracingContext) {
  5.     logger.debug(
  6.         tracingContext,
  7.         "LastKnownService -> getting getUsersLastKnowns for userIds {}",
  8.         userIds.stream().map(UserId::value).collect(Collectors.joining(",")));
  9.  
  10.     final CompletableFuture<Map<DeviceId, Optional<Map<String, String>>>> resultFuture =
  11.         new CompletableFuture<>();
  12.  
  13.     final List<String> userIdsParams =
  14.         userIds.stream().map(UserId::value).collect(Collectors.toList());
  15.     final CSVParams categories = new CSVParams(WANTED_CATEGORIES);
  16.     final Call<UsersLastKnownsInternal> call =
  17.         lastKnownApi.getUsersLastKnowns(
  18.             userIdsParams, categories, tracingContext.getCorrelationId().getValue());
  19.  
  20.     enqueue(
  21.         call,
  22.         tracingContext,
  23.         handleResultWith404(
  24.             resultFuture,
  25.             true,
  26.             result ->
  27.                 Optional.ofNullable(result)
  28.                     .map(
  29.                         r ->
  30.                             r.getUsers().stream()
  31.                                 .flatMap(item -> item.getDevices().stream())
  32.                                 .collect(
  33.                                     JavaUtils.collectMapAndAddMissing(
  34.                                         deviceIds,
  35.                                         d -> DeviceId.create(d.getDeviceId()),
  36.                                         d ->
  37.                                             d.getLastKnowns().stream()
  38.                                                 .collect(
  39.                                                     Collectors.toMap(
  40.                                                         LastKnownInternal::getCategory,
  41.                                                         LastKnownInternal::getInfo)))))
  42.                     .orElse(Collections.emptyMap()),
  43.             tracingContext));
  44.     return resultFuture;
  45.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement