From 4b9609156d8d306616d7e21853d6a65a1ceb2e8f Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Wed, 20 Nov 2024 16:24:38 -0700 Subject: [PATCH 01/10] rename any received message or submission id to inboundReportId --- .../etor/EtorDomainRegistration.java | 23 ++-- .../etor/messages/MessageRequestHandler.java | 4 +- .../etor/messages/SendMessageHelper.java | 39 +++--- .../metadata/partner/PartnerMetadata.java | 22 ++-- .../partner/PartnerMetadataOrchestrator.java | 29 ++--- .../partner/PartnerMetadataStorage.java | 5 +- .../etor/orders/SendOrderUseCase.java | 8 +- .../etor/results/SendResultUseCase.java | 8 +- .../DatabasePartnerMetadataStorage.java | 20 +-- .../hapi/HapiPartnerMetadataConverter.java | 2 +- .../localfile/FilePartnerMetadataStorage.java | 30 ++--- etor/src/main/resources/openapi_etor.yaml | 2 +- .../etor/EtorDomainRegistrationTest.groovy | 22 ++-- .../messages/SendMessageHelperTest.groovy | 22 ++-- .../PartnerMetadataOrchestratorTest.groovy | 122 +++++++++--------- .../partner/PartnerMetadataTest.groovy | 32 ++--- .../etor/orders/SendOrderUseCaseTest.groovy | 24 ++-- .../etor/results/SendResultUseCaseTest.groovy | 18 +-- .../DatabasePartnerMetadataStorageTest.groovy | 26 ++-- .../hapi/HapiMetadataConverterTest.groovy | 8 +- .../FilePartnerMetadataStorageTest.groovy | 28 ++-- 21 files changed, 241 insertions(+), 253 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 eb5c648cf..4dbdf6bb3 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 @@ -153,9 +153,9 @@ public String openApiSpecification() throws UnableToReadOpenApiSpecificationExce DomainResponse handleOrders(DomainRequest request) { return handleMessageRequest( request, - receivedSubmissionId -> { + inboundReportId -> { Order orders = orderController.parseOrders(request); - sendOrderUseCase.convertAndSend(orders, receivedSubmissionId); + sendOrderUseCase.convertAndSend(orders, inboundReportId); return domainResponseHelper.constructOkResponse(new OrderResponse(orders)); }, "order"); @@ -164,9 +164,9 @@ DomainResponse handleOrders(DomainRequest request) { DomainResponse handleResults(DomainRequest request) { return handleMessageRequest( request, - receivedSubmissionId -> { + inboundReportId -> { Result results = resultController.parseResults(request); - sendResultUseCase.convertAndSend(results, receivedSubmissionId); + sendResultUseCase.convertAndSend(results, inboundReportId); return domainResponseHelper.constructOkResponse(new ResultResponse(results)); }, "results"); @@ -186,8 +186,7 @@ DomainResponse handleMetadata(DomainRequest request) { var metadata = metadataOptional.get(); Set messageIdsToLink = - partnerMetadataOrchestrator.findMessagesIdsToLink( - metadata.receivedSubmissionId()); + partnerMetadataOrchestrator.findMessagesIdsToLink(metadata.inboundReportId()); FhirMetadata responseObject = partnerMetadataConverter.extractPublicMetadataToOperationOutcome( @@ -223,12 +222,12 @@ protected DomainResponse handleMessageRequest( DomainRequest request, MessageRequestHandler requestHandler, String messageType) { - String receivedSubmissionId = getReceivedSubmissionId(request); + String inboundReportId = getReceivedSubmissionId(request); boolean markMetadataAsFailed = false; String errorMessage = ""; try { - return requestHandler.handle(receivedSubmissionId); + return requestHandler.handle(inboundReportId); } catch (FhirParseException e) { errorMessage = "Unable to parse " + messageType + " request"; logger.logError(errorMessage, e); @@ -243,7 +242,7 @@ protected DomainResponse handleMessageRequest( if (markMetadataAsFailed) { try { partnerMetadataOrchestrator.setMetadataStatusToFailed( - receivedSubmissionId, errorMessage); + inboundReportId, errorMessage); } catch (PartnerMetadataException innerE) { logger.logError("Unable to update metadata status", innerE); } @@ -253,11 +252,11 @@ protected DomainResponse handleMessageRequest( protected String getReceivedSubmissionId(DomainRequest request) { - String receivedSubmissionId = request.getHeaders().get("recordid"); - if (receivedSubmissionId == null || receivedSubmissionId.isEmpty()) { + String inboundReportId = request.getHeaders().get("recordid"); + if (inboundReportId == null || inboundReportId.isEmpty()) { logger.logError("Missing required header or empty: RecordId"); return null; } - return receivedSubmissionId; + return inboundReportId; } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/MessageRequestHandler.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/MessageRequestHandler.java index 640c33ac0..a96c050db 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/MessageRequestHandler.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/MessageRequestHandler.java @@ -12,10 +12,10 @@ public interface MessageRequestHandler { /** * Parses the request, converts and sends the message * - * @param receivedSubmissionId the ID for the submission returned from ReportStream + * @param inboundReportId the ID for the report returned from ReportStream * @return the response * @throws FhirParseException if there is an error parsing the FHIR data * @throws UnableToSendMessageException if there is an error sending the message */ - T handle(String receivedSubmissionId) throws FhirParseException, UnableToSendMessageException; + T handle(String inboundReportId) throws FhirParseException, UnableToSendMessageException; } 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 20983f086..ce7de9ccc 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 @@ -22,66 +22,65 @@ public static SendMessageHelper getInstance() { private SendMessageHelper() {} public void savePartnerMetadataForReceivedMessage(PartnerMetadata partnerMetadata) { - if (partnerMetadata.receivedSubmissionId() == null) { + if (partnerMetadata.inboundReportId() == null) { logger.logWarning( - "Received submissionId is null so not saving metadata for received message"); + "Inbound reportId is null so not saving metadata for received message"); return; } try { partnerMetadataOrchestrator.updateMetadataForReceivedMessage(partnerMetadata); } catch (PartnerMetadataException e) { logger.logError( - "Unable to save metadata for receivedSubmissionId " - + partnerMetadata.receivedSubmissionId(), + "Unable to save metadata for inboundReportId " + + partnerMetadata.inboundReportId(), e); } } - public void saveSentMessageSubmissionId(String receivedSubmissionId, String sentSubmissionId) { - if (sentSubmissionId == null || receivedSubmissionId == null) { + public void saveSentMessageSubmissionId(String inboundReportId, String sentSubmissionId) { + if (sentSubmissionId == null || inboundReportId == null) { logger.logWarning( - "Received and/or sent submissionId is null so not saving metadata for sent result"); + "Inbound and/or sent reportId is null so not saving metadata for sent result"); return; } try { partnerMetadataOrchestrator.updateMetadataForSentMessage( - receivedSubmissionId, sentSubmissionId); + inboundReportId, sentSubmissionId); } catch (PartnerMetadataException e) { logger.logError( - "Unable to update metadata for received submissionId " - + receivedSubmissionId + "Unable to update metadata for inbound reportId " + + inboundReportId + " and sent submissionId " + sentSubmissionId, e); } } - public void linkMessage(String receivedSubmissionId) { - if (receivedSubmissionId == null) { - logger.logWarning("Received submissionId is null so not linking messages"); + public void linkMessage(String inboundReportId) { + if (inboundReportId == null) { + logger.logWarning("Inbound reportId is null so not linking messages"); return; } try { Set messageIdsToLink = - partnerMetadataOrchestrator.findMessagesIdsToLink(receivedSubmissionId); + partnerMetadataOrchestrator.findMessagesIdsToLink(inboundReportId); if (messageIdsToLink == null || messageIdsToLink.isEmpty()) { return; } - // Add receivedSubmissionId to complete the list of messageIds to link - messageIdsToLink.add(receivedSubmissionId); + // Add inboundReportId to complete the list of messageIds to link + messageIdsToLink.add(inboundReportId); logger.logInfo( - "Found messages to link for receivedSubmissionId {}: {}", - receivedSubmissionId, + "Found messages to link for inboundReportId {}: {}", + inboundReportId, messageIdsToLink); partnerMetadataOrchestrator.linkMessages(messageIdsToLink); } catch (PartnerMetadataException | MessageLinkException e) { - logger.logError( - "Unable to link messages for received submissionId " + receivedSubmissionId, e); + logger.logError("Unable to link messages for inbound reportId " + inboundReportId, e); } } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadata.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadata.java index 14bbe2206..2f3264f84 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadata.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadata.java @@ -6,7 +6,7 @@ /** * The partner-facing metadata. * - * @param receivedSubmissionId The received submission ID. + * @param inboundReportId The inbound report ID. * @param sentSubmissionId The sent submission ID. * @param timeReceived The time the message was received. * @param timeDelivered The time the message was delivered. @@ -14,7 +14,7 @@ * @param deliveryStatus the status of the message based on an enum */ public record PartnerMetadata( - String receivedSubmissionId, + String inboundReportId, String sentSubmissionId, Instant timeReceived, Instant timeDelivered, @@ -36,7 +36,7 @@ public record PartnerMetadata( } public PartnerMetadata( - String receivedSubmissionId, + String inboundReportId, String hash, PartnerMetadataMessageType messageType, MessageHdDataType sendingApplicationDetails, @@ -45,7 +45,7 @@ public PartnerMetadata( MessageHdDataType receivingFacilityDetails, String placerOrderNumber) { this( - receivedSubmissionId, + inboundReportId, null, null, null, @@ -60,9 +60,9 @@ public PartnerMetadata( placerOrderNumber); } - public PartnerMetadata(String receivedSubmissionId, PartnerMetadataStatus deliveryStatus) { + public PartnerMetadata(String inboundReportId, PartnerMetadataStatus deliveryStatus) { this( - receivedSubmissionId, + inboundReportId, null, null, null, @@ -79,7 +79,7 @@ public PartnerMetadata(String receivedSubmissionId, PartnerMetadataStatus delive public PartnerMetadata withSentSubmissionId(String sentSubmissionId) { return new PartnerMetadata( - this.receivedSubmissionId, + this.inboundReportId, sentSubmissionId, this.timeReceived, this.timeDelivered, @@ -96,7 +96,7 @@ public PartnerMetadata withSentSubmissionId(String sentSubmissionId) { public PartnerMetadata withTimeReceived(Instant timeReceived) { return new PartnerMetadata( - this.receivedSubmissionId, + this.inboundReportId, this.sentSubmissionId, timeReceived, this.timeDelivered, @@ -113,7 +113,7 @@ public PartnerMetadata withTimeReceived(Instant timeReceived) { public PartnerMetadata withTimeDelivered(Instant timeDelivered) { return new PartnerMetadata( - this.receivedSubmissionId, + this.inboundReportId, this.sentSubmissionId, this.timeReceived, timeDelivered, @@ -130,7 +130,7 @@ public PartnerMetadata withTimeDelivered(Instant timeDelivered) { public PartnerMetadata withDeliveryStatus(PartnerMetadataStatus deliveryStatus) { return new PartnerMetadata( - this.receivedSubmissionId, + this.inboundReportId, this.sentSubmissionId, this.timeReceived, this.timeDelivered, @@ -147,7 +147,7 @@ public PartnerMetadata withDeliveryStatus(PartnerMetadataStatus deliveryStatus) public PartnerMetadata withFailureMessage(String failureMessage) { return new PartnerMetadata( - this.receivedSubmissionId, + this.inboundReportId, this.sentSubmissionId, this.timeReceived, this.timeDelivered, diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java index 80dce9132..32131c788 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java @@ -45,15 +45,15 @@ public void updateMetadataForReceivedMessage(PartnerMetadata partnerMetadata) throws PartnerMetadataException { logger.logInfo( - "Looking up sender name and timeReceived from RS delivery API for receivedSubmissionId: {}", - partnerMetadata.receivedSubmissionId()); + "Looking up sender name and timeReceived from RS delivery API for inboundReportId: {}", + partnerMetadata.inboundReportId()); Instant timeReceived; try { String bearerToken = rsclient.getRsToken(); String responseBody = rsclient.requestDeliveryEndpoint( - partnerMetadata.receivedSubmissionId(), bearerToken); + partnerMetadata.inboundReportId(), bearerToken); Map responseObject = formatter.convertJsonToObject(responseBody, new TypeReference<>() {}); @@ -77,11 +77,11 @@ public void updateMetadataForReceivedMessage(PartnerMetadata partnerMetadata) timeReceived = Instant.parse(timestamp); } catch (Exception e) { - // write the received submission ID so that the rest of the metadata flow works even if + // write the inbound report ID so that the rest of the metadata flow works even if // some data is missing logger.logWarning( "Unable to retrieve metadata from RS delivery API, but writing basic metadata entry anyway for received submission ID {}", - partnerMetadata.receivedSubmissionId()); + partnerMetadata.inboundReportId()); partnerMetadataStorage.saveMetadata(partnerMetadata); throw new PartnerMetadataException( @@ -93,7 +93,7 @@ public void updateMetadataForReceivedMessage(PartnerMetadata partnerMetadata) partnerMetadataStorage.saveMetadata(updatedPartnerMetadata); } - public void updateMetadataForSentMessage(String receivedSubmissionId, String sentSubmissionId) + public void updateMetadataForSentMessage(String inboundReportId, String sentSubmissionId) throws PartnerMetadataException { if (sentSubmissionId == null) { @@ -101,10 +101,9 @@ public void updateMetadataForSentMessage(String receivedSubmissionId, String sen } Optional optionalPartnerMetadata = - partnerMetadataStorage.readMetadata(receivedSubmissionId); + partnerMetadataStorage.readMetadata(inboundReportId); if (optionalPartnerMetadata.isEmpty()) { - logger.logWarning( - "Metadata not found for receivedSubmissionId: {}", receivedSubmissionId); + logger.logWarning("Metadata not found for inboundReportId: {}", inboundReportId); return; } @@ -119,12 +118,12 @@ public void updateMetadataForSentMessage(String receivedSubmissionId, String sen partnerMetadataStorage.saveMetadata(partnerMetadata); } - public Optional getMetadata(String receivedSubmissionId) + public Optional getMetadata(String inboundReportId) throws PartnerMetadataException { Optional optionalPartnerMetadata = - partnerMetadataStorage.readMetadata(receivedSubmissionId); + partnerMetadataStorage.readMetadata(inboundReportId); if (optionalPartnerMetadata.isEmpty()) { - logger.logInfo("Metadata not found for receivedSubmissionId: {}", receivedSubmissionId); + logger.logInfo("Metadata not found for inboundReportId: {}", inboundReportId); return Optional.empty(); } @@ -206,7 +205,7 @@ public Map> getConsolidatedMetadata(String senderNam return metadataSet.stream() .collect( Collectors.toMap( - PartnerMetadata::receivedSubmissionId, + PartnerMetadata::inboundReportId, metadata -> { var status = String.valueOf(metadata.deliveryStatus()); var stale = metadataIsStale(metadata); @@ -221,10 +220,10 @@ public Map> getConsolidatedMetadata(String senderNam })); } - public Set findMessagesIdsToLink(String receivedSubmissionId) + public Set findMessagesIdsToLink(String inboundReportId) throws PartnerMetadataException { - return partnerMetadataStorage.readMetadataForMessageLinking(receivedSubmissionId); + return partnerMetadataStorage.readMetadataForMessageLinking(inboundReportId); } public void linkMessages(Set messageIds) throws MessageLinkException { diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataStorage.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataStorage.java index 5137a01f5..799febd73 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataStorage.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataStorage.java @@ -9,11 +9,10 @@ public interface PartnerMetadataStorage { /** * This method will retrieve and return the metadata for the given submissionId, if it exists. * - * @param receivedSubmissionId The submission Id to read the metadata for. + * @param inboundReportId The inbound report id to read the metadata for. * @return The metadata, if it exists. Otherwise, an empty Optional. */ - Optional readMetadata(String receivedSubmissionId) - throws PartnerMetadataException; + Optional readMetadata(String inboundReportId) throws PartnerMetadataException; /** * This method will do "upserts". If the record doesn't exist, it is created. If the record diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java index edf3ed746..2aaaa758b 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java @@ -26,12 +26,12 @@ public static SendOrderUseCase getInstance() { } @Override - public void convertAndSend(final Order order, String receivedSubmissionId) + public void convertAndSend(final Order order, String inboundReportId) throws UnableToSendMessageException { PartnerMetadata partnerMetadata = new PartnerMetadata( - receivedSubmissionId, + inboundReportId, String.valueOf(order.hashCode()), PartnerMetadataMessageType.ORDER, order.getSendingApplicationDetails(), @@ -47,8 +47,8 @@ public void convertAndSend(final Order order, String receivedSubmissionId) String outboundReportId = sender.send(order).orElse(null); logger.logInfo("Sent order reportId: {}", outboundReportId); - sendMessageHelper.linkMessage(receivedSubmissionId); + sendMessageHelper.linkMessage(inboundReportId); - sendMessageHelper.saveSentMessageSubmissionId(receivedSubmissionId, outboundReportId); + sendMessageHelper.saveSentMessageSubmissionId(inboundReportId, outboundReportId); } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java index 7f10d391d..6060fe60a 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java @@ -27,12 +27,12 @@ public static SendResultUseCase getInstance() { } @Override - public void convertAndSend(Result result, String receivedSubmissionId) + public void convertAndSend(Result result, String inboundReportId) throws UnableToSendMessageException { PartnerMetadata partnerMetadata = new PartnerMetadata( - receivedSubmissionId, + inboundReportId, String.valueOf(result.hashCode()), PartnerMetadataMessageType.RESULT, result.getSendingApplicationDetails(), @@ -48,8 +48,8 @@ public void convertAndSend(Result result, String receivedSubmissionId) String outboundReportId = sender.send(result).orElse(null); logger.logInfo("Sent result reportId: {}", outboundReportId); - sendMessageHelper.linkMessage(receivedSubmissionId); + sendMessageHelper.linkMessage(inboundReportId); - sendMessageHelper.saveSentMessageSubmissionId(receivedSubmissionId, outboundReportId); + sendMessageHelper.saveSentMessageSubmissionId(inboundReportId, outboundReportId); } } 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 08bfc8814..1c022f65f 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 @@ -27,7 +27,7 @@ public class DatabasePartnerMetadataStorage implements PartnerMetadataStorage { private static final DatabasePartnerMetadataStorage INSTANCE = new DatabasePartnerMetadataStorage(); - private static final String METADATA_TABLE_RECEIVED_MESSAGE_ID = "received_message_id"; + private static final String METADATA_TABLE_INBOUND_REPORT_ID = "inbound_report_id"; @Inject DbDao dao; @@ -51,7 +51,7 @@ public Optional readMetadata(final String uniqueId) try { PreparedStatement statement = connection.prepareStatement( - "SELECT * FROM metadata where received_message_id = ? OR sent_message_id = ?"); + "SELECT * FROM metadata where inbound_report_id = ? OR sent_message_id = ?"); statement.setString(1, uniqueId); statement.setString(2, uniqueId); return statement; @@ -73,7 +73,7 @@ public void saveMetadata(final PartnerMetadata metadata) throws PartnerMetadataE try { List columns = createDbColumnsFromMetadata(metadata); - dao.upsertData("metadata", columns, "(" + METADATA_TABLE_RECEIVED_MESSAGE_ID + ")"); + dao.upsertData("metadata", columns, "(" + METADATA_TABLE_INBOUND_REPORT_ID + ")"); } catch (SQLException e) { throw new PartnerMetadataException("Error saving metadata", e); } catch (FormatterProcessingException e) { @@ -122,14 +122,14 @@ public Set readMetadataForMessageLinking(String submissionId) PreparedStatement statement = connection.prepareStatement( """ - SELECT m2.received_message_id + SELECT m2.inbound_report_id FROM metadata m1 JOIN metadata m2 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 = ?; + AND m1.inbound_report_id <> m2.inbound_report_id + WHERE m1.inbound_report_id = ?; """); // -- LIMIT 50 This is a potential fix for load test failures // since they link all the ids together; @@ -163,7 +163,7 @@ PartnerMetadata partnerMetadataFromResultSet(ResultSet resultSet) { } return new PartnerMetadata( - resultSet.getString(METADATA_TABLE_RECEIVED_MESSAGE_ID), + resultSet.getString(METADATA_TABLE_INBOUND_REPORT_ID), resultSet.getString("sent_message_id"), timeReceived, timeDelivered, @@ -192,7 +192,7 @@ PartnerMetadata partnerMetadataFromResultSet(ResultSet resultSet) { String idsFromResult(ResultSet resultSet) { try { - return resultSet.getString(METADATA_TABLE_RECEIVED_MESSAGE_ID); + return resultSet.getString(METADATA_TABLE_INBOUND_REPORT_ID); } catch (SQLException e) { throw new RuntimeException(e); } @@ -202,8 +202,8 @@ private List createDbColumnsFromMetadata(PartnerMetadata metadata) throws FormatterProcessingException { return List.of( new DbColumn( - METADATA_TABLE_RECEIVED_MESSAGE_ID, - metadata.receivedSubmissionId(), + METADATA_TABLE_INBOUND_REPORT_ID, + metadata.inboundReportId(), false, Types.VARCHAR), new DbColumn("sent_message_id", metadata.sentSubmissionId(), true, Types.VARCHAR), diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiPartnerMetadataConverter.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiPartnerMetadataConverter.java index 49a8d0198..fecc839a9 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiPartnerMetadataConverter.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiPartnerMetadataConverter.java @@ -82,7 +82,7 @@ public FhirMetadata extractPublicMetadataToOperationOutcome( .getIssue() .add( createInformationIssueComponent( - "inbound submission id", metadata.receivedSubmissionId())); + "inbound submission id", metadata.inboundReportId())); return new HapiFhirMetadata(operation); } 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 de8a874b2..a925e5631 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 @@ -63,7 +63,7 @@ public Optional readMetadata(final String submissionId) @Override public void saveMetadata(final PartnerMetadata metadata) throws PartnerMetadataException { try { - Path previousMetadataFilePath = searchFilePath(metadata.receivedSubmissionId()); + Path previousMetadataFilePath = searchFilePath(metadata.inboundReportId()); if (previousMetadataFilePath != null) { // delete the pre-existing metadata file so that we don't find the old file when we // search for a given metadata ID @@ -71,22 +71,19 @@ public void saveMetadata(final PartnerMetadata metadata) throws PartnerMetadataE } } catch (IOException e) { throw new PartnerMetadataException( - "Error deleting previous metadata file for " + metadata.receivedSubmissionId(), - e); + "Error deleting previous metadata file for " + metadata.inboundReportId(), e); } Path metadataFilePath = - getFilePath(metadata.receivedSubmissionId() + "-" + metadata.sentSubmissionId()); + getFilePath(metadata.inboundReportId() + "-" + metadata.sentSubmissionId()); try { String content = formatter.convertToJsonString(metadata); Files.writeString(metadataFilePath, content); logger.logInfo( - "Saved metadata for {} to {}", - metadata.receivedSubmissionId(), - metadataFilePath); + "Saved metadata for {} to {}", metadata.inboundReportId(), metadataFilePath); } catch (IOException | FormatterProcessingException e) { throw new PartnerMetadataException( - "Error saving metadata for " + metadata.receivedSubmissionId(), e); + "Error saving metadata for " + metadata.inboundReportId(), e); } } @@ -108,23 +105,19 @@ public Set readMetadataForSender(String senderUniversalId) } @Override - public Set readMetadataForMessageLinking(String receivedSubmissionId) + public Set readMetadataForMessageLinking(String inboundReportId) throws PartnerMetadataException { try { Set existingMetadata = getPartnerMetadata(); PartnerMetadata match = existingMetadata.stream() - .filter( - metadata -> - metadata.receivedSubmissionId() - .equals(receivedSubmissionId)) + .filter(metadata -> metadata.inboundReportId().equals(inboundReportId)) .findFirst() .orElse(null); if (match == null) { logger.logWarning( - "Matching metadata not found for receivedSubmissionId: {}", - receivedSubmissionId); + "Matching metadata not found for inboundReportId: {}", inboundReportId); return Set.of(); } @@ -138,13 +131,12 @@ public Set readMetadataForMessageLinking(String receivedSubmissionId) .equals( match .receivingFacilityDetails())) - && !metadata.receivedSubmissionId() - .equals(receivedSubmissionId)) - .map(PartnerMetadata::receivedSubmissionId) + && !metadata.inboundReportId().equals(inboundReportId)) + .map(PartnerMetadata::inboundReportId) .collect(Collectors.toSet()); } catch (Exception e) { throw new PartnerMetadataException( - "Failed reading metadata for submissionId: " + receivedSubmissionId, e); + "Failed reading metadata for inbound reportId: " + inboundReportId, e); } } diff --git a/etor/src/main/resources/openapi_etor.yaml b/etor/src/main/resources/openapi_etor.yaml index 76dbefe75..be158bf95 100644 --- a/etor/src/main/resources/openapi_etor.yaml +++ b/etor/src/main/resources/openapi_etor.yaml @@ -149,7 +149,7 @@ components: ConsolidatedMetadata: type: map> properties: - receivedSubmissionId: + inboundReportId: type: string properties: value: 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 593fd5816..faa88bda0 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 @@ -171,15 +171,15 @@ class EtorDomainRegistrationTest extends Specification { def "metadata endpoint happy path"() { given: def expectedStatusCode = 200 - def receivedSubmissionId = "receivedSubmissionId" - def metadata = new PartnerMetadata("receivedSubmissionId", "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number") - def linkedMessageIds = Set.of(receivedSubmissionId, "Test1", "Test2") + def inboundReportId = "inboundReportId" + def metadata = new PartnerMetadata("inboundReportId", "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number") + def linkedMessageIds = Set.of(inboundReportId, "Test1", "Test2") def connector = new EtorDomainRegistration() TestApplicationContext.register(EtorDomainRegistration, connector) def request = new DomainRequest() - request.setPathParams(["id": receivedSubmissionId]) + request.setPathParams(["id": inboundReportId]) def mockPartnerMetadataOrchestrator = Mock(PartnerMetadataOrchestrator) TestApplicationContext.register(PartnerMetadataOrchestrator, mockPartnerMetadataOrchestrator) @@ -202,8 +202,8 @@ class EtorDomainRegistrationTest extends Specification { then: actualStatusCode == expectedStatusCode - 1 * mockPartnerMetadataOrchestrator.getMetadata(receivedSubmissionId) >> Optional.ofNullable(metadata) - 1 * mockPartnerMetadataOrchestrator.findMessagesIdsToLink(receivedSubmissionId) >> linkedMessageIds + 1 * mockPartnerMetadataOrchestrator.getMetadata(inboundReportId) >> Optional.ofNullable(metadata) + 1 * mockPartnerMetadataOrchestrator.findMessagesIdsToLink(inboundReportId) >> linkedMessageIds 1 * mockPartnerMetadataConverter.extractPublicMetadataToOperationOutcome(_ as PartnerMetadata, _ as String, linkedMessageIds) >> Mock(FhirMetadata) 1 * mockResponseHelper.constructOkResponseFromString(_ as String) >> new DomainResponse(expectedStatusCode) } @@ -211,10 +211,10 @@ class EtorDomainRegistrationTest extends Specification { def "metadata endpoint returns metadata even when the submitted ID is different from ID used for linking"() { given: def expectedStatusCode = 200 - def receivedSubmissionId = "receivedSubmissionId" + def inboundReportId = "inboundReportId" def sentSubmissionId = "sentSubmissionId" - def metadata = new PartnerMetadata(receivedSubmissionId, "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number").withSentSubmissionId(sentSubmissionId) - def linkedMessageIds = Set.of(receivedSubmissionId, "Test1", "Test2") + def metadata = new PartnerMetadata(inboundReportId, "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number").withSentSubmissionId(sentSubmissionId) + def linkedMessageIds = Set.of(inboundReportId, "Test1", "Test2") def connector = new EtorDomainRegistration() TestApplicationContext.register(EtorDomainRegistration, connector) @@ -244,7 +244,7 @@ class EtorDomainRegistrationTest extends Specification { then: actualStatusCode == expectedStatusCode 1 * mockPartnerMetadataOrchestrator.getMetadata(sentSubmissionId) >> Optional.ofNullable(metadata) - 1 * mockPartnerMetadataOrchestrator.findMessagesIdsToLink(receivedSubmissionId) >> linkedMessageIds + 1 * mockPartnerMetadataOrchestrator.findMessagesIdsToLink(inboundReportId) >> linkedMessageIds 1 * mockPartnerMetadataConverter.extractPublicMetadataToOperationOutcome(_ as PartnerMetadata, _ as String, linkedMessageIds) >> Mock(FhirMetadata) 1 * mockResponseHelper.constructOkResponseFromString(_ as String) >> new DomainResponse(expectedStatusCode) } @@ -430,7 +430,7 @@ class EtorDomainRegistrationTest extends Specification { 2 * mockLogger.logError(_ as String, _ as Exception) } - def "handleMessageRequest logs an error and continues when the receivedSubmissionId is missing or empty because we want to know when our integration with RS is broken"() { + def "handleMessageRequest logs an error and continues when the inboundReportId is missing or empty because we want to know when our integration with RS is broken"() { given: def connector = new EtorDomainRegistration() TestApplicationContext.register(EtorDomainRegistration, connector) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy index 08deb143d..71c7e6a59 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy @@ -27,7 +27,7 @@ class SendMessageHelperTest extends Specification { TestApplicationContext.register(Logger, mockLogger) TestApplicationContext.injectRegisteredImplementations() partnerMetadata = new PartnerMetadata( - "receivedId", + "inboundReportId", new Random().nextInt().toString(), PartnerMetadataMessageType.RESULT, sendingApp, @@ -44,7 +44,7 @@ class SendMessageHelperTest extends Specification { 1 * mockOrchestrator.updateMetadataForReceivedMessage(_) } - def "savePartnerMetadataForReceivedMessage should log warnings for null receivedSubmissionId"() { + def "savePartnerMetadataForReceivedMessage should log warnings for null inboundReportId"() { when: PartnerMetadata warningPartnerMetadata = new PartnerMetadata( null, @@ -77,22 +77,22 @@ class SendMessageHelperTest extends Specification { def "saveSentMessageSubmissionId works"() { given: def sentSubmissionId = "sentId" - def receivedSubmissionId = "receivedId" - mockOrchestrator.updateMetadataForSentMessage(receivedSubmissionId, _ as String) >> { throw new PartnerMetadataException("Error") } + def inboundReportId = "inboundReportId" + mockOrchestrator.updateMetadataForSentMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } when: - SendMessageHelper.getInstance().saveSentMessageSubmissionId(receivedSubmissionId, sentSubmissionId) + SendMessageHelper.getInstance().saveSentMessageSubmissionId(inboundReportId, sentSubmissionId) then: 1 * mockOrchestrator.updateMetadataForSentMessage(_, _) } - def "saveSentMessageSubmissionId should log warnings for null receivedSubmissionId"() { + def "saveSentMessageSubmissionId should log warnings for null inboundReportId"() { given: - def receivedSubmissionId = "receivedId" + def inboundReportId = "inboundReportId" when: - SendMessageHelper.getInstance().saveSentMessageSubmissionId(null, receivedSubmissionId) + SendMessageHelper.getInstance().saveSentMessageSubmissionId(null, inboundReportId) then: 1 * mockLogger.logWarning(_) @@ -101,11 +101,11 @@ class SendMessageHelperTest extends Specification { def "saveSentMessageSubmissionId should log error and continues when updateMetadataForSentMessage throws error"() { given: def sentSubmissionId = "sentId" - def receivedSubmissionId = "receivedId" - mockOrchestrator.updateMetadataForSentMessage(receivedSubmissionId, _ as String) >> { throw new PartnerMetadataException("Error") } + def inboundReportId = "inboundReportId" + mockOrchestrator.updateMetadataForSentMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } when: - SendMessageHelper.getInstance().saveSentMessageSubmissionId(receivedSubmissionId, sentSubmissionId) + SendMessageHelper.getInstance().saveSentMessageSubmissionId(inboundReportId, sentSubmissionId) then: 1 * mockLogger.logError(_, _) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy index cd81b33fe..5187836ac 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy @@ -19,7 +19,7 @@ class PartnerMetadataOrchestratorTest extends Specification { def mockMessageLinkStorage def mockClient def mockFormatter - def receivedSubmissionId = "receivedSubmissionId" + def inboundReportId = "inboundReportId" def sentSubmissionId = "sentSubmissionId" def hashCode = "hash" def bearerToken = "token" @@ -48,7 +48,7 @@ class PartnerMetadataOrchestratorTest extends Specification { receivingApp = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") receivingFacility = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - testMetadata = new PartnerMetadata(receivedSubmissionId, + testMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, @@ -109,7 +109,7 @@ class PartnerMetadataOrchestratorTest extends Specification { """ def expectedMetadata = new PartnerMetadata( - receivedSubmissionId, + inboundReportId, sentSubmissionId, Instant.parse(timestamp), timeDelivered, @@ -129,25 +129,25 @@ class PartnerMetadataOrchestratorTest extends Specification { then: 1 * mockClient.getRsToken() >> bearerToken - 1 * mockClient.requestDeliveryEndpoint(receivedSubmissionId, bearerToken) >> rsDeliveryApiResponse + 1 * mockClient.requestDeliveryEndpoint(inboundReportId, bearerToken) >> rsDeliveryApiResponse 1 * mockPartnerMetadataStorage.saveMetadata(expectedMetadata) } def "updateMetadataForSentMessage test case when sentSubmissionId is null"() { when: def sentSubmissionId = null - PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(receivedSubmissionId, sentSubmissionId) + PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(inboundReportId, sentSubmissionId) then: - 0 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) + 0 * mockPartnerMetadataStorage.readMetadata(inboundReportId) } def "updateMetadataForSentMessage test case when PartnerMetadata returns no data"() { given: - mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.empty() + mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.empty() when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(receivedSubmissionId, sentSubmissionId) + PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(inboundReportId, sentSubmissionId) then: 0 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) @@ -155,11 +155,11 @@ class PartnerMetadataOrchestratorTest extends Specification { def "updateMetadataForSentMessage ends when sentSubmissionId matches the one provided by PartnerMetadata"() { given: - def optional = Optional.of(new PartnerMetadata(receivedSubmissionId, sentSubmissionId, Instant.now(), null, "", PartnerMetadataStatus.FAILED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber)) - mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> optional + def optional = Optional.of(new PartnerMetadata(inboundReportId, sentSubmissionId, Instant.now(), null, "", PartnerMetadataStatus.FAILED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber)) + mockPartnerMetadataStorage.readMetadata(inboundReportId) >> optional when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(receivedSubmissionId, sentSubmissionId) + PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(inboundReportId, sentSubmissionId) then: 0 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) @@ -167,15 +167,15 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata returns empty Optional when data is not found"() { given: - String receivedSubmissionId = "receivedSubmissionId" + String inboundReportId = "inboundReportId" def mockMetadata = Optional.empty() when: - def result = PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + def result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: !result.isPresent() - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> mockMetadata + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> mockMetadata } def "updateMetadataForReceivedMessage throws PartnerMetadataException on client error"() { @@ -188,7 +188,7 @@ class PartnerMetadataOrchestratorTest extends Specification { then: 1 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) >> { PartnerMetadata metadata -> - assert metadata.receivedSubmissionId() == receivedSubmissionId + assert metadata.inboundReportId() == inboundReportId } thrown(PartnerMetadataException) } @@ -270,27 +270,27 @@ class PartnerMetadataOrchestratorTest extends Specification { def "updateMetadataForSentMessage updates metadata successfully"() { given: - def partnerMetadata = new PartnerMetadata(receivedSubmissionId, "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def partnerMetadata = new PartnerMetadata(inboundReportId, "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) def updatedPartnerMetadata = partnerMetadata.withSentSubmissionId(sentSubmissionId) when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(receivedSubmissionId, sentSubmissionId) + PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(inboundReportId, sentSubmissionId) then: - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(partnerMetadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(partnerMetadata) 1 * mockPartnerMetadataStorage.saveMetadata(updatedPartnerMetadata) } def "getMetadata throws PartnerMetadataException on client error"() { given: - def partnerMetadata = new PartnerMetadata(receivedSubmissionId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, "failureReason", PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def partnerMetadata = new PartnerMetadata(inboundReportId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, "failureReason", PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(partnerMetadata) + mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(partnerMetadata) mockClient.getRsToken() >> "token" mockClient.requestDeliveryEndpoint(_ as String, _ as String) >> { throw new ReportStreamEndpointClientException("Client error", new Exception()) } when: - PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: thrown(PartnerMetadataException) @@ -299,15 +299,15 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata throws PartnerMetadataException on formatter error"() { given: def rsHistoryApiResponse = "{\"destinations\": [{\"organization_id\": \"org\", \"service\": \"service\"}]}" - def partnerMetadata = new PartnerMetadata(receivedSubmissionId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, "failureReason", PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def partnerMetadata = new PartnerMetadata(inboundReportId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, "failureReason", PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(partnerMetadata) + mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(partnerMetadata) mockClient.getRsToken() >> "token" mockClient.requestHistoryEndpoint(_ as String, _ as String) >> rsHistoryApiResponse mockFormatter.convertJsonToObject(rsHistoryApiResponse, _ as TypeReference) >> { throw new FormatterProcessingException("Formatter error", new Exception()) } when: - PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: thrown(PartnerMetadataException) @@ -315,42 +315,42 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata retrieves metadata successfully with the sender already filled"() { given: - def metadata = new PartnerMetadata(receivedSubmissionId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def metadata = new PartnerMetadata(inboundReportId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) when: - def result = PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + def result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: result.isPresent() result.get() == metadata - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(metadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(metadata) 0 * mockClient.requestHistoryEndpoint(_, _) } def "getMetadata skips lookup with stale metadata and missing sentSubmissionId"() { given: - def metadata = new PartnerMetadata(receivedSubmissionId, null, Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number") + def metadata = new PartnerMetadata(inboundReportId, null, Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number") when: - PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(metadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(metadata) 0 * mockClient.requestHistoryEndpoint(_, _) notThrown(PartnerMetadataException) } def "getMetadata retrieves metadata successfully when receiver is present and sentSubmissionId is missing"() { given: - def metadata = new PartnerMetadata(receivedSubmissionId, null, Instant.now(), null, "hash", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def metadata = new PartnerMetadata(inboundReportId, null, Instant.now(), null, "hash", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) when: - def result = PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + def result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: result.isPresent() result.get() == metadata - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(metadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(metadata) } def "getMetadata gets receiver if missing from metadata"() { @@ -358,8 +358,8 @@ class PartnerMetadataOrchestratorTest extends Specification { def timeDelivered = Instant.now() def rsHistoryApiResponse = "{\"actualCompletionAt\": \"2023-10-24T19:48:26.921Z\",\"destinations\": [{\"organization_id\": \"org\", \"service\": \"service\"}]}" def receivingFacilityWithMissingUniversalId = new MessageHdDataType("receiving_app_name", null, "receiving_app_type") - def missingReceiverMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacilityWithMissingUniversalId, placerOrderNumber) - def expectedMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacilityWithMissingUniversalId, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacilityWithMissingUniversalId, placerOrderNumber) + def expectedMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacilityWithMissingUniversalId, placerOrderNumber) mockClient.getRsToken() >> bearerToken mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse @@ -373,20 +373,20 @@ class PartnerMetadataOrchestratorTest extends Specification { ] when: - Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: result.isPresent() result.get() == expectedMetadata - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(missingReceiverMetadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(missingReceiverMetadata) 1 * mockPartnerMetadataStorage.saveMetadata(expectedMetadata) } def "getMetadata gets status if still pending in metadata"() { given: def rsHistoryApiResponse = "{\"destinations\": [{\"organization_id\": \"org\", \"service\": \"service\"}]}" - def missingReceiverMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - def expectedMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.FAILED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def expectedMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.FAILED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockClient.getRsToken() >> bearerToken mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse @@ -399,12 +399,12 @@ class PartnerMetadataOrchestratorTest extends Specification { ] when: - Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: result.isPresent() result.get() == expectedMetadata - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(missingReceiverMetadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(missingReceiverMetadata) 1 * mockPartnerMetadataStorage.saveMetadata(expectedMetadata) } @@ -412,8 +412,8 @@ class PartnerMetadataOrchestratorTest extends Specification { given: def timeDelivered = Instant.now() def rsHistoryApiResponse = "whatever" - def missingReceiverMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - def expectedMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def expectedMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockClient.getRsToken() >> bearerToken mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse @@ -431,19 +431,19 @@ class PartnerMetadataOrchestratorTest extends Specification { ] when: - Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: result.isPresent() result.get() == expectedMetadata - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(missingReceiverMetadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(missingReceiverMetadata) 1 * mockPartnerMetadataStorage.saveMetadata(expectedMetadata) } def "getMetadata saves pending without delivery time if nobody has delivery times"() { given: def rsHistoryApiResponse = "whatever" - def missingReceiverMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockClient.getRsToken() >> bearerToken mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse @@ -461,20 +461,20 @@ class PartnerMetadataOrchestratorTest extends Specification { ] when: - Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: result.isPresent() result.get() == missingReceiverMetadata - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(missingReceiverMetadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(missingReceiverMetadata) 1 * mockPartnerMetadataStorage.saveMetadata(missingReceiverMetadata) } def "getMetadata saves loaded delivered metadata if found"() { given: def rsHistoryApiResponse = "whatever" - def missingReceiverMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - def expectedMetadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.DELIVERED, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def expectedMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.DELIVERED, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockClient.getRsToken() >> bearerToken mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse @@ -492,12 +492,12 @@ class PartnerMetadataOrchestratorTest extends Specification { ] when: - Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(receivedSubmissionId) + Optional result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) then: result.isPresent() result.get() == expectedMetadata - 1 * mockPartnerMetadataStorage.readMetadata(receivedSubmissionId) >> Optional.of(missingReceiverMetadata) + 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(missingReceiverMetadata) 1 * mockPartnerMetadataStorage.saveMetadata(expectedMetadata) } @@ -540,7 +540,7 @@ class PartnerMetadataOrchestratorTest extends Specification { then: 1 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) >> { PartnerMetadata partnerMetadata -> assert partnerMetadata.deliveryStatus() == PartnerMetadataStatus.FAILED - assert partnerMetadata.receivedSubmissionId() == submissionId + assert partnerMetadata.inboundReportId() == submissionId } } @@ -714,22 +714,22 @@ class PartnerMetadataOrchestratorTest extends Specification { def "findMessagesIdsToLink returns a list of message ids"() { given: def placerOrderNumber = "placerOrderNumber" - def receivedSubmissionId1 = "1" - def receivedSubmissionId2 = "2" + def inboundReportId1 = "1" + def inboundReportId2 = "2" def sendingAppDetails = new MessageHdDataType("sending_app_name", "sending_app_id", "sending_app_type") def sendingFacilityDetails = new MessageHdDataType("sending_facility_name", "sending_facility_id", "sending_facility_type") def receivingAppDetails = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - def partnerMetadata1 = new PartnerMetadata(receivedSubmissionId1, "hash1", PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) - def partnerMetadata2 = new PartnerMetadata(receivedSubmissionId2, "hash2", PartnerMetadataMessageType.RESULT, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) - def metadataSetForMessageLinking = Set.of(receivedSubmissionId1, receivedSubmissionId2) - mockPartnerMetadataStorage.readMetadataForMessageLinking(receivedSubmissionId) >> metadataSetForMessageLinking + def partnerMetadata1 = new PartnerMetadata(inboundReportId1, "hash1", PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) + def partnerMetadata2 = new PartnerMetadata(inboundReportId2, "hash2", PartnerMetadataMessageType.RESULT, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) + def metadataSetForMessageLinking = Set.of(inboundReportId1, inboundReportId2) + mockPartnerMetadataStorage.readMetadataForMessageLinking(inboundReportId) >> metadataSetForMessageLinking when: - def result = PartnerMetadataOrchestrator.getInstance().findMessagesIdsToLink(receivedSubmissionId) + def result = PartnerMetadataOrchestrator.getInstance().findMessagesIdsToLink(inboundReportId) then: - result == Set.of(receivedSubmissionId1, receivedSubmissionId2) + result == Set.of(inboundReportId1, inboundReportId2) } def "linkMessages links messages successfully"() { diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataTest.groovy index 28ef621db..3d74c2858 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataTest.groovy @@ -17,7 +17,7 @@ class PartnerMetadataTest extends Specification { def "test constructor"() { given: - def receivedSubmissionId = "receivedSubmissionId" + def inboundReportId = "inboundReportId" def sentSubmissionId = "sentSubmissionId" def timeReceived = Instant.now() def timeDelivered = Instant.now() @@ -31,10 +31,10 @@ class PartnerMetadataTest extends Specification { def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") when: - def metadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, timeDelivered, hash, PartnerMetadataStatus.DELIVERED, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def metadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hash, PartnerMetadataStatus.DELIVERED, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") then: - metadata.receivedSubmissionId() == receivedSubmissionId + metadata.inboundReportId() == inboundReportId metadata.sentSubmissionId() == sentSubmissionId metadata.timeDelivered() == timeDelivered metadata.timeReceived() == timeReceived @@ -47,16 +47,16 @@ class PartnerMetadataTest extends Specification { metadata.receivingFacilityDetails() == receivingFacilityDetails } - def "test constructor with only received submission ID and status"() { + def "test constructor with only inbound message ID and status"() { given: - def receivedSubmissionId = "receivedSubmissionId" + def inboundReportId = "inboundReportId" def deliverStatus = PartnerMetadataStatus.DELIVERED when: - def metadata = new PartnerMetadata(receivedSubmissionId, deliverStatus) + def metadata = new PartnerMetadata(inboundReportId, deliverStatus) then: - metadata.receivedSubmissionId() == receivedSubmissionId + metadata.inboundReportId() == inboundReportId metadata.sentSubmissionId() == null metadata.timeReceived() == null metadata.timeDelivered() == null @@ -66,7 +66,7 @@ class PartnerMetadataTest extends Specification { def "test withSentSubmissionId to update PartnerMetadata"() { given: - def receivedSubmissionId = "receivedSubmissionId" + def inboundReportId = "inboundReportId" def sentSubmissionId = "sentSubmissionId" def messageType = PartnerMetadataMessageType.RESULT def timeReceived = Instant.now() @@ -78,13 +78,13 @@ class PartnerMetadataTest extends Specification { def receivingAppDetails = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - def metadata = new PartnerMetadata(receivedSubmissionId, null, timeReceived, null, hash, status, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def metadata = new PartnerMetadata(inboundReportId, null, timeReceived, null, hash, status, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") when: def updatedMetadata = metadata.withSentSubmissionId(sentSubmissionId) then: - updatedMetadata.receivedSubmissionId() == receivedSubmissionId + updatedMetadata.inboundReportId() == inboundReportId updatedMetadata.sentSubmissionId() == sentSubmissionId updatedMetadata.timeReceived() == timeReceived updatedMetadata.hash() == hash @@ -97,7 +97,7 @@ class PartnerMetadataTest extends Specification { def "test withDeliveryStatus to update PartnerMetadata"() { given: - def receivedSubmissionId = "receivedSubmissionId" + def inboundReportId = "inboundReportId" def sentSubmissionId = "sentSubmissionId" def timeReceived = Instant.now() def timeDelivered = null @@ -108,14 +108,14 @@ class PartnerMetadataTest extends Specification { def sendingFacilityDetails = new MessageHdDataType("sending_facility_name", "sending_facility_id", "sending_facility_type") def receivingAppDetails = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - def metadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, timeDelivered, hash, PartnerMetadataStatus.PENDING, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def metadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hash, PartnerMetadataStatus.PENDING, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") when: def newStatus = PartnerMetadataStatus.DELIVERED def updatedMetadata = metadata.withSentSubmissionId(sentSubmissionId).withDeliveryStatus(newStatus) then: - updatedMetadata.receivedSubmissionId() == receivedSubmissionId + updatedMetadata.inboundReportId() == inboundReportId updatedMetadata.sentSubmissionId() == sentSubmissionId updatedMetadata.timeReceived() == timeReceived updatedMetadata.timeDelivered() == null @@ -130,7 +130,7 @@ class PartnerMetadataTest extends Specification { def "test withTimeDelivered to update PartnerMetadata"() { given: - def receivedSubmissionId = "receivedSubmissionId" + def inboundReportId = "inboundReportId" def sentSubmissionId = "sentSubmissionId" def timeReceived = Instant.now() def timeDelivered = Instant.now() @@ -141,13 +141,13 @@ class PartnerMetadataTest extends Specification { def sendingFacilityDetails = new MessageHdDataType("sending_facility_name", "sending_facility_id", "sending_facility_type") def receivingAppDetails = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - def metadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, timeReceived, null, hash, PartnerMetadataStatus.PENDING, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def metadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hash, PartnerMetadataStatus.PENDING, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") when: def updatedMetadata = metadata.withTimeDelivered(timeDelivered) then: - updatedMetadata.receivedSubmissionId() == receivedSubmissionId + updatedMetadata.inboundReportId() == inboundReportId updatedMetadata.sentSubmissionId() == sentSubmissionId updatedMetadata.timeReceived() == timeReceived updatedMetadata.timeDelivered() == timeDelivered 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 d2fb18319..093f2a681 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 @@ -34,7 +34,7 @@ class SendOrderUseCaseTest extends Specification { def "send sends successfully"() { given: - def receivedSubmissionId = "receivedId" + def inboundReportId = "inboundReportId" def sentSubmissionId = "sentId" def messagesIdsToLink = new HashSet<>(Set.of("messageId1", "messageId2")) def mockOrder = new OrderMock(null, null, null, null, null, null, null, null) @@ -42,15 +42,15 @@ class SendOrderUseCaseTest extends Specification { TestApplicationContext.injectRegisteredImplementations() when: - SendOrderUseCase.getInstance().convertAndSend(mockOrder, receivedSubmissionId) + SendOrderUseCase.getInstance().convertAndSend(mockOrder, inboundReportId) then: 1 * mockEngine.runRules(mockOrder) 1 * mockSender.send(mockOrder) >> Optional.of(sentSubmissionId) 1 * mockOrchestrator.updateMetadataForReceivedMessage(_ as PartnerMetadata) - 1 * mockOrchestrator.updateMetadataForSentMessage(receivedSubmissionId, sentSubmissionId) - 1 * mockOrchestrator.findMessagesIdsToLink(receivedSubmissionId) >> messagesIdsToLink - 1 * mockOrchestrator.linkMessages(messagesIdsToLink + receivedSubmissionId) + 1 * mockOrchestrator.updateMetadataForSentMessage(inboundReportId, sentSubmissionId) + 1 * mockOrchestrator.findMessagesIdsToLink(inboundReportId) >> messagesIdsToLink + 1 * mockOrchestrator.linkMessages(messagesIdsToLink + inboundReportId) } def "send fails to send"() { @@ -65,7 +65,7 @@ class SendOrderUseCaseTest extends Specification { thrown(UnableToSendMessageException) } - def "convertAndSend should log warnings for null receivedSubmissionId"() { + def "convertAndSend should log warnings for null inboundReportId"() { given: mockSender.send(_) >> Optional.of("sentSubmissionId") TestApplicationContext.injectRegisteredImplementations() @@ -81,18 +81,18 @@ class SendOrderUseCaseTest extends Specification { def "convertAndSend logs error and continues when updateMetadataForReceivedOrder throws exception"() { given: def order = Mock(Order) - def receivedSubmissionId = "receivedId" + def inboundReportId = "inboundReportId" mockOrchestrator.updateMetadataForReceivedMessage(_ as PartnerMetadata) >> { throw new PartnerMetadataException("Error") } TestApplicationContext.injectRegisteredImplementations() when: - SendOrderUseCase.getInstance().convertAndSend(order, receivedSubmissionId) + SendOrderUseCase.getInstance().convertAndSend(order, inboundReportId) then: 1 * mockLogger.logError(_, _) 1 * mockEngine.runRules(order) - 1 * mockOrchestrator.findMessagesIdsToLink(receivedSubmissionId) >> Set.of() + 1 * mockOrchestrator.findMessagesIdsToLink(inboundReportId) >> Set.of() 1 * mockSender.send(order) >> Optional.of("sentId") } @@ -100,11 +100,11 @@ class SendOrderUseCaseTest extends Specification { given: def order = Mock(Order) def partnerMetadataException = new PartnerMetadataException("Error") - mockOrchestrator.updateMetadataForSentMessage("receivedId", _) >> { throw partnerMetadataException} + mockOrchestrator.updateMetadataForSentMessage("inboundReportId", _) >> { throw partnerMetadataException} TestApplicationContext.injectRegisteredImplementations() when: - SendOrderUseCase.getInstance().convertAndSend(order, "receivedId") + SendOrderUseCase.getInstance().convertAndSend(order, "inboundReportId") then: 1 * mockEngine.runRules(order) @@ -121,7 +121,7 @@ class SendOrderUseCaseTest extends Specification { mockSender.send(_) >> Optional.empty() when: - SendOrderUseCase.getInstance().convertAndSend(mockOrder, "receivedId") + SendOrderUseCase.getInstance().convertAndSend(mockOrder, "inboundReportId") then: 1 * mockLogger.logWarning(_) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy index a4583ceba..ddbe30097 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy @@ -36,10 +36,10 @@ class SendResultUseCaseTest extends Specification { def "convertAndSend works"() { given: def mockResult = new ResultMock(null, "Mock result", null, null, null, null, null) - def receivedSubmissionId = "receivedId" + def inboundReportId = "inboundReportId" when: - SendResultUseCase.getInstance().convertAndSend(mockResult, receivedSubmissionId) + SendResultUseCase.getInstance().convertAndSend(mockResult, inboundReportId) then: 1 * mockEngine.runRules(mockResult) @@ -48,11 +48,11 @@ class SendResultUseCaseTest extends Specification { def "convertAndSend throws exception when send fails"() { given: - def receivedSubmissionId = "receivedId" + def inboundReportId = "inboundReportId" mockSender.send(_) >> { throw new UnableToSendMessageException("DogCow", new NullPointerException()) } when: - SendResultUseCase.getInstance().convertAndSend(Mock(Result), receivedSubmissionId) + SendResultUseCase.getInstance().convertAndSend(Mock(Result), inboundReportId) then: thrown(UnableToSendMessageException) @@ -61,12 +61,12 @@ class SendResultUseCaseTest extends Specification { def "convertAndSend logs error and continues when updateMetadataForReceivedMessage throws exception"() { given: def result = Mock(Result) - def receivedSubmissionId = "receivedId" + def inboundReportId = "inboundReportId" mockOrchestrator.updateMetadataForReceivedMessage(_ as PartnerMetadata) >> { throw new PartnerMetadataException("Error") } TestApplicationContext.injectRegisteredImplementations() when: - SendResultUseCase.getInstance().convertAndSend(result, receivedSubmissionId) + SendResultUseCase.getInstance().convertAndSend(result, inboundReportId) then: 1 * mockLogger.logError(_, _) @@ -77,12 +77,12 @@ class SendResultUseCaseTest extends Specification { def "convertAndSend logs error and continues when updateMetadataForSentMessage throws exception"() { given: def result = Mock(Result) - def receivedSubmissionId = "receivedId" - mockOrchestrator.updateMetadataForSentMessage(receivedSubmissionId, _ as String) >> { throw new PartnerMetadataException("Error") } + def inboundReportId = "inboundReportId" + mockOrchestrator.updateMetadataForSentMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } TestApplicationContext.injectRegisteredImplementations() when: - SendResultUseCase.getInstance().convertAndSend(result, receivedSubmissionId) + SendResultUseCase.getInstance().convertAndSend(result, inboundReportId) then: 1 * mockEngine.runRules(result) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.groovy index 0f32a2e9d..1171ef38d 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.groovy @@ -31,7 +31,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { def sendingFacilityDetails = new MessageHdDataType("sending_facility_name", "sending_facility_id", "sending_facility_type") def receivingAppDetails = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - def mockMetadata = new PartnerMetadata("receivedSubmissionId", "sentSubmissionId", Instant.now(), Instant.now(), "hash", PartnerMetadataStatus.DELIVERED, "failure reason", PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def mockMetadata = new PartnerMetadata("inboundReportId", "sentSubmissionId", Instant.now(), Instant.now(), "hash", PartnerMetadataStatus.DELIVERED, "failure reason", PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") def setup() { TestApplicationContext.reset() @@ -52,7 +52,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { mockDao.fetchFirstData(_ as Function, _ as Function) >> mockMetadata when: - def actualResult = DatabasePartnerMetadataStorage.getInstance().readMetadata(mockMetadata.receivedSubmissionId()) + def actualResult = DatabasePartnerMetadataStorage.getInstance().readMetadata(mockMetadata.inboundReportId()) then: actualResult == expectedResult @@ -63,7 +63,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { mockDao.fetchFirstData(_ as Function, _ as Function) >> { throw new SQLException("Something went wrong!") } when: - DatabasePartnerMetadataStorage.getInstance().readMetadata("receivedSubmissionId") + DatabasePartnerMetadataStorage.getInstance().readMetadata("inboundReportId") then: thrown(PartnerMetadataException) @@ -103,7 +103,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { def testMapper = new ObjectMapper() List columns = List.of( - new DbColumn("received_message_id", mockMetadata.receivedSubmissionId(), false, Types.VARCHAR), + new DbColumn("inbound_report_id", mockMetadata.inboundReportId(), false, Types.VARCHAR), new DbColumn("sent_message_id", mockMetadata.sentSubmissionId(), true, Types.VARCHAR), new DbColumn("hash_of_message", mockMetadata.hash(), false, Types.VARCHAR), new DbColumn("time_received", Timestamp.from(mockMetadata.timeReceived()),false, Types.TIMESTAMP), @@ -124,7 +124,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { DatabasePartnerMetadataStorage.getInstance().saveMetadata(mockMetadata) then: - 1 * mockDao.upsertData("metadata", columns, "(received_message_id)") + 1 * mockDao.upsertData("metadata", columns, "(inbound_report_id)") } def "saveMetadata unhappy path works"() { @@ -200,7 +200,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { given: def testMapper = new ObjectMapper() def mockMetadata = new PartnerMetadata( - "receivedSubmissionId", + "inboundReportId", "sentSubmissionId", null, null, @@ -217,7 +217,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { List columns = List.of( - new DbColumn("received_message_id", mockMetadata.receivedSubmissionId(), false, Types.VARCHAR), + new DbColumn("inbound_report_id", mockMetadata.inboundReportId(), false, Types.VARCHAR), new DbColumn("sent_message_id", mockMetadata.sentSubmissionId(), true, Types.VARCHAR), new DbColumn("hash_of_message", mockMetadata.hash(), false, Types.VARCHAR), new DbColumn("time_received", null, false, Types.TIMESTAMP), @@ -238,7 +238,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { DatabasePartnerMetadataStorage.getInstance().saveMetadata(mockMetadata) then: - 1 * mockDao.upsertData("metadata", columns, "(received_message_id)") + 1 * mockDao.upsertData("metadata", columns, "(inbound_report_id)") } def "readMetadataForMessageLinking happy path works"() { @@ -248,7 +248,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { mockDao.fetchManyData(_ as Function, _ as Function, _) >> expectedResult when: - def actualResult = DatabasePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(mockMetadata.receivedSubmissionId()) + def actualResult = DatabasePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(mockMetadata.inboundReportId()) then: actualResult == expectedResult @@ -259,7 +259,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { mockDao.fetchManyData(_ as Function, _ as Function, _) >> { throw new SQLException("Something went wrong!") } when: - DatabasePartnerMetadataStorage.getInstance().readMetadataForMessageLinking("receivedSubmissionId") + DatabasePartnerMetadataStorage.getInstance().readMetadataForMessageLinking("inboundReportId") then: thrown(PartnerMetadataException) @@ -300,7 +300,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { def "partnerMetadataFromResultSet returns partner metadata"() { given: - def receivedMessageId = "12345" + def inboundReportId = "12345" def sentMessageId = "7890" def sender = "DogCow" def receiver = "You'll get your just reward" @@ -313,11 +313,11 @@ class DatabasePartnerMetadataStorageTest extends Specification { def reason = "It done Goofed" def messageType = PartnerMetadataMessageType.RESULT def placerOrderNumber = "placer_order_number" - def expected = new PartnerMetadata(receivedMessageId, sentMessageId, timeReceived, timeDelivered, hash, status, reason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) + def expected = new PartnerMetadata(inboundReportId, sentMessageId, timeReceived, timeDelivered, hash, status, reason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) def mockResultSet = Mock(ResultSet) mockResultSet.next() >> true - mockResultSet.getString("received_message_id") >> receivedMessageId + mockResultSet.getString("inbound_report_id") >> inboundReportId mockResultSet.getString("sent_message_id") >> sentMessageId mockResultSet.getString("sender") >> sender mockResultSet.getString("receiver") >> receiver diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMetadataConverterTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMetadataConverterTest.groovy index ce98a0951..a51ef7d3f 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMetadataConverterTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMetadataConverterTest.groovy @@ -36,13 +36,13 @@ class HapiMetadataConverterTest extends Specification { def messageType = PartnerMetadataMessageType.ORDER def messageIds = Set.of("TestId") PartnerMetadata metadata = new PartnerMetadata( - "receivedSubmissionId", "sentSubmissionId", time, time, hash, PartnerMetadataStatus.DELIVERED, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + "inboundReportId", "sentSubmissionId", time, time, hash, PartnerMetadataStatus.DELIVERED, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") when: - def result = HapiPartnerMetadataConverter.getInstance().extractPublicMetadataToOperationOutcome(metadata, "receivedSubmissionId", messageIds).getUnderlyingOutcome() as OperationOutcome + def result = HapiPartnerMetadataConverter.getInstance().extractPublicMetadataToOperationOutcome(metadata, "inboundReportId", messageIds).getUnderlyingOutcome() as OperationOutcome then: - result.getId() == "receivedSubmissionId" + result.getId() == "inboundReportId" result.getIssue().get(0).diagnostics == messageIds.toString() result.getIssue().get(1).diagnostics == sendingFacilityId result.getIssue().get(2).diagnostics == receivingFacilityId @@ -53,6 +53,6 @@ class HapiMetadataConverterTest extends Specification { result.getIssue().get(7).diagnostics == failureReason result.getIssue().get(8).diagnostics == messageType.toString() result.getIssue().get(9).diagnostics == "sentSubmissionId" - result.getIssue().get(10).diagnostics == "receivedSubmissionId" + result.getIssue().get(10).diagnostics == "inboundReportId" } } 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 ecc94242f..75b2de4f0 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 @@ -31,8 +31,8 @@ class FilePartnerMetadataStorageTest extends Specification { def "save and read metadata successfully"() { given: - def expectedReceivedSubmissionId = "receivedSubmissionId" - def expectedSentSubmissionId = "receivedSubmissionId" + def expectedReceivedSubmissionId = "inboundReportId" + def expectedSentSubmissionId = "inboundReportId" PartnerMetadata metadata = new PartnerMetadata(expectedReceivedSubmissionId, expectedSentSubmissionId, Instant.parse("2023-12-04T18:51:48.941875Z"), Instant.parse("2023-12-04T18:51:48.941875Z"), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") TestApplicationContext.register(Formatter, Jackson.getInstance()) @@ -48,7 +48,7 @@ class FilePartnerMetadataStorageTest extends Specification { def "saveMetadata throws PartnerMetadataException when unable to save file"() { given: - PartnerMetadata metadata = new PartnerMetadata("receivedSubmissionId", "sentSubmissionId", Instant.now(), Instant.now(), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + PartnerMetadata metadata = new PartnerMetadata("inboundReportId", "sentSubmissionId", Instant.now(), Instant.now(), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") def mockFormatter = Mock(Formatter) mockFormatter.convertToJsonString(_ as PartnerMetadata) >> {throw new FormatterProcessingException("error", new Exception())} @@ -65,7 +65,7 @@ class FilePartnerMetadataStorageTest extends Specification { def "saveMetadata overwrites a file if it had been saved before"() { given: - def expectedReceivedSubmissionId = "receivedSubmissionId" + def expectedReceivedSubmissionId = "inboundReportId" def expectedSentSubmissionId = "sentSubmissionId" PartnerMetadata metadata1 = new PartnerMetadata(expectedReceivedSubmissionId, expectedSentSubmissionId, Instant.parse("2023-12-04T18:51:48.941875Z"), Instant.parse("2023-12-04T18:51:48.941875Z"), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") PartnerMetadata metadata2 = new PartnerMetadata(expectedReceivedSubmissionId, PartnerMetadataStatus.DELIVERED) @@ -134,32 +134,32 @@ class FilePartnerMetadataStorageTest extends Specification { TestApplicationContext.injectRegisteredImplementations() when: - def receivedSubmissionId1 = "receivedSubmissionId1" + def inboundReportId1 = "inboundReportId1" def matchingPlacerOrderNumber1 = "placerOrderNumber1" def matchingSendingFacilityDetails1 = new MessageHdDataType("sending_facility_name1", "sending_facility_id1", "sending_facility_type1") - def matchingSendingFacilityDetailsMetadata1 = new PartnerMetadata(receivedSubmissionId1, null, null, null, null, null, null, null, null, matchingSendingFacilityDetails1, null, new MessageHdDataType(null, null, null), matchingPlacerOrderNumber1) + def matchingSendingFacilityDetailsMetadata1 = new PartnerMetadata(inboundReportId1, null, null, null, null, null, null, null, null, matchingSendingFacilityDetails1, null, new MessageHdDataType(null, null, null), matchingPlacerOrderNumber1) def otherMatchingSendingFacilityDetailsMetadata1 = new PartnerMetadata("1", null, null, null, null, null, null, null, null, matchingSendingFacilityDetails1, null, new MessageHdDataType(null, null, null), matchingPlacerOrderNumber1) FilePartnerMetadataStorage.getInstance().saveMetadata(matchingSendingFacilityDetailsMetadata1) FilePartnerMetadataStorage.getInstance().saveMetadata(otherMatchingSendingFacilityDetailsMetadata1) - def metadataSetWithMatchingSendingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(receivedSubmissionId1) + def metadataSetWithMatchingSendingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(inboundReportId1) then: - metadataSetWithMatchingSendingFacilityDetails.contains(otherMatchingSendingFacilityDetailsMetadata1.receivedSubmissionId()) - !metadataSetWithMatchingSendingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata1.receivedSubmissionId()) + metadataSetWithMatchingSendingFacilityDetails.contains(otherMatchingSendingFacilityDetailsMetadata1.inboundReportId()) + !metadataSetWithMatchingSendingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata1.inboundReportId()) when: - def receivedSubmissionId2 = "receivedSubmissionId2" + def inboundReportId2 = "inboundReportId2" def matchingPlacerOrderNumber2 = "placerOrderNumber2" def matchingSendingFacilityDetails2 = new MessageHdDataType("sending_facility_name2", "sending_facility_id2", "sending_facility_type2") - def matchingSendingFacilityDetailsMetadata2 = new PartnerMetadata(receivedSubmissionId2, null, null, null, null, null, null, null, null, matchingSendingFacilityDetails2, null, new MessageHdDataType(null, null, null), matchingPlacerOrderNumber2) + def matchingSendingFacilityDetailsMetadata2 = new PartnerMetadata(inboundReportId2, null, null, null, null, null, null, null, null, matchingSendingFacilityDetails2, null, new MessageHdDataType(null, null, null), matchingPlacerOrderNumber2) def matchingReceivingFacilityDetailsMetadata2 = new PartnerMetadata("2", null, null, null, null, null, null, null, null, new MessageHdDataType(null, null, null), null, matchingSendingFacilityDetails2, matchingPlacerOrderNumber2) FilePartnerMetadataStorage.getInstance().saveMetadata(matchingSendingFacilityDetailsMetadata2) FilePartnerMetadataStorage.getInstance().saveMetadata(matchingReceivingFacilityDetailsMetadata2) - def metadataSetWithMatchingSendingAndReceivingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(receivedSubmissionId2) + def metadataSetWithMatchingSendingAndReceivingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(inboundReportId2) then: - metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingReceivingFacilityDetailsMetadata2.receivedSubmissionId()) - !metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata2.receivedSubmissionId()) + metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingReceivingFacilityDetailsMetadata2.inboundReportId()) + !metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata2.inboundReportId()) } def "readMetadataForMessageLinking returns an empty set when no metadata is found"() { From bdfb3d772919b8b59d34689ff5a91afd046502cc Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Wed, 20 Nov 2024 16:57:09 -0700 Subject: [PATCH 02/10] rename sent submission and message id to be outbound report id --- .../etor/EtorDomainRegistration.java | 4 +- .../etor/messages/SendMessageHelper.java | 14 ++-- .../metadata/partner/PartnerMetadata.java | 16 ++--- .../partner/PartnerMetadataOrchestrator.java | 18 ++--- .../etor/orders/SendOrderUseCase.java | 2 +- .../etor/results/SendResultUseCase.java | 2 +- .../DatabasePartnerMetadataStorage.java | 7 +- .../hapi/HapiPartnerMetadataConverter.java | 2 +- .../localfile/FilePartnerMetadataStorage.java | 2 +- .../etor/EtorDomainRegistrationTest.groovy | 8 +-- .../messages/SendMessageHelperTest.groovy | 22 +++---- .../PartnerMetadataOrchestratorTest.groovy | 66 +++++++++---------- .../partner/PartnerMetadataTest.groovy | 30 ++++----- .../etor/orders/SendOrderUseCaseTest.groovy | 16 ++--- .../etor/results/SendResultUseCaseTest.groovy | 10 +-- .../DatabasePartnerMetadataStorageTest.groovy | 14 ++-- .../hapi/HapiMetadataConverterTest.groovy | 4 +- .../FilePartnerMetadataStorageTest.groovy | 20 +++--- 18 files changed, 129 insertions(+), 128 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 4dbdf6bb3..13c7e30ae 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 @@ -222,7 +222,7 @@ protected DomainResponse handleMessageRequest( DomainRequest request, MessageRequestHandler requestHandler, String messageType) { - String inboundReportId = getReceivedSubmissionId(request); + String inboundReportId = getInboundReportId(request); boolean markMetadataAsFailed = false; String errorMessage = ""; @@ -250,7 +250,7 @@ protected DomainResponse handleMessageRequest( } } - protected String getReceivedSubmissionId(DomainRequest request) { + protected String getInboundReportId(DomainRequest request) { String inboundReportId = request.getHeaders().get("recordid"); if (inboundReportId == null || inboundReportId.isEmpty()) { 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 ce7de9ccc..af99cebf4 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 @@ -37,22 +37,22 @@ public void savePartnerMetadataForReceivedMessage(PartnerMetadata partnerMetadat } } - public void saveSentMessageSubmissionId(String inboundReportId, String sentSubmissionId) { - if (sentSubmissionId == null || inboundReportId == null) { + public void saveReportIds(String inboundReportId, String outboundReportId) { + if (outboundReportId == null || inboundReportId == null) { logger.logWarning( - "Inbound and/or sent reportId is null so not saving metadata for sent result"); + "Inbound and/or outbound reportId is null so not saving metadata for sent result"); return; } try { - partnerMetadataOrchestrator.updateMetadataForSentMessage( - inboundReportId, sentSubmissionId); + partnerMetadataOrchestrator.updateMetadataForOutboundMessage( + inboundReportId, outboundReportId); } catch (PartnerMetadataException e) { logger.logError( "Unable to update metadata for inbound reportId " + inboundReportId - + " and sent submissionId " - + sentSubmissionId, + + " and sent outbound reportId " + + outboundReportId, e); } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadata.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadata.java index 2f3264f84..8396b6f0a 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadata.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadata.java @@ -7,7 +7,7 @@ * The partner-facing metadata. * * @param inboundReportId The inbound report ID. - * @param sentSubmissionId The sent submission ID. + * @param outboundReportId The outbound report ID. * @param timeReceived The time the message was received. * @param timeDelivered The time the message was delivered. * @param hash The hash of the message. @@ -15,7 +15,7 @@ */ public record PartnerMetadata( String inboundReportId, - String sentSubmissionId, + String outboundReportId, Instant timeReceived, Instant timeDelivered, String hash, @@ -77,10 +77,10 @@ public PartnerMetadata(String inboundReportId, PartnerMetadataStatus deliverySta null); } - public PartnerMetadata withSentSubmissionId(String sentSubmissionId) { + public PartnerMetadata withOutboundReportId(String outboundReportId) { return new PartnerMetadata( this.inboundReportId, - sentSubmissionId, + outboundReportId, this.timeReceived, this.timeDelivered, this.hash, @@ -97,7 +97,7 @@ public PartnerMetadata withSentSubmissionId(String sentSubmissionId) { public PartnerMetadata withTimeReceived(Instant timeReceived) { return new PartnerMetadata( this.inboundReportId, - this.sentSubmissionId, + this.outboundReportId, timeReceived, this.timeDelivered, this.hash, @@ -114,7 +114,7 @@ public PartnerMetadata withTimeReceived(Instant timeReceived) { public PartnerMetadata withTimeDelivered(Instant timeDelivered) { return new PartnerMetadata( this.inboundReportId, - this.sentSubmissionId, + this.outboundReportId, this.timeReceived, timeDelivered, this.hash, @@ -131,7 +131,7 @@ public PartnerMetadata withTimeDelivered(Instant timeDelivered) { public PartnerMetadata withDeliveryStatus(PartnerMetadataStatus deliveryStatus) { return new PartnerMetadata( this.inboundReportId, - this.sentSubmissionId, + this.outboundReportId, this.timeReceived, this.timeDelivered, this.hash, @@ -148,7 +148,7 @@ public PartnerMetadata withDeliveryStatus(PartnerMetadataStatus deliveryStatus) public PartnerMetadata withFailureMessage(String failureMessage) { return new PartnerMetadata( this.inboundReportId, - this.sentSubmissionId, + this.outboundReportId, this.timeReceived, this.timeDelivered, this.hash, diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java index 32131c788..9aa0fbebb 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java @@ -93,10 +93,10 @@ public void updateMetadataForReceivedMessage(PartnerMetadata partnerMetadata) partnerMetadataStorage.saveMetadata(updatedPartnerMetadata); } - public void updateMetadataForSentMessage(String inboundReportId, String sentSubmissionId) + public void updateMetadataForOutboundMessage(String inboundReportId, String outboundReportId) throws PartnerMetadataException { - if (sentSubmissionId == null) { + if (outboundReportId == null) { return; } @@ -109,12 +109,12 @@ public void updateMetadataForSentMessage(String inboundReportId, String sentSubm PartnerMetadata partnerMetadata = optionalPartnerMetadata.get(); - if (sentSubmissionId.equals(partnerMetadata.sentSubmissionId())) { + if (outboundReportId.equals(partnerMetadata.outboundReportId())) { return; } - logger.logInfo("Updating metadata with sentSubmissionId: {}", sentSubmissionId); - partnerMetadata = partnerMetadata.withSentSubmissionId(sentSubmissionId); + logger.logInfo("Updating metadata with outboundReportId: {}", outboundReportId); + partnerMetadata = partnerMetadata.withOutboundReportId(outboundReportId); partnerMetadataStorage.saveMetadata(partnerMetadata); } @@ -128,11 +128,11 @@ public Optional getMetadata(String inboundReportId) } PartnerMetadata partnerMetadata = optionalPartnerMetadata.get(); - var sentSubmissionId = partnerMetadata.sentSubmissionId(); - if (metadataIsStale(partnerMetadata) && sentSubmissionId != null) { + var outboundReportId = partnerMetadata.outboundReportId(); + if (metadataIsStale(partnerMetadata) && outboundReportId != null) { logger.logInfo( "Receiver name not found in metadata or delivery status still pending, looking up {} from RS history API", - sentSubmissionId); + outboundReportId); String rsStatus; String rsMessage = ""; @@ -140,7 +140,7 @@ public Optional getMetadata(String inboundReportId) try { String bearerToken = rsclient.getRsToken(); String responseBody = - rsclient.requestHistoryEndpoint(sentSubmissionId, bearerToken); + rsclient.requestHistoryEndpoint(outboundReportId, bearerToken); var parsedResponseBody = getDataFromReportStream(responseBody); rsStatus = parsedResponseBody[0]; rsMessage = parsedResponseBody[1]; diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java index 2aaaa758b..d61f7b3cb 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java @@ -49,6 +49,6 @@ public void convertAndSend(final Order order, String inboundReportId) sendMessageHelper.linkMessage(inboundReportId); - sendMessageHelper.saveSentMessageSubmissionId(inboundReportId, outboundReportId); + sendMessageHelper.saveReportIds(inboundReportId, outboundReportId); } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java index 6060fe60a..63e6ccf26 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java @@ -50,6 +50,6 @@ public void convertAndSend(Result result, String inboundReportId) sendMessageHelper.linkMessage(inboundReportId); - sendMessageHelper.saveSentMessageSubmissionId(inboundReportId, outboundReportId); + sendMessageHelper.saveReportIds(inboundReportId, outboundReportId); } } 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 1c022f65f..cadd32e70 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 @@ -51,7 +51,7 @@ public Optional readMetadata(final String uniqueId) try { PreparedStatement statement = connection.prepareStatement( - "SELECT * FROM metadata where inbound_report_id = ? OR sent_message_id = ?"); + "SELECT * FROM metadata where inbound_report_id = ? OR outbound_report_id = ?"); statement.setString(1, uniqueId); statement.setString(2, uniqueId); return statement; @@ -164,7 +164,7 @@ PartnerMetadata partnerMetadataFromResultSet(ResultSet resultSet) { return new PartnerMetadata( resultSet.getString(METADATA_TABLE_INBOUND_REPORT_ID), - resultSet.getString("sent_message_id"), + resultSet.getString("outbound_report_id"), timeReceived, timeDelivered, resultSet.getString("hash_of_message"), @@ -206,7 +206,8 @@ private List createDbColumnsFromMetadata(PartnerMetadata metadata) metadata.inboundReportId(), false, Types.VARCHAR), - new DbColumn("sent_message_id", metadata.sentSubmissionId(), true, Types.VARCHAR), + new DbColumn( + "outbound_report_id", metadata.outboundReportId(), true, Types.VARCHAR), new DbColumn("hash_of_message", metadata.hash(), false, Types.VARCHAR), new DbColumn( "time_received", diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiPartnerMetadataConverter.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiPartnerMetadataConverter.java index fecc839a9..c0d8182c5 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiPartnerMetadataConverter.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiPartnerMetadataConverter.java @@ -76,7 +76,7 @@ public FhirMetadata extractPublicMetadataToOperationOutcome( .getIssue() .add( createInformationIssueComponent( - "outbound submission id", metadata.sentSubmissionId())); + "outbound submission id", metadata.outboundReportId())); operation .getIssue() 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 a925e5631..5edeaa519 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 @@ -75,7 +75,7 @@ public void saveMetadata(final PartnerMetadata metadata) throws PartnerMetadataE } Path metadataFilePath = - getFilePath(metadata.inboundReportId() + "-" + metadata.sentSubmissionId()); + getFilePath(metadata.inboundReportId() + "-" + metadata.outboundReportId()); try { String content = formatter.convertToJsonString(metadata); Files.writeString(metadataFilePath, content); 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 faa88bda0..eaa665ab9 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 @@ -212,15 +212,15 @@ class EtorDomainRegistrationTest extends Specification { given: def expectedStatusCode = 200 def inboundReportId = "inboundReportId" - def sentSubmissionId = "sentSubmissionId" - def metadata = new PartnerMetadata(inboundReportId, "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number").withSentSubmissionId(sentSubmissionId) + def outboundReportId = "outboundReportId" + def metadata = new PartnerMetadata(inboundReportId, "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number").withOutboundReportId(outboundReportId) def linkedMessageIds = Set.of(inboundReportId, "Test1", "Test2") def connector = new EtorDomainRegistration() TestApplicationContext.register(EtorDomainRegistration, connector) def request = new DomainRequest() - request.setPathParams(["id": sentSubmissionId]) + request.setPathParams(["id": outboundReportId]) def mockPartnerMetadataOrchestrator = Mock(PartnerMetadataOrchestrator) TestApplicationContext.register(PartnerMetadataOrchestrator, mockPartnerMetadataOrchestrator) @@ -243,7 +243,7 @@ class EtorDomainRegistrationTest extends Specification { then: actualStatusCode == expectedStatusCode - 1 * mockPartnerMetadataOrchestrator.getMetadata(sentSubmissionId) >> Optional.ofNullable(metadata) + 1 * mockPartnerMetadataOrchestrator.getMetadata(outboundReportId) >> Optional.ofNullable(metadata) 1 * mockPartnerMetadataOrchestrator.findMessagesIdsToLink(inboundReportId) >> linkedMessageIds 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/messages/SendMessageHelperTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy index 71c7e6a59..fcd698687 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy @@ -74,38 +74,38 @@ class SendMessageHelperTest extends Specification { 1 * mockLogger.logError(_, _) } - def "saveSentMessageSubmissionId works"() { + def "saveReportIds works"() { given: - def sentSubmissionId = "sentId" + def outboundReportId = "outboundReportId" def inboundReportId = "inboundReportId" - mockOrchestrator.updateMetadataForSentMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } + mockOrchestrator.updateMetadataForOutboundMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } when: - SendMessageHelper.getInstance().saveSentMessageSubmissionId(inboundReportId, sentSubmissionId) + SendMessageHelper.getInstance().saveReportIds(inboundReportId, outboundReportId) then: - 1 * mockOrchestrator.updateMetadataForSentMessage(_, _) + 1 * mockOrchestrator.updateMetadataForOutboundMessage(_, _) } - def "saveSentMessageSubmissionId should log warnings for null inboundReportId"() { + def saveReportIds() { given: def inboundReportId = "inboundReportId" when: - SendMessageHelper.getInstance().saveSentMessageSubmissionId(null, inboundReportId) + SendMessageHelper.getInstance().saveReportIds(null, inboundReportId) then: 1 * mockLogger.logWarning(_) } - def "saveSentMessageSubmissionId should log error and continues when updateMetadataForSentMessage throws error"() { + def "saveReportIds should log error and continues when updateMetadataForOutboundMessage throws error"() { given: - def sentSubmissionId = "sentId" + def outboundReportId = "outboundReportId" def inboundReportId = "inboundReportId" - mockOrchestrator.updateMetadataForSentMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } + mockOrchestrator.updateMetadataForOutboundMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } when: - SendMessageHelper.getInstance().saveSentMessageSubmissionId(inboundReportId, sentSubmissionId) + SendMessageHelper.getInstance().saveReportIds(inboundReportId, outboundReportId) then: 1 * mockLogger.logError(_, _) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy index 5187836ac..58341a237 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy @@ -20,7 +20,7 @@ class PartnerMetadataOrchestratorTest extends Specification { def mockClient def mockFormatter def inboundReportId = "inboundReportId" - def sentSubmissionId = "sentSubmissionId" + def outboundReportId = "outboundReportId" def hashCode = "hash" def bearerToken = "token" def placerOrderNumber = "placer_order_number" @@ -49,7 +49,7 @@ class PartnerMetadataOrchestratorTest extends Specification { receivingFacility = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") testMetadata = new PartnerMetadata(inboundReportId, - sentSubmissionId, + outboundReportId, timeReceived, timeDelivered, hashCode, @@ -110,7 +110,7 @@ class PartnerMetadataOrchestratorTest extends Specification { def expectedMetadata = new PartnerMetadata( inboundReportId, - sentSubmissionId, + outboundReportId, Instant.parse(timestamp), timeDelivered, hashCode, @@ -133,33 +133,33 @@ class PartnerMetadataOrchestratorTest extends Specification { 1 * mockPartnerMetadataStorage.saveMetadata(expectedMetadata) } - def "updateMetadataForSentMessage test case when sentSubmissionId is null"() { + def "updateMetadataForOutboundMessage test case when outboundReportId is null"() { when: - def sentSubmissionId = null - PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(inboundReportId, sentSubmissionId) + def outboundReportId = null + PartnerMetadataOrchestrator.getInstance().updateMetadataForOutboundMessage(inboundReportId, outboundReportId) then: 0 * mockPartnerMetadataStorage.readMetadata(inboundReportId) } - def "updateMetadataForSentMessage test case when PartnerMetadata returns no data"() { + def "updateMetadataForOutboundMessage test case when PartnerMetadata returns no data"() { given: mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.empty() when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(inboundReportId, sentSubmissionId) + PartnerMetadataOrchestrator.getInstance().updateMetadataForOutboundMessage(inboundReportId, outboundReportId) then: 0 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) } - def "updateMetadataForSentMessage ends when sentSubmissionId matches the one provided by PartnerMetadata"() { + def "updateMetadataForOutboundMessage ends when outboundReportId matches the one provided by PartnerMetadata"() { given: - def optional = Optional.of(new PartnerMetadata(inboundReportId, sentSubmissionId, Instant.now(), null, "", PartnerMetadataStatus.FAILED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber)) + def optional = Optional.of(new PartnerMetadata(inboundReportId, outboundReportId, Instant.now(), null, "", PartnerMetadataStatus.FAILED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber)) mockPartnerMetadataStorage.readMetadata(inboundReportId) >> optional when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(inboundReportId, sentSubmissionId) + PartnerMetadataOrchestrator.getInstance().updateMetadataForOutboundMessage(inboundReportId, outboundReportId) then: 0 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) @@ -268,13 +268,13 @@ class PartnerMetadataOrchestratorTest extends Specification { thrown(PartnerMetadataException) } - def "updateMetadataForSentMessage updates metadata successfully"() { + def "updateMetadataForOutboundMessage updates metadata successfully"() { given: def partnerMetadata = new PartnerMetadata(inboundReportId, "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - def updatedPartnerMetadata = partnerMetadata.withSentSubmissionId(sentSubmissionId) + def updatedPartnerMetadata = partnerMetadata.withOutboundReportId(outboundReportId) when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForSentMessage(inboundReportId, sentSubmissionId) + PartnerMetadataOrchestrator.getInstance().updateMetadataForOutboundMessage(inboundReportId, outboundReportId) then: 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(partnerMetadata) @@ -283,7 +283,7 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata throws PartnerMetadataException on client error"() { given: - def partnerMetadata = new PartnerMetadata(inboundReportId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, "failureReason", PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def partnerMetadata = new PartnerMetadata(inboundReportId, "outboundReportId", Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, "failureReason", PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(partnerMetadata) mockClient.getRsToken() >> "token" @@ -299,7 +299,7 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata throws PartnerMetadataException on formatter error"() { given: def rsHistoryApiResponse = "{\"destinations\": [{\"organization_id\": \"org\", \"service\": \"service\"}]}" - def partnerMetadata = new PartnerMetadata(inboundReportId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, "failureReason", PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def partnerMetadata = new PartnerMetadata(inboundReportId, "outboundReportId", Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, "failureReason", PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockPartnerMetadataStorage.readMetadata(inboundReportId) >> Optional.of(partnerMetadata) mockClient.getRsToken() >> "token" @@ -315,7 +315,7 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata retrieves metadata successfully with the sender already filled"() { given: - def metadata = new PartnerMetadata(inboundReportId, "sentSubmissionId", Instant.now(), null, "hash", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def metadata = new PartnerMetadata(inboundReportId, "outboundReportId", Instant.now(), null, "hash", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) when: def result = PartnerMetadataOrchestrator.getInstance().getMetadata(inboundReportId) @@ -327,7 +327,7 @@ class PartnerMetadataOrchestratorTest extends Specification { 0 * mockClient.requestHistoryEndpoint(_, _) } - def "getMetadata skips lookup with stale metadata and missing sentSubmissionId"() { + def "getMetadata skips lookup with stale metadata and missing outboundReportId"() { given: def metadata = new PartnerMetadata(inboundReportId, null, Instant.now(), null, "hash", PartnerMetadataStatus.PENDING, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number") @@ -340,7 +340,7 @@ class PartnerMetadataOrchestratorTest extends Specification { notThrown(PartnerMetadataException) } - def "getMetadata retrieves metadata successfully when receiver is present and sentSubmissionId is missing"() { + def "getMetadata retrieves metadata successfully when receiver is present and outboundReportId is missing"() { given: def metadata = new PartnerMetadata(inboundReportId, null, Instant.now(), null, "hash", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.RESULT, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) @@ -358,11 +358,11 @@ class PartnerMetadataOrchestratorTest extends Specification { def timeDelivered = Instant.now() def rsHistoryApiResponse = "{\"actualCompletionAt\": \"2023-10-24T19:48:26.921Z\",\"destinations\": [{\"organization_id\": \"org\", \"service\": \"service\"}]}" def receivingFacilityWithMissingUniversalId = new MessageHdDataType("receiving_app_name", null, "receiving_app_type") - def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacilityWithMissingUniversalId, placerOrderNumber) - def expectedMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacilityWithMissingUniversalId, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacilityWithMissingUniversalId, placerOrderNumber) + def expectedMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacilityWithMissingUniversalId, placerOrderNumber) mockClient.getRsToken() >> bearerToken - mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse + mockClient.requestHistoryEndpoint(outboundReportId, bearerToken) >> rsHistoryApiResponse mockFormatter.convertJsonToObject(rsHistoryApiResponse, _ as TypeReference) >> [ overallStatus: "Delivered", actualCompletionAt: timeDelivered.toString(), @@ -385,11 +385,11 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata gets status if still pending in metadata"() { given: def rsHistoryApiResponse = "{\"destinations\": [{\"organization_id\": \"org\", \"service\": \"service\"}]}" - def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - def expectedMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.FAILED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def expectedMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, null, hashCode, PartnerMetadataStatus.FAILED, "", messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockClient.getRsToken() >> bearerToken - mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse + mockClient.requestHistoryEndpoint(outboundReportId, bearerToken) >> rsHistoryApiResponse mockFormatter.convertJsonToObject(rsHistoryApiResponse, _ as TypeReference) >> [ overallStatus: "Not Delivering", destinations: [ @@ -412,11 +412,11 @@ class PartnerMetadataOrchestratorTest extends Specification { given: def timeDelivered = Instant.now() def rsHistoryApiResponse = "whatever" - def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - def expectedMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def expectedMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, timeDelivered, hashCode, PartnerMetadataStatus.DELIVERED, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockClient.getRsToken() >> bearerToken - mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse + mockClient.requestHistoryEndpoint(outboundReportId, bearerToken) >> rsHistoryApiResponse mockFormatter.convertJsonToObject(rsHistoryApiResponse, _ as TypeReference) >> [ overallStatus: "Delivered", actualCompletionAt: timeDelivered.toString(), @@ -443,10 +443,10 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata saves pending without delivery time if nobody has delivery times"() { given: def rsHistoryApiResponse = "whatever" - def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockClient.getRsToken() >> bearerToken - mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse + mockClient.requestHistoryEndpoint(outboundReportId, bearerToken) >> rsHistoryApiResponse mockFormatter.convertJsonToObject(rsHistoryApiResponse, _ as TypeReference) >> [ overallStatus: "Pending", actualCompletionAt: null, @@ -473,11 +473,11 @@ class PartnerMetadataOrchestratorTest extends Specification { def "getMetadata saves loaded delivered metadata if found"() { given: def rsHistoryApiResponse = "whatever" - def missingReceiverMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) - def expectedMetadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hashCode, PartnerMetadataStatus.DELIVERED, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def missingReceiverMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, null, hashCode, PartnerMetadataStatus.PENDING, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) + def expectedMetadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, null, hashCode, PartnerMetadataStatus.DELIVERED, null, messageType, sendingApp, sendingFacility, receivingApp, receivingFacility, placerOrderNumber) mockClient.getRsToken() >> bearerToken - mockClient.requestHistoryEndpoint(sentSubmissionId, bearerToken) >> rsHistoryApiResponse + mockClient.requestHistoryEndpoint(outboundReportId, bearerToken) >> rsHistoryApiResponse mockFormatter.convertJsonToObject(rsHistoryApiResponse, _ as TypeReference) >> [ overallStatus: "Delivered", actualCompletionAt: null, diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataTest.groovy index 3d74c2858..7680f7a45 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataTest.groovy @@ -18,7 +18,7 @@ class PartnerMetadataTest extends Specification { def "test constructor"() { given: def inboundReportId = "inboundReportId" - def sentSubmissionId = "sentSubmissionId" + def outboundReportId = "outboundReportId" def timeReceived = Instant.now() def timeDelivered = Instant.now() def hash = "abcd" @@ -31,11 +31,11 @@ class PartnerMetadataTest extends Specification { def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") when: - def metadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hash, PartnerMetadataStatus.DELIVERED, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def metadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, timeDelivered, hash, PartnerMetadataStatus.DELIVERED, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") then: metadata.inboundReportId() == inboundReportId - metadata.sentSubmissionId() == sentSubmissionId + metadata.outboundReportId() == outboundReportId metadata.timeDelivered() == timeDelivered metadata.timeReceived() == timeReceived metadata.hash() == hash @@ -57,17 +57,17 @@ class PartnerMetadataTest extends Specification { then: metadata.inboundReportId() == inboundReportId - metadata.sentSubmissionId() == null + metadata.outboundReportId() == null metadata.timeReceived() == null metadata.timeDelivered() == null metadata.hash() == null metadata.deliveryStatus() == deliverStatus } - def "test withSentSubmissionId to update PartnerMetadata"() { + def 'test withOutboundReportId to update PartnerMetadata'() { given: def inboundReportId = "inboundReportId" - def sentSubmissionId = "sentSubmissionId" + def outboundReportId = "outboundReportId" def messageType = PartnerMetadataMessageType.RESULT def timeReceived = Instant.now() def hash = "abcd" @@ -81,11 +81,11 @@ class PartnerMetadataTest extends Specification { def metadata = new PartnerMetadata(inboundReportId, null, timeReceived, null, hash, status, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") when: - def updatedMetadata = metadata.withSentSubmissionId(sentSubmissionId) + def updatedMetadata = metadata.withOutboundReportId(outboundReportId) then: updatedMetadata.inboundReportId() == inboundReportId - updatedMetadata.sentSubmissionId() == sentSubmissionId + updatedMetadata.outboundReportId() == outboundReportId updatedMetadata.timeReceived() == timeReceived updatedMetadata.hash() == hash updatedMetadata.deliveryStatus() == status @@ -98,7 +98,7 @@ class PartnerMetadataTest extends Specification { def "test withDeliveryStatus to update PartnerMetadata"() { given: def inboundReportId = "inboundReportId" - def sentSubmissionId = "sentSubmissionId" + def outboundReportId = "outboundReportId" def timeReceived = Instant.now() def timeDelivered = null def messageType = PartnerMetadataMessageType.RESULT @@ -108,15 +108,15 @@ class PartnerMetadataTest extends Specification { def sendingFacilityDetails = new MessageHdDataType("sending_facility_name", "sending_facility_id", "sending_facility_type") def receivingAppDetails = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - def metadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, timeDelivered, hash, PartnerMetadataStatus.PENDING, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def metadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, timeDelivered, hash, PartnerMetadataStatus.PENDING, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") when: def newStatus = PartnerMetadataStatus.DELIVERED - def updatedMetadata = metadata.withSentSubmissionId(sentSubmissionId).withDeliveryStatus(newStatus) + def updatedMetadata = metadata.withOutboundReportId(outboundReportId).withDeliveryStatus(newStatus) then: updatedMetadata.inboundReportId() == inboundReportId - updatedMetadata.sentSubmissionId() == sentSubmissionId + updatedMetadata.outboundReportId() == outboundReportId updatedMetadata.timeReceived() == timeReceived updatedMetadata.timeDelivered() == null updatedMetadata.hash() == hash @@ -131,7 +131,7 @@ class PartnerMetadataTest extends Specification { def "test withTimeDelivered to update PartnerMetadata"() { given: def inboundReportId = "inboundReportId" - def sentSubmissionId = "sentSubmissionId" + def outboundReportId = "outboundReportId" def timeReceived = Instant.now() def timeDelivered = Instant.now() def messageType = PartnerMetadataMessageType.RESULT @@ -141,14 +141,14 @@ class PartnerMetadataTest extends Specification { def sendingFacilityDetails = new MessageHdDataType("sending_facility_name", "sending_facility_id", "sending_facility_type") def receivingAppDetails = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - def metadata = new PartnerMetadata(inboundReportId, sentSubmissionId, timeReceived, null, hash, PartnerMetadataStatus.PENDING, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def metadata = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, null, hash, PartnerMetadataStatus.PENDING, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") when: def updatedMetadata = metadata.withTimeDelivered(timeDelivered) then: updatedMetadata.inboundReportId() == inboundReportId - updatedMetadata.sentSubmissionId() == sentSubmissionId + updatedMetadata.outboundReportId() == outboundReportId updatedMetadata.timeReceived() == timeReceived updatedMetadata.timeDelivered() == timeDelivered updatedMetadata.hash() == hash 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 093f2a681..29376f184 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 @@ -35,7 +35,7 @@ class SendOrderUseCaseTest extends Specification { def "send sends successfully"() { given: def inboundReportId = "inboundReportId" - def sentSubmissionId = "sentId" + def outboundReportId = "outboundReportId" def messagesIdsToLink = new HashSet<>(Set.of("messageId1", "messageId2")) def mockOrder = new OrderMock(null, null, null, null, null, null, null, null) @@ -46,9 +46,9 @@ class SendOrderUseCaseTest extends Specification { then: 1 * mockEngine.runRules(mockOrder) - 1 * mockSender.send(mockOrder) >> Optional.of(sentSubmissionId) + 1 * mockSender.send(mockOrder) >> Optional.of(outboundReportId) 1 * mockOrchestrator.updateMetadataForReceivedMessage(_ as PartnerMetadata) - 1 * mockOrchestrator.updateMetadataForSentMessage(inboundReportId, sentSubmissionId) + 1 * mockOrchestrator.updateMetadataForOutboundMessage(inboundReportId, outboundReportId) 1 * mockOrchestrator.findMessagesIdsToLink(inboundReportId) >> messagesIdsToLink 1 * mockOrchestrator.linkMessages(messagesIdsToLink + inboundReportId) } @@ -67,7 +67,7 @@ class SendOrderUseCaseTest extends Specification { def "convertAndSend should log warnings for null inboundReportId"() { given: - mockSender.send(_) >> Optional.of("sentSubmissionId") + mockSender.send(_) >> Optional.of("outboundReportId") TestApplicationContext.injectRegisteredImplementations() when: @@ -93,14 +93,14 @@ class SendOrderUseCaseTest extends Specification { 1 * mockLogger.logError(_, _) 1 * mockEngine.runRules(order) 1 * mockOrchestrator.findMessagesIdsToLink(inboundReportId) >> Set.of() - 1 * mockSender.send(order) >> Optional.of("sentId") + 1 * mockSender.send(order) >> Optional.of("outboundReportId") } def "convertAndSend logs error and continues when updating the metadata for the sent order throws exception"() { given: def order = Mock(Order) def partnerMetadataException = new PartnerMetadataException("Error") - mockOrchestrator.updateMetadataForSentMessage("inboundReportId", _) >> { throw partnerMetadataException} + mockOrchestrator.updateMetadataForOutboundMessage("inboundReportId", _) >> { throw partnerMetadataException} TestApplicationContext.injectRegisteredImplementations() when: @@ -109,7 +109,7 @@ class SendOrderUseCaseTest extends Specification { then: 1 * mockEngine.runRules(order) 1 * mockOrchestrator.findMessagesIdsToLink(_ as String) >> Set.of() - 1 * mockSender.send(order) >> Optional.of("sentId") + 1 * mockSender.send(order) >> Optional.of("outboundReportId") 1 * mockLogger.logError(_, partnerMetadataException) } @@ -126,6 +126,6 @@ class SendOrderUseCaseTest extends Specification { then: 1 * mockLogger.logWarning(_) 1 * mockOrchestrator.findMessagesIdsToLink(_ as String) >> Set.of() - 0 * mockOrchestrator.updateMetadataForSentMessage(_ as String, _ as String) + 0 * mockOrchestrator.updateMetadataForOutboundMessage(_ as String, _ as String) } } diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy index ddbe30097..51f1a378b 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy @@ -43,7 +43,7 @@ class SendResultUseCaseTest extends Specification { then: 1 * mockEngine.runRules(mockResult) - 1 * mockSender.send(mockResult) >> Optional.of("sentSubmissionId") + 1 * mockSender.send(mockResult) >> Optional.of("outboundReportId") } def "convertAndSend throws exception when send fails"() { @@ -71,14 +71,14 @@ class SendResultUseCaseTest extends Specification { then: 1 * mockLogger.logError(_, _) 1 * mockEngine.runRules(result) - 1 * mockSender.send(result) >> Optional.of("sentId") + 1 * mockSender.send(result) >> Optional.of("outboundReportId") } - def "convertAndSend logs error and continues when updateMetadataForSentMessage throws exception"() { + def "convertAndSend logs error and continues when updateMetadataForOutboundMessage throws exception"() { given: def result = Mock(Result) def inboundReportId = "inboundReportId" - mockOrchestrator.updateMetadataForSentMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } + mockOrchestrator.updateMetadataForOutboundMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } TestApplicationContext.injectRegisteredImplementations() when: @@ -86,7 +86,7 @@ class SendResultUseCaseTest extends Specification { then: 1 * mockEngine.runRules(result) - 1 * mockSender.send(result) >> Optional.of("sentId") + 1 * mockSender.send(result) >> Optional.of("outboundReportId") 1 * mockLogger.logError(_, _) } } diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.groovy index 1171ef38d..189df5a8e 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.groovy @@ -31,7 +31,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { def sendingFacilityDetails = new MessageHdDataType("sending_facility_name", "sending_facility_id", "sending_facility_type") def receivingAppDetails = new MessageHdDataType("receiving_app_name", "receiving_app_id", "receiving_app_type") def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") - def mockMetadata = new PartnerMetadata("inboundReportId", "sentSubmissionId", Instant.now(), Instant.now(), "hash", PartnerMetadataStatus.DELIVERED, "failure reason", PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def mockMetadata = new PartnerMetadata("inboundReportId", "outboundReportId", Instant.now(), Instant.now(), "hash", PartnerMetadataStatus.DELIVERED, "failure reason", PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") def setup() { TestApplicationContext.reset() @@ -104,7 +104,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { List columns = List.of( new DbColumn("inbound_report_id", mockMetadata.inboundReportId(), false, Types.VARCHAR), - new DbColumn("sent_message_id", mockMetadata.sentSubmissionId(), true, Types.VARCHAR), + new DbColumn("outbound_report_id", mockMetadata.outboundReportId(), true, Types.VARCHAR), new DbColumn("hash_of_message", mockMetadata.hash(), false, Types.VARCHAR), new DbColumn("time_received", Timestamp.from(mockMetadata.timeReceived()),false, Types.TIMESTAMP), new DbColumn("time_delivered", Timestamp.from(mockMetadata.timeDelivered()),true, Types.TIMESTAMP), @@ -201,7 +201,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { def testMapper = new ObjectMapper() def mockMetadata = new PartnerMetadata( "inboundReportId", - "sentSubmissionId", + "outboundReportId", null, null, "hash", @@ -218,7 +218,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { List columns = List.of( new DbColumn("inbound_report_id", mockMetadata.inboundReportId(), false, Types.VARCHAR), - new DbColumn("sent_message_id", mockMetadata.sentSubmissionId(), true, Types.VARCHAR), + new DbColumn("outbound_report_id", mockMetadata.outboundReportId(), true, Types.VARCHAR), new DbColumn("hash_of_message", mockMetadata.hash(), false, Types.VARCHAR), new DbColumn("time_received", null, false, Types.TIMESTAMP), new DbColumn("time_delivered", null,true, Types.TIMESTAMP), @@ -301,7 +301,7 @@ class DatabasePartnerMetadataStorageTest extends Specification { def "partnerMetadataFromResultSet returns partner metadata"() { given: def inboundReportId = "12345" - def sentMessageId = "7890" + def outboundReportId = "7890" def sender = "DogCow" def receiver = "You'll get your just reward" Timestamp timestampForMock = Timestamp.from(Instant.parse("2024-01-03T15:45:33.30Z")) @@ -313,12 +313,12 @@ class DatabasePartnerMetadataStorageTest extends Specification { def reason = "It done Goofed" def messageType = PartnerMetadataMessageType.RESULT def placerOrderNumber = "placer_order_number" - def expected = new PartnerMetadata(inboundReportId, sentMessageId, timeReceived, timeDelivered, hash, status, reason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) + def expected = new PartnerMetadata(inboundReportId, outboundReportId, timeReceived, timeDelivered, hash, status, reason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) def mockResultSet = Mock(ResultSet) mockResultSet.next() >> true mockResultSet.getString("inbound_report_id") >> inboundReportId - mockResultSet.getString("sent_message_id") >> sentMessageId + mockResultSet.getString("outbound_report_id") >> outboundReportId mockResultSet.getString("sender") >> sender mockResultSet.getString("receiver") >> receiver mockResultSet.getTimestamp("time_received") >> timestampForMock diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMetadataConverterTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMetadataConverterTest.groovy index a51ef7d3f..52bc0df1d 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMetadataConverterTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMetadataConverterTest.groovy @@ -36,7 +36,7 @@ class HapiMetadataConverterTest extends Specification { def messageType = PartnerMetadataMessageType.ORDER def messageIds = Set.of("TestId") PartnerMetadata metadata = new PartnerMetadata( - "inboundReportId", "sentSubmissionId", time, time, hash, PartnerMetadataStatus.DELIVERED, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + "inboundReportId", "outboundReportId", time, time, hash, PartnerMetadataStatus.DELIVERED, failureReason, messageType, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") when: def result = HapiPartnerMetadataConverter.getInstance().extractPublicMetadataToOperationOutcome(metadata, "inboundReportId", messageIds).getUnderlyingOutcome() as OperationOutcome @@ -52,7 +52,7 @@ class HapiMetadataConverterTest extends Specification { result.getIssue().get(6).diagnostics == PartnerMetadataStatus.DELIVERED.toString() result.getIssue().get(7).diagnostics == failureReason result.getIssue().get(8).diagnostics == messageType.toString() - result.getIssue().get(9).diagnostics == "sentSubmissionId" + result.getIssue().get(9).diagnostics == "outboundReportId" result.getIssue().get(10).diagnostics == "inboundReportId" } } 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 75b2de4f0..cecda8187 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 @@ -31,16 +31,16 @@ class FilePartnerMetadataStorageTest extends Specification { def "save and read metadata successfully"() { given: - def expectedReceivedSubmissionId = "inboundReportId" - def expectedSentSubmissionId = "inboundReportId" - PartnerMetadata metadata = new PartnerMetadata(expectedReceivedSubmissionId, expectedSentSubmissionId, Instant.parse("2023-12-04T18:51:48.941875Z"), Instant.parse("2023-12-04T18:51:48.941875Z"), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + def expectedInboundReportId = "inboundReportId" + def expectedOutboundReportId = "outboundReportId" + PartnerMetadata metadata = new PartnerMetadata(expectedInboundReportId, expectedOutboundReportId, Instant.parse("2023-12-04T18:51:48.941875Z"), Instant.parse("2023-12-04T18:51:48.941875Z"), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") TestApplicationContext.register(Formatter, Jackson.getInstance()) TestApplicationContext.injectRegisteredImplementations() when: FilePartnerMetadataStorage.getInstance().saveMetadata(metadata) - def actualMetadata = FilePartnerMetadataStorage.getInstance().readMetadata(expectedReceivedSubmissionId) + def actualMetadata = FilePartnerMetadataStorage.getInstance().readMetadata(expectedInboundReportId) then: actualMetadata.get() == metadata @@ -48,7 +48,7 @@ class FilePartnerMetadataStorageTest extends Specification { def "saveMetadata throws PartnerMetadataException when unable to save file"() { given: - PartnerMetadata metadata = new PartnerMetadata("inboundReportId", "sentSubmissionId", Instant.now(), Instant.now(), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + PartnerMetadata metadata = new PartnerMetadata("inboundReportId", "outboundReportId", Instant.now(), Instant.now(), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") def mockFormatter = Mock(Formatter) mockFormatter.convertToJsonString(_ as PartnerMetadata) >> {throw new FormatterProcessingException("error", new Exception())} @@ -65,10 +65,10 @@ class FilePartnerMetadataStorageTest extends Specification { def "saveMetadata overwrites a file if it had been saved before"() { given: - def expectedReceivedSubmissionId = "inboundReportId" - def expectedSentSubmissionId = "sentSubmissionId" - PartnerMetadata metadata1 = new PartnerMetadata(expectedReceivedSubmissionId, expectedSentSubmissionId, Instant.parse("2023-12-04T18:51:48.941875Z"), Instant.parse("2023-12-04T18:51:48.941875Z"), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") - PartnerMetadata metadata2 = new PartnerMetadata(expectedReceivedSubmissionId, PartnerMetadataStatus.DELIVERED) + def expectedInboundReportId = "inboundReportId" + def expectedOutboundReportId = "outboundReportId" + PartnerMetadata metadata1 = new PartnerMetadata(expectedInboundReportId, expectedOutboundReportId, Instant.parse("2023-12-04T18:51:48.941875Z"), Instant.parse("2023-12-04T18:51:48.941875Z"), "abcd", PartnerMetadataStatus.DELIVERED, null, PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, "placer_order_number") + PartnerMetadata metadata2 = new PartnerMetadata(expectedInboundReportId, PartnerMetadataStatus.DELIVERED) TestApplicationContext.register(Formatter, Jackson.getInstance()) @@ -77,7 +77,7 @@ class FilePartnerMetadataStorageTest extends Specification { when: FilePartnerMetadataStorage.getInstance().saveMetadata(metadata1) FilePartnerMetadataStorage.getInstance().saveMetadata(metadata2) - def actualMetadata = FilePartnerMetadataStorage.getInstance().readMetadata(expectedReceivedSubmissionId) + def actualMetadata = FilePartnerMetadataStorage.getInstance().readMetadata(expectedInboundReportId) then: actualMetadata.get() == metadata2 From ed3f694bc24d83e78c79f6fdc02d76ad4ff5ea49 Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Wed, 20 Nov 2024 17:06:23 -0700 Subject: [PATCH 03/10] cleanup renaming --- .../etor/messages/SendMessageHelper.java | 4 +-- .../partner/PartnerMetadataOrchestrator.java | 2 +- .../etor/orders/SendOrderUseCase.java | 2 +- .../etor/results/SendResultUseCase.java | 4 +-- .../messages/SendMessageHelperTest.groovy | 16 +++++------ .../PartnerMetadataOrchestratorTest.groovy | 28 +++++++++---------- .../etor/orders/SendOrderUseCaseTest.groovy | 6 ++-- .../etor/results/SendResultUseCaseTest.groovy | 4 +-- 8 files changed, 33 insertions(+), 33 deletions(-) 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 af99cebf4..920c660d6 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 @@ -21,14 +21,14 @@ public static SendMessageHelper getInstance() { private SendMessageHelper() {} - public void savePartnerMetadataForReceivedMessage(PartnerMetadata partnerMetadata) { + public void savePartnerMetadataForInboundMessage(PartnerMetadata partnerMetadata) { if (partnerMetadata.inboundReportId() == null) { logger.logWarning( "Inbound reportId is null so not saving metadata for received message"); return; } try { - partnerMetadataOrchestrator.updateMetadataForReceivedMessage(partnerMetadata); + partnerMetadataOrchestrator.updateMetadataForInboundMessage(partnerMetadata); } catch (PartnerMetadataException e) { logger.logError( "Unable to save metadata for inboundReportId " diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java index 9aa0fbebb..9c439a6d7 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java @@ -41,7 +41,7 @@ public static PartnerMetadataOrchestrator getInstance() { private PartnerMetadataOrchestrator() {} - public void updateMetadataForReceivedMessage(PartnerMetadata partnerMetadata) + public void updateMetadataForInboundMessage(PartnerMetadata partnerMetadata) throws PartnerMetadataException { logger.logInfo( diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java index d61f7b3cb..8aee41c50 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java @@ -40,7 +40,7 @@ public void convertAndSend(final Order order, String inboundReportId) order.getReceivingFacilityDetails(), order.getPlacerOrderNumber()); - sendMessageHelper.savePartnerMetadataForReceivedMessage(partnerMetadata); + sendMessageHelper.savePartnerMetadataForInboundMessage(partnerMetadata); transformationEngine.runRules(order); diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java index 63e6ccf26..96f56738b 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java @@ -41,12 +41,12 @@ public void convertAndSend(Result result, String inboundReportId) result.getReceivingFacilityDetails(), result.getPlacerOrderNumber()); - sendMessageHelper.savePartnerMetadataForReceivedMessage(partnerMetadata); + sendMessageHelper.savePartnerMetadataForInboundMessage(partnerMetadata); transformationEngine.runRules(result); String outboundReportId = sender.send(result).orElse(null); - logger.logInfo("Sent result reportId: {}", outboundReportId); + logger.logInfo("Outbound result reportId: {}", outboundReportId); sendMessageHelper.linkMessage(inboundReportId); diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy index fcd698687..becbf5f53 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy @@ -36,15 +36,15 @@ class SendMessageHelperTest extends Specification { receivingFacility, placerOrderNumber) } - def "savePartnerMetadataForReceivedMessage works"() { + def "savePartnerMetadataForInboundMessage works"() { when: - SendMessageHelper.getInstance().savePartnerMetadataForReceivedMessage(partnerMetadata) + SendMessageHelper.getInstance().savePartnerMetadataForInboundMessage(partnerMetadata) then: - 1 * mockOrchestrator.updateMetadataForReceivedMessage(_) + 1 * mockOrchestrator.updateMetadataForInboundMessage(_) } - def "savePartnerMetadataForReceivedMessage should log warnings for null inboundReportId"() { + def "savePartnerMetadataForInboundMessage should log warnings for null inboundReportId"() { when: PartnerMetadata warningPartnerMetadata = new PartnerMetadata( null, @@ -55,20 +55,20 @@ class SendMessageHelperTest extends Specification { receivingApp, receivingFacility, placerOrderNumber) - SendMessageHelper.getInstance().savePartnerMetadataForReceivedMessage(warningPartnerMetadata) + SendMessageHelper.getInstance().savePartnerMetadataForInboundMessage(warningPartnerMetadata) then: 1 * mockLogger.logWarning(_) } - def "savePartnerMetadataForReceivedMessage logs error and continues when updateMetadataForReceivedMessage throws error"() { + def "savePartnerMetadataForInboundMessage logs error and continues when updateMetadataForInboundMessage throws error"() { given: def hashCode = new Random().nextInt() def messageType = PartnerMetadataMessageType.RESULT - mockOrchestrator.updateMetadataForReceivedMessage(partnerMetadata) >> { throw new PartnerMetadataException("Error") } + mockOrchestrator.updateMetadataForInboundMessage(partnerMetadata) >> { throw new PartnerMetadataException("Error") } when: - SendMessageHelper.getInstance().savePartnerMetadataForReceivedMessage(partnerMetadata) + SendMessageHelper.getInstance().savePartnerMetadataForInboundMessage(partnerMetadata) then: 1 * mockLogger.logError(_, _) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy index 58341a237..b2ed2d3de 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy @@ -73,7 +73,7 @@ class PartnerMetadataOrchestratorTest extends Specification { TestApplicationContext.injectRegisteredImplementations() } - def "updateMetadataForReceivedMessage updates metadata successfully"() { + def "updateMetadataForInboundMessage updates metadata successfully"() { given: TestApplicationContext.register(Formatter, Jackson.getInstance()) @@ -125,7 +125,7 @@ class PartnerMetadataOrchestratorTest extends Specification { ) when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForReceivedMessage(testMetadata) + PartnerMetadataOrchestrator.getInstance().updateMetadataForInboundMessage(testMetadata) then: 1 * mockClient.getRsToken() >> bearerToken @@ -178,13 +178,13 @@ class PartnerMetadataOrchestratorTest extends Specification { 1 * mockPartnerMetadataStorage.readMetadata(inboundReportId) >> mockMetadata } - def "updateMetadataForReceivedMessage throws PartnerMetadataException on client error"() { + def "updateMetadataForInboundMessage throws PartnerMetadataException on client error"() { given: mockClient.getRsToken() >> "token" mockClient.requestDeliveryEndpoint(_ as String, _ as String) >> { throw new ReportStreamEndpointClientException("Client error", new Exception()) } when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForReceivedMessage(testMetadata) + PartnerMetadataOrchestrator.getInstance().updateMetadataForInboundMessage(testMetadata) then: 1 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) >> { PartnerMetadata metadata -> @@ -193,7 +193,7 @@ class PartnerMetadataOrchestratorTest extends Specification { thrown(PartnerMetadataException) } - def "updateMetadataForReceivedMessage throws PartnerMetadataException on formatter error"() { + def "updateMetadataForInboundMessage throws PartnerMetadataException on formatter error"() { given: def rsDeliveryApiResponse = "{ASDF}" @@ -202,13 +202,13 @@ class PartnerMetadataOrchestratorTest extends Specification { mockFormatter.convertJsonToObject(rsDeliveryApiResponse, _ as TypeReference) >> { throw new FormatterProcessingException("Formatter error", new Exception()) } when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForReceivedMessage(testMetadata) + PartnerMetadataOrchestrator.getInstance().updateMetadataForInboundMessage(testMetadata) then: thrown(PartnerMetadataException) } - def "updateMetadataForReceivedMessage throws PartnerMetadataException on formatter error due to unexpected response format"() { + def "updateMetadataForInboundMessage throws PartnerMetadataException on formatter error due to unexpected response format"() { given: def wrongFormatResponse = "{\"someotherkey\": \"value\"}" @@ -217,13 +217,13 @@ class PartnerMetadataOrchestratorTest extends Specification { mockFormatter.convertJsonToObject(wrongFormatResponse, _ as TypeReference) >> [someotherkey: "value"] when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForReceivedMessage(testMetadata) + PartnerMetadataOrchestrator.getInstance().updateMetadataForInboundMessage(testMetadata) then: thrown(PartnerMetadataException) } - def "updateMetadataForReceivedMessage throws PartnerMetadataException due to 0 originalIngestions"() { + def "updateMetadataForInboundMessage throws PartnerMetadataException due to 0 originalIngestions"() { given: def wrongFormatResponse = "{\"originalIngestion\": []}" @@ -232,13 +232,13 @@ class PartnerMetadataOrchestratorTest extends Specification { mockFormatter.convertJsonToObject(wrongFormatResponse, _ as TypeReference) >> [originalIngestion: []] when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForReceivedMessage(testMetadata) + PartnerMetadataOrchestrator.getInstance().updateMetadataForInboundMessage(testMetadata) then: thrown(PartnerMetadataException) } - def "updateMetadataForReceivedMessage throws PartnerMetadataException due to null originalIngestion"() { + def "updateMetadataForInboundMessage throws PartnerMetadataException due to null originalIngestion"() { given: def wrongFormatResponse = "{\"someOtherKey\": {}}" @@ -247,13 +247,13 @@ class PartnerMetadataOrchestratorTest extends Specification { mockFormatter.convertJsonToObject(wrongFormatResponse, _ as TypeReference) >> [someOtherKey:{}] when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForReceivedMessage(testMetadata) + PartnerMetadataOrchestrator.getInstance().updateMetadataForInboundMessage(testMetadata) then: thrown(PartnerMetadataException) } - def "updateMetadataForReceivedMessage throws PartnerMetadataException due to empty originalIngestion"() { + def "updateMetadataForInboundMessage throws PartnerMetadataException due to empty originalIngestion"() { given: def wrongFormatResponse = "{\"originalIngestion\": {}}" @@ -262,7 +262,7 @@ class PartnerMetadataOrchestratorTest extends Specification { mockFormatter.convertJsonToObject(wrongFormatResponse, _ as TypeReference) >> [originalIngestion:[]] when: - PartnerMetadataOrchestrator.getInstance().updateMetadataForReceivedMessage(testMetadata) + PartnerMetadataOrchestrator.getInstance().updateMetadataForInboundMessage(testMetadata) then: thrown(PartnerMetadataException) 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 29376f184..f77abd74f 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 @@ -47,7 +47,7 @@ class SendOrderUseCaseTest extends Specification { then: 1 * mockEngine.runRules(mockOrder) 1 * mockSender.send(mockOrder) >> Optional.of(outboundReportId) - 1 * mockOrchestrator.updateMetadataForReceivedMessage(_ as PartnerMetadata) + 1 * mockOrchestrator.updateMetadataForInboundMessage(_ as PartnerMetadata) 1 * mockOrchestrator.updateMetadataForOutboundMessage(inboundReportId, outboundReportId) 1 * mockOrchestrator.findMessagesIdsToLink(inboundReportId) >> messagesIdsToLink 1 * mockOrchestrator.linkMessages(messagesIdsToLink + inboundReportId) @@ -75,7 +75,7 @@ class SendOrderUseCaseTest extends Specification { then: 3 * mockLogger.logWarning(_) - 0 * mockOrchestrator.updateMetadataForReceivedMessage(_, _) + 0 * mockOrchestrator.updateMetadataForInboundMessage(_, _) } def "convertAndSend logs error and continues when updateMetadataForReceivedOrder throws exception"() { @@ -83,7 +83,7 @@ class SendOrderUseCaseTest extends Specification { def order = Mock(Order) def inboundReportId = "inboundReportId" - mockOrchestrator.updateMetadataForReceivedMessage(_ as PartnerMetadata) >> { throw new PartnerMetadataException("Error") } + mockOrchestrator.updateMetadataForInboundMessage(_ as PartnerMetadata) >> { throw new PartnerMetadataException("Error") } TestApplicationContext.injectRegisteredImplementations() when: diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy index 51f1a378b..f1a684bc3 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCaseTest.groovy @@ -58,11 +58,11 @@ class SendResultUseCaseTest extends Specification { thrown(UnableToSendMessageException) } - def "convertAndSend logs error and continues when updateMetadataForReceivedMessage throws exception"() { + def "convertAndSend logs error and continues when updateMetadataForInboundMessage throws exception"() { given: def result = Mock(Result) def inboundReportId = "inboundReportId" - mockOrchestrator.updateMetadataForReceivedMessage(_ as PartnerMetadata) >> { throw new PartnerMetadataException("Error") } + mockOrchestrator.updateMetadataForInboundMessage(_ as PartnerMetadata) >> { throw new PartnerMetadataException("Error") } TestApplicationContext.injectRegisteredImplementations() when: From a8086d3c69ced69526d0743ea20498b6ae753b63 Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Wed, 20 Nov 2024 17:08:21 -0700 Subject: [PATCH 04/10] add comment on recordid --- .../cdc/trustedintermediary/etor/EtorDomainRegistration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 13c7e30ae..0711d05b7 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 @@ -251,7 +251,7 @@ protected DomainResponse handleMessageRequest( } protected String getInboundReportId(DomainRequest request) { - + // recordid is the inbound report id String inboundReportId = request.getHeaders().get("recordid"); if (inboundReportId == null || inboundReportId.isEmpty()) { logger.logError("Missing required header or empty: RecordId"); From 487472236fdcd46e351e00f891dbb34550601e74 Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Wed, 20 Nov 2024 17:10:29 -0700 Subject: [PATCH 05/10] rephrase comment --- .../etor/messages/MessageRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/MessageRequestHandler.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/MessageRequestHandler.java index a96c050db..5805ecd76 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/MessageRequestHandler.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/messages/MessageRequestHandler.java @@ -12,7 +12,7 @@ public interface MessageRequestHandler { /** * Parses the request, converts and sends the message * - * @param inboundReportId the ID for the report returned from ReportStream + * @param inboundReportId the report id created by ReportStream and sent to us in the request * @return the response * @throws FhirParseException if there is an error parsing the FHIR data * @throws UnableToSendMessageException if there is an error sending the message From 420f01522aa1796d83c7455eb9a308329400afbe Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Thu, 21 Nov 2024 08:56:08 -0700 Subject: [PATCH 06/10] remove whitespace between variable name --- .../etor/messages/SendMessageHelper.java | 12 ++++++------ .../etor/results/SendResultUseCase.java | 2 +- .../localfile/FilePartnerMetadataStorage.java | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) 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 920c660d6..121d1ce10 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 @@ -24,7 +24,7 @@ private SendMessageHelper() {} public void savePartnerMetadataForInboundMessage(PartnerMetadata partnerMetadata) { if (partnerMetadata.inboundReportId() == null) { logger.logWarning( - "Inbound reportId is null so not saving metadata for received message"); + "inboundReportId is null so not saving metadata for received message"); return; } try { @@ -40,7 +40,7 @@ public void savePartnerMetadataForInboundMessage(PartnerMetadata partnerMetadata public void saveReportIds(String inboundReportId, String outboundReportId) { if (outboundReportId == null || inboundReportId == null) { logger.logWarning( - "Inbound and/or outbound reportId is null so not saving metadata for sent result"); + "Inbound and/or outboundReportId is null so not saving metadata for sent result"); return; } @@ -49,9 +49,9 @@ public void saveReportIds(String inboundReportId, String outboundReportId) { inboundReportId, outboundReportId); } catch (PartnerMetadataException e) { logger.logError( - "Unable to update metadata for inbound reportId " + "Unable to update metadata for inboundReportId " + inboundReportId - + " and sent outbound reportId " + + " and sent outboundReportId " + outboundReportId, e); } @@ -59,7 +59,7 @@ public void saveReportIds(String inboundReportId, String outboundReportId) { public void linkMessage(String inboundReportId) { if (inboundReportId == null) { - logger.logWarning("Inbound reportId is null so not linking messages"); + logger.logWarning("inboundReportId is null so not linking messages"); return; } @@ -80,7 +80,7 @@ public void linkMessage(String inboundReportId) { messageIdsToLink); partnerMetadataOrchestrator.linkMessages(messageIdsToLink); } catch (PartnerMetadataException | MessageLinkException e) { - logger.logError("Unable to link messages for inbound reportId " + inboundReportId, e); + logger.logError("Unable to link messages for inboundReportId " + inboundReportId, e); } } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java index 96f56738b..9bc79cdb2 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java @@ -46,7 +46,7 @@ public void convertAndSend(Result result, String inboundReportId) transformationEngine.runRules(result); String outboundReportId = sender.send(result).orElse(null); - logger.logInfo("Outbound result reportId: {}", outboundReportId); + logger.logInfo("Outbound result outboundReportId: {}", outboundReportId); sendMessageHelper.linkMessage(inboundReportId); 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 5edeaa519..3ea7680cc 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 @@ -136,7 +136,7 @@ public Set readMetadataForMessageLinking(String inboundReportId) .collect(Collectors.toSet()); } catch (Exception e) { throw new PartnerMetadataException( - "Failed reading metadata for inbound reportId: " + inboundReportId, e); + "Failed reading metadata for inboundReportId: " + inboundReportId, e); } } From e99728b2c535a6b6fbdeade70f8a1d07c5019915 Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Thu, 21 Nov 2024 09:01:17 -0700 Subject: [PATCH 07/10] alter log --- .../trustedintermediary/etor/messages/SendMessageHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 121d1ce10..8e28f0337 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 @@ -51,7 +51,7 @@ public void saveReportIds(String inboundReportId, String outboundReportId) { logger.logError( "Unable to update metadata for inboundReportId " + inboundReportId - + " and sent outboundReportId " + + " and outboundReportId " + outboundReportId, e); } From 67de6ff0bf1e5782ff851265679bacb585c3fca8 Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Thu, 21 Nov 2024 12:42:40 -0700 Subject: [PATCH 08/10] revert comment --- .../cdc/trustedintermediary/etor/results/SendResultUseCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java index 9bc79cdb2..d8735d129 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java @@ -46,7 +46,7 @@ public void convertAndSend(Result result, String inboundReportId) transformationEngine.runRules(result); String outboundReportId = sender.send(result).orElse(null); - logger.logInfo("Outbound result outboundReportId: {}", outboundReportId); + logger.logInfo("Sent result outboundReportId: {}", outboundReportId); sendMessageHelper.linkMessage(inboundReportId); From 0638326db87d33cad5e9c32c3099aaafbffb0a35 Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Fri, 22 Nov 2024 13:17:11 -0700 Subject: [PATCH 09/10] rename function and related tests --- .../etor/messages/SendMessageHelper.java | 2 +- .../etor/orders/SendOrderUseCase.java | 2 +- .../etor/results/SendResultUseCase.java | 2 +- .../etor/messages/SendMessageHelperTest.groovy | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) 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 8e28f0337..e0545c0fa 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 @@ -37,7 +37,7 @@ public void savePartnerMetadataForInboundMessage(PartnerMetadata partnerMetadata } } - public void saveReportIds(String inboundReportId, String outboundReportId) { + public void saveOutboundReportId(String inboundReportId, String outboundReportId) { if (outboundReportId == null || inboundReportId == null) { logger.logWarning( "Inbound and/or outboundReportId is null so not saving metadata for sent result"); diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java index 8aee41c50..f241bd151 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/orders/SendOrderUseCase.java @@ -49,6 +49,6 @@ public void convertAndSend(final Order order, String inboundReportId) sendMessageHelper.linkMessage(inboundReportId); - sendMessageHelper.saveReportIds(inboundReportId, outboundReportId); + sendMessageHelper.saveOutboundReportId(inboundReportId, outboundReportId); } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java index d8735d129..590095696 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/results/SendResultUseCase.java @@ -50,6 +50,6 @@ public void convertAndSend(Result result, String inboundReportId) sendMessageHelper.linkMessage(inboundReportId); - sendMessageHelper.saveReportIds(inboundReportId, outboundReportId); + sendMessageHelper.saveOutboundReportId(inboundReportId, outboundReportId); } } diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy index becbf5f53..b8d2bf95c 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/messages/SendMessageHelperTest.groovy @@ -74,38 +74,38 @@ class SendMessageHelperTest extends Specification { 1 * mockLogger.logError(_, _) } - def "saveReportIds works"() { + def "saveOutboundReportId works"() { given: def outboundReportId = "outboundReportId" def inboundReportId = "inboundReportId" mockOrchestrator.updateMetadataForOutboundMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } when: - SendMessageHelper.getInstance().saveReportIds(inboundReportId, outboundReportId) + SendMessageHelper.getInstance().saveOutboundReportId(inboundReportId, outboundReportId) then: 1 * mockOrchestrator.updateMetadataForOutboundMessage(_, _) } - def saveReportIds() { + def saveOutboundReportId() { given: def inboundReportId = "inboundReportId" when: - SendMessageHelper.getInstance().saveReportIds(null, inboundReportId) + SendMessageHelper.getInstance().saveOutboundReportId(null, inboundReportId) then: 1 * mockLogger.logWarning(_) } - def "saveReportIds should log error and continues when updateMetadataForOutboundMessage throws error"() { + def "saveOutboundReportId should log error and continues when updateMetadataForOutboundMessage throws error"() { given: def outboundReportId = "outboundReportId" def inboundReportId = "inboundReportId" mockOrchestrator.updateMetadataForOutboundMessage(inboundReportId, _ as String) >> { throw new PartnerMetadataException("Error") } when: - SendMessageHelper.getInstance().saveReportIds(inboundReportId, outboundReportId) + SendMessageHelper.getInstance().saveOutboundReportId(inboundReportId, outboundReportId) then: 1 * mockLogger.logError(_, _) From e826741cdcd5e3550156e7db84206d929485e562 Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Mon, 25 Nov 2024 11:58:32 -0700 Subject: [PATCH 10/10] add change set for column rename --- etor/databaseMigrations/metadata.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/etor/databaseMigrations/metadata.yml b/etor/databaseMigrations/metadata.yml index ed417ceeb..c93735d8a 100644 --- a/etor/databaseMigrations/metadata.yml +++ b/etor/databaseMigrations/metadata.yml @@ -168,3 +168,29 @@ databaseChangeLog: - dropColumn: tableName: metadata columnName: receiver + + - changeSet: + id: 8 + author: pluckyswan + labels: update-metadata-table + context: metadata + comment: update metadata table to rename column sent_message_id to outbound_report_id + changes: + - renameColumn: + columnDataType: varchar(40) + oldColumnName: sent_message_id + newColumnName: outbound_report_id + tableName: metadata + + - changeSet: + id: 9 + author: pluckyswan + labels: update-metadata-table + context: metadata + comment: update metadata table to rename column received_message_id to inbound_report_id + changes: + - renameColumn: + columnDataType: varchar(40) + oldColumnName: received_message_id + newColumnName: inbound_report_id + tableName: metadata