Skip to content

Commit

Permalink
cherry pick changes from PR CU-86b1kajgv_PW-1958--NullPointerExceptio…
Browse files Browse the repository at this point in the history
…n-in-MxSwiftMessageapplyStra
  • Loading branch information
zubri committed Aug 14, 2024
1 parent 8e4e55d commit cf5c986
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Prowide ISO 20022 - CHANGELOG

#### 10.1.7 - August 2024
* (PW-1958) Fixed the `DefaultMxMetadataStrategy` NPE issue when the amount values are null

#### 10.1.6 - May 2024
* (PW-1875) Changed the BusinessApplicationHeaderV01 marshaller to always use Zulu timezone with "Z" indicator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ public Optional<Money> amount(AbstractMessage message) {

private Money getCamt29Amount(MxNode document) {
MxNode amount = document.findFirst("./RsltnOfInvstgtn/CxlDtls/OrgnlPmtInfAndSts/TxInfAndSts/OrgnlInstdAmt");
if (amount != null) {
if (amount != null && amount.getValue() != null) {
return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue()));
}
return null;
}

private Money getCamt52Amount(MxNode document) {
MxNode amount = document.findFirst("./BkToCstmrAcctRpt/Rpt/Bal/Amt");
if (amount != null) {
if (amount != null && amount.getValue() != null) {
return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue()));
}
return null;
}

private Money getCamt53Amount(MxNode document) {
MxNode amount = document.findFirst("./BkToCstmrStmt/Stmt/Bal/Amt");
if (amount != null) {
if (amount != null && amount.getValue() != null) {
return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue()));
}
return null;
Expand All @@ -121,23 +121,23 @@ private Money getCamt54Amount(MxNode document) {
if (amount == null) {
amount = document.findFirst("./BkToCstmrDbtCdtNtfctn/Ntfctn/Ntry/NtryDtls/TxDtls/Amt");
}
if (amount != null) {
if (amount != null && amount.getValue() != null) {
return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue()));
}
return null;
}

private Money getCamt56Amount(MxNode document) {
MxNode amount = document.findFirst("./FIToFIPmtCxlReq/Undrlyg/TxInf/OrgnlIntrBkSttlmAmt");
if (amount != null) {
if (amount != null && amount.getValue() != null) {
return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue()));
}
return null;
}

private Money getCamt57Amount(MxNode document) {
MxNode amount = document.findFirst("./NtfctnToRcv/Ntfctn/TtlAmt");
if (amount != null) {
if (amount != null && amount.getValue() != null) {
return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue()));
}
return null;
Expand All @@ -148,7 +148,7 @@ private Money getPacs004Amount(MxNode document) {
if (amount == null) {
amount = document.findFirst("./PmtRtr/TxInf/RtrdIntrBkSttlmAmt");
}
if (amount != null) {
if (amount != null && amount.getValue() != null) {
return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue()));
}
return null;
Expand Down Expand Up @@ -181,7 +181,7 @@ private Money getPacsAmount(MxNode document) {
MxNode cdtTrfNode = document.findFirstByName("CdtTrfTxInf");
if (cdtTrfNode != null) {
MxNode amount = cdtTrfNode.findFirst("./IntrBkSttlmAmt");
if (amount != null) {
if (amount != null && amount.getValue() != null) {
return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue()));
}
}
Expand Down
114 changes: 114 additions & 0 deletions iso20022-core/src/test/java/com/prowidesoftware/issues/Issue1958.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.prowidesoftware.issues;

import static org.junit.jupiter.api.Assertions.fail;

import com.prowidesoftware.swift.model.MxSwiftMessage;
import org.junit.jupiter.api.Test;

public class Issue1958 {

@Test
void test() {
try {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ "<RequestPayload>"
+ "<h:AppHdr xmlns:h=\"urn:swift:xsd:$ahV10\">"
+ " <h:From>"
+ " <h:Type>BIC</h:Type>"
+ " <h:Id>AAAANGL0XXX</h:Id>"
+ " </h:From>"
+ " <h:To>"
+ " <h:Type>BIC</h:Type>"
+ " <h:Id>BBBBUS33XXX</h:Id>"
+ " </h:To>"
+ " <h:MsgName>pacs.008.001.08</h:MsgName>"
+ " <h:MsgRef>FOOBAR1</h:MsgRef>"
+ " <h:CrDate>2022-05-05T06:07:14Z</h:CrDate>"
+ "</h:AppHdr>"
+ "<Doc:Document xmlns:Doc=\"urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08\">"
+ " <Doc:FIToFICstmrCdtTrf>"
+ " <Doc:GrpHdr>"
+ " <Doc:MsgId>FOOBAR2</Doc:MsgId>"
+ " <Doc:CreDtTm>2022-05-05T06:07:14Z</Doc:CreDtTm>"
+ " <Doc:NbOfTxs>1</Doc:NbOfTxs>"
+ " <Doc:SttlmInf>"
+ " <Doc:SttlmMtd>INDA</Doc:SttlmMtd>"
+ " <Doc:SttlmAcct>"
+ " <Doc:Id>"
+ " <Doc:Othr>"
+ " <Doc:Id>04435001</Doc:Id>"
+ " </Doc:Othr>"
+ " </Doc:Id>"
+ " </Doc:SttlmAcct>"
+ " </Doc:SttlmInf>"
+ " <Doc:InstgAgt>"
+ " <Doc:FinInstnId>"
+ " <Doc:BICFI>AAAANGL0XXX</Doc:BICFI>"
+ " </Doc:FinInstnId>"
+ " </Doc:InstgAgt>"
+ " <Doc:InstdAgt>"
+ " <Doc:FinInstnId>"
+ " <Doc:BICFI>BBBBUS33XXX</Doc:BICFI>"
+ " </Doc:FinInstnId>"
+ " </Doc:InstdAgt>"
+ " </Doc:GrpHdr>"
+ " <Doc:CdtTrfTxInf>"
+ " <Doc:PmtId>"
+ " <Doc:InstrId>REF333222333</Doc:InstrId>"
+ " <Doc:EndToEndId>RRRR345345</Doc:EndToEndId>"
+ " <Doc:TxId>FFDD34534</Doc:TxId>"
+ " </Doc:PmtId>"
+ " <Doc:IntrBkSttlmAmt Ccy=\"USD\"></Doc:IntrBkSttlmAmt>"
+ " <Doc:IntrBkSttlmDt>2022-05-05</Doc:IntrBkSttlmDt>"
+ " <Doc:InstdAmt Ccy=\"USD\"></Doc:InstdAmt>"
+ " <Doc:ChrgBr>DEBT</Doc:ChrgBr>"
+ " <Doc:Dbtr>"
+ " <Doc:Nm>FOO FEED MILLS COLTD</Doc:Nm>"
+ " <Doc:PstlAdr>"
+ " <Doc:AdrLine>1 GOLDEN PENNY PLACE, WHARF ROAD,</Doc:AdrLine>"
+ " <Doc:AdrLine>APAPA LAGOS</Doc:AdrLine>"
+ " </Doc:PstlAdr>"
+ " </Doc:Dbtr>"
+ " <Doc:DbtrAcct>"
+ " <Doc:Id>"
+ " <Doc:Othr>"
+ " <Doc:Id>2028766092</Doc:Id>"
+ " </Doc:Othr>"
+ " </Doc:Id>"
+ " </Doc:DbtrAcct>"
+ " <Doc:DbtrAgt>"
+ " <Doc:FinInstnId>"
+ " <Doc:BICFI>AAAANGLA</Doc:BICFI>"
+ " </Doc:FinInstnId>"
+ " </Doc:DbtrAgt>"
+ " <Doc:CdtrAgt>"
+ " <Doc:FinInstnId>"
+ " <Doc:BICFI>BBBBRU21</Doc:BICFI>"
+ " </Doc:FinInstnId>"
+ " </Doc:CdtrAgt>"
+ " <Doc:Cdtr>"
+ " <Doc:Nm>TEST</Doc:Nm>"
+ " <Doc:PstlAdr>"
+ " <Doc:AdrLine>TEST</Doc:AdrLine>"
+ " </Doc:PstlAdr>"
+ " </Doc:Cdtr>"
+ " <Doc:CdtrAcct>"
+ " <Doc:Id>"
+ " <Doc:Othr>"
+ " <Doc:Id>TEST</Doc:Id>"
+ " </Doc:Othr>"
+ " </Doc:Id>"
+ " </Doc:CdtrAcct>"
+ " <Doc:RmtInf>"
+ " <Doc:Ustrd>AGRICULTURAL SECTOR</Doc:Ustrd>"
+ " </Doc:RmtInf>"
+ " </Doc:CdtTrfTxInf>"
+ " </Doc:FIToFICstmrCdtTrf>"
+ "</Doc:Document>"
+ "</RequestPayload>";
new MxSwiftMessage(xml);
} catch (Exception e) {
fail();
}
}
}

0 comments on commit cf5c986

Please sign in to comment.