Package org.compiere.model
Class MAttachment
java.lang.Object
org.compiere.model.PO
org.compiere.model.X_AD_Attachment
org.compiere.model.MAttachment
- All Implemented Interfaces:
Serializable,AutoCloseable,Cloneable,Comparator<Object>,I_AD_Attachment,I_Persistent,Evaluatee
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 Summary
FieldsModifier and TypeFieldDescriptionfinal Stringstring replaces the attachment root in stored xml file to allow the changing of the attachment root.List of Entry Datastatic final StringIndicator for no datastatic final StringIndicator for xml data (store on file system)static final StringIndicator for zip dataFields inherited from class org.compiere.model.PO
ACCESSLEVEL_ALL, ACCESSLEVEL_CLIENT, ACCESSLEVEL_CLIENTORG, ACCESSLEVEL_ORG, ACCESSLEVEL_SYSTEM, ACCESSLEVEL_SYSTEMCLIENT, ENTITYTYPE_Dictionary, ENTITYTYPE_UserMaintained, I_ZERO, LOCAL_TRX_PREFIX, log, p_ctx, p_info, UUID_NEW_RECORD, XML_ATTRIBUTE_AD_Table_ID, XML_ATTRIBUTE_Record_IDFields inherited from interface org.compiere.model.I_AD_Attachment
accessLevel, COLUMNNAME_AD_Attachment_ID, COLUMNNAME_AD_Attachment_UU, COLUMNNAME_AD_Client_ID, COLUMNNAME_AD_Org_ID, COLUMNNAME_AD_StorageProvider_ID, COLUMNNAME_AD_Table_ID, COLUMNNAME_BinaryData, COLUMNNAME_Created, COLUMNNAME_CreatedBy, COLUMNNAME_IsActive, COLUMNNAME_Record_ID, COLUMNNAME_Record_UU, COLUMNNAME_TextMsg, COLUMNNAME_Title, COLUMNNAME_Updated, COLUMNNAME_UpdatedBy, Model, Table_ID, Table_Name -
Constructor Summary
ConstructorsConstructorDescriptionMAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName) Deprecated.MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String Record_UU, String trxName) MAttachment(Properties ctx, int AD_Attachment_ID, String trxName) Standard ConstructorMAttachment(Properties ctx, String AD_Attachment_UU, String trxName) UUID based ConstructorMAttachment(Properties ctx, ResultSet rs, String trxName) Load ConstructorMAttachment(MAttachment copy) Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd new item to attachmentbooleanAdd new item to attachmentbooleanAdd attachment entrybooleanaddEntry(MAttachmentEntry item) Add item to attachmentvoidaddTextMsg(String added) Add to Text Msgprotected booleanafterSave(boolean newRecord, boolean success) Called after Save for Post-Save Operation.
Default implementation is nop, to be implemented in sub-classes that needed it.protected booleanExecute before Delete operations.
Default implementation is nop, to be implemented in sub-classes that needed it.protected booleanbeforeSave(boolean newRecord) Called before Save for Pre-Save Operation.
Default implementation is nop, to be implemented in sub-classes that needed it.voidclose()booleandeleteEntry(int index) Delete EntryvoidDump Entry Names to standard outstatic MAttachmentget(Properties ctx, int AD_Table_ID, int Record_ID) static MAttachmentget(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)static MAttachmentget(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)static AttachmentDatagetAttachmentData(String path, Object id) Get attachment data from path expression and idstatic AttachmentDataGet attachment data from attachment URL pathGet Attachment Entries as arraygetEntry(int index) Get Attachment EntryintGet Entry Countbyte[]getEntryData(int index) Get Entry DatagetEntryFile(int index, File file) Get Entry File with namegetEntryFile(int index, String fileName) Get Entry File with namegetEntryName(int index) Get Entry Namestatic intgetID(int Table_ID, int Record_ID) Deprecated.UsegetID(int, int, String)insteadstatic intIDEMPIERE-530 Get the attachment ID based on table_id and record_uustatic StringgetImageAttachmentURLFromPath(String contextPath, String path) Get web image attachment url from attachment: expressionstatic StringgetStyleSheetAttachmentURLFromPath(String contextPath, String path) Get web style sheet attachment url from attachment: expressionGet Text Msgstatic booleanisAttachmentURLPath(String path) Is attachment URL pathbooleanIf the related record is on System and the user is operating on Tenant, the attachment is read-onlybooleanisReadOnly(boolean isDelete) If the related record is on System and the user is operating on Tenant, the attachment is read-onlyprotected booleanAsk storage provider to remove attachment contentSave attachment as zip filevoidsetClientOrg(int AD_Client_ID, int AD_Org_ID) Set Client OrgvoidSet Storage Provider.toString()String RepresentationbooleanupdateEntry(int i, byte[] data) Update existing entrybooleanupdateEntry(int i, File file) Update existing entryMethods inherited from class org.compiere.model.X_AD_Attachment
get_AccessLevel, getAD_Attachment_ID, getAD_Attachment_UU, getAD_StorageProvider, getAD_StorageProvider_ID, getAD_Table, getAD_Table_ID, getBinaryData, getKeyNamePair, getRecord_ID, getRecord_UU, getTitle, initPO, setAD_Attachment_ID, setAD_Attachment_UU, setAD_StorageProvider_ID, setAD_Table_ID, setBinaryData, setRecord_ID, setRecord_UU, setTextMsg, setTitleMethods inherited from class org.compiere.model.PO
afterDelete, buildInsertSQL, checkImmutable, clearCrossTenantSafe, clone, columnExists, columnExists, compare, copyPO, copyValues, copyValues, createAttachment, delete, delete, delete_Accounting, delete_Tree, deleteEx, deleteEx, dump, dump, equals, get_Attribute, get_Attributes, get_ColumnCount, get_ColumnDescription, get_ColumnDisplayType, get_ColumnIndex, get_ColumnLabel, get_ColumnLookup, get_ColumnName, get_DisplayValue, get_HashMap, get_ID, get_IDOld, get_KeyColumns, get_Logger, get_OptimisticLockingColumns, get_Table_ID, get_TableAttribute, get_TableAttributeAsBoolean, get_TableAttributeAsInt, get_TableAttributes, get_TableName, get_Translation, get_Translation, get_Translation, get_Translation, get_Translation, get_TrxName, get_UUID, get_Value, get_Value, get_ValueAsBoolean, get_ValueAsInt, get_ValueAsInt, get_ValueAsString, get_ValueAsString, get_ValueDifference, get_ValueDifference, get_ValueE, get_ValueOfColumn, get_ValueOld, get_ValueOld, get_ValueOldAsInt, get_WhereClause, get_WhereClause, get_xmlDocument, get_xmlString, getAD_Client_ID, getAD_Org_ID, getAllIDs, getAttachment, getAttachment, getAttachmentData, getCreated, getCreatedBy, getCtx, getDoc, getFindParameter, getPdfAttachment, getUpdated, getUpdatedBy, getUUIDColumnName, getUUIDColumnName, hashCode, insert_Accounting, insert_Tree, insert_Tree, is_Changed, is_Immutable, is_new, is_UseOptimisticLocking, is_ValueChanged, is_ValueChanged, isActive, isAttachment, isColumnMandatory, isColumnUpdateable, isMandatoryOK, isPdfAttachment, isReplication, load, load, load, load, loadByUU, loadComplete, loadDefaults, loadPO, loadSpecial, lock, makeImmutable, retrieveIdOfParentValue, retrieveIdOfParentValue, save, save, saveCrossTenantSafe, saveCrossTenantSafeEx, saveCrossTenantSafeEx, saveEx, saveEx, saveNew_afterSetID, saveNew_getID, saveNewSpecial, saveReplica, saveUpdate, set_Attribute, set_ColumnUpdateable, set_CustomColumn, set_CustomColumnReturningBoolean, set_OptimisticLockingColumns, set_TrxName, set_TrxName, set_UseOptimisticLocking, set_Value, set_Value, set_Value, set_Value, set_ValueE, set_ValueNoCheck, set_ValueNoCheckE, set_ValueOfColumn, set_ValueOfColumn, set_ValueOfColumnReturningBoolean, set_ValueOfColumnReturningBoolean, setAD_Client_ID, setAD_Org_ID, setClientOrg, setCrossTenantSafe, setDoc, setDocWorkflowMgr, setIsActive, setProcessedOn, setReplication, setStandardDefaults, setUpdateable, setUpdatedBy, toInsertSQL, unlock, update_Tree, validForeignKeys, validForeignKeysExMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongMethods inherited from interface org.compiere.model.I_AD_Attachment
getAD_Client_ID, getAD_Org_ID, getCreated, getCreatedBy, getUpdated, getUpdatedBy, isActive, setAD_Org_ID, setIsActiveMethods inherited from interface org.compiere.model.I_Persistent
save
-
Field Details
-
NONE
Indicator for no data- See Also:
-
ZIP
Indicator for zip data- See Also:
-
XML
Indicator for xml data (store on file system)- See Also:
-
m_items
List of Entry Data -
ATTACHMENT_FOLDER_PLACEHOLDER
string replaces the attachment root in stored xml file to allow the changing of the attachment root.- See Also:
-
-
Constructor Details
-
MAttachment
UUID based Constructor- Parameters:
ctx- ContextAD_Attachment_UU- UUID keytrxName- Transaction
-
MAttachment
Standard Constructor- Parameters:
ctx- contextAD_Attachment_ID- idtrxName- transaction
-
MAttachment
Deprecated.- Parameters:
ctx- contextAD_Table_ID- tableRecord_ID- recordtrxName- transaction
-
MAttachment
public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String Record_UU, String trxName) - Parameters:
ctx- contextAD_Table_ID- tableRecord_ID- recordRecord_UU- record UUIDtrxName- transaction
-
MAttachment
Load Constructor- Parameters:
ctx- contextrs- result settrxName- transaction
-
MAttachment
Copy constructor- Parameters:
copy-
-
-
Method Details
-
get
- Parameters:
ctx-AD_Table_ID-Record_ID-- Returns:
- attachment or null
-
get
Get Attachment (if there are more than one attachment, it gets the first in no specific order)- Parameters:
ctx- contextAD_Table_ID- tableRecord_ID- recordtrxName-- 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- contextAD_Table_ID- tableRecord_ID- recordRecord_UU- record UUIDtrxName-- 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:
-
isReadOnly
public boolean isReadOnly(boolean isDelete) If the related record is on System and the user is operating on Tenant, the attachment is read-only- Parameters:
isDelete-- Returns:
-
setClientOrg
public void setClientOrg(int AD_Client_ID, int AD_Org_ID) Set Client Org- Overrides:
setClientOrgin classPO- Parameters:
AD_Client_ID- clientAD_Org_ID- org
-
addTextMsg
Add to Text Msg- Parameters:
added- text
-
getTextMsg
Get Text Msg- Specified by:
getTextMsgin interfaceI_AD_Attachment- Overrides:
getTextMsgin classX_AD_Attachment- Returns:
- trimmed message
-
toString
String Representation- Overrides:
toStringin classX_AD_Attachment- Returns:
- info
-
addEntry
Add new item to attachment- Parameters:
file- file content of new item- Returns:
- true if added
-
addEntry
Add new item to attachment- Parameters:
name- name of new itemdata- data content of new item- Returns:
- true if added
-
addEntry
Add attachment entry- Parameters:
name-file-- Returns:
- true if success, false otherwise
-
addEntry
Add item to attachment- Parameters:
item- attachment entry- Returns:
- true if added
-
getEntry
Get Attachment Entry- Parameters:
index- index of the item (zero base)- Returns:
- Entry or null
-
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
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
Get Entry File with name- Parameters:
index- index of itemfileName- optional file name- Returns:
- file or null
-
getEntryFile
Get Entry File with name- Parameters:
index- index of itemfile- file- Returns:
- file or null
-
beforeSave
protected boolean beforeSave(boolean newRecord) Description copied from class:POCalled before Save for Pre-Save Operation.
Default implementation is nop, to be implemented in sub-classes that needed it.- Overrides:
beforeSavein classPO- Parameters:
newRecord- true if it is a new record- Returns:
- true if record can be saved
-
afterSave
protected boolean afterSave(boolean newRecord, boolean success) Description copied from class:POCalled after Save for Post-Save Operation.
Default implementation is nop, to be implemented in sub-classes that needed it. -
beforeDelete
protected boolean beforeDelete()Description copied from class:POExecute before Delete operations.
Default implementation is nop, to be implemented in sub-classes that needed it.- Overrides:
beforeDeletein classPO- Returns:
- true if record can be deleted
-
postDelete
protected boolean postDelete()Ask storage provider to remove attachment content- Overrides:
postDeletein classPO- Returns:
- true if saved
-
updateEntry
Update existing entry- Parameters:
i- index of itemfile- 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 itemdata- byte[] content of item- Returns:
- true if success, false otherwise
-
getID
Deprecated.UsegetID(int, int, String)insteadIDEMPIERE-530 Get the attachment ID based on table_id and record_id- Parameters:
Table_ID-Record_ID-- Returns:
- AD_Attachment_ID
-
getID
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
Save attachment as zip file- Returns:
- zip file
-
setStorageProvider
Set Storage Provider. Used temporarily by the storage migration process to migrate storage provider.- Parameters:
p- Storage provider
-
getAttachmentData
Get attachment data from path expression and id- Parameters:
path- attachment/tableName/index or filenameid- record id or record uuid- Returns:
- data of attachment item
-
getImageAttachmentURLFromPath
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
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
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
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
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
MAttachment(Properties, int, int, String, String)instead