diff --git a/base/src/org/compiere/model/MAttachment.java b/base/src/org/compiere/model/MAttachment.java index 15e0cb9865..fd68a85f97 100644 --- a/base/src/org/compiere/model/MAttachment.java +++ b/base/src/org/compiere/model/MAttachment.java @@ -111,10 +111,13 @@ public class MAttachment extends X_AD_Attachment */ public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName) { - this (ctx, 0, trxName); - setAD_Table_ID (AD_Table_ID); - setRecord_ID (Record_ID); - initAttachmentStoreDetails(ctx, trxName); + this (ctx + , MAttachment.get(ctx, AD_Table_ID, Record_ID) == null ? 0 : MAttachment.get(ctx, AD_Table_ID, Record_ID).get_ID() + , trxName); + if (MAttachment.get(ctx, AD_Table_ID, Record_ID) == null) { + setAD_Table_ID (AD_Table_ID); + setRecord_ID (Record_ID); + } } // MAttachment /** @@ -241,7 +244,7 @@ public class MAttachment extends X_AD_Attachment log.warning("No File"); return false; } - if (!file.exists() || file.isDirectory()) + if (!file.exists() || file.isDirectory() || !file.canRead()) { log.warning("not added - " + file + ", Exists=" + file.exists() + ", Directory=" + file.isDirectory()); @@ -290,14 +293,24 @@ public class MAttachment extends X_AD_Attachment */ public boolean addEntry (MAttachmentEntry item) { + boolean replaced = false; + boolean retValue = false; if (item == null) return false; if (m_items == null) loadLOBData(); - boolean retValue = m_items.add(item); + for (int i = 0; i < m_items.size(); i++) { + if (m_items.get(i).getName().equals(item.getName()) ) { + m_items.set(i, item); + replaced = true; + } + } + if (!replaced) { + retValue = m_items.add(item); + } log.fine(item.toStringX()); - addTextMsg(" "); // otherwise not saved - return retValue; + setBinaryData(new byte[0]); // ATTENTION! HEAVY HACK HERE... Else it will not save :( + return retValue || replaced; } // addEntry /** @@ -802,24 +815,24 @@ public class MAttachment extends X_AD_Attachment */ protected boolean beforeDelete () { - if(isStoreAttachmentsOnFileSystem){ - //delete all attachment files and folder - for(int i=0; i 0 || m_attachment.getEntryCount() > 0) { if (m_change) - { + { + m_attachment.setBinaryData(new byte[0]); // ATTENTION! HEAVY HACK HERE... Else it will not save :( m_attachment.setTextMsg(text.getText()); m_attachment.save(); }