From 5653d895193e05b30a9d34233c531c680b0c858c Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:55:37 -0700 Subject: [PATCH] Modified readMetadataForMessageLinking query so it doesn't return itself in the results --- .../etor/EtorDomainRegistration.java | 4 ---- .../etor/messages/SendMessageHelper.java | 4 ++++ .../database/DatabasePartnerMetadataStorage.java | 1 + .../localfile/FilePartnerMetadataStorage.java | 4 +++- .../etor/EtorDomainRegistrationTest.groovy | 5 ++--- .../etor/orders/SendOrderUseCaseTest.groovy | 14 ++------------ .../FilePartnerMetadataStorageTest.groovy | 6 ++++-- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java index cd7486bea..cf16fb0ad 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java @@ -231,10 +231,6 @@ DomainResponse handleMetadata(DomainRequest request) { Set messageIdsToLink = partnerMetadataOrchestrator.findMessagesIdsToLink(metadataId); - // Remove the metadataId from the set of messageIdsToLink to avoid showing it in the - // partner metadata's linked ids - messageIdsToLink.remove(metadataId); - FhirMetadata responseObject = partnerMetadataConverter.extractPublicMetadataToOperationOutcome( metadata.get(), metadataId, messageIdsToLink); diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelper.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelper.java index deaa20bdf..20983f086 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelper.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelper.java @@ -70,6 +70,10 @@ public void linkMessage(String receivedSubmissionId) { if (messageIdsToLink == null || messageIdsToLink.isEmpty()) { return; } + + // Add receivedSubmissionId to complete the list of messageIds to link + messageIdsToLink.add(receivedSubmissionId); + logger.logInfo( "Found messages to link for receivedSubmissionId {}: {}", receivedSubmissionId, diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorage.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorage.java index d26be9b1a..0a7a7b74e 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorage.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorage.java @@ -128,6 +128,7 @@ public Set readMetadataForMessageLinking(String submissionId) ON m1.placer_order_number = m2.placer_order_number AND (m1.sending_facility_details = m2.sending_facility_details OR m1.sending_facility_details = m2.receiving_facility_details) + AND m1.received_message_id <> m2.received_message_id WHERE m1.received_message_id = ?; """); statement.setString(1, submissionId); diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorage.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorage.java index cae299061..aeaf138cb 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorage.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorage.java @@ -138,7 +138,9 @@ public Set readMetadataForMessageLinking(String receivedSubmiss || metadata.sendingFacilityDetails() .equals( match - .receivingFacilityDetails()))) + .receivingFacilityDetails())) + && !metadata.receivedSubmissionId() + .equals(receivedSubmissionId)) .collect(Collectors.toSet()); } catch (Exception e) { throw new PartnerMetadataException( diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy index 38f6e9d14..50da04acf 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy @@ -279,8 +279,7 @@ class EtorDomainRegistrationTest extends Specification { def metadata = new PartnerMetadata("receivedSubmissionId", "sender", Instant.now(), null, "hash", PartnerMetadataStatus.DELIVERED, PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number") - def linkedMessageIds = new HashSet<>(Set.of(receivedSubmissionId, "Test1", "Test2")) - def relevantMessageIds = linkedMessageIds.findAll { it != receivedSubmissionId } + def linkedMessageIds = Set.of(receivedSubmissionId, "Test1", "Test2") def connector = new EtorDomainRegistration() TestApplicationContext.register(EtorDomainRegistration, connector) @@ -311,7 +310,7 @@ class EtorDomainRegistrationTest extends Specification { actualStatusCode == expectedStatusCode 1 * mockPartnerMetadataOrchestrator.getMetadata(receivedSubmissionId) >> Optional.ofNullable(metadata) 1 * mockPartnerMetadataOrchestrator.findMessagesIdsToLink(receivedSubmissionId) >> linkedMessageIds - 1 * mockPartnerMetadataConverter.extractPublicMetadataToOperationOutcome(_ as PartnerMetadata, _ as String, relevantMessageIds) >> Mock(FhirMetadata) + 1 * mockPartnerMetadataConverter.extractPublicMetadataToOperationOutcome(_ as PartnerMetadata, _ as String, linkedMessageIds) >> Mock(FhirMetadata) 1 * mockResponseHelper.constructOkResponseFromString(_ as String) >> new DomainResponse(expectedStatusCode) } diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCaseTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCaseTest.groovy index 09675fae4..8ce8aa81e 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCaseTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCaseTest.groovy @@ -36,22 +36,12 @@ class SendOrderUseCaseTest extends Specification { given: def receivedSubmissionId = "receivedId" def sentSubmissionId = "sentId" - def messagesIdsToLink = Set.of("messageId1", "messageId2") + def messagesIdsToLink = new HashSet<>(Set.of("messageId1", "messageId2")) def sendOrder = SendOrderUseCase.getInstance() def mockOrder = new OrderMock(null, null, null, null, null, null, null, null) def mockOmlOrder = Mock(Order) - def partnerMetadata = new PartnerMetadata(receivedSubmissionId, - _ as String, - PartnerMetadataMessageType.ORDER, - mockOrder.getSendingApplicationDetails(), - mockOrder.getSendingFacilityDetails(), - mockOrder.getReceivingApplicationDetails(), - mockOrder.getReceivingFacilityDetails(), - mockOrder.getPlacerOrderNumber() - ) - TestApplicationContext.injectRegisteredImplementations() when: @@ -68,7 +58,7 @@ class SendOrderUseCaseTest extends Specification { 1 * mockOrchestrator.updateMetadataForReceivedMessage(_ as PartnerMetadata) 1 * mockOrchestrator.updateMetadataForSentMessage(receivedSubmissionId, sentSubmissionId) 1 * mockOrchestrator.findMessagesIdsToLink(receivedSubmissionId) >> messagesIdsToLink - 1 * mockOrchestrator.linkMessages(messagesIdsToLink) + 1 * mockOrchestrator.linkMessages(messagesIdsToLink + receivedSubmissionId) } def "send fails to send"() { diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorageTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorageTest.groovy index f3c42d909..b7308ae52 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorageTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorageTest.groovy @@ -145,7 +145,8 @@ class FilePartnerMetadataStorageTest extends Specification { def metadataSetWithMatchingSendingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(receivedSubmissionId1) then: - metadataSetWithMatchingSendingFacilityDetails.containsAll(Set.of(matchingSendingFacilityDetailsMetadata1, otherMatchingSendingFacilityDetailsMetadata1)) + metadataSetWithMatchingSendingFacilityDetails.contains(otherMatchingSendingFacilityDetailsMetadata1) + !metadataSetWithMatchingSendingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata1) when: def receivedSubmissionId2 = "receivedSubmissionId2" @@ -158,7 +159,8 @@ class FilePartnerMetadataStorageTest extends Specification { def metadataSetWithMatchingSendingAndReceivingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(receivedSubmissionId2) then: - metadataSetWithMatchingSendingAndReceivingFacilityDetails.containsAll(Set.of(matchingSendingFacilityDetailsMetadata2, matchingReceivingFacilityDetailsMetadata2)) + metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingReceivingFacilityDetailsMetadata2) + !metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata2) } def "readMetadataForMessageLinking returns an empty set when no metadata is found"() {