Override public Optional<MessageExchange> getMessageByOperationId(String operationId) {…
Private research annotation
Sign in to add a private research label or note.
- User
Override public Optional getMessageByOperationId(String operationId) { String correlationId = messagePersistencePort.findMessageByOperationId(operationId) .map(Message::getCorrelationId) .orElse((x) -> { log.warn("Swift not found for operationId=" + operationId); })
codereturn apiMessageExchangePort.getMessageByCorrelationId(correlationId) .orElse(() -> { log.warn("API Exchange returned no message for operationId={}", operationId); return Optional.empty(); }); } Assistant
Here's the corrected version of the method:
java@Override public Optional<MessageExchange> getMessageByOperationId(String operationId) { String correlationId = messagePersistencePort.findMessageByOperationId(operationId) .map(Message::getCorrelationId) .orElseGet(() -> { log.warn("Swift not found for operationId={}", operationId); return null; }); if (correlationId == null) { return Optional.empty(); } return apiMessageExchangePort.getMessageByCorrelationId(correlationId) .map(Optional::of) .orElseGet(() -> { log.warn("API Exchange returned no message for operationId={}", operationId); return Optional.empty(); }); }- User
le .or() ne fonctionne pas
Assistant
Voici la correction avec
.or()qui est disponible depuis Java 9 :java@Override public Optional<MessageExchange> getMessageByOperationId(String operationId) { String correlationId = messagePersistencePort.findMessageByOperationId(operationId) .map(Message::getCorrelationId) .orElseGet(() -> { log.warn("Swift not found for operationId={}", operationId); return null; }); if (correlationId == null) { return Optional.empty(); } Optional<MessageExchange> result = apiMessageExchangePort.getMessageByCorrelationId(correlationId); if (result.isEmpty()) { log.warn("API Exchange returned no message for operationId={}", operationId); } return result; }- User
getMessageByCorrelationId retourne des Either donc adapte ton code avec vavr
Assistant
Voici le code adapté avec Vavr :
java@Override public Optional<MessageExchange> getMessageByOperationId(String operationId) { String correlationId = messagePersistencePort.findMessageByOperationId(operationId) .map(Message::getCorrelationId) .orElseGet(() -> { log.warn("Swift not found for operationId={}", operationId); return null; }); if (correlationId == null) { return Optional.empty(); } return apiMessageExchangePort.getMessageByCorrelationId(correlationId) .fold( left -> { log.warn("API Exchange returned no message for operationId={}", operationId); return Optional.empty(); }, right -> Optional.of(right) ); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.