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)
{
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<m_items.size(); i++) {
final MAttachmentEntry entry = m_items.get(i);
final File file = entry.getFile();
if(file !=null && file.exists()){
if(!file.delete()){
log.warning("unable to delete " + file.getAbsolutePath());
if (isStoreAttachmentsOnFileSystem) {
//delete all attachment files and folder
for (int i=0; i<m_items.size(); i++) {
final MAttachmentEntry entry = m_items.get(i);
final File file = entry.getFile();
if(file !=null && file.exists()){
if(!file.delete()){
log.warning("unable to delete " + file.getAbsolutePath());
}
}
}
}
final File folder = new File(m_attachmentPathRoot + getAttachmentPathSnippet());
if(folder.exists()){
if(!folder.delete()){
log.warning("unable to delete " + folder.getAbsolutePath());
final File folder = new File(m_attachmentPathRoot + getAttachmentPathSnippet());
if(folder.exists()){
if(!folder.delete()){
log.warning("unable to delete " + folder.getAbsolutePath());
}
}
}
}
return true;
} // beforeDelete

View File

@ -372,7 +372,8 @@ public final class Attachment extends CDialog
if (newText.length() > 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();
}