public abstract class AbstractSwiftMessage
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
identifier |
protected static java.lang.String |
IDENTIFIER_ACK
Identifier constant for acknowledge service messages
|
protected static java.lang.String |
IDENTIFIER_NAK
Identifier constant for non-acknowledge service messages
|
static java.lang.String |
PROPERTY_NAME |
protected java.lang.String |
receiver |
protected java.lang.String |
sender |
Modifier | Constructor and Description |
---|---|
|
AbstractSwiftMessage()
Empty constructor provided for ORM persistence.
|
protected |
AbstractSwiftMessage(java.io.File file)
Creates a new message reading the message the content from a file.
|
protected |
AbstractSwiftMessage(java.io.File file,
FileFormat fileFormat) |
protected |
AbstractSwiftMessage(java.io.InputStream stream)
Creates a new message reading the message the content from an input stream, using UTF-8 as encoding.
|
protected |
AbstractSwiftMessage(java.io.InputStream stream,
FileFormat fileFormat) |
protected |
AbstractSwiftMessage(java.lang.String content)
Creates a new message reading the message the content from a string.
|
protected |
AbstractSwiftMessage(java.lang.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.
|
protected java.lang.String |
bic11(java.lang.String address)
Creates a BIC11 from the given address.
|
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 obj) |
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 |
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.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.
|
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.
|
abstract AbstractSwiftMessage |
readFile(java.io.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(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) |
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 java.lang.String IDENTIFIER_ACK
protected static final java.lang.String IDENTIFIER_NAK
protected java.lang.String identifier
protected java.lang.String sender
protected java.lang.String receiver
public static final transient java.lang.String PROPERTY_NAME
public AbstractSwiftMessage()
protected AbstractSwiftMessage(java.lang.String content)
updateFromMessage()
} to fill the specific metadata attributes.content
- a swift message contentprotected AbstractSwiftMessage(java.lang.String content, FileFormat fileFormat)
content
- fileFormat
- AbstractSwiftMessage(String)
protected AbstractSwiftMessage(java.io.InputStream stream) throws java.io.IOException
updateFromMessage()
} to fill the specific metadata attributes.stream
- java.io.IOException
protected AbstractSwiftMessage(java.io.InputStream stream, FileFormat fileFormat) throws java.io.IOException
stream
- fileFormat
- java.io.IOException
AbstractSwiftMessage(InputStream)
protected AbstractSwiftMessage(java.io.File file) throws java.io.IOException
updateFromMessage()
} to fill the specific metadata attributes.file
- an existing file name containing only one message.java.io.IOException
protected AbstractSwiftMessage(java.io.File file, FileFormat fileFormat) throws java.io.IOException
file
- fileFormat
- java.io.IOException
AbstractSwiftMessage(File)
protected abstract void updateFromMessage()
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)}
,
public java.lang.String getIdentifier()
IDENTIFIER_ACK
IDENTIFIER_NAK
null
public void setIdentifier(java.lang.String identifier)
identifier
- public 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
- SwiftMessageUtils.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)
checksumBlock4
- the checksum to setpublic java.util.Calendar getLastModified()
public void setLastModified(java.util.Calendar lastModified)
lastModified
- public java.util.Calendar getCreationDate()
public void setCreationDate(java.util.Calendar creationDate)
creationDate
- public 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
- addStatus(SwiftMessageStatusInfo)
public java.lang.String getStatus()
null
if none is found.public void setStatus(java.lang.String status)
status
- addStatus(SwiftMessageStatusInfo)
public java.lang.String getSender()
public void setSender(java.lang.String sender)
sender
- public java.lang.String getReceiver()
public void setReceiver(java.lang.String receiver)
receiver
- public MessageIOType getDirection()
public void setDirection(MessageIOType direction)
direction
- public java.lang.String getFilename()
public void setFilename(java.lang.String filename)
filename
- public 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
- public boolean isStatus(java.lang.Enum status)
status
- public 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
- public boolean isStatus(java.lang.Enum... statuses)
statuses
- public 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 java.lang.String getPaddedId()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
@Deprecated @ProwideDeprecated(phase4=_2018) public abstract AbstractSwiftMessage readFile(java.io.File file) throws java.io.IOException
AbstractSwiftMessage(File)
insteadjava.io.IOException
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
- 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 java.lang.String getReference()
public void setReference(java.lang.String reference)
reference
- public java.lang.String getCurrency()
null
if non is present or does not apply for this message typepublic void setCurrency(java.lang.String currency)
currency
- public java.math.BigDecimal getAmount()
null
if non is present or does not apply for this message typepublic void setAmount(java.math.BigDecimal amount)
amount
- public 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 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 otherwiseprotected java.lang.String bic11(java.lang.String address)
address
- a BIC8, BIC11 or full logical terminal address (BIC12)BIC.getBic11()
public 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 search