Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/SRU2024' into SRU2024_v10
Browse files Browse the repository at this point in the history
  • Loading branch information
zubri committed Jun 29, 2024
2 parents 99819f5 + 5ff39e8 commit fdef2c2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ public Optional<String> getBusinessService() {
* @param businessService a string value to set as discriminator, for example "swift.cbprplus.cov.02"
* @since 9.5.0
*/
public void setBusinessService(String businessService) {
public MxId setBusinessService(String businessService) {
this.businessService = businessService;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public static BusinessAppHdrV02 createBusinessAppHdrV02(

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

h.setCreDt(OffsetDateTime.now());
Expand Down Expand Up @@ -151,6 +154,9 @@ public static BusinessAppHdrV03 createBusinessAppHdrV03(

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

h.setCreDt(OffsetDateTime.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static String getBICFromDN(final String dn) {
public static Optional<MxId> identifyMessage(final String xml) {
Optional<String> namespace = NamespaceReader.findDocumentNamespace(xml);
if (namespace.isPresent()) {
return namespace.map(MxId::new);
return enrichBusinessService(namespace.map(MxId::new).orElse(null), xml);
}

// if the Document does not have a namespace, try to identify the message from the header
Expand All @@ -205,7 +205,7 @@ public static Optional<MxId> identifyMessage(final String xml) {
}
if (element.isPresent()) {
try {
return Optional.of(new MxId(element.get().getElementText()));
return enrichBusinessService(new MxId(element.get().getElementText()), xml);
} catch (XMLStreamException e) {
log.finer("Error identifying message: " + e.getMessage());
}
Expand All @@ -214,6 +214,21 @@ public static Optional<MxId> identifyMessage(final String xml) {
return Optional.empty();
}

private static Optional<MxId> enrichBusinessService(MxId mxId, final String xml) {
if (mxId == null) {
return Optional.empty();
}
Optional<XMLStreamReader> element = NamespaceReader.findElement(xml, "BizSvc");
if (element.isPresent()) {
try {
mxId.setBusinessService(element.get().getElementText());
} catch (XMLStreamException e) {
log.finer("Error identifying business service: " + e.getMessage());
}
}
return Optional.of(mxId);
}

/**
* This method is intended to fix some malformed XML content that is not compliant with the XML specification
* to enable the parsing and processing of the payload to be lenient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ void createBusinessAppHdrV01() {
// for BAH v01 the date time must be ISONormalisedDateTime
assertTrue(xml.contains("Z</CreDt>"));
}

@Test
void createBusinessAppHdrV02_WithBusinessService() {
BusinessAppHdrV02 h = AppHdrFactory.createBusinessAppHdrV02(
"AAAAUSXXXXX",
"BBBBUSXXXXX",
"REF12345",
new MxId("pacs.009.001.08").setBusinessService("swift.cbprplus.cov.02"));
assertNotNull(h);
assertEquals("swift.cbprplus.cov.02", h.getBizSvc());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void testIdentifyMessage_FromBAH() {
MxId id = MxParseUtils.identifyMessage(xml).orElse(null);
assertNotNull(id);
assertEquals("seev.031.002.03", id.id());
assertEquals("CSD", id.getBusinessService().orElse(null));
}

@Test
Expand Down

0 comments on commit fdef2c2

Please sign in to comment.