Skip to content

Commit

Permalink
Add support for business application header version head.001.001.04 v…
Browse files Browse the repository at this point in the history
…10 (#124)
  • Loading branch information
zubri authored Aug 2, 2024
1 parent 5d04614 commit 77dbd01
Show file tree
Hide file tree
Showing 12 changed files with 1,524 additions and 33 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Prowide ISO 20022 - CHANGELOG

#### 10.2.2 - SNAPSHOT
#### 10.2.2 - August 2024
* (PW-1947) Updated MX model with latest SWIFT SRU2024 schema update, including new messages such as trck.001.001.03
* (PW-1933) Fix backward compatibility issue on DateTime fields when doing JSON to model conversion (thanks @elominp)
* (PW-1875) Fixed the `ZuluDateTimeAdapter` to convert the datetime to UTC offset if needed
* Add support for Business Application Header version head.001.001.04

#### 10.2.1 - June 2024
* Enhanced the AppHdrFactory to honor the business service set in the parameter MxId
Expand All @@ -11,7 +13,7 @@
#### 10.2.0 - May 2024
* SWIFT Standard release update 2024 (live 16 November 2024)
* Yearly revision of deprecation phase (see https://dev.prowidesoftware.com/SRU2024/getting-started/deprecation/)
* Added message categories for File Management (cafm), Fraud Reporting and Disposition (cafm), Network Management (canm) and Settlement Reporting (casr)
* Added message categories for File Management (cafm), Fraud Reporting and Disposition (cafm), Network Management (canm), and Settlement Reporting (casr)
* Add support in the MxWriteConfiguration to use standard envelopes for SWIFT and ISO 20022
* Changed the default Document prefix to the message category; "camt", "pacs", etc...
* Enhanced MxId with optional and transient businessService field to act as a message type discriminator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ public String message(MxWriteConfiguration conf) {
// handle manually at this method level
params.includeXMLDeclaration = false;

EnvelopeType envelope = usableConf.envelopeTyoe;
String envelopeElement = envelope == EnvelopeType.CUSTOM ? usableConf.rootElement : envelope.rootElement();
EnvelopeType envelopeType = usableConf.envelopeType;
String envelopeElement =
envelopeType == EnvelopeType.CUSTOM ? usableConf.rootElement : envelopeType.rootElement();

StringBuilder xml = new StringBuilder();
if (usableConf.includeXMLDeclaration) {
Expand All @@ -250,35 +251,35 @@ public String message(MxWriteConfiguration conf) {
if (header != null) {
// open envelope element
xml.append("<");
if (envelope.prefix() != null) {
xml.append(envelope.prefix()).append(":");
if (envelopeType.prefix() != null) {
xml.append(envelopeType.prefix()).append(":");
}
xml.append(envelopeElement);

if (envelope != EnvelopeType.CUSTOM) {
if (envelopeType != EnvelopeType.CUSTOM) {
xml.append(" xmlns=\"")
.append(usableConf.envelopeTyoe.namespace())
.append(usableConf.envelopeType.namespace())
.append("\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
}
xml.append(">\n");

// for ISO envelopes we have to add an extra element wrapping the header
if (envelope.name().startsWith("BME")) {
xml.append("<").append(envelope.prefix()).append(":Hdr>\n");
if (envelopeType.name().startsWith("BME")) {
xml.append("<").append(envelopeType.prefix()).append(":Hdr>\n");
}

// write AppHdr
xml.append(header).append("\n");

// for ISO envelopes we have to close the extra element wrapping the header
if (envelope.name().startsWith("BME")) {
xml.append("</").append(envelope.prefix()).append(":Hdr>\n");
if (envelopeType.name().startsWith("BME")) {
xml.append("</").append(envelopeType.prefix()).append(":Hdr>\n");
}
}

// for ISO envelopes we have to wrap the Document in an extra element
if (envelope.name().startsWith("BME")) {
xml.append("<").append(envelope.prefix()).append(":Doc>\n");
if (envelopeType.name().startsWith("BME")) {
xml.append("<").append(envelopeType.prefix()).append(":Doc>\n");
}

// write Document
Expand All @@ -290,15 +291,15 @@ public String message(MxWriteConfiguration conf) {
xml.append(document(params)).append("\n");

// for ISO envelopes we have to close the extra element wrapping the Document
if (envelope.name().startsWith("BME")) {
xml.append("</").append(envelope.prefix()).append(":Doc>\n");
if (envelopeType.name().startsWith("BME")) {
xml.append("</").append(envelopeType.prefix()).append(":Doc>\n");
}

if (header != null) {
// close the envelope element
xml.append("</");
if (envelope.prefix() != null) {
xml.append(envelope.prefix()).append(":");
if (envelopeType.prefix() != null) {
xml.append(envelopeType.prefix()).append(":");
}
xml.append(envelopeElement).append(">");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,53 @@ public static BusinessAppHdrV03 createBusinessAppHdrV03(
return h;
}

/**
* Convenient method to create a new ISO header version 4, initialized from simple parameters.
*
* <p>All parameters are optional but in order for the header to be valid the sender, receiver and reference must
* be set. Creation date will be set to current time.
*
* @param sender optional sender BIC for the Fr element or null to leave not set
* @param receiver optional receiver BIC for the To element or null to leave not set
* @param reference optional reference for the BizMsgIdr (business message identifier) or null to leave not set
* @param id optional MX identification for the MsgDefIdr (message definition identifier) element or null to leave not set
* @return new header initialized from parameters.
* @since 9.5.3
*/
public static BusinessAppHdrV04 createBusinessAppHdrV04(
final String sender, final String receiver, final String reference, final MxId id) {
BusinessAppHdrV04 h = new BusinessAppHdrV04();

if (sender != null) {
h.setFr(new Party51Choice());
h.getFr().setFIId(new BranchAndFinancialInstitutionIdentification8());
h.getFr().getFIId().setFinInstnId(new FinancialInstitutionIdentification23());
h.getFr().getFIId().getFinInstnId().setBICFI(sender);
}

if (receiver != null) {
h.setTo(new Party51Choice());
h.getTo().setFIId(new BranchAndFinancialInstitutionIdentification8());
h.getTo().getFIId().setFinInstnId(new FinancialInstitutionIdentification23());
h.getTo().getFIId().getFinInstnId().setBICFI(receiver);
}

if (reference != null) {
h.setBizMsgIdr(reference);
}

if (id != null) {
h.setMsgDefIdr(id.id());
if (id.getBusinessService().isPresent()) {
h.setBizSvc(id.getBusinessService().get());
}
}

h.setCreDt(OffsetDateTime.now());

return h;
}

/**
* Convenient method to create a new legacy SWIFT header, initialized from simple parameters.
*
Expand Down Expand Up @@ -226,6 +273,8 @@ public static AppHdr createAppHdr(
return createBusinessAppHdrV02(sender, receiver, reference, id);
case BAH_V3:
return createBusinessAppHdrV03(sender, receiver, reference, id);
case BAH_V4:
return createBusinessAppHdrV04(sender, receiver, reference, id);
default:
throw new ProwideException("Don't know how to create header " + type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ private static AppHdr parseHeaderFromSAXSource(
return (LegacyAppHdr)
MxParseUtils.parseSAXSource(source, LegacyAppHdr.class, LegacyAppHdr._classes, params);

} else if (StringUtils.equals(BusinessAppHdrV01.NAMESPACE, namespace)) {
// parse BAH version 1
return (BusinessAppHdrV01)
MxParseUtils.parseSAXSource(source, BusinessAppHdrV01.class, BusinessAppHdrV01._classes, params);

} else if (StringUtils.equals(BusinessAppHdrV02.NAMESPACE, namespace)) {
// parse BAH version 2
return (BusinessAppHdrV02)
Expand All @@ -93,10 +98,15 @@ private static AppHdr parseHeaderFromSAXSource(
return (BusinessAppHdrV03)
MxParseUtils.parseSAXSource(source, BusinessAppHdrV03.class, BusinessAppHdrV03._classes, params);

} else if (StringUtils.equals(BusinessAppHdrV04.NAMESPACE, namespace)) {
// parse BAH version 4
return (BusinessAppHdrV04)
MxParseUtils.parseSAXSource(source, BusinessAppHdrV04.class, BusinessAppHdrV04._classes, params);

} else {
// by default try to parse to BAH version 1
return (BusinessAppHdrV01)
MxParseUtils.parseSAXSource(source, BusinessAppHdrV01.class, BusinessAppHdrV01._classes, params);
// by default try to parse to BAH version 2 (most common version, used by CBPR+)
return (BusinessAppHdrV02)
MxParseUtils.parseSAXSource(source, BusinessAppHdrV02.class, BusinessAppHdrV02._classes, params);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public enum AppHdrType {
LEGACY(LegacyAppHdr.NAMESPACE, LegacyAppHdr.class),
BAH_V1(BusinessAppHdrV01.NAMESPACE, BusinessAppHdrV01.class),
BAH_V2(BusinessAppHdrV02.NAMESPACE, BusinessAppHdrV02.class),
BAH_V3(BusinessAppHdrV03.NAMESPACE, BusinessAppHdrV03.class);
BAH_V3(BusinessAppHdrV03.NAMESPACE, BusinessAppHdrV03.class),
BAH_V4(BusinessAppHdrV04.NAMESPACE, BusinessAppHdrV04.class);

private String namespace;
private Class headerClass;
Expand Down
Loading

0 comments on commit 77dbd01

Please sign in to comment.