-
Notifications
You must be signed in to change notification settings - Fork 1
Fix misc ddex4.0 and sme processing bugs #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1d569fe
9f0177a
d65dbbf
5b76967
12f58f6
3b723ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,12 +110,14 @@ function generateAcknowledgementXml({ | |
| releases, | ||
| isSuccess, | ||
| error, | ||
| recipientPartyId, | ||
| }: { | ||
| source: string, | ||
| messageId: string, | ||
| releases: DDEXRelease[], | ||
| isSuccess: boolean, | ||
| error?: string | ||
| error?: string, | ||
| recipientPartyId?: string | ||
| }): string { | ||
| const $ = cheerio.load('', { xmlMode: true }) | ||
|
|
||
|
|
@@ -139,7 +141,8 @@ function generateAcknowledgementXml({ | |
|
|
||
| // MessageRecipient (Source) | ||
| const messageRecipient = $('<MessageRecipient></MessageRecipient>') | ||
| messageRecipient.append($(`<PartyId>${source.toUpperCase()}</PartyId>`)) | ||
| const resolvedRecipient = recipientPartyId || (source === 'sme' ? 'PADPIDA2007040502I' : source.toUpperCase()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what our prototype/roughness comfort level is in this repo. But this seems like it should be a constant and/or some kind of function that can determine the value. Having the source check for a particular label hard-coded in here feels cryptic and hard to maintain :-D |
||
| messageRecipient.append($(`<PartyId>${resolvedRecipient}</PartyId>`)) | ||
| const recipientPartyName = $('<PartyName></PartyName>') | ||
| recipientPartyName.append($(`<FullName>${getSourcePartyName(source)}</FullName>`)) | ||
| messageRecipient.append(recipientPartyName) | ||
|
|
@@ -175,31 +178,27 @@ function generateAcknowledgementXml({ | |
| // ReleaseStatus - different values for success vs error | ||
| if (isSuccess) { | ||
| releaseStatus.append($('<ReleaseStatus>SuccessfullyIngestedByReleaseDistributor</ReleaseStatus>')) | ||
| const acknowledgement = $('<Acknowledgement></Acknowledgement>') | ||
| acknowledgement.append($('<MessageType>NewReleaseMessage</MessageType>')) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why it feels wild to me that we're doing all of these lines with string literals for tag names to incrementally build XML. This def feels like something that could eventually be |
||
| acknowledgement.append($(`<MessageId>${messageId}</MessageId>`)) | ||
| const messageStatus = $('<MessageStatus></MessageStatus>') | ||
| messageStatus.append($('<Status>FileOK</Status>')) | ||
| acknowledgement.append(messageStatus) | ||
| releaseStatus.append(acknowledgement) | ||
| } else { | ||
| releaseStatus.append($('<ReleaseStatus>ProcessingErrorAtReleaseDistributor</ReleaseStatus>')) | ||
|
|
||
| // Add ErrorText for failures (at ReleaseStatus level) | ||
| const acknowledgement = $('<Acknowledgement></Acknowledgement>') | ||
| acknowledgement.append($('<MessageType>NewReleaseMessage</MessageType>')) | ||
| acknowledgement.append($(`<MessageId>${messageId}</MessageId>`)) | ||
| const messageStatus = $('<MessageStatus></MessageStatus>') | ||
| messageStatus.append($('<Status>ResourceCorrupt</Status>')) | ||
| if (error) { | ||
| releaseStatus.append($(`<ErrorText>${error}</ErrorText>`)) | ||
| messageStatus.append($(`<StatusMessage>${error}</StatusMessage>`)) | ||
| } | ||
| acknowledgement.append(messageStatus) | ||
| releaseStatus.append(acknowledgement) | ||
| } | ||
|
|
||
| // Acknowledgement | ||
| const acknowledgement = $('<Acknowledgement></Acknowledgement>') | ||
| acknowledgement.append($('<MessageType>NewReleaseMessage</MessageType>')) | ||
| acknowledgement.append($(`<MessageId>${messageId}</MessageId>`)) | ||
|
|
||
| const messageStatus = $('<MessageStatus></MessageStatus>') | ||
| if (isSuccess) { | ||
| messageStatus.append($('<Status>FileOK</Status>')) | ||
| } else { | ||
| // Use ResourceCorrupt for errors as per the example | ||
| messageStatus.append($('<Status>ResourceCorrupt</Status>')) | ||
| } | ||
|
|
||
| acknowledgement.append(messageStatus) | ||
| releaseStatus.append(acknowledgement) | ||
|
|
||
| root.append(releaseStatus) | ||
| } | ||
| } else { | ||
|
|
@@ -263,7 +262,8 @@ async function sendAcknowledgement(source: string, xml: string) { | |
| }) | ||
|
|
||
| if (!statusResponse.ok) { | ||
| throw new Error(`Status post failed: ${statusResponse.status} ${statusResponse.statusText}`) | ||
| const errText = await statusResponse.text().catch(() => '') | ||
| throw new Error(`Status post failed: ${statusResponse.status} ${statusResponse.statusText} ${errText ? '- ' + errText : ''}`) | ||
| } | ||
|
|
||
| console.log('Acknowledgement XML posted successfully') | ||
|
|
@@ -315,7 +315,8 @@ export async function acknowledgeReleaseSuccess({ | |
| source, | ||
| messageId, | ||
| releases, | ||
| isSuccess: true | ||
| isSuccess: true, | ||
| recipientPartyId: source === 'sme' ? 'PADPIDA2007040502I' : undefined | ||
| } | ||
| ) | ||
| console.log(acknowledgementXml) | ||
|
|
@@ -337,12 +338,14 @@ export async function acknowledgeReleaseFailure({ | |
| messageId, | ||
| messageTimestamp, | ||
| error, | ||
| releases, | ||
| }: { | ||
| source: string | ||
| xmlUrl: string | ||
| messageId: string | ||
| messageTimestamp: string | ||
| error: string | Error | ||
| releases?: DDEXRelease[] | ||
| }) { | ||
| const errorMessage = error instanceof Error ? error.message : error | ||
|
|
||
|
|
@@ -366,9 +369,10 @@ export async function acknowledgeReleaseFailure({ | |
| { | ||
| source, | ||
| messageId, | ||
| releases: [], // Empty releases array for failures | ||
| releases: releases || [], // Include releases when available | ||
| isSuccess: false, | ||
| error: errorMessage | ||
| error: errorMessage, | ||
| recipientPartyId: source === 'sme' ? 'PADPIDA2007040502I' : undefined | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now that I've seen it thrice, definitely should be a helper |
||
| } | ||
| ) | ||
| console.log(acknowledgementXml) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this typical TS? or some other kind of error?