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:
Carlos Ruiz 2021-01-28 14:37:13 +01:00 committed by GitHub
parent 4493373b96
commit 9c1c4a54a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 1 deletions

View File

@ -1,16 +1,20 @@
package org.adempiere.pipo2; package org.adempiere.pipo2;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.zip.ZipInputStream;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MArchive;
import org.compiere.model.MAttachment; import org.compiere.model.MAttachment;
import org.compiere.model.MAttachmentEntry; import org.compiere.model.MAttachmentEntry;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
import org.compiere.model.MImage;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.POInfo; import org.compiere.model.POInfo;
@ -408,8 +412,31 @@ public class PoFiller{
throw new AdempiereException(e.getLocalizedMessage(), e); 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); po.set_ValueNoCheck(qName, data);
} }
} }
} }
}
} }