public abstract class AbstractSwiftMessage extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected String |
identifier
Message type identification as specify by SWIFT.
|
protected static String |
IDENTIFIER_ACK
Identifier constant for acknowledge service messages
|
protected static String |
IDENTIFIER_NAK
Identifier constant for non-acknowledge service messages
|
static String |
PROPERTY_NAME |
protected String |
receiver
Receivers BIC8 code.
For MT messages this is the BIC8 portion of the receiver logical terminal; for outgoing messages the LT at block 2 is used, and for incoming messages it is the LT at block 1. |
protected String |
sender
Senders BIC8 code.
For MT messages this is the BIC8 portion of the sender logical terminal; for outgoing messages the LT at block 1 is used, and for incoming messages it is the LT at the MIR of block 2. |
Modifier | Constructor and Description |
---|---|
|
AbstractSwiftMessage()
Empty constructor provided for ORM persistence.
|
protected |
AbstractSwiftMessage(File file)
Creates a new message reading the message the content from a file.
|
protected |
AbstractSwiftMessage(File file,
FileFormat fileFormat) |
protected |
AbstractSwiftMessage(InputStream stream)
Creates a new message reading the message the content from an input stream, using UTF-8 as encoding.
|
protected |
AbstractSwiftMessage(InputStream stream,
FileFormat fileFormat) |
protected |
AbstractSwiftMessage(String content)
Creates a new message reading the message the content from a string.
|
protected |
AbstractSwiftMessage(String content,
FileFormat fileFormat) |
Modifier and Type | Method and Description |
---|---|
void |
addNote(SwiftMessageNote n)
Adds a new note to the messages, initializing the note list if necessary.
|
void |
addRevision(SwiftMessageRevision revision)
Adds a new revision to the messages, initializing the revision list if necessary.
|
void |
addStatus(SwiftMessageStatusInfo status)
Adds a status to the message's status trail and current status attribute, initializing the statuses trail list if necessary.
|
boolean |
contains(Enum... statuses)
Tell if this message has any of the given statuses in his status trail
|
boolean |
contains(String... statuses)
Tell if this message has any of the given statuses in his status trail
|
void |
copyTo(AbstractSwiftMessage msg)
Copies attributes from the current object to msg.
|
SwiftMessageRevision |
createRevision()
Creates a new revision of the message and adds it to the revision list.
|
boolean |
equals(Object obj) |
SwiftMessageStatusInfo |
findStatusInfo(String... statusNames)
Finds the first status info from the status trail, with a name matching any of the given status names, or returns
null if not found
This method is similar to findStatusInfoLast(String...) but checks the status trail in ascending order from oldest to latest. |
SwiftMessageStatusInfo |
findStatusInfo(String statusName)
Finds the first status info from the status trail, with the given name or returns
null if not found |
SwiftMessageStatusInfo |
findStatusInfoLast(String... statusNames)
Finds the last status info from the status trail, with a name matching any of the given status names, or returns
null if not found. |
SwiftMessageStatusInfo |
findStatusInfoLast(String statusName)
Finds the last status info from the status trail, with the given name or returns
null if not found |
String |
formattedAmount()
If the amount is set, returns its currency and value formatted using the default locale.
|
String |
formattedAmount(Locale locale,
boolean includeCurrency)
If the amount is set, returns its value formatted for the given locale.
|
BigDecimal |
getAmount() |
String |
getChecksum()
|
Calendar |
getCreationDate() |
String |
getCurrency() |
MessageIOType |
getDirection() |
FileFormat |
getFileFormat() |
String |
getFilename() |
Long |
getId()
Returns the persisted message unique identifier.
|
String |
getIdentifier()
|
String |
getLastData() |
String |
getLastData(String... statuses)
Get the last saved status data of this message or empty string if not found
|
Calendar |
getLastModified() |
String |
getMessage()
Same as {
message() } |
String |
getMessageName()
Get the value of the property under the
PROPERTY_NAME key or null if not found |
List<SwiftMessageNote> |
getNotes() |
String |
getPaddedId()
Returns the internal unique id as fixed length string, padded with zeros.
|
SwiftMessageStatusInfo |
getPreviousStatusInfo()
Retrieves from the status trail, the status info before the current one; or
null if none is found. |
Map<String,String> |
getProperties() |
String |
getProperty(Enum key) |
String |
getProperty(String key)
Get the value of the property under the given key or
null if the key is not found or its value is empty |
boolean |
getPropertyBoolean(Enum key) |
boolean |
getPropertyBoolean(String key)
Returns true if the message has a property with the given key name and value "true"
|
String |
getReceiver()
|
String |
getReference() |
List<SwiftMessageRevision> |
getRevisions() |
String |
getSender()
|
String |
getStatus()
Get the name of the last status set to this message, or
null if none is found. |
SwiftMessageStatusInfo |
getStatusInfo()
Retrieves from the status trail, the current status info; or
null if none is found. |
List<SwiftMessageStatusInfo> |
getStatusTrail() |
int |
hashCode() |
boolean |
identifiedAsACK()
Returns true if this message identifier is
IDENTIFIER_ACK |
boolean |
identifiedAsNAK()
Returns true if this message identifier is
IDENTIFIER_NAK |
Boolean |
isIncoming() |
boolean |
isInput() |
boolean |
isMT()
True if the message is an
MtSwiftMessage , false otherwise |
boolean |
isMX()
True if the message is an
MxSwiftMessage , false otherwise |
boolean |
isOutgoing() |
Boolean |
isOutput() |
boolean |
isStatus(Enum... statuses)
Tell if this message has any of the given statuses as current status
|
boolean |
isStatus(Enum status)
Returns true if the current status is equals to the parameter status
|
boolean |
isStatus(String... statuses)
Tell if this message has any of the given statuses as current status
|
boolean |
isStatus(String status)
Returns true if the current status is equals to the parameter status
|
boolean |
match(String regex)
Applies the parameter regex to the message identifier.
|
String |
message()
Returns the internal swift message in its original raw format.
|
MessageStandardType |
messageStandardType()
Returns the enumeration value corresponding to this message.
|
abstract AbstractSwiftMessage |
readFile(File file)
Deprecated.
use the constructor
AbstractSwiftMessage(File) instead |
void |
sanityCheckProperties()
Iterate message properties and truncate all needed values issuing a log entry for each truncated one
|
void |
setAmount(BigDecimal amount) |
void |
setChecksum(String checksum) |
void |
setCreationDate(Calendar creationDate) |
void |
setCurrency(String currency) |
void |
setDirection(MessageIOType direction) |
void |
setFileFormat(FileFormat fileFormat)
This should mostly be set automatically by update API in implementing subclasses
|
void |
setFilename(String filename) |
void |
setId(Long id)
Used by the ORM to set the database unique identifier.
|
void |
setIdentifier(String identifier) |
void |
setLastModified(Calendar lastModified) |
void |
setMessage(String message)
Set the raw content of the message.
|
void |
setNotes(List<SwiftMessageNote> notes) |
void |
setProperties(Map<String,String> properties) |
void |
setProperty(Enum key,
String value) |
void |
setProperty(String key,
String value)
Sets a property using the given key and value, if the key exists the value is overwritten.
|
void |
setReceiver(String receiver) |
void |
setReference(String reference) |
void |
setRevisions(List<SwiftMessageRevision> revisions) |
void |
setSender(String sender) |
void |
setStatus(String status)
Sets the status attribute.
|
void |
setStatus(SwiftMessageStatusInfo status) |
void |
setStatusTrail(List<SwiftMessageStatusInfo> statusTrail) |
protected abstract void |
updateFromMessage()
Updates the object attributes with metadata parsed from the message raw content:
identifier, sender, receiver, direction and specific data for the implementing subclass.
|
protected static final String IDENTIFIER_ACK
protected static final String IDENTIFIER_NAK
protected String identifier
IDENTIFIER_ACK
IDENTIFIER_NAK
null
protected String sender
protected String receiver
public static final transient String PROPERTY_NAME
public AbstractSwiftMessage()
protected AbstractSwiftMessage(String content)
updateFromMessage()
} to fill the specific metadata attributes.content
- a swift message contentprotected AbstractSwiftMessage(String content, FileFormat fileFormat)
content
- fileFormat
- AbstractSwiftMessage(String)
protected AbstractSwiftMessage(InputStream stream) throws IOException
updateFromMessage()
} to fill the specific metadata attributes.stream
- IOException
protected AbstractSwiftMessage(InputStream stream, FileFormat fileFormat) throws IOException
stream
- fileFormat
- IOException
AbstractSwiftMessage(InputStream)
protected AbstractSwiftMessage(File file) throws IOException
updateFromMessage()
} to fill the specific metadata attributes.file
- an existing file name containing only one message.IOException
protected AbstractSwiftMessage(File file, FileFormat fileFormat) throws IOException
file
- fileFormat
- IOException
AbstractSwiftMessage(File)
protected abstract void updateFromMessage()
public Long getId()
public void setId(Long id)
public String message()
public void setMessage(String message)
IMPORTANT: this will not automatically update the metadata attributes. Consider using one of the specific update methods from the specific subclass instead.
message
- raw content of the messagepublic String getIdentifier()
public void setIdentifier(String identifier)
public String getChecksum()
public void setChecksum(String checksum)
public Calendar getLastModified()
public void setLastModified(Calendar lastModified)
public Calendar getCreationDate()
public void setCreationDate(Calendar creationDate)
public List<SwiftMessageNote> getNotes()
public void setNotes(List<SwiftMessageNote> notes)
public List<SwiftMessageStatusInfo> getStatusTrail()
public void setStatusTrail(List<SwiftMessageStatusInfo> statusTrail)
public String getStatus()
null
if none is found.public void setStatus(String status)
status
- addStatus(SwiftMessageStatusInfo)
public String getSender()
public void setSender(String sender)
public String getReceiver()
public void setReceiver(String receiver)
public MessageIOType getDirection()
public void setDirection(MessageIOType direction)
public String getFilename()
public void setFilename(String filename)
public String getMessageName()
PROPERTY_NAME
key or null
if not foundpublic void addStatus(SwiftMessageStatusInfo status)
status
- the status to addpublic boolean isOutgoing()
public boolean isInput()
isOutgoing()
public Boolean isIncoming()
public Boolean isOutput()
isIncoming()
public void setStatus(SwiftMessageStatusInfo status)
addStatus(SwiftMessageStatusInfo)
public boolean isStatus(String status)
status
- public boolean isStatus(Enum status)
status
- public SwiftMessageStatusInfo getStatusInfo()
null
if none is found.public SwiftMessageStatusInfo getPreviousStatusInfo()
null
if none is found.public boolean contains(Enum... statuses)
statuses
- a list of statuses to check in the status trailpublic boolean contains(String... statuses)
statuses
- a list of statuses to check in the status trailpublic boolean isStatus(String... statuses)
statuses
- public boolean isStatus(Enum... statuses)
statuses
- public String getLastData(String... statuses)
statuses
- an array of statuses to check data into, if null
all message statuses are checked for datapublic String getLastData()
public SwiftMessageStatusInfo findStatusInfo(String... statusNames)
null
if not found
This method is similar to findStatusInfoLast(String...)
but checks the status trail in ascending order from oldest to latest.public SwiftMessageStatusInfo findStatusInfo(String statusName)
null
if not foundfindStatusInfo(String...)
public SwiftMessageStatusInfo findStatusInfoLast(String... statusNames)
null
if not found.
This method is similar to findStatusInfo(String...)
but checks the status trail in descending order from latest to oldest.public SwiftMessageStatusInfo findStatusInfoLast(String statusName)
null
if not foundfindStatusInfoLast(String...)
public void addNote(SwiftMessageNote n)
n
- note to addpublic void sanityCheckProperties()
public String getProperty(String key)
null
if the key is not found or its value is emptypublic String getProperty(Enum key)
getProperty(String)
public void setProperty(String key, String value)
public void setProperty(Enum key, String value)
setProperty(String, String)
public boolean getPropertyBoolean(String key)
public boolean getPropertyBoolean(Enum key)
getPropertyBoolean(String)
public String getPaddedId()
@Deprecated @ProwideDeprecated(phase4=_2018) public abstract AbstractSwiftMessage readFile(File file) throws IOException
AbstractSwiftMessage(File)
insteadIOException
public void copyTo(AbstractSwiftMessage msg)
msg
- public List<SwiftMessageRevision> getRevisions()
public void setRevisions(List<SwiftMessageRevision> revisions)
revisions
- public void addRevision(SwiftMessageRevision revision)
revision
- revision to addpublic SwiftMessageRevision createRevision()
SwiftMessageRevision.SwiftMessageRevision(AbstractSwiftMessage)
public boolean isMT()
MtSwiftMessage
, false otherwisepublic boolean isMX()
MxSwiftMessage
, false otherwisepublic MessageStandardType messageStandardType()
public FileFormat getFileFormat()
public void setFileFormat(FileFormat fileFormat)
fileFormat
- public String getReference()
public void setReference(String reference)
public String getCurrency()
null
if non is present or does not apply for this message typepublic void setCurrency(String currency)
public BigDecimal getAmount()
null
if non is present or does not apply for this message typepublic void setAmount(BigDecimal amount)
public boolean match(String regex)
Notice the identifier will contain:
fin.*
matches all MT messages, fin.*STP
matches all STP MT messages
and camt.*
matches all MX messages in the category camt.
regex
- to matchpublic String formattedAmount()
getAmount()
,
formattedAmount(Locale, boolean)
public String formattedAmount(Locale locale, boolean includeCurrency)
locale
- a specific locale to use or null
to use the current default localeincludeCurrency
- if true and the currency is set, the formatted value will be prefixed by the currency symbolgetAmount()
public boolean identifiedAsACK()
IDENTIFIER_ACK
The implementation does not check the inner content of the message.
It is safe to use this method to check if message is effectively and acknowledge only when the API is used with the provided subclasses for MT and MX and when the identifier has not been altered by the accesor.
IDENTIFIER_ACK
false otherwisepublic boolean identifiedAsNAK()
IDENTIFIER_NAK
The implementation does not check the inner content of the message.
It is safe to use this method to check if message is effectively and non-acknowledge only when the API is used with the provided subclasses for MT and MX and when the identifier has not been altered by the accesor.
IDENTIFIER_NAK
false otherwise