IDEMPIERE-2144 Pack in of Attachment: Update entry is using wrong index.

This commit is contained in:
Heng Sin Low 2014-08-13 15:06:08 +08:00
parent 1b75bb4e78
commit 6758daac61
3 changed files with 11 additions and 1 deletions

View File

@ -303,6 +303,7 @@ public class MAttachment extends X_AD_Attachment
} }
if (!replaced) { if (!replaced) {
retValue = m_items.add(item); retValue = m_items.add(item);
item.setIndex(m_items.size());
} }
if (log.isLoggable(Level.FINE)) log.fine(item.toStringX()); if (log.isLoggable(Level.FINE)) log.fine(item.toStringX());
setBinaryData(new byte[0]); // ATTENTION! HEAVY HACK HERE... Else it will not save :( setBinaryData(new byte[0]); // ATTENTION! HEAVY HACK HERE... Else it will not save :(

View File

@ -295,5 +295,9 @@ public class MAttachmentEntry
return null; return null;
return new ByteArrayInputStream(m_data); return new ByteArrayInputStream(m_data);
} // getInputStream } // getInputStream
public void setIndex(int index) {
m_index = index;
}
} // MAttachmentItem } // MAttachmentItem

View File

@ -304,15 +304,20 @@ public class PoFiller{
MAttachment attach = ((MAttachment)po); MAttachment attach = ((MAttachment)po);
for (File file : files) { for (File file : files) {
boolean found = false; boolean found = false;
int index = -1;
for (MAttachmentEntry entry : attach.getEntries()) { for (MAttachmentEntry entry : attach.getEntries()) {
index++;
if (entry.getName().equals(file.getName())) { if (entry.getName().equals(file.getName())) {
found = true; found = true;
attach.updateEntry(entry.getIndex(), file); attach.updateEntry(index, file);
break;
} }
} }
if (! found) if (! found)
attach.addEntry(file); attach.addEntry(file);
} }
if (!attach.is_Changed())
attach.set_ValueNoCheck("Updated", new Timestamp(System.currentTimeMillis()));
} }
} else { } else {
Object data = null; Object data = null;