IDEMPIERE-4674 PackIn AD_Image or AD_Archive leave corrupt record when using FileSystem storage provider (#558)
* IDEMPIERE-4674 PackIn AD_Image or AD_Archive leave corrupt record when using FileSystem storage provider * * Fixes suggested by @hengsin
This commit is contained in:
parent
4493373b96
commit
9c1c4a54a8
|
@ -1,16 +1,20 @@
|
|||
package org.adempiere.pipo2;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.model.MArchive;
|
||||
import org.compiere.model.MAttachment;
|
||||
import org.compiere.model.MAttachmentEntry;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MImage;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.model.POInfo;
|
||||
|
@ -408,8 +412,31 @@ public class PoFiller{
|
|||
throw new AdempiereException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
if ("BinaryData".equals(qName) && data instanceof byte[]) {
|
||||
if (po instanceof MArchive) {
|
||||
/* it comes as a zip file with a single PDF file */
|
||||
byte[] output = null;
|
||||
try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream((byte[]) data));) {
|
||||
if (zipStream.getNextEntry() != null) {
|
||||
output = zipStream.readAllBytes();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new AdempiereException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
if (output != null) {
|
||||
((MArchive) po).setBinaryData((byte[]) output);
|
||||
} else {
|
||||
throw new AdempiereException("Zip file for Archive could not be decompressed");
|
||||
}
|
||||
} else if (po instanceof MImage) {
|
||||
((MImage) po).setBinaryData((byte[]) data);
|
||||
} else {
|
||||
po.set_ValueNoCheck(qName, data);
|
||||
}
|
||||
} else {
|
||||
po.set_ValueNoCheck(qName, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue