Class MtSwiftMessage

  • All Implemented Interfaces:
    JsonSerializable, java.io.Serializable

    @Entity(name="mt")
    public class MtSwiftMessage
    extends AbstractSwiftMessage
    MT messages entity for JPA persistence.

    Contains the raw FIN message content plus metadata shared by all MT types.

    Since:
    7.0
    See Also:
    Serialized Form
    • Constructor Detail

      • MtSwiftMessage

        public MtSwiftMessage()
      • MtSwiftMessage

        public MtSwiftMessage​(java.lang.String fin,
                              MessageMetadataStrategy metadataStrategy)
        Creates a new MT entity reading the message content from the plain message content.

        If the FIN content contains several messages (because it is an RJE batch file for example) then the whole content will be stored in the message attribute but the metadata (such as the message type) will be extracted from the first message only.

        Notice that if an ACK/NAK message is used as parameter, this object will represent the ACK/NAK. Even if the original message is attached after the service 21 messages.

        File format is set to FileFormat.FIN

        Parameters:
        fin - the plain FIN message content
        metadataStrategy - a strategy for metadata extraction
        Since:
        9.1.4
      • MtSwiftMessage

        public MtSwiftMessage​(java.io.InputStream stream,
                              MessageMetadataStrategy metadataStrategy)
                       throws java.io.IOException
        Creates a new message reading the message the content from an input stream.
        File format is set to FileFormat.FIN.
        Parameters:
        stream - input stream to read
        metadataStrategy - a strategy for metadata extraction
        Throws:
        java.io.IOException - on error during file reading
        Since:
        9.1.4
      • MtSwiftMessage

        public MtSwiftMessage​(java.io.File file,
                              MessageMetadataStrategy metadataStrategy)
                       throws java.io.IOException
        Creates a new message reading the message the content from a file.
        File format is set to FileFormat.FIN
        Parameters:
        file - file holding message content
        metadataStrategy - a strategy for metadata extraction
        Throws:
        java.io.IOException - on error during file reading
        Since:
        9.1.4
      • MtSwiftMessage

        public MtSwiftMessage​(AbstractMT mt,
                              MessageMetadataStrategy metadataStrategy)
        Creates an MtSwiftMessage from a subclass of AbstractMT.
        Parameters:
        mt - the MT message to create this entity from
        metadataStrategy - a strategy for metadata extraction
        Since:
        9.1.4
      • MtSwiftMessage

        public MtSwiftMessage​(SwiftMessage model,
                              MessageMetadataStrategy metadataStrategy)
        Creates an MtSwiftMessage from a SwiftMessage.
        Parameters:
        model - the MT message to create this entity from
        metadataStrategy - a strategy for metadata extraction
        Since:
        9.1.4
    • Method Detail

      • parse

        public static MtSwiftMessage parse​(java.lang.String fin)
        Creates a new message reading the message the content from a string. This is a static version of the constructor MtSwiftMessage(String)
        Since:
        7.7
      • parse

        public static MtSwiftMessage parse​(java.io.InputStream stream)
                                    throws java.io.IOException
        Creates a new message reading the message the content from an input stream. This is a static version of the constructor MtSwiftMessage(InputStream)
        Throws:
        java.io.IOException
        Since:
        7.7
      • parse

        public static MtSwiftMessage parse​(java.io.File file)
                                    throws java.io.IOException
        Creates a new message reading the message the content from a file. This is a static version of the constructor MtSwiftMessage(File)
        Throws:
        java.io.IOException
        Since:
        7.7
      • fromJson

        public static MtSwiftMessage fromJson​(java.lang.String json)
        This method deserializes the JSON data into an MT message object.
        Parameters:
        json - JSON representation
        Returns:
        message object
        Since:
        7.10.3
      • updateFromFIN

        public void updateFromFIN​(java.lang.String fin,
                                  MessageMetadataStrategy metadataStrategy)
        Updates the the attributes with the raw message and its metadata from the given raw (FIN) message content.
        Parameters:
        fin - the new message content
        metadataStrategy - a strategy implementation to extract the metadata from the FIN content
        Since:
        9.1.4
      • updateFromModel

        public void updateFromModel​(SwiftMessage model,
                                    MessageMetadataStrategy metadataStrategy)
        The SwiftMessage is serialized to its FIN raw format to set the internal raw message attribute. And the header attributes are set with data from the parameter SwiftMessage. Notice that the SwiftMessage is not stored as internal attribute.
        Parameters:
        model - the new message content
        metadataStrategy - a strategy implementation to extract the metadata from the model
        Since:
        9.1.4
      • updateFromModel

        public void updateFromModel​(AbstractMT mt,
                                    MessageMetadataStrategy metadataStrategy)
        The AbstractMT is serialized to its FIN raw format to set the internal raw message attribute. And the header attributes are set with data from the parameter AbstractMT. Notice that the AbstractMT is not stored as internal attribute.
        Parameters:
        mt - the new message content to set
        metadataStrategy - a strategy implementation to extract the metadata from the model
        Since:
        9.1.4
      • modelMessage

        public SwiftMessage modelMessage()
        Parses the raw message content into a SwiftMessage object.
        Returns:
        the parsed message or null if the raw content is not set or cannot be parsed
        Since:
        7.8.9
      • getMessageTypeInt

        public java.lang.Integer getMessageTypeInt()
        Get the integer value of the AbstractSwiftMessage.getMessageType() or null if the identifier attribute is not set or not a number.
        Returns:
        message type as integer
      • isType

        public boolean isType​(java.lang.Integer... type)
        Tell if this message is any of the given types.
        Parameters:
        type - a variable list of integers for testing to match as the current message type
        Returns:
        true if the current message type is any of the integers given as parameters, and false in any other case
      • isType

        public boolean isType​(int type)
        Test if this message is a given specific type.
        Parameters:
        type - the message type given as int, to test
        Returns:
        true if this message type is the type given, or false in any other case
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getPde

        public java.lang.String getPde()
        Gets PDE (Possible Duplicate Emission) flag from the trailer block or null if the trailer or the PDE field is not present
        Returns:
        the PDE flag or null
      • getPdm

        public java.lang.String getPdm()
        Gets PDM from the trailer block or null if the trailer or the PDM field is not present
        Returns:
        PDM flag or null
      • getMir

        public java.lang.String getMir()
        Gets the MIR (Message Input Reference)
        Returns:
        MIR
        See Also:
        SwiftMessage.getMIR()
      • getMur

        public java.lang.String getMur()
        Gets the MUR (Message User Reference) from block 3
        Returns:
        the MUR or null if not present in the message
        See Also:
        SwiftMessage.getMUR()
      • getUuid

        public java.lang.String getUuid()
        Gets a UUID (User Unique Identifier).
        Returns:
        UUID
        See Also:
        SwiftMessage.getUUID()
      • getVariant

        public MTVariant getVariant()
        Returns the message type variant
        Returns:
        the variant or null if the message has no variant
        Since:
        7.10.4
      • getMtId

        public MtId getMtId()
        Returns this message MT identification
        Returns:
        the identification object for this message
        Since:
        7.10.4
      • getCategory

        public 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
        Specified by:
        getCategory in class AbstractSwiftMessage
        Returns:
        a string with the category or empty if the identifier is invalid or not present
        Since:
        7.10.4
      • updateMetadata

        public void updateMetadata​(MessageMetadataStrategy strategy)
        Enables injecting your own implementation for the entity metadata extraction, to set the generic properties shared by all message types: main reference, main amount and currency, value date, trade date.
        Parameters:
        strategy - meta data strategy
        Since:
        9.1.4