BF [2991251] - Attachment handle replacements

https://sourceforge.net/tracker/?func=detail&aid=2991251&group_id=176962&atid=879332
This commit is contained in:
trifonnt 2010-04-23 08:13:21 +00:00
parent 9045226d7b
commit 36fab48e2f
2 changed files with 37 additions and 23 deletions

View File

@ -111,10 +111,13 @@ public class MAttachment extends X_AD_Attachment
*/ */
public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName) public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName)
{ {
this (ctx, 0, trxName); this (ctx
setAD_Table_ID (AD_Table_ID); , MAttachment.get(ctx, AD_Table_ID, Record_ID) == null ? 0 : MAttachment.get(ctx, AD_Table_ID, Record_ID).get_ID()
setRecord_ID (Record_ID); , trxName);
initAttachmentStoreDetails(ctx, trxName); if (MAttachment.get(ctx, AD_Table_ID, Record_ID) == null) {
setAD_Table_ID (AD_Table_ID);
setRecord_ID (Record_ID);
}
} // MAttachment } // MAttachment
/** /**
@ -241,7 +244,7 @@ public class MAttachment extends X_AD_Attachment
log.warning("No File"); log.warning("No File");
return false; return false;
} }
if (!file.exists() || file.isDirectory()) if (!file.exists() || file.isDirectory() || !file.canRead())
{ {
log.warning("not added - " + file log.warning("not added - " + file
+ ", Exists=" + file.exists() + ", Directory=" + file.isDirectory()); + ", Exists=" + file.exists() + ", Directory=" + file.isDirectory());
@ -290,14 +293,24 @@ public class MAttachment extends X_AD_Attachment
*/ */
public boolean addEntry (MAttachmentEntry item) public boolean addEntry (MAttachmentEntry item)
{ {
boolean replaced = false;
boolean retValue = false;
if (item == null) if (item == null)
return false; return false;
if (m_items == null) if (m_items == null)
loadLOBData(); 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()); log.fine(item.toStringX());
addTextMsg(" "); // otherwise not saved setBinaryData(new byte[0]); // ATTENTION! HEAVY HACK HERE... Else it will not save :(
return retValue; return retValue || replaced;
} // addEntry } // addEntry
/** /**
@ -802,24 +815,24 @@ public class MAttachment extends X_AD_Attachment
*/ */
protected boolean beforeDelete () protected boolean beforeDelete ()
{ {
if(isStoreAttachmentsOnFileSystem){ if (isStoreAttachmentsOnFileSystem) {
//delete all attachment files and folder //delete all attachment files and folder
for(int i=0; i<m_items.size(); i++) { for (int i=0; i<m_items.size(); i++) {
final MAttachmentEntry entry = m_items.get(i); final MAttachmentEntry entry = m_items.get(i);
final File file = entry.getFile(); final File file = entry.getFile();
if(file !=null && file.exists()){ if(file !=null && file.exists()){
if(!file.delete()){ if(!file.delete()){
log.warning("unable to delete " + file.getAbsolutePath()); log.warning("unable to delete " + file.getAbsolutePath());
}
} }
} }
} final File folder = new File(m_attachmentPathRoot + getAttachmentPathSnippet());
final File folder = new File(m_attachmentPathRoot + getAttachmentPathSnippet()); if(folder.exists()){
if(folder.exists()){ if(!folder.delete()){
if(!folder.delete()){ log.warning("unable to delete " + folder.getAbsolutePath());
log.warning("unable to delete " + folder.getAbsolutePath()); }
} }
} }
}
return true; return true;
} // beforeDelete } // beforeDelete

View File

@ -372,7 +372,8 @@ public final class Attachment extends CDialog
if (newText.length() > 0 || m_attachment.getEntryCount() > 0) if (newText.length() > 0 || m_attachment.getEntryCount() > 0)
{ {
if (m_change) 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.setTextMsg(text.getText());
m_attachment.save(); m_attachment.save();
} }