diff --git a/src/main/java/it/pagopa/pn/paperchannel/middleware/db/dao/impl/PaperRequestErrorDAOImpl.java b/src/main/java/it/pagopa/pn/paperchannel/middleware/db/dao/impl/PaperRequestErrorDAOImpl.java index ffe2eb3fc..d12e437f4 100644 --- a/src/main/java/it/pagopa/pn/paperchannel/middleware/db/dao/impl/PaperRequestErrorDAOImpl.java +++ b/src/main/java/it/pagopa/pn/paperchannel/middleware/db/dao/impl/PaperRequestErrorDAOImpl.java @@ -1,17 +1,12 @@ package it.pagopa.pn.paperchannel.middleware.db.dao.impl; import it.pagopa.pn.paperchannel.config.AwsPropertiesConfig; -import it.pagopa.pn.paperchannel.encryption.DataEncryption; -import it.pagopa.pn.paperchannel.generated.openapi.server.v1.dto.InfoDownloadDTO; import it.pagopa.pn.paperchannel.middleware.db.dao.PaperRequestErrorDAO; import it.pagopa.pn.paperchannel.middleware.db.dao.common.BaseDAO; import it.pagopa.pn.paperchannel.middleware.db.entities.PnRequestError; import it.pagopa.pn.paperchannel.utils.Const; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient; import software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional; diff --git a/src/main/java/it/pagopa/pn/paperchannel/middleware/queue/consumer/handler/NotRetryableErrorMessageHandler.java b/src/main/java/it/pagopa/pn/paperchannel/middleware/queue/consumer/handler/NotRetryableErrorMessageHandler.java index 49674c6d0..96c7fa073 100644 --- a/src/main/java/it/pagopa/pn/paperchannel/middleware/queue/consumer/handler/NotRetryableErrorMessageHandler.java +++ b/src/main/java/it/pagopa/pn/paperchannel/middleware/queue/consumer/handler/NotRetryableErrorMessageHandler.java @@ -8,6 +8,7 @@ import it.pagopa.pn.paperchannel.utils.PnLogAudit; import reactor.core.publisher.Mono; + public class NotRetryableErrorMessageHandler extends SendToDeliveryPushHandler { private final PaperRequestErrorDAO paperRequestErrorDAO; @@ -22,14 +23,16 @@ public Mono handleMessage(PnDeliveryRequest entity, PaperProgressStatusEve PnAuditLogBuilder auditLogBuilder = new PnAuditLogBuilder(); PnLogAudit pnLogAudit = new PnLogAudit(auditLogBuilder); pnLogAudit.addsBeforeDiscard(entity.getIun(), String.format("requestId = %s finish retry to External Channel", entity.getRequestId())); - return super.handleMessage(entity, paperRequest) - .doOnSuccess(pnRequestError -> { - paperRequestErrorDAO.created(entity.getRequestId(), entity.getStatusCode(), entity.getStatusDetail()); - pnLogAudit.addsSuccessDiscard(entity.getIun(), String.format("requestId = %s finish retry to External Channel", entity.getRequestId())); - }) + .then(Mono.defer(() -> + paperRequestErrorDAO.created(entity.getRequestId(), entity.getStatusCode(), entity.getStatusDetail()) + .doOnSuccess(requestError -> + pnLogAudit.addsSuccessDiscard(entity.getIun(), String.format("requestId = %s finish retry to External Channel", entity.getRequestId())) + ) + )) .doOnError(throwable -> pnLogAudit.addsFailDiscard(entity.getIun(), String.format("requestId = %s finish retry to External Channel", entity.getRequestId()))) .then(); + } } diff --git a/src/test/java/it/pagopa/pn/paperchannel/middleware/queue/consumer/handler/NotRetryableErrorMessageHandlerTest.java b/src/test/java/it/pagopa/pn/paperchannel/middleware/queue/consumer/handler/NotRetryableErrorMessageHandlerTest.java index da46e48d8..2dda8fe6b 100644 --- a/src/test/java/it/pagopa/pn/paperchannel/middleware/queue/consumer/handler/NotRetryableErrorMessageHandlerTest.java +++ b/src/test/java/it/pagopa/pn/paperchannel/middleware/queue/consumer/handler/NotRetryableErrorMessageHandlerTest.java @@ -8,6 +8,7 @@ import it.pagopa.pn.paperchannel.service.SqsSender; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import reactor.core.publisher.Mono; import java.time.OffsetDateTime; @@ -42,7 +43,7 @@ void handleMessageTest() { .statusDateTime(instant) .clientRequestTimeStamp(instant); - when(paperRequestErrorDAOMock.created("requestId", "statusCode", "statusDetails")) + when(paperRequestErrorDAOMock.created(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(new PnRequestError())); assertDoesNotThrow(() -> handler.handleMessage(entity, paperRequest).block());