diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field151.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field151.java index 6825dd53..2baf2c4b 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field151.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field151.java @@ -518,6 +518,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field151 fromJson(final String json) { final Field151 field = new Field151(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field152.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field152.java index 93144a84..ccecc586 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field152.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field152.java @@ -518,6 +518,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field152 fromJson(final String json) { final Field152 field = new Field152(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field153.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field153.java index 2f315884..b3d189f1 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field153.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field153.java @@ -518,6 +518,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field153 fromJson(final String json) { final Field153 field = new Field153(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15A.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15A.java index 554de639..fa2d1a84 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15A.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15A.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15A fromJson(final String json) { final Field15A field = new Field15A(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15B.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15B.java index 631c70c5..4bd32514 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15B.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15B.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15B fromJson(final String json) { final Field15B field = new Field15B(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15C.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15C.java index 42784c96..09bb33eb 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15C.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15C.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15C fromJson(final String json) { final Field15C field = new Field15C(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15D.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15D.java index bdffa9d1..8e46d34b 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15D.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15D.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15D fromJson(final String json) { final Field15D field = new Field15D(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15E.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15E.java index f6841fde..216d5c73 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15E.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15E.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15E fromJson(final String json) { final Field15E field = new Field15E(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15F.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15F.java index cb84151c..2b1d18ec 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15F.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15F.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15F fromJson(final String json) { final Field15F field = new Field15F(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15G.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15G.java index 2b6a4281..6ae17e59 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15G.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15G.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15G fromJson(final String json) { final Field15G field = new Field15G(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15H.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15H.java index 9a2fbca9..ee14a792 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15H.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15H.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15H fromJson(final String json) { final Field15H field = new Field15H(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15I.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15I.java index fc60eedf..923c1b65 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15I.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15I.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15I fromJson(final String json) { final Field15I field = new Field15I(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15J.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15J.java index 74f6a710..8e522dc7 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15J.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15J.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15J fromJson(final String json) { final Field15J field = new Field15J(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15K.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15K.java index 0d61a6c4..b51059ff 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15K.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15K.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15K fromJson(final String json) { final Field15K field = new Field15K(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15L.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15L.java index fb2cfc65..3fc890da 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15L.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15L.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15L fromJson(final String json) { final Field15L field = new Field15L(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15M.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15M.java index 7dd20489..f52bf9fe 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15M.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15M.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15M fromJson(final String json) { final Field15M field = new Field15M(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15N.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15N.java index f8d8a6d7..3872bbae 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15N.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15N.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15N fromJson(final String json) { final Field15N field = new Field15N(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15O.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15O.java index 1ecbee46..2ad88255 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15O.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15O.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15O fromJson(final String json) { final Field15O field = new Field15O(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field15P.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field15P.java index 635cd04f..caf7d7c9 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field15P.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field15P.java @@ -414,6 +414,7 @@ public static List getAll(final SwiftTagListBlock block) { * @since 7.10.3 * @see Field#fromJson(String) */ + @SuppressWarnings("unused") public static Field15P fromJson(final String json) { final Field15P field = new Field15P(); diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field50F.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field50F.java index a0cbb866..35ec6087 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field50F.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field50F.java @@ -1434,25 +1434,29 @@ public String getComponentLabel(final int number) { */ public String getLabelForLineNumber(String lineIdentifier) { if (StringUtils.isNumeric(StringUtils.trimToNull(lineIdentifier))) { - int number = Integer.valueOf(lineIdentifier.trim()); - if (number == 1) { - return "Name of the Ordering Customer"; - } else if (number == 2) { - return "Address Line"; - } else if (number == 3) { - return "Country and Town"; - } else if (number == 4) { - return "Date of Birth"; - } else if (number == 5) { - return "Place of Birth"; - } else if (number == 6) { - return "Customer Identification Number"; - } else if (number == 7) { - return "National Identity Number"; - } else if (number == 8) { - return "Additional Information"; - } - } + try { + int number = Integer.valueOf(lineIdentifier.trim()); + if (number == 1) { + return "Name of the Ordering Customer"; + } else if (number == 2) { + return "Address Line"; + } else if (number == 3) { + return "Country and Town"; + } else if (number == 4) { + return "Date of Birth"; + } else if (number == 5) { + return "Place of Birth"; + } else if (number == 6) { + return "Customer Identification Number"; + } else if (number == 7) { + return "National Identity Number"; + } else if (number == 8) { + return "Additional Information"; + } + } catch (NumberFormatException e) { + // ignore + } + } return null; } diff --git a/src/generated/java/com/prowidesoftware/swift/model/field/Field59F.java b/src/generated/java/com/prowidesoftware/swift/model/field/Field59F.java index daf7828e..14331d3f 100644 --- a/src/generated/java/com/prowidesoftware/swift/model/field/Field59F.java +++ b/src/generated/java/com/prowidesoftware/swift/model/field/Field59F.java @@ -1416,14 +1416,18 @@ public String getComponentLabel(final int number) { */ public String getLabelForLineNumber(String lineIdentifier) { if (StringUtils.isNumeric(StringUtils.trimToNull(lineIdentifier))) { - int number = Integer.valueOf(lineIdentifier.trim()); - if (number == 1) { - return "Name of Beneficiary Customer"; - } else if (number == 2) { - return "Address Line"; - } else if (number == 3) { - return "Country and Town"; - } + try { + int number = Integer.valueOf(lineIdentifier.trim()); + if (number == 1) { + return "Name of Beneficiary Customer"; + } else if (number == 2) { + return "Address Line"; + } else if (number == 3) { + return "Country and Town"; + } + } catch (NumberFormatException e) { + // ignore + } } return null; } diff --git a/src/main/java/com/prowidesoftware/swift/io/parser/XMLParser.java b/src/main/java/com/prowidesoftware/swift/io/parser/XMLParser.java index 342f40ba..1e52044d 100644 --- a/src/main/java/com/prowidesoftware/swift/io/parser/XMLParser.java +++ b/src/main/java/com/prowidesoftware/swift/io/parser/XMLParser.java @@ -380,7 +380,13 @@ private Field getField(final Node t) { String text = getText(n); // normalize line feeds (DOM parser removes carriage return characters from original XML file) text = StringUtils.replace(text, "\n", FINWriterVisitor.SWIFT_EOL); - field.setComponent(Integer.parseInt(number), text); + try { + field.setComponent(Integer.parseInt(number), text); + } catch (NumberFormatException e) { + log.warning( + "error setting component " + number + " for field " + name + ": " + e.getMessage()); + return null; + } } } } diff --git a/src/main/java/com/prowidesoftware/swift/model/MtSwiftMessage.java b/src/main/java/com/prowidesoftware/swift/model/MtSwiftMessage.java index 6b93734b..8f47fff0 100644 --- a/src/main/java/com/prowidesoftware/swift/model/MtSwiftMessage.java +++ b/src/main/java/com/prowidesoftware/swift/model/MtSwiftMessage.java @@ -70,6 +70,7 @@ public MtSwiftMessage() {} /** * Calls {@link #MtSwiftMessage(String, MessageMetadataStrategy)} with the {@link DefaultMtMetadataStrategy} + * * @param fin the plain FIN message content */ public MtSwiftMessage(final String fin) { @@ -98,6 +99,7 @@ public MtSwiftMessage(final String fin, final MessageMetadataStrategy metadataSt /** * Calls {@link #MtSwiftMessage(InputStream, MessageMetadataStrategy)} with the {@link DefaultMtMetadataStrategy} + * * @param stream input stream to read * @throws IOException on error during file reading */ @@ -110,7 +112,7 @@ public MtSwiftMessage(final InputStream stream) throws IOException { *
* File format is set to {@link FileFormat#FIN}. * - * @param stream input stream to read + * @param stream input stream to read * @param metadataStrategy a strategy for metadata extraction * @throws IOException on error during file reading * @since 9.1.4 @@ -134,7 +136,7 @@ public MtSwiftMessage(final File file) throws IOException { *
* File format is set to {@link FileFormat#FIN} * - * @param file file holding message content + * @param file file holding message content * @param metadataStrategy a strategy for metadata extraction * @throws IOException on error during file reading * @since 9.1.4 @@ -342,6 +344,7 @@ private void applyStrategy(SwiftMessage model, MessageMetadataStrategy strategy) /** * Calls {@link #updateFromFIN(String, MessageMetadataStrategy)} with the {@link DefaultMtMetadataStrategy} + * * @param fin raw (FIN) message content to update from */ public void updateFromFIN(final String fin) { @@ -451,10 +454,13 @@ public SwiftMessage modelMessage() { public Integer getMessageTypeInt() { final String number = getMessageType(); if (StringUtils.isNumeric(number)) { - return Integer.parseInt(number); - } else { - return null; + try { + return Integer.parseInt(number); + } catch (NumberFormatException e) { + log.log(Level.WARNING, "error parsing message type as number: " + e.getMessage(), e); + } } + return null; } /** diff --git a/src/main/java/com/prowidesoftware/swift/model/Tag.java b/src/main/java/com/prowidesoftware/swift/model/Tag.java index a39b7a27..ceac8f6c 100644 --- a/src/main/java/com/prowidesoftware/swift/model/Tag.java +++ b/src/main/java/com/prowidesoftware/swift/model/Tag.java @@ -401,7 +401,11 @@ public Integer getNumber() { } } if (sb.length() > 0) { - return Integer.parseInt(sb.toString()); + try { + return Integer.parseInt(sb.toString()); + } catch (NumberFormatException e) { + return null; + } } } return null; diff --git a/src/main/java/com/prowidesoftware/swift/model/UnparsedTextList.java b/src/main/java/com/prowidesoftware/swift/model/UnparsedTextList.java index 42c9d3cb..34cc34c4 100644 --- a/src/main/java/com/prowidesoftware/swift/model/UnparsedTextList.java +++ b/src/main/java/com/prowidesoftware/swift/model/UnparsedTextList.java @@ -247,21 +247,6 @@ public void addText(final SwiftMessage message) { this.addText(msg); } - /** - * removes an unparsed text - * - * @param index the index of the text to remove - * @throws IllegalArgumentException if parameter index is null - * @throws IndexOutOfBoundsException if parameter index is out of bounds - */ - public void removeText(final Integer index) { - // sanity check - Objects.requireNonNull(index, WRITER_MESSAGE); - - // remove the text - this.texts.remove(index.intValue()); - } - /** * removes an unparsed text * diff --git a/src/main/java/com/prowidesoftware/swift/utils/IsoUtils.java b/src/main/java/com/prowidesoftware/swift/utils/IsoUtils.java index ff3d75f9..5eaea97e 100644 --- a/src/main/java/com/prowidesoftware/swift/utils/IsoUtils.java +++ b/src/main/java/com/prowidesoftware/swift/utils/IsoUtils.java @@ -56,7 +56,7 @@ public static IsoUtils getInstance() { } public Set getCurrencies() { - return currencies; + return Collections.unmodifiableSet(currencies); } public void setCurrencies(Set currencies) { @@ -64,7 +64,7 @@ public void setCurrencies(Set currencies) { } public Set getCountries() { - return countries; + return Collections.unmodifiableSet(countries); } public void setCountries(Set countries) { @@ -115,6 +115,20 @@ public void addCountry(final String countryCode) { countries.add(countryCode); } + /** + * Removes the given country code from the current list of codes. + * + * @param countryCode a two capital letters country code, for example: XK + * @throws IllegalArgumentException if the parameter code is null or not two uppercase letters + * @since 9.4.18 + */ + public void removeCountry(final String countryCode) { + Validate.isTrue( + countryCode != null && countryCode.length() == 2 && countryCode.matches("[A-Z]*"), + "The country code must be indicated with two uppercase letters"); + countries.remove(countryCode); + } + /** * Adds the given currency code to the current list of codes, verifying that it does not exist previously. * @@ -128,4 +142,18 @@ public void addCurrency(final String currencyCode) { "The currency code must by indicated with three uppercase letters"); currencies.add(currencyCode); } + + /** + * Removes the given currency code from the current list of codes. + * + * @param currencyCode a three capital letters currency code, for example: ARS + * @throws IllegalArgumentException if the parameter code is null or not three uppercase letters + * @since 9.4.18 + */ + public void removeCurrency(final String currencyCode) { + Validate.isTrue( + currencyCode != null && currencyCode.length() == 3 && currencyCode.matches("[A-Z]*"), + "The currency code must be indicated with three uppercase letters"); + currencies.remove(currencyCode); + } } diff --git a/src/test/java/com/prowidesoftware/swift/utils/IsoUtilsTest.java b/src/test/java/com/prowidesoftware/swift/utils/IsoUtilsTest.java index 93278070..e7cfea1a 100644 --- a/src/test/java/com/prowidesoftware/swift/utils/IsoUtilsTest.java +++ b/src/test/java/com/prowidesoftware/swift/utils/IsoUtilsTest.java @@ -44,9 +44,10 @@ public void testCurrencies() { assertFalse(IsoUtils.getInstance().isValidISOCurrency(null)); assertFalse(IsoUtils.getInstance().isValidISOCurrency("XYZ")); - IsoUtils.getInstance().getCurrencies().add("XYZ"); + IsoUtils.getInstance().addCurrency("XYZ"); assertTrue(IsoUtils.getInstance().isValidISOCurrency("XYZ")); - IsoUtils.getInstance().getCurrencies().remove("XYZ"); + IsoUtils.getInstance().removeCurrency("XYZ"); + assertFalse(IsoUtils.getInstance().isValidISOCurrency("XYZ")); } @Test @@ -126,7 +127,8 @@ public void testAddCountry_4() { public void testAddCountry_5() { IsoUtils.getInstance().addCountry("SZ"); assertTrue(IsoUtils.getInstance().isValidISOCountry("SZ")); - IsoUtils.getInstance().getCountries().remove("SZ"); + IsoUtils.getInstance().removeCountry("SZ"); + assertFalse(IsoUtils.getInstance().isValidISOCountry("SZ")); } @Test @@ -157,6 +159,7 @@ public void testAddCurrency_4() { public void testAddCurrency_5() { IsoUtils.getInstance().addCurrency("DSZ"); assertTrue(IsoUtils.getInstance().isValidISOCurrency("DSZ")); - IsoUtils.getInstance().getCurrencies().remove("DSZ"); + IsoUtils.getInstance().removeCurrency("DSZ"); + assertFalse(IsoUtils.getInstance().isValidISOCurrency("DSZ")); } }