@Entity public abstract class AbstractSwiftMessage extends java.lang.Object implements java.io.Serializable, JsonSerializable
This class hierarchy is designed as a container of the raw message contents (xml for MX and FIN for MT) plus minimal message metadata. The extra data contains several common attributes for all messages, and the subclasses add additional information mainly to identify the specific message type.
This minimal abstraction make this model optimal for an ORM mapping (ex: for Hibernate) to store all messages in a single and simple table.
XML metadata may be used to override or augment these JPA annotations.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PROPERTY_NAME |
Constructor and Description |
---|
AbstractSwiftMessage()
Empty constructor provided for ORM persistence.
|
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(java.lang.Enum... statuses)
Tell if this message has any of the given statuses in his status trail
|
boolean |
contains(java.lang.String... statuses)
Tell if this message has any of the given statuses in his status trail
|
void |
copyTo(AbstractSwiftMessage msg)
Creates a full copy of the current message object into another message.
|
SwiftMessageRevision |
createRevision()
Creates a new revision of the message and adds it to the revision list.
|
boolean |
equals(java.lang.Object o) |
SwiftMessageStatusInfo |
findStatusInfo(java.lang.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(java.lang.String statusName)
Finds the first status info from the status trail, with the given name or returns
null if not found |
SwiftMessageStatusInfo |
findStatusInfoLast(java.lang.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(java.lang.String statusName)
Finds the last status info from the status trail, with the given name or returns
null if not found |
java.lang.String |
formattedAmount()
If the amount is set, returns its currency and value formatted using the default locale.
|
java.lang.String |
formattedAmount(java.util.Locale locale,
boolean includeCurrency)
If the amount is set, returns its value formatted for the given locale.
|
java.math.BigDecimal |
getAmount()
Main amount
|
java.lang.String |
getCategory()
For MT messages returns the category number and for MX messages return the business process.
|
java.lang.String |
getChecksum()
Proprietary checksum computed for the whole raw message content, helpful for integrity verification or duplicates detection.
|
java.lang.String |
getChecksumBody()
Gets the proprietary checksum calculated for the text block (block 4) only in MT or Document only in MX, helpful for integrity verification or duplicates detection.
|
BIC |
getCorrespondentBIC()
Returns the correspondent BIC code from the headers.
For an outgoing message, the BIC address identifies the receiver of the message. |
java.util.Calendar |
getCreationDate()
Creation date and time.
|
java.lang.String |
getCreationDayOfMonth()
The day of month when the message was created, extracted from the
getCreationDate()
Helper read-only property useful for faceting search |
java.lang.String |
getCreationMonth()
The month when the message was created, extracted from the
getCreationDate()
Helper read-only property useful for faceting search |
java.lang.String |
getCreationYear()
The year when the message was created, extracted from the
getCreationDate()
Helper read-only property useful for faceting search |
java.lang.String |
getCurrency()
Main currency
|
MessageIOType |
getDirection()
Direction from application perspective;
message is sent to SWIFT are outgoing and
messages received from SWIFT are incoming.
|
FileFormat |
getFileFormat()
Original file format if applies.
|
java.lang.String |
getFilename()
Original filename if applies.
|
java.lang.Long |
getId()
Returns the persisted message unique identifier.
|
java.lang.String |
getIdentifier()
Message type identification as specify by SWIFT.
|
java.lang.String |
getLastData()
Same as
getLastData(String...) passing a null array parameter |
java.lang.String |
getLastData(java.lang.String... statuses)
Get the last saved status data of this message or empty string if not found
|
java.util.Calendar |
getLastModified()
Last modification date and time.
|
java.lang.String |
getMessage()
Raw message content.
|
java.lang.String |
getMessageName()
Get the value of the property under the
PROPERTY_NAME key or null if not found |
java.lang.String |
getMessageType()
Get the message type.
For MTs this is the MT type number present in the identifier attribute. |
java.util.List<SwiftMessageNote> |
getNotes()
User comments attached to this message.
|
java.lang.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. |
java.util.Map<java.lang.String,java.lang.String> |
getProperties()
Flexible property container to extend message metadata.
|
java.lang.String |
getProperty(java.lang.Enum key) |
java.lang.String |
getProperty(java.lang.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(java.lang.Enum key) |
boolean |
getPropertyBoolean(java.lang.String key)
Returns true if the message has a property with the given key name and value "true"
|
java.lang.String |
getReceiver()
Receivers BIC11 code.
For MT messages this is the BIC11 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. |
java.lang.String |
getReference()
Message reference
|
java.util.List<SwiftMessageRevision> |
getRevisions()
Snapshots of message content used to track its changes history
|
java.lang.String |
getSender()
Senders BIC11 code.
For MT messages this is the BIC11 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. |
java.lang.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. |
java.util.List<SwiftMessageStatusInfo> |
getStatusTrail()
Status history for this message.
|
java.util.Calendar |
getTradeDate() |
java.util.Calendar |
getValueDate() |
int |
hashCode() |
boolean |
identifiedAsACK()
Returns true if this message identifier is
IDENTIFIER_ACK |
boolean |
identifiedAsNAK()
Returns true if this message identifier is
IDENTIFIER_NAK |
java.lang.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() |
java.lang.Boolean |
isOutput() |
boolean |
isStatus(java.lang.Enum... statuses)
Tell if this message has any of the given statuses as current status
|
boolean |
isStatus(java.lang.Enum status)
Returns true if the current status is equals to the parameter status
|
boolean |
isStatus(java.lang.String... statuses)
Tell if this message has any of the given statuses as current status
|
boolean |
isStatus(java.lang.String status)
Returns true if the current status is equals to the parameter status
|
boolean |
match(java.lang.String regex)
Applies the parameter regex to the message identifier.
|
java.lang.String |
message()
Returns the internal swift message in its original raw format.
|
MessageStandardType |
messageStandardType()
Returns the enumeration value corresponding to this message.
|
boolean |
propertyEquals(java.lang.Enum key,
java.lang.Enum expectedValue) |
boolean |
propertyEquals(java.lang.Enum key,
java.lang.String expectedValue) |
boolean |
propertyEquals(java.lang.String key,
java.lang.String expectedValue)
Checks if a given property has a specific value
|
void |
sanityCheckProperties()
Iterate message properties and truncate all needed values issuing a log entry for each truncated one
|
void |
setAmount(java.math.BigDecimal amount)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setChecksum(java.lang.String checksum)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setChecksumBody(java.lang.String checksumBody)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setCreationDate(java.util.Calendar creationDate)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setCurrency(java.lang.String currency)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setDirection(MessageIOType direction)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setFileFormat(FileFormat fileFormat)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setFilename(java.lang.String filename)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setId(java.lang.Long id)
Used by the ORM to set the database unique identifier.
|
void |
setIdentifier(java.lang.String identifier)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setLastModified(java.util.Calendar lastModified)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setMessage(java.lang.String message)
Set the raw content of the message.
|
void |
setNotes(java.util.List<SwiftMessageNote> notes) |
void |
setProperties(java.util.Map<java.lang.String,java.lang.String> properties) |
void |
setProperty(java.lang.Enum key,
java.lang.String value) |
void |
setProperty(java.lang.String key,
java.lang.String value)
Sets a property using the given key and value, if the key exists the value is overwritten.
|
void |
setReceiver(java.lang.String receiver)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setReference(java.lang.String reference)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setRevisions(java.util.List<SwiftMessageRevision> revisions) |
void |
setSender(java.lang.String sender)
This field is automatically set by the constructor or when the message is updated by using a specific subclass update method.
|
void |
setStatus(java.lang.String status)
Sets the status attribute.
|
void |
setStatus(SwiftMessageStatusInfo status) |
void |
setStatusTrail(java.util.List<SwiftMessageStatusInfo> statusTrail) |
void |
setTradeDate(java.util.Calendar tradeDate) |
void |
setValueDate(java.util.Calendar valueDate) |
java.lang.String |
toJson()
Gets a JSON representation of this message.
|
public static final transient java.lang.String PROPERTY_NAME
public AbstractSwiftMessage()
public java.lang.Long getId()
public void setId(java.lang.Long id)
public java.lang.String getMessage()
public java.lang.String message()
getMessage()
public void setMessage(java.lang.String message)
IMPORTANT: this will not automatically update the metadata attributes. Consider using one of the specific subclass update methods.
message
- raw content of the messageMtSwiftMessage.updateFromFIN(String)}
,
MtSwiftMessage.updateFromModel(com.prowidesoftware.swift.model.mt.AbstractMT)}
,
MtSwiftMessage.updateFromModel(SwiftMessage)}
,
MxSwiftMessage.updateFromXML(String)}
,
MxSwiftMessage.updateFromModel(com.prowidesoftware.swift.model.mx.AbstractMX)
public java.lang.String getIdentifier()
IDENTIFIER_ACK
IDENTIFIER_NAK
null
public void setIdentifier(java.lang.String identifier)
identifier
- the message identifier such as fin.103public java.lang.String getChecksum()
At the moment this is only implemented for MT messages
public void setChecksum(java.lang.String checksum)
At the moment this is only implemented for MT messages
checksum
- the calculated checksum to setSwiftMessageUtils.calculateChecksum(SwiftMessage)
public java.lang.String getChecksumBody()
At the moment this is only implemented for MT messages
SwiftMessageUtils.calculateChecksum(SwiftBlock4)
public void setChecksumBody(java.lang.String checksumBody)
checksumBody
- the checksum to setpublic java.util.Calendar getLastModified()
public void setLastModified(java.util.Calendar lastModified)
lastModified
- the last modification timestamp to setpublic java.util.Calendar getCreationDate()
public void setCreationDate(java.util.Calendar creationDate)
creationDate
- the creation timestamp to setpublic java.util.List<SwiftMessageNote> getNotes()
public void setNotes(java.util.List<SwiftMessageNote> notes)
addNote(SwiftMessageNote)
public java.util.Map<java.lang.String,java.lang.String> getProperties()
public void setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
public java.util.List<SwiftMessageStatusInfo> getStatusTrail()
public void setStatusTrail(java.util.List<SwiftMessageStatusInfo> statusTrail)
statusTrail
- a list with statuses informationaddStatus(SwiftMessageStatusInfo)
public java.lang.String getStatus()
null
if none is found.public void setStatus(java.lang.String status)
status
- the current message status nameaddStatus(SwiftMessageStatusInfo)
public java.lang.String getSender()
public void setSender(java.lang.String sender)
sender
- the sender addresspublic java.lang.String getReceiver()
public void setReceiver(java.lang.String receiver)
receiver
- the receiver addresspublic MessageIOType getDirection()
public void setDirection(MessageIOType direction)
direction
- the direction (either incoming or outgoing)public java.lang.String getFilename()
public void setFilename(java.lang.String filename)
filename
- the name of the file read to create this message instancepublic java.lang.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 java.lang.Boolean isIncoming()
public java.lang.Boolean isOutput()
isIncoming()
public void setStatus(SwiftMessageStatusInfo status)
addStatus(SwiftMessageStatusInfo)
public boolean isStatus(java.lang.String status)
status
- a status namepublic boolean isStatus(java.lang.Enum status)
status
- a status enum keyFgetpublic SwiftMessageStatusInfo getStatusInfo()
null
if none is found.public SwiftMessageStatusInfo getPreviousStatusInfo()
null
if none is found.public boolean contains(java.lang.Enum... statuses)
statuses
- a list of statuses to check in the status trailpublic boolean contains(java.lang.String... statuses)
statuses
- a list of statuses to check in the status trailpublic boolean isStatus(java.lang.String... statuses)
statuses
- a list of status names to checkpublic boolean isStatus(java.lang.Enum... statuses)
statuses
- a list of status enum keys to checkpublic java.lang.String getLastData(java.lang.String... statuses)
statuses
- an array of statuses to check data into, if null
all message statuses are checked for datapublic java.lang.String getLastData()
getLastData(String...)
passing a null array parameterpublic SwiftMessageStatusInfo findStatusInfo(java.lang.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(java.lang.String statusName)
null
if not foundfindStatusInfo(String...)
public SwiftMessageStatusInfo findStatusInfoLast(java.lang.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(java.lang.String statusName)
null
if not foundfindStatusInfoLast(String...)
public void addNote(SwiftMessageNote n)
n
- note to addpublic void sanityCheckProperties()
public java.lang.String getProperty(java.lang.String key)
null
if the key is not found or its value is emptypublic java.lang.String getProperty(java.lang.Enum key)
getProperty(String)
public void setProperty(java.lang.String key, java.lang.String value)
public void setProperty(java.lang.Enum key, java.lang.String value)
setProperty(String, String)
public boolean getPropertyBoolean(java.lang.String key)
public boolean getPropertyBoolean(java.lang.Enum key)
getPropertyBoolean(String)
public boolean propertyEquals(java.lang.String key, java.lang.String expectedValue)
key
- the property key to checkexpectedValue
- the expected valuepublic boolean propertyEquals(java.lang.Enum key, java.lang.String expectedValue)
propertyEquals(String, String)
public boolean propertyEquals(java.lang.Enum key, java.lang.Enum expectedValue)
propertyEquals(String, String)
public java.lang.String getPaddedId()
public void copyTo(AbstractSwiftMessage msg)
The implementation works as a copy constructor. All attributes are replicated into new instances in the target message. The only fields that are not copied are the Long id because they are intended for ORM (persistence) autogeneration. Preexisting data in the target message will be overwritten.
msg
- target messagepublic java.util.List<SwiftMessageRevision> getRevisions()
public void setRevisions(java.util.List<SwiftMessageRevision> revisions)
revisions
- a list of message modification revisionspublic void addRevision(SwiftMessageRevision revision)
revision
- revision to addpublic SwiftMessageRevision createRevision()
SwiftMessageRevision.SwiftMessageRevision(AbstractSwiftMessage)
public java.util.Calendar getValueDate()
public void setValueDate(java.util.Calendar valueDate)
public java.util.Calendar getTradeDate()
public void setTradeDate(java.util.Calendar tradeDate)
public boolean isMT()
MtSwiftMessage
, false otherwisepublic boolean isMX()
MxSwiftMessage
, false otherwisepublic MessageStandardType messageStandardType()
public FileFormat getFileFormat()
public void setFileFormat(FileFormat fileFormat)
fileFormat
- the file format readpublic java.lang.String getReference()
public void setReference(java.lang.String reference)
reference
- the message referencepublic java.lang.String getCurrency()
null
if non is present or does not apply for this message typepublic void setCurrency(java.lang.String currency)
currency
- the message main currencypublic java.math.BigDecimal getAmount()
null
if non is present or does not apply for this message typepublic void setAmount(java.math.BigDecimal amount)
amount
- the message main amountpublic boolean match(java.lang.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 java.lang.String formattedAmount()
getAmount()
,
formattedAmount(Locale, boolean)
public java.lang.String formattedAmount(java.util.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 equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public 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 otherwisepublic BIC getCorrespondentBIC()
public java.lang.String getCreationYear()
getCreationDate()
Helper read-only property useful for faceting searchpublic java.lang.String getCreationMonth()
getCreationDate()
Helper read-only property useful for faceting searchpublic java.lang.String getCreationDayOfMonth()
getCreationDate()
Helper read-only property useful for faceting searchpublic java.lang.String toJson()
toJson
in interface JsonSerializable
public java.lang.String getCategory()
public java.lang.String getMessageType()