IDEMPIERE-3508 2pack: support export from text column to string column (#674)

This commit is contained in:
Carlos Ruiz 2021-05-04 16:42:17 +02:00 committed by GitHub
parent b002667750
commit 9d40f6b5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -85,6 +85,8 @@ public class PackOut
public static final int MAX_OFFICIAL_ID = MTable.MAX_OFFICIAL_ID;
public static final String PACKOUT_BLOB_FILE_EXTENSION = ".dat";
public static void addTextElement(TransformerHandler handler, String qName, String text, AttributesImpl atts) throws SAXException {
handler.startElement("", "", qName, atts);
append(handler, text);
@ -381,7 +383,7 @@ public class PackOut
*/
public String writeBlob(byte[] data) throws IOException {
blobCount++;
String fileName = blobCount + ".dat";
String fileName = blobCount + PACKOUT_BLOB_FILE_EXTENSION;
File path = new File(packageDirectory+File.separator+"blobs"+File.separator);
path.mkdirs();
File file = new File(path, fileName);

View File

@ -39,6 +39,9 @@ public class PoExporter {
private TransformerHandler transformerHandler;
public static final String POEXPORTER_BLOB_TYPE_STRING = "string";
public static final String POEXPORTER_BLOB_TYPE_BYTEARRAY = "byte[]";
private void addTextElement(String qName, String text, AttributesImpl atts) {
try {
transformerHandler.startElement("", "", qName, atts);
@ -337,15 +340,15 @@ public class PoExporter {
PackOut packOut = ctx.packOut;
byte[] data = null;
String dataType = null;
String dataType = null; // see PoFiller.isBlobOnPackinFile
String fileName = null;
try {
if (value instanceof String) {
data = ((String)value).getBytes("UTF-8");
dataType = "string";
dataType = POEXPORTER_BLOB_TYPE_STRING;
} else {
data = (byte[]) value;
dataType = "byte[]";
dataType = POEXPORTER_BLOB_TYPE_BYTEARRAY;
}
fileName = packOut.writeBlob(data);

View File

@ -59,8 +59,10 @@ public class PoFiller{
return false;
String strParts [] = value.split("[|]");
return strParts.length == 2;
return ( strParts.length == 2
&& strParts[0].endsWith(PackOut.PACKOUT_BLOB_FILE_EXTENSION)
&& ( PoExporter.POEXPORTER_BLOB_TYPE_STRING.equals(strParts[1]) // see PoExporter.addBlob
|| PoExporter.POEXPORTER_BLOB_TYPE_BYTEARRAY.equals(strParts[1])));
}
/**
@ -357,11 +359,15 @@ public class PoFiller{
}
} else if (DisplayType.isLOB(info.getColumnDisplayType(index))) {
setBlob(qName);
} else {
if (isBlobOnPackinFile(qName)) {
setBlob(qName);
} else {
setString(qName);
}
}
}
}
return notFounds;
}
@ -410,7 +416,7 @@ public class PoFiller{
PackIn packIn = ctx.packIn;
try {
bytes = packIn.readBlob(fileName);
if ("byte[]".equals(dataType)) {
if (PoExporter.POEXPORTER_BLOB_TYPE_BYTEARRAY.equals(dataType)) {
data = bytes;
} else {
data = new String(bytes, "UTF-8");