Class SwiftMessageUtils
- java.lang.Object
-
- com.prowidesoftware.swift.model.SwiftMessageUtils
-
public class SwiftMessageUtils extends java.lang.Object
Utility methods that provide higher level access toSwiftMessage
- Since:
- 6.0
-
-
Constructor Summary
Constructors Constructor Description SwiftMessageUtils()
Deprecated.Use the static API insteadSwiftMessageUtils(SwiftMessage m)
Deprecated.Use the static API instead
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String
calculateChecksum(SwiftBlock4 b4)
Proprietary checksum for message text block (block 4) integrity verification or duplicates detectionstatic java.lang.String
calculateChecksum(SwiftMessage model)
Proprietary checksum for message integrity verification or duplicates detection.static SwiftTagListBlock
createSequenceSingle(java.lang.Class<? extends AbstractMT> mt, java.lang.String sequenceName, Tag... tags)
static SwiftTagListBlock
createSubsequenceWithParents(java.lang.Class<? extends AbstractMT> mt, java.lang.String sequenceName, Tag... tags)
Creates a sequence and all it's containing parents.java.util.List<java.lang.String>
currencyStrings()
Deprecated.Use the staticcurrencyStrings(SwiftMessage)
insteadstatic java.util.List<java.lang.String>
currencyStrings(SwiftMessage m)
Get all message currencies for fields implementingCurrencyContainer
static java.lang.String
identifier(SwiftMessage m)
Get a string in the form of businessprocess.messagetype.variantstatic SwiftTagListBlock
join(SwiftTagListBlock... sequences)
Joins all the given sequences in one single list.static SwiftTagListBlock
join(java.util.List<? extends SwiftTagListBlock> sequences)
Joins all the given sequences in one single list.protected Money
money()
Deprecated.Use the staticmoney(SwiftMessage)
insteadstatic Money
money(SwiftMessage m)
Gets the message main amountstatic java.lang.String
receiver(SwiftMessage m)
Gets the message receiver BIC from the message headers.java.lang.String
reference()
Deprecated.Use the staticreference(SwiftMessage)
insteadstatic java.lang.String
reference(SwiftMessage m)
Gets the message reference from field 20 (if present) or from field 20C:SEME if message category is 5.static SwiftTagListBlock
removeInnerSequences(SwiftTagListBlock sequence)
Iterates through the parameter tags and removes all inner blocks enclosed between sequences boundary fields 16R and 16S
This method requires a sequence starting with 16R and ending with 16S, so first and last tags must be those.static java.lang.String
sender(SwiftMessage m)
Gets the message sender BIC from the message headers.static java.util.Map<java.lang.String,SwiftTagListBlock>
splitByField15(SwiftMessage msg)
Splits the given message by field 15, returning the letter option in field 15 as the key in the map.static java.util.List<SwiftTagListBlock>
splitByField15(SwiftMessage msg, java.lang.String letterOption)
Helper method to retrieve all sequences starting with 15X where X is the letterOption parameterstatic java.util.Map<java.lang.String,SwiftTagListBlock>
splitByField15(SwiftTagListBlock block)
Split the given block content by the field 15, returning the letter option in field 15 as the key in the mapstatic java.util.List<SwiftTagListBlock>
splitByField15(SwiftTagListBlock block, java.lang.String letterOption)
Helper method to retrieve all sequences starting with 15X where X is the letterOption parameter.static java.util.Calendar
tradeDate(SwiftMessage m)
Gets the trade date of a message.java.util.Calendar
valueDate()
Deprecated.Use the staticvalueDate(SwiftMessage)
insteadstatic java.util.Calendar
valueDate(SwiftMessage m)
Gets the value date of a message.
-
-
-
Constructor Detail
-
SwiftMessageUtils
@Deprecated @ProwideDeprecated(phase4=SRU2024) public SwiftMessageUtils()
Deprecated.Use the static API instead
-
SwiftMessageUtils
@Deprecated @ProwideDeprecated(phase4=SRU2024) public SwiftMessageUtils(SwiftMessage m)
Deprecated.Use the static API instead
-
-
Method Detail
-
currencyStrings
public static java.util.List<java.lang.String> currencyStrings(SwiftMessage m)
Get all message currencies for fields implementingCurrencyContainer
- Parameters:
m
- the message instance- Returns:
- an empty list if none found
-
removeInnerSequences
public static SwiftTagListBlock removeInnerSequences(SwiftTagListBlock sequence) throws java.lang.IllegalArgumentException
Iterates through the parameter tags and removes all inner blocks enclosed between sequences boundary fields 16R and 16S
This method requires a sequence starting with 16R and ending with 16S, so first and last tags must be those. Due to this constraint, null, empty and sequences with less than 3 tags will be returned without any modification.- Parameters:
sequence
- a block with a sequence to filter- Returns:
- a new block containing all tags that are outside a 16R/S block, the only 16R/S tags returned are the first and last delimiters.
- Throws:
java.lang.IllegalArgumentException
- if the starting tag is not 16R or the ending tag is not the matching 16S- Since:
- 7.8.1
-
valueDate
public static java.util.Calendar valueDate(SwiftMessage m)
Gets the value date of a message.The value date is meaningful and defined by the standard only for a subset of message types. In most of the cases it is contained in the date subfield of field 32A (for example MT103) or field 30 (for example MT101).
Notice a lot of messages do not define a value date.
Also a few define several fields as value date, or the value date can be repeated. for those messages the first one is returned as follows:
- For MT450 returns the first value date occurrence of field 32A
- For MT455 returns the value date from field 32A (not from 33[C,D])
- For MT456 returns the first value date occurrence of field 33D
- For MT564 returns the value date from Cash Movements Field 98a with qualifier PAYD (not qualifier VALU)
- Parameters:
m
- the message where the value date is to be found- Returns:
- found date or null if the message does not defines a value date, or if the defined value date field is not present in the message
- Since:
- 7.7
-
tradeDate
public static java.util.Calendar tradeDate(SwiftMessage m)
Gets the trade date of a message.The implementation tries first to get the trade date from field 30T (present in many category 3 messages) and if not found it tries to get the trade date from field 98a::TRAD (present in many category 5 messages).
Notice a lot of messages do not define a trade date.
- Parameters:
m
- the message where the value date is to be found- Returns:
- found date or null if the message does not defines a trade date, or if the defined trade date field is not present in the message
- Since:
- 7.10.4
-
sender
public static java.lang.String sender(SwiftMessage m)
Gets the message sender BIC from the message headers.For outgoing messages this is the logical terminal at block 1, and for incoming messages this is logical terminal at the MIR of block 2.
for service message (example acknowledges) always returns the logical terminal from block1
- Returns:
- the proper sender address or null if blocks 1 or 2 are not found or incomplete
- Since:
- 9.3.19
-
receiver
public static java.lang.String receiver(SwiftMessage m)
Gets the message receiver BIC from the message headers.For outgoing messages this is the receiver address at block 2, and for incoming messages this is logical terminal at block 1.
for service message (example acknowledges) always returns null
- Returns:
- the proper receiver address or null if blocks 1 or 2 are not found or incomplete
- Since:
- 9.3.19
-
identifier
public static java.lang.String identifier(SwiftMessage m)
Get a string in the form of businessprocess.messagetype.variant- Returns:
- a string with the MT message type identification
- Since:
- 9.3.19
-
calculateChecksum
public static java.lang.String calculateChecksum(SwiftMessage model)
Proprietary checksum for message integrity verification or duplicates detection.Please notice this is not the SWIFT trailer CHK field.
The implementation computes an SHA-256 on the complete message in FIN format. The result hash is a 32 character string, you may consider encoding it with base64 on top to have the same information stored in 22 characters.
- Parameters:
model
- the message- Returns:
- computed hash or null if errors occurred during computation or the message is null
-
calculateChecksum
public static java.lang.String calculateChecksum(SwiftBlock4 b4)
Proprietary checksum for message text block (block 4) integrity verification or duplicates detectionPlease notice this is not the SWIFT trailer CHK field.
The implementation computes an SHA-256 on the complete message in FIN format. The result hash is a 32 character string, you may consider encoding it with base64 on top to have the same information stored in 22 characters.
- Parameters:
b4
- the message text block- Returns:
- computed hash or null if errors occurred during computation or the block is null
- Since:
- 7.9.5
-
splitByField15
public static java.util.Map<java.lang.String,SwiftTagListBlock> splitByField15(SwiftMessage msg)
Splits the given message by field 15, returning the letter option in field 15 as the key in the map.- Parameters:
msg
- message to split- Returns:
- map with key being the letter option in field 15
- See Also:
splitByField15(SwiftTagListBlock)
-
splitByField15
public static java.util.Map<java.lang.String,SwiftTagListBlock> splitByField15(SwiftTagListBlock block)
Split the given block content by the field 15, returning the letter option in field 15 as the key in the map- Parameters:
block
- the content to split- Returns:
- a map with letter options as keys, and blocks as value
- Since:
- 7.7
-
splitByField15
public static java.util.List<SwiftTagListBlock> splitByField15(SwiftMessage msg, java.lang.String letterOption)
Helper method to retrieve all sequences starting with 15X where X is the letterOption parameter- Since:
- 7.7
- See Also:
splitByField15(SwiftTagListBlock, String)
-
splitByField15
public static java.util.List<SwiftTagListBlock> splitByField15(SwiftTagListBlock block, java.lang.String letterOption)
Helper method to retrieve all sequences starting with 15X where X is the letterOption parameter. Field 15a is used as a boundary for sequences, so the letter option correspond to a subsequence name.- Parameters:
block
- the content to split into subsequencesletterOption
- a letter option for the field boundary- Returns:
- found subsequences or an empty list if field 15 is not found
- Since:
- 7.7
-
reference
public static java.lang.String reference(SwiftMessage m)
Gets the message reference from field 20 (if present) or from field 20C:SEME if message category is 5. If no Field20 or 20C are found and MUR is present, returns the MUR value (field 108 from block 3).- Parameters:
m
- the message where the reference is to be found- Returns:
- found reference or null if the message does not defines a reference, or if the defined reference field is not present in the message
- Since:
- 7.8
-
join
public static SwiftTagListBlock join(java.util.List<? extends SwiftTagListBlock> sequences)
Joins all the given sequences in one single list.- Parameters:
sequences
- the sequences to be joined. Can be null or empty, in which case this method returnsSwiftTagListBlock.EMPTY_LIST
- Returns:
- a single
SwiftTagListBlock
containing all elements in order of each of the given sequences orSwiftTagListBlock.EMPTY_LIST
if sequences is null or empty - Since:
- 7.8
-
join
public static SwiftTagListBlock join(SwiftTagListBlock... sequences)
Joins all the given sequences in one single list.- Parameters:
sequences
- the sequences to be joined. Can be null or empty, in which case this method returnsSwiftTagListBlock.EMPTY_LIST
- Returns:
- a single
SwiftTagListBlock
containing all elements in order of each of the given sequences orSwiftTagListBlock.EMPTY_LIST
if sequences is null or empty - Since:
- 9.2.0
-
createSubsequenceWithParents
public static SwiftTagListBlock createSubsequenceWithParents(java.lang.Class<? extends AbstractMT> mt, java.lang.String sequenceName, Tag... tags)
Creates a sequence and all it's containing parents. This method is mainly useful for writing test cases. Instead of writing:
This method is the same with a much cleaner code literature:MT535.SequenceB.newInstance( MT535.SequenceB1b.newInstance( MT535.SequenceB1b.newInstance( MT535.SequenceB1b1.newInstance( tags ) ) ) );
Note:SwiftMessageUtils.createSequenceWithParents(MT535.class, "B1b1", tags);
Using
Is virtually the same as:SwiftMessageUtils.createSequenceWithParents(MT535.class, "B", tags);
MT535.SequenceB.newInstance(tags);
- Parameters:
mt
- the MT class for which the sequence is to be createdsequenceName
- name of the sequencetags
- the content to put in the sequence- Returns:
- the SwiftTagListBlock containing all parent sequences, the sequence requested and the contents
- Since:
- 7.8
-
createSequenceSingle
public static SwiftTagListBlock createSequenceSingle(java.lang.Class<? extends AbstractMT> mt, java.lang.String sequenceName, Tag... tags)
-
money
public static Money money(SwiftMessage m)
Gets the message main amountThe amount is meaningful and defined by the standard only for a subset of message types. In most of the cases it is contained in the currency and amount subfields of fields 32a in payments messages and 19A in securities.
This implementation is a work in progress and the interpretation of which field is consider the main amount for each message type may change from time to time adding more cases or even changing the used field.
- Parameters:
m
- a message with some amount field- Returns:
- the currency and amount object extracted from the message or null if non is present or cannot be created from its fields
- Since:
- 8.0.1
-
currencyStrings
@Deprecated @ProwideDeprecated(phase4=SRU2024) public java.util.List<java.lang.String> currencyStrings()
Deprecated.Use the staticcurrencyStrings(SwiftMessage)
instead
-
valueDate
@Deprecated @ProwideDeprecated(phase4=SRU2024) public java.util.Calendar valueDate()
Deprecated.Use the staticvalueDate(SwiftMessage)
instead
-
reference
@Deprecated @ProwideDeprecated(phase4=SRU2024) public final java.lang.String reference()
Deprecated.Use the staticreference(SwiftMessage)
instead
-
money
@Deprecated @ProwideDeprecated(phase4=SRU2024) protected Money money()
Deprecated.Use the staticmoney(SwiftMessage)
instead
-
-