Skip to content

Commit

Permalink
[PRMT-4727] Added functionality to store FailureReason in DynamoDB.
Browse files Browse the repository at this point in the history
Signed-off-by: martin-nhs <[email protected]>
  • Loading branch information
martin-nhs committed Apr 8, 2024
1 parent 050496f commit 648a976
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import software.amazon.awssdk.services.dynamodb.model.*;
import uk.nhs.prm.repo.ehrtransferservice.config.AppConfig;
import uk.nhs.prm.repo.ehrtransferservice.database.enumeration.ConversationTransferStatus;
import uk.nhs.prm.repo.ehrtransferservice.database.enumeration.FailureReason;
import uk.nhs.prm.repo.ehrtransferservice.database.model.ConversationRecord;
import uk.nhs.prm.repo.ehrtransferservice.exceptions.FailedToPersistException;
import uk.nhs.prm.repo.ehrtransferservice.exceptions.database.ConversationAlreadyPresentException;
Expand Down Expand Up @@ -176,7 +177,7 @@ void updateConversationStatus(UUID inboundConversationId, ConversationTransferSt
}
}

void updateConversationStatusWithFailure(UUID inboundConversationId, String failureCode) {
void updateConversationStatusWithFailure(UUID inboundConversationId, String failureCode, FailureReason failureReason) {
if(!isInboundConversationPresent(inboundConversationId)) {
throw new ConversationUpdateException(inboundConversationId);
}
Expand All @@ -199,6 +200,11 @@ void updateConversationStatusWithFailure(UUID inboundConversationId, String fail
.action(AttributeAction.PUT)
.build());

updateItems.put(FAILURE_REASON.name, AttributeValueUpdate.builder()
.value(AttributeValue.builder().s(failureReason.reason).build())
.action(AttributeAction.ADD)
.build());

updateItems.put(FAILURE_CODE.name, AttributeValueUpdate.builder()
.value(AttributeValue.builder().s(failureCode).build())
.action(AttributeAction.PUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import uk.nhs.prm.repo.ehrtransferservice.database.enumeration.ConversationTransferStatus;
import uk.nhs.prm.repo.ehrtransferservice.database.enumeration.FailureReason;
import uk.nhs.prm.repo.ehrtransferservice.database.model.ConversationRecord;
import uk.nhs.prm.repo.ehrtransferservice.exceptions.base.DatabaseException;
import uk.nhs.prm.repo.ehrtransferservice.repo_incoming.RepoIncomingEvent;
Expand Down Expand Up @@ -67,10 +68,10 @@ public void updateConversationTransferStatus(UUID inboundConversationId, Convers
inboundConversationId, conversationTransferStatus.name());
}

public void updateConversationTransferStatusWithFailure(UUID inboundConversationId, String failureCode) {
transferRepository.updateConversationStatusWithFailure(inboundConversationId, failureCode);
log.info("Updated conversation record with Inbound Conversation ID {} to {}, with failure code {}",
inboundConversationId, INBOUND_FAILED.name(), failureCode);
public void updateConversationTransferStatusWithFailure(UUID inboundConversationId, String failureCode, FailureReason failureReason) {
transferRepository.updateConversationStatusWithFailure(inboundConversationId, failureCode, failureReason);
log.info("Updated conversation record with Inbound Conversation ID {} to {} - with failure code {} and reason {}",
inboundConversationId, INBOUND_FAILED.name(), failureCode, failureReason);
}

public UUID getEhrCoreInboundMessageIdForInboundConversationId(UUID inboundConversationId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum TransferTableAttribute {
DESTINATION_GP("DestinationGp"),
TRANSFER_STATUS("TransferStatus"),
FAILURE_CODE("FailureCode"),
FAILURE_REASON("FailureReason"),
INBOUND_MESSAGE_ID("InboundMessageId"),
NEMS_MESSAGE_ID("NemsMessageId"),
CREATED_AT("CreatedAt"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.UUID;

import static uk.nhs.prm.repo.ehrtransferservice.database.enumeration.ConversationTransferStatus.INBOUND_FAILED;
import static uk.nhs.prm.repo.ehrtransferservice.database.enumeration.FailureReason.NEGATIVE_ACKNOWLEDGEMENT_RECEIVED;

@Slf4j
@Service
Expand All @@ -29,7 +30,8 @@ public void handleMessage(Acknowledgement acknowledgement) {

transferService.updateConversationTransferStatusWithFailure(
inboundConversationId,
getFailureCodeForDb(acknowledgement)
getFailureCodeForDb(acknowledgement),
NEGATIVE_ACKNOWLEDGEMENT_RECEIVED
);

auditService.publishAuditMessage(inboundConversationId, INBOUND_FAILED, nemsMessageId);
Expand Down

0 comments on commit 648a976

Please sign in to comment.