/** * Set a Multipart Form url encoded body to this request saving it as a raw body. * * @param data the multipart-form parameters * @param temporaryFileCreator the temporary file creator. * @param mat a Akka Streams Materializer * @return the modified builder */ public RequestBuilder bodyRaw(List<MultipartFormData.Part<Source<ByteString, ?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat) { String boundary = MultipartFormatter.randomBoundary(); try { ByteString materializedData = MultipartFormatter .transform(Source.from(data), boundary) .runWith(Sink.reduce(ByteString::concat), mat) .toCompletableFuture() .get(); play.api.mvc.RawBuffer buffer = new play.api.mvc.RawBuffer(materializedData.size(), temporaryFileCreator.asScala(), materializedData); return body(new RequestBody(JavaParsers.toJavaRaw(buffer)), MultipartFormatter.boundaryToContentType(boundary)); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException("Failure while materializing Multipart/Form Data", e); } }
/** * Set a Multipart Form url encoded body to this request saving it as a raw body. * * @param data the multipart-form parameters * @param temporaryFileCreator the temporary file creator. * @param mat a Akka Streams Materializer * @return the modified builder */ public RequestBuilder bodyRaw(List<MultipartFormData.Part<Source<ByteString, ?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat) { String boundary = MultipartFormatter.randomBoundary(); try { ByteString materializedData = MultipartFormatter .transform(Source.from(data), boundary) .runWith(Sink.reduce(ByteString::concat), mat) .toCompletableFuture() .get(); play.api.mvc.RawBuffer buffer = new play.api.mvc.RawBuffer(materializedData.size(), temporaryFileCreator.asScala(), materializedData); return body(new RequestBody(JavaParsers.toJavaRaw(buffer)), MultipartFormatter.boundaryToContentType(boundary)); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException("Failure while materializing Multipart/Form Data", e); } }
/** * Set a Multipart Form url encoded body to this request saving it as a raw body. * * @param data the multipart-form parameters * @param temporaryFileCreator the temporary file creator. * @param mat a Akka Streams Materializer * @return the modified builder */ public RequestBuilder bodyRaw(List<MultipartFormData.Part<Source<ByteString, ?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat) { String boundary = MultipartFormatter.randomBoundary(); try { ByteString materializedData = MultipartFormatter .transform(Source.from(data), boundary) .runWith(Sink.reduce(ByteString::concat), mat) .toCompletableFuture() .get(); play.api.mvc.RawBuffer buffer = new play.api.mvc.RawBuffer(materializedData.size(), temporaryFileCreator.asScala(), materializedData); return body(new RequestBody(JavaParsers.toJavaRaw(buffer)), MultipartFormatter.boundaryToContentType(boundary)); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException("Failure while materializing Multipart/Form Data", e); } }
/** * Purge namespaces from some persistent storage. * * @param namespaceDescriptors storage-specific identifiers to describe namespaces. * @return source of any errors during the purge. */ default Source<List<Throwable>, NotUsed> purgeAll(final Collection<S> namespaceDescriptors) { return Source.from(namespaceDescriptors) .flatMapConcat(this::purge) .grouped(namespaceDescriptors.size()) .map(errors -> errors.stream() .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList())); }
private Source<Success, NotUsed> dropIndices(final String collectionName, final List<String> indices) { if (indices.isEmpty()) { return Source.empty(); } return Source.from(indices) .flatMapConcat(index -> dropIndex(collectionName, index)); }
private Source<Success, NotUsed> createIndices(final String collectionName, final List<Index> indices) { if (indices.isEmpty()) { return Source.empty(); } return Source.from(indices) .flatMapConcat(index -> createIndex(collectionName, index)); }
private Source<Success, NotUsed> createIndices(final String collectionName, final List<Index> indices) { if (indices.isEmpty()) { return Source.empty(); } return Source.from(indices) .flatMapConcat(index -> createIndex(collectionName, index)); }
private Source<Success, NotUsed> dropIndices(final String collectionName, final List<String> indices) { if (indices.isEmpty()) { return Source.empty(); } return Source.from(indices) .flatMapConcat(index -> dropIndex(collectionName, index)); }
private void retrieveThingsAndSendResult(final List<String> thingIds, @Nullable final JsonFieldSelector selectedFields, final Command<?> command, final ActorRef resultReceiver) { final DittoHeaders dittoHeaders = command.getDittoHeaders(); final CompletionStage<?> commandResponseSource = Source.from(thingIds) .filter(Objects::nonNull) .filterNot(String::isEmpty) .filter(thingId -> THING_ID_PATTERN.matcher(thingId).matches()) .map(thingId -> { final Command<?> toBeWrapped; if (command instanceof RetrieveThings) { toBeWrapped = Optional.ofNullable(selectedFields) .map(sf -> RetrieveThing.getBuilder(thingId, dittoHeaders) .withSelectedFields(sf) .build()) .orElse(RetrieveThing.of(thingId, dittoHeaders)); } else { toBeWrapped = Optional.ofNullable(selectedFields) .map(sf -> SudoRetrieveThing.of(thingId, sf, dittoHeaders)) .orElse(SudoRetrieveThing.of(thingId, dittoHeaders)); } return ConciergeWrapper.wrapForEnforcer(toBeWrapped); }) .ask(calculateParallelism(thingIds), targetActor, Jsonifiable.class, Timeout.apply(retrieveSingleThingTimeout.toMillis(), TimeUnit.MILLISECONDS)) .log("command-response", log) .runWith(StreamRefs.sourceRef(), actorMaterializer); PatternsCS.pipe(commandResponseSource, aggregatorDispatcher) .to(resultReceiver); }