Class AbstractSwiftMessage

  • All Implemented Interfaces:
    JsonSerializable, java.io.Serializable
    Direct Known Subclasses:
    MtSwiftMessage

    @Entity
    public abstract class AbstractSwiftMessage
    extends java.lang.Object
    implements java.io.Serializable, JsonSerializable
    Base entity for MT and MX message persistence.

    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 is specially suited for JPA to store all messages in a single table.

    XML may be used to override or augment these default JPA annotations.

    Since:
    7.0
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field 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  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method 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 o)  
      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 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 findStatusInfoLast​(java.lang.String statusName)
      Finds the last 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.
      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
      abstract 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 from the Prowide ISO20022 library, false otherwise
      boolean isOutgoing()  
      java.lang.Boolean isOutput()  
      boolean isStatus​(java.lang.Enum status)
      Returns true if the current status is equals to the parameter status
      boolean isStatus​(java.lang.Enum... 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 isStatus​(java.lang.String... statuses)
      Tell if this message has any of the given statuses as current 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​(SwiftMessageStatusInfo status)  
      void setStatus​(java.lang.String status)
      Sets the status attribute.
      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.
      protected java.lang.String toJsonImpl()
      Isolated Json implementation, useful for mocked test
      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 void updateFromMessage​(MessageMetadataStrategy metadataStrategy)
      Updates the object attributes with metadata parsed from the message raw content using the provided strategy implementation for several of the metadata fields.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PROPERTY_NAME

        public static final transient java.lang.String PROPERTY_NAME
        See Also:
        Constant Field Values
      • IDENTIFIER_ACK

        protected static final java.lang.String IDENTIFIER_ACK
        Identifier constant for acknowledge service messages
        Since:
        7.8.8
        See Also:
        Constant Field Values
      • IDENTIFIER_NAK

        protected static final java.lang.String IDENTIFIER_NAK
        Identifier constant for non-acknowledge service messages
        Since:
        7.8.8
        See Also:
        Constant Field Values
      • identifier

        protected java.lang.String identifier
      • sender

        protected java.lang.String sender
      • receiver

        protected java.lang.String receiver
    • Constructor Detail

      • AbstractSwiftMessage

        public AbstractSwiftMessage()
        Empty constructor provided for the ORM only, use one of the specific constructors instead.
        Since:
        7.7
      • AbstractSwiftMessage

        protected AbstractSwiftMessage​(java.lang.String content,
                                       FileFormat fileFormat,
                                       MessageMetadataStrategy metadataStrategy)
        Creates a new message reading the message the content from a string.

        The complete string content will be read and set as raw message content, but if the string contains multiple messages, only the first one will be used for metadata and message identification.

        Parameters:
        content - a swift MT or MX plain message content
        fileFormat - the source file format
        metadataStrategy - the specific metadata extraction to apply
        Since:
        9.1.4
      • AbstractSwiftMessage

        protected AbstractSwiftMessage​(java.io.InputStream stream,
                                       FileFormat fileFormat,
                                       MessageMetadataStrategy metadataStrategy)
                                throws java.io.IOException
        Creates a new message reading the message the content from an input stream, using UTF-8 as encoding.

        The complete stream content will be read and set as raw message content, but if the stream contains multiple messages, only the first one will be used for metadata and message identification.

        Parameters:
        stream - a stream with the raw mesasge content to read
        fileFormat - the source file format
        metadataStrategy - the specific metadata extraction to apply
        Throws:
        java.io.IOException
        Since:
        9.1.4
      • AbstractSwiftMessage

        protected AbstractSwiftMessage​(java.io.File file,
                                       FileFormat fileFormat,
                                       MessageMetadataStrategy metadataStrategy)
                                throws java.io.IOException
        Creates a new message reading the message the content from a file.

        The complete file content will be read and set as raw message content, but if the file contains multiple messages, only the first one will be used for metadata and message identification.

        Parameters:
        file - an existing file containing message payload
        fileFormat - the source file format
        metadataStrategy - the specific metadata extraction to apply
        Throws:
        java.io.IOException - on error during file reading
        Since:
        9.1.4
    • Method Detail

      • updateFromMessage

        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. The method is called during message creation or update.
        Since:
        7.7
      • updateFromMessage

        protected void updateFromMessage​(MessageMetadataStrategy metadataStrategy)
        Updates the object attributes with metadata parsed from the message raw content using the provided strategy implementation for several of the metadata fields. The method is called during message creation or update.

        This method is expected to be overwritten by subclasses. This default implementation will just ignore the parameter strategy.

        Since:
        9.1.4
      • getId

        public java.lang.Long getId()
        Returns the persisted message unique identifier.
      • setId

        public void setId​(java.lang.Long id)
        Used by the ORM to set the database unique identifier.
      • getMessage

        public java.lang.String getMessage()
        Raw message content. FIN for MTS, and XML for MX.
      • message

        public java.lang.String message()
        Returns the internal swift message in its original raw format. Same as getMessage()
        Returns:
        raw content of the message
        Since:
        7.7
      • getIdentifier

        public java.lang.String getIdentifier()
        Message type identification as specify by SWIFT.
        • For MT: fin.type[.variant] for example fin.103.STP, fin.103.REMIT, fin.202, fin.202.COV
        • For MX: the message business area, type, variant and version; for example: camt.034.001.02
        • For acknowledge service messages IDENTIFIER_ACK
        • For non-acknowledge service messages IDENTIFIER_NAK
        • For other service messages the identifier is left null
      • setIdentifier

        public 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.
        Parameters:
        identifier - the message identifier such as fin.103
      • getChecksum

        public java.lang.String getChecksum()
        Proprietary checksum computed for the whole raw message content, helpful for integrity verification or duplicates detection.

        At the moment this is only implemented for MT messages

        See Also:
        SwiftMessageUtils.calculateChecksum(SwiftMessage)
      • setChecksum

        public 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.

        At the moment this is only implemented for MT messages

        Parameters:
        checksum - the calculated checksum to set
        See Also:
        SwiftMessageUtils.calculateChecksum(SwiftMessage)
      • getChecksumBody

        public 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.

        At the moment this is only implemented for MT messages

        Since:
        7.9.5
        See Also:
        SwiftMessageUtils.calculateChecksum(SwiftBlock4)
      • setChecksumBody

        public 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.
        Parameters:
        checksumBody - the checksum to set
        Since:
        7.9.5
      • getLastModified

        public java.util.Calendar getLastModified()
        Last modification date and time.
      • setLastModified

        public 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.
        Parameters:
        lastModified - the last modification timestamp to set
      • getCreationDate

        public java.util.Calendar getCreationDate()
        Creation date and time.
      • setCreationDate

        public 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.
        Parameters:
        creationDate - the creation timestamp to set
      • getNotes

        public java.util.List<SwiftMessageNote> getNotes()
        User comments attached to this message.
      • getProperties

        public java.util.Map<java.lang.String,​java.lang.String> getProperties()
        Flexible property container to extend message metadata.
      • getStatusTrail

        public java.util.List<SwiftMessageStatusInfo> getStatusTrail()
        Status history for this message. current status is the last one in the list.
      • getStatus

        public java.lang.String getStatus()
        Get the name of the last status set to this message, or null if none is found.
      • setStatus

        public void setStatus​(java.lang.String status)
        Sets the status attribute. Notice that this method does not update the status trail.
        Parameters:
        status - the current message status name
        See Also:
        addStatus(SwiftMessageStatusInfo)
      • getSender

        public 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. For MX messages this is the (capitalized) BIC information in the "From" tag of the Application Header.
      • setSender

        public 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.
        Parameters:
        sender - the sender address
      • getReceiver

        public 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. For MX messages this is the (capitalized) BIC information in the "To" tag of the Application Header.
      • setReceiver

        public 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.
        Parameters:
        receiver - the receiver address
      • getDirection

        public MessageIOType getDirection()
        Direction from application perspective; message is sent to SWIFT are outgoing and messages received from SWIFT are incoming.
      • setDirection

        public 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.
        Parameters:
        direction - the direction (either incoming or outgoing)
      • getFilename

        public java.lang.String getFilename()
        Original filename if applies.
      • setFilename

        public 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.
        Parameters:
        filename - the name of the file read to create this message instance
      • getMessageName

        public java.lang.String getMessageName()
        Get the value of the property under the PROPERTY_NAME key or null if not found
      • addStatus

        public void addStatus​(SwiftMessageStatusInfo status)
        Adds a status to the message's status trail and current status attribute, initializing the statuses trail list if necessary.
        Parameters:
        status - the status to add
      • isOutgoing

        public boolean isOutgoing()
        Returns:
        true if the message is outgoing (sent to SWIFT), false other case; using the direction attribute.
      • isIncoming

        public java.lang.Boolean isIncoming()
        Returns:
        true if the message is incoming (received from SWIFT), false other case; using the direction attribute.
      • isOutput

        public java.lang.Boolean isOutput()
        See Also:
        isIncoming()
      • isStatus

        public boolean isStatus​(java.lang.String status)
        Returns true if the current status is equals to the parameter status
        Parameters:
        status - a status name
      • isStatus

        public boolean isStatus​(java.lang.Enum status)
        Returns true if the current status is equals to the parameter status
        Parameters:
        status - a status enum keyFget
      • getStatusInfo

        public SwiftMessageStatusInfo getStatusInfo()
        Retrieves from the status trail, the current status info; or null if none is found.
      • getPreviousStatusInfo

        public SwiftMessageStatusInfo getPreviousStatusInfo()
        Retrieves from the status trail, the status info before the current one; or null if none is found.
      • contains

        public boolean contains​(java.lang.Enum... statuses)
        Tell if this message has any of the given statuses in his status trail
        Parameters:
        statuses - a list of statuses to check in the status trail
      • contains

        public boolean contains​(java.lang.String... statuses)
        Tell if this message has any of the given statuses in his status trail
        Parameters:
        statuses - a list of statuses to check in the status trail
      • isStatus

        public boolean isStatus​(java.lang.String... statuses)
        Tell if this message has any of the given statuses as current status
        Parameters:
        statuses - a list of status names to check
      • isStatus

        public boolean isStatus​(java.lang.Enum... statuses)
        Tell if this message has any of the given statuses as current status
        Parameters:
        statuses - a list of status enum keys to check
      • getLastData

        public java.lang.String getLastData​(java.lang.String... statuses)
        Get the last saved status data of this message or empty string if not found
        Parameters:
        statuses - an array of statuses to check data into, if null all message statuses are checked for data
        Returns:
        the most recent (last) status data found
      • getLastData

        public java.lang.String getLastData()
        Same as getLastData(String...) passing a null array parameter
      • findStatusInfo

        public 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.
        Parameters:
        statusNames - status name candidates
        Since:
        7.8.8
      • findStatusInfoLast

        public 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. This method is similar to findStatusInfo(String...) but checks the status trail in descending order from latest to oldest.
        Since:
        7.8.8
      • findStatusInfoLast

        public 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
        Since:
        7.8.8
        See Also:
        findStatusInfoLast(String...)
      • addNote

        public void addNote​(SwiftMessageNote n)
        Adds a new note to the messages, initializing the note list if necessary.
        Parameters:
        n - note to add
      • sanityCheckProperties

        public void sanityCheckProperties()
        Iterate message properties and truncate all needed values issuing a log entry for each truncated one
      • getProperty

        public 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
        Parameters:
        key - the property key to get
      • getProperty

        public java.lang.String getProperty​(java.lang.Enum key)
        Parameters:
        key - the property key to get
        See Also:
        getProperty(String)
      • setProperty

        public 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.
        Parameters:
        key - the property to set
        value - the value for the property
      • setProperty

        public void setProperty​(java.lang.Enum key,
                                java.lang.String value)
        Parameters:
        key - the property to set
        value - the value for the property
        See Also:
        setProperty(String, String)
      • getPropertyBoolean

        public boolean getPropertyBoolean​(java.lang.String key)
        Returns true if the message has a property with the given key name and value "true"
        Parameters:
        key - the property key to get
      • getPropertyBoolean

        public boolean getPropertyBoolean​(java.lang.Enum key)
        Parameters:
        key - the property key to get
        See Also:
        getPropertyBoolean(String)
      • propertyEquals

        public boolean propertyEquals​(java.lang.String key,
                                      java.lang.String expectedValue)
        Checks if a given property has a specific value
        Parameters:
        key - the property key to check
        expectedValue - the expected value
        Returns:
        true if the property is set and the value matches, false otherwise
        Since:
        7.10.4
      • propertyEquals

        public boolean propertyEquals​(java.lang.Enum key,
                                      java.lang.String expectedValue)
        Parameters:
        key - the property key to check
        expectedValue - the expected value
        Since:
        7.10.4
        See Also:
        propertyEquals(String, String)
      • propertyEquals

        public boolean propertyEquals​(java.lang.Enum key,
                                      java.lang.Enum expectedValue)
        Since:
        7.10.4
        See Also:
        propertyEquals(String, String)
      • getPaddedId

        public java.lang.String getPaddedId()
        Returns the internal unique id as fixed length string, padded with zeros.
        Returns:
        string with 10 characters with this message identifier
      • copyTo

        public void copyTo​(AbstractSwiftMessage msg)
        Creates a full copy of the current message object into another message.

        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.

        Parameters:
        msg - target message
        Since:
        7.7
      • getRevisions

        public java.util.List<SwiftMessageRevision> getRevisions()
        Snapshots of message content used to track its changes history
        Returns:
        this message revisions or empty list if none is set
        Since:
        7.8
      • setRevisions

        public void setRevisions​(java.util.List<SwiftMessageRevision> revisions)
        Parameters:
        revisions - a list of message modification revisions
        Since:
        7.8
      • addRevision

        public void addRevision​(SwiftMessageRevision revision)
        Adds a new revision to the messages, initializing the revision list if necessary.
        Parameters:
        revision - revision to add
        Since:
        7.8
      • getValueDate

        public java.util.Calendar getValueDate()
        Since:
        7.10.8
      • setValueDate

        public void setValueDate​(java.util.Calendar valueDate)
        Since:
        7.10.8
      • getTradeDate

        public java.util.Calendar getTradeDate()
        Since:
        7.10.8
      • setTradeDate

        public void setTradeDate​(java.util.Calendar tradeDate)
        Since:
        7.10.8
      • isMT

        public boolean isMT()
        True if the message is an MtSwiftMessage, false otherwise
        Since:
        7.8
      • isMX

        public boolean isMX()
        True if the message is an MxSwiftMessage from the Prowide ISO20022 library, false otherwise
        Since:
        7.8
      • messageStandardType

        public MessageStandardType messageStandardType()
        Returns the enumeration value corresponding to this message.
        Returns:
        standard enumeration value or null if messages cannot be identified as either standard
        Since:
        7.8.3
      • getFileFormat

        public FileFormat getFileFormat()
        Original file format if applies.
        Returns:
        this message file format if any is set
        Since:
        7.8.4
      • setFileFormat

        public 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.
        Parameters:
        fileFormat - the file format read
        Since:
        7.8.4
      • getReference

        public java.lang.String getReference()
        Message reference
      • setReference

        public 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.
        Parameters:
        reference - the message reference
      • getCurrency

        public java.lang.String getCurrency()
        Main currency
        Returns:
        the main currency or null if non is present or does not apply for this message type
        Since:
        7.8.8
      • setCurrency

        public 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.
        Parameters:
        currency - the message main currency
      • getAmount

        public java.math.BigDecimal getAmount()
        Main amount
        Returns:
        the main amount or null if non is present or does not apply for this message type
        Since:
        7.8.8
      • setAmount

        public 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.
        Parameters:
        amount - the message main amount
      • match

        public boolean match​(java.lang.String regex)
        Applies the parameter regex to the message identifier.

        Notice the identifier will contain:

        • For MT: fin.<msgtype>[.<mug|variant>] for example fin.103.STP, fin.103.REMIT, fin.202, fin.202.COV
        • For MX: <bus.area>.<msgtype>.<variant>.<version> for example: camt.034.001.02, ifds.001.001.01
        So for example fin.* matches all MT messages, fin.*STP matches all STP MT messages and camt.* matches all MX messages in the category camt.
        Parameters:
        regex - to match
        Returns:
        true if regex match identifier, false otherwise
        Since:
        7.8.4
      • formattedAmount

        public java.lang.String formattedAmount()
        If the amount is set, returns its currency and value formatted using the default locale.
        Returns:
        formatted amount for example USD 123,456.78 or empty string if amount is not set
        Since:
        7.8.8
        See Also:
        getAmount(), formattedAmount(Locale, boolean)
      • formattedAmount

        public java.lang.String formattedAmount​(java.util.Locale locale,
                                                boolean includeCurrency)
        If the amount is set, returns its value formatted for the given locale.
        Parameters:
        locale - a specific locale to use or null to use the current default locale
        includeCurrency - if true and the currency is set, the formatted value will be prefixed by the currency symbol
        Returns:
        formatted amount for example USD 123,456.78 or empty string if amount is not set
        Since:
        7.8.8
        See Also:
        getAmount()
      • identifiedAsACK

        public boolean identifiedAsACK()
        Returns true if this message identifier is 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.

        Returns:
        true if the identifier is IDENTIFIER_ACK false otherwise
        Since:
        7.8.8
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • identifiedAsNAK

        public boolean identifiedAsNAK()
        Returns true if this message identifier is 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.

        Returns:
        true if the identifier is IDENTIFIER_NAK false otherwise
        Since:
        7.8.8
      • bic11

        protected java.lang.String bic11​(java.lang.String address)
        Creates a BIC11 from the given address. If the address contains a logical terminal it wil be dropped. If the address does not contain a branch, the default XXX will be used
        Parameters:
        address - a BIC8, BIC11 or full logical terminal address (BIC12)
        Returns:
        the bic11 or null if address is null
        Since:
        7.9.5
        See Also:
        BIC.getBic11()
      • getCorrespondentBIC

        public BIC getCorrespondentBIC()
        Returns the correspondent BIC code from the headers.
        For an outgoing message, the BIC address identifies the receiver of the message. Where for an incoming message it identifies the sender of the message.
        Returns:
        the correspondent BIC code or null if headers are not properly set
        Since:
        7.9.5
      • getCreationYear

        public java.lang.String getCreationYear()
        The year when the message was created, extracted from the getCreationDate() Helper read-only property useful for faceting search
        Returns:
        the year in YYYY format
        Since:
        7.9.7
      • getCreationMonth

        public java.lang.String getCreationMonth()
        The month when the message was created, extracted from the getCreationDate() Helper read-only property useful for faceting search
        Returns:
        the month number, 1 based and padded with zero, such as 01, 02, 12
        Since:
        7.9.7
      • getCreationDayOfMonth

        public 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
        Returns:
        the day of month, padded with zero, such as 01, 02, 31
        Since:
        7.9.7
      • toJson

        public java.lang.String toJson()
        Gets a JSON representation of this message.
        Specified by:
        toJson in interface JsonSerializable
        Returns:
        the message content as JSON
        Since:
        7.10.3
      • toJsonImpl

        protected java.lang.String toJsonImpl()
        Isolated Json implementation, useful for mocked test
        Returns:
        json serialization using Gson
        Since:
        7.10.6
      • getCategory

        public abstract java.lang.String getCategory()
        For MT messages returns the category number and for MX messages return the business process. For example for MT103 returns 1 and for pacs.004.001.06 returns pacs
        Returns:
        a string with the category or empty if the identifier is invalid or not present
        Since:
        7.10.4
      • getMessageType

        public java.lang.String getMessageType()
        Get the message type.
        For MTs this is the MT type number present in the identifier attribute. For example for fin.103.STP returns 103 For MX returns the same as #getIdentifier()