Class MAttachment

All Implemented Interfaces:
Serializable, Cloneable, Comparator<Object>, I_AD_Attachment, I_Persistent, Evaluatee

public class MAttachment extends X_AD_Attachment
Attachment Model. One Attachment can have multiple entries (usually stored as zip files).
Version:
$Id: MAttachment.java,v 1.4 2006/07/30 00:58:37 jjanke Exp $
Author:
Jorg Janke, Silvano Trinchero
  • BF [ 2992291] MAttachment.addEntry not closing streams if an exception occur https://sourceforge.net/p/adempiere/bugs/2392/
  • See Also:
    • Field Details

    • Constructor Details

      • MAttachment

        public MAttachment(Properties ctx, String AD_Attachment_UU, String trxName)
        UUID based Constructor
        Parameters:
        ctx - Context
        AD_Attachment_UU - UUID key
        trxName - Transaction
      • MAttachment

        public MAttachment(Properties ctx, int AD_Attachment_ID, String trxName)
        Standard Constructor
        Parameters:
        ctx - context
        AD_Attachment_ID - id
        trxName - transaction
      • MAttachment

        public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName)
        Parameters:
        ctx - context
        AD_Table_ID - table
        Record_ID - record
        trxName - transaction
      • MAttachment

        public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String Record_UU, String trxName)
        Parameters:
        ctx - context
        AD_Table_ID - table
        Record_ID - record
        Record_UU - record UUID
        trxName - transaction
      • MAttachment

        public MAttachment(Properties ctx, ResultSet rs, String trxName)
        Load Constructor
        Parameters:
        ctx - context
        rs - result set
        trxName - transaction
      • MAttachment

        public MAttachment(MAttachment copy)
        Copy constructor
        Parameters:
        copy -
    • Method Details

      • get

        public static MAttachment get(Properties ctx, int AD_Table_ID, int Record_ID)
        Parameters:
        ctx -
        AD_Table_ID -
        Record_ID -
        Returns:
        attachment or null
      • get

        public static MAttachment get(Properties ctx, int AD_Table_ID, int Record_ID, String trxName)
        Get Attachment (if there are more than one attachment, it gets the first in no specific order)
        Parameters:
        ctx - context
        AD_Table_ID - table
        Record_ID - record
        trxName -
        Returns:
        attachment or null
      • get

        public static MAttachment get(Properties ctx, int AD_Table_ID, int Record_ID, String Record_UU, String trxName)
        Get Attachment (if there are more than one attachment, it gets the first in no specific order)
        Parameters:
        ctx - context
        AD_Table_ID - table
        Record_ID - record
        Record_UU - record UUID
        trxName -
        Returns:
        attachment or null
      • isReadOnly

        public boolean isReadOnly()
        If the related record is on System and the user is operating on Tenant, the attachment is read-only
        Returns:
      • setClientOrg

        public void setClientOrg(int AD_Client_ID, int AD_Org_ID)
        Set Client Org
        Overrides:
        setClientOrg in class PO
        Parameters:
        AD_Client_ID - client
        AD_Org_ID - org
      • addTextMsg

        public void addTextMsg(String added)
        Add to Text Msg
        Parameters:
        added - text
      • getTextMsg

        public String getTextMsg()
        Get Text Msg
        Specified by:
        getTextMsg in interface I_AD_Attachment
        Overrides:
        getTextMsg in class X_AD_Attachment
        Returns:
        trimmed message
      • toString

        public String toString()
        String Representation
        Overrides:
        toString in class X_AD_Attachment
        Returns:
        info
      • addEntry

        public boolean addEntry(File file)
        Add new item to attachment
        Parameters:
        file - file content of new item
        Returns:
        true if added
      • addEntry

        public boolean addEntry(String name, byte[] data)
        Add new item to attachment
        Parameters:
        name - name of new item
        data - data content of new item
        Returns:
        true if added
      • addEntry

        public boolean addEntry(MAttachmentEntry item)
        Add item to attachment
        Parameters:
        item - attachment entry
        Returns:
        true if added
      • getEntry

        public MAttachmentEntry getEntry(int index)
        Get Attachment Entry
        Parameters:
        index - index of the item (zero base)
        Returns:
        Entry or null
      • getEntries

        public MAttachmentEntry[] getEntries()
        Get Attachment Entries as array
        Returns:
        array of attachment item or null
      • deleteEntry

        public boolean deleteEntry(int index)
        Delete Entry
        Parameters:
        index - index of item to delete
        Returns:
        true if deleted
      • getEntryCount

        public int getEntryCount()
        Get Entry Count
        Returns:
        number of entries
      • getEntryName

        public String getEntryName(int index)
        Get Entry Name
        Parameters:
        index - index of item
        Returns:
        name or null
      • dumpEntryNames

        public void dumpEntryNames()
        Dump Entry Names to standard out
      • getEntryData

        public byte[] getEntryData(int index)
        Get Entry Data
        Parameters:
        index - index of item
        Returns:
        data or null
      • getEntryFile

        public File getEntryFile(int index, String fileName)
        Get Entry File with name
        Parameters:
        index - index of item
        fileName - optional file name
        Returns:
        file or null
      • getEntryFile

        public File getEntryFile(int index, File file)
        Get Entry File with name
        Parameters:
        index - index of item
        file - file
        Returns:
        file or null
      • beforeSave

        protected boolean beforeSave(boolean newRecord)
        Description copied from class: PO
        Called before Save for Pre-Save Operation.
        Default implementation is nop, to be implemented in sub-classes that needed it.
        Overrides:
        beforeSave in class PO
        Parameters:
        newRecord - true if it is a new record
        Returns:
        true if record can be saved
      • beforeDelete

        protected boolean beforeDelete()
        Description copied from class: PO
        Execute before Delete operations.
        Default implementation is nop, to be implemented in sub-classes that needed it.
        Overrides:
        beforeDelete in class PO
        Returns:
        true if record can be deleted
      • postDelete

        protected boolean postDelete()
        Ask storage provider to remove attachment content
        Overrides:
        postDelete in class PO
        Returns:
        true if saved
      • updateEntry

        public boolean updateEntry(int i, File file)
        Update existing entry
        Parameters:
        i - index of item
        file - file content of item
        Returns:
        true if success, false otherwise
      • updateEntry

        public boolean updateEntry(int i, byte[] data)
        Update existing entry
        Parameters:
        i - index of item
        data - byte[] content of item
        Returns:
        true if success, false otherwise
      • getID

        public static int getID(int Table_ID, int Record_ID)
        Deprecated.
        IDEMPIERE-530 Get the attachment ID based on table_id and record_id
        Parameters:
        Table_ID -
        Record_ID -
        Returns:
        AD_Attachment_ID
      • getID

        public static int getID(int Table_ID, int Record_ID, String Record_UU)
        IDEMPIERE-530 Get the attachment ID based on table_id and record_uu
        Parameters:
        Table_ID -
        Record_ID -
        Record_UU - record UUID
        Returns:
        AD_Attachment_ID
      • saveAsZip

        public File saveAsZip()
        Save attachment as zip file
        Returns:
        zip file
      • setStorageProvider

        public void setStorageProvider(MStorageProvider p)
        Set Storage Provider. Used temporarily by the storage migration process to migrate storage provider.
        Parameters:
        p - Storage provider
      • getAttachmentData

        public static AttachmentData getAttachmentData(String path, Object id)
        Get attachment data from path expression and id
        Parameters:
        path - attachment/tableName/index or filename
        id - record id or record uuid
        Returns:
        data of attachment item
      • getImageAttachmentURLFromPath

        public static String getImageAttachmentURLFromPath(String contextPath, String path)
        Get web image attachment url from attachment: expression
        Parameters:
        contextPath - web context path (not needed for zk component, pass null instead)
        path - attachment:{tableName}/{index or filename pattern},{record id or uuid}
        Returns:
        image attachment url
      • getStyleSheetAttachmentURLFromPath

        public static String getStyleSheetAttachmentURLFromPath(String contextPath, String path)
        Get web style sheet attachment url from attachment: expression
        Parameters:
        contextPath - web context path (not needed for zk component, pass null instead)
        path - attachment:{tableName}/{index or filename pattern},{record id or uuid}
        Returns:
        image attachment url
      • isAttachmentURLPath

        public static boolean isAttachmentURLPath(String path)
        Is attachment URL path
        Parameters:
        path - attachment:table/{index or file name pattern},{record id or uuid}
        Returns:
        true if path is attachment path
      • getDataFromAttachmentURLPath

        public static AttachmentData getDataFromAttachmentURLPath(String path)
        Get attachment data from attachment URL path
        Parameters:
        path - attachment:table/{index or file name pattern},{record id or uuid}
        Returns:
        attachment data or null