Skip to content

Commit

Permalink
Merge pull request #759 from CDCgov/story-672-write_metadata_anyway
Browse files Browse the repository at this point in the history
672: Write Metadata Even If RS History API Fails
halprin authored Jan 8, 2024
2 parents 67321f3 + 4b3427a commit 8ea1536
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -25,6 +25,10 @@ public PartnerMetadata(
this(receivedSubmissionId, null, sender, null, timeReceived, hash);
}

public PartnerMetadata(String receivedSubmissionId, String hash) {
this(receivedSubmissionId, null, null, null, null, hash);
}

public PartnerMetadata withSentSubmissionId(String sentSubmissionId) {
return new PartnerMetadata(
this.receivedSubmissionId,
Original file line number Diff line number Diff line change
@@ -54,6 +54,14 @@ public void updateMetadataForReceivedOrder(String receivedSubmissionId, String o
timeReceived = Instant.parse(timestamp);

} catch (Exception e) {
// write the received submission ID so that the rest of the metadata flow works even if
// some data is missing
logger.logWarning(
"Unable to retrieve metadata from RS history API, but writing basic metadata entry anyway for received submission ID {}",
receivedSubmissionId);
PartnerMetadata partnerMetadata = new PartnerMetadata(receivedSubmissionId, orderHash);
partnerMetadataStorage.saveMetadata(partnerMetadata);

throw new PartnerMetadataException(
"Unable to retrieve metadata from RS history API", e);
}
Original file line number Diff line number Diff line change
@@ -101,6 +101,9 @@ class PartnerMetadataOrchestratorTest extends Specification {
PartnerMetadataOrchestrator.getInstance().updateMetadataForReceivedOrder(receivedSubmissionId, "hash")

then:
1 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) >> { PartnerMetadata metadata ->
assert metadata.receivedSubmissionId() == receivedSubmissionId
}
thrown(PartnerMetadataException)
}

Original file line number Diff line number Diff line change
@@ -54,6 +54,23 @@ class PartnerMetadataTest extends Specification {
metadata.hash() == hash
}

def "test constructor with only received submission ID and hash"() {
given:
def receivedSubmissionId = "receivedSubmissionId"
def hash = "abcd"

when:
def metadata = new PartnerMetadata(receivedSubmissionId, hash)

then:
metadata.receivedSubmissionId() == receivedSubmissionId
metadata.sentSubmissionId() == null
metadata.sender() == null
metadata.receiver() == null
metadata.timeReceived() == null
metadata.hash() == hash
}

def "test withSentSubmissionId and withReceiver to update PartnerMetadata"() {
given:
def receivedSubmissionId = "receivedSubmissionId"

0 comments on commit 8ea1536

Please sign in to comment.