use of org.mule.runtime.core.internal.message.InternalEvent.Builder in project mule by mulesoft.
the class ModuleFlowProcessingPhase method createEvent.
private CoreEvent createEvent(ModuleFlowProcessingPhaseTemplate template, ComponentLocation sourceLocation, CompletableFuture responseCompletion, FlowConstruct flowConstruct) {
Message message = template.getMessage();
Builder eventBuilder;
if (message.getPayload().getValue() instanceof SourceResultAdapter) {
SourceResultAdapter adapter = (SourceResultAdapter) message.getPayload().getValue();
eventBuilder = createEventBuilder(sourceLocation, responseCompletion, flowConstruct, adapter.getCorrelationId().orElse(null), message);
CoreEvent templateEvent = eventBuilder.build();
final Result<?, ?> result = adapter.getResult();
final Object resultValue = result.getOutput();
if (resultValue instanceof Collection && adapter.isCollection()) {
message = toMessage(Result.<Collection<Message>, TypedValue>builder().output(toMessageCollection((Collection<Result>) resultValue, adapter.getCursorProviderFactory(), templateEvent)).mediaType(result.getMediaType().orElse(ANY)).build());
} else {
message = toMessage(result, adapter.getMediaType(), adapter.getCursorProviderFactory(), templateEvent);
}
return eventBuilder.message(message).build();
}
return createEventBuilder(sourceLocation, responseCompletion, flowConstruct, null, message).build();
}
Aggregations