hg merge release-2.0 (merge release2 into development)
This commit is contained in:
commit
1ab126b461
|
@ -229,6 +229,21 @@ public class DocumentEngine implements DocAction
|
|||
*/
|
||||
public boolean processIt (String processAction, String docAction)
|
||||
{
|
||||
//ensure doc status not change by other session
|
||||
if (m_document instanceof PO) {
|
||||
PO docPO = (PO) m_document;
|
||||
if (docPO.get_ID() > 0 && docPO.get_TrxName() != null && docPO.get_ValueOld("DocStatus") != null) {
|
||||
DB.getDatabase().forUpdate(docPO, 30);
|
||||
String docStatusOriginal = (String) docPO.get_ValueOld("DocStatus");
|
||||
String currentStatus = DB.getSQLValueString((String)null,
|
||||
"SELECT DocStatus FROM " + docPO.get_TableName() + " WHERE " + docPO.get_KeyColumns()[0] + " = ? ",
|
||||
docPO.get_ID());
|
||||
if (!docStatusOriginal.equals(currentStatus) && currentStatus != null) {
|
||||
throw new IllegalStateException("Document status have been change by other session, please refresh your window and try again. " + docPO.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_message = null;
|
||||
m_action = null;
|
||||
// Std User Workflows - see MWFNodeNext.isValidFor
|
||||
|
@ -1270,21 +1285,6 @@ public class DocumentEngine implements DocAction
|
|||
public static boolean processIt(DocAction doc, String processAction) {
|
||||
boolean success = false;
|
||||
|
||||
//ensure doc status not change by other session
|
||||
if (doc instanceof PO) {
|
||||
PO docPO = (PO) doc;
|
||||
if (docPO.get_ID() > 0 && docPO.get_TrxName() != null && docPO.get_ValueOld("DocStatus") != null) {
|
||||
DB.getDatabase().forUpdate(docPO, 30);
|
||||
String docStatusOriginal = (String) docPO.get_ValueOld("DocStatus");
|
||||
String currentStatus = DB.getSQLValueString((String)null,
|
||||
"SELECT DocStatus FROM " + docPO.get_TableName() + " WHERE " + docPO.get_KeyColumns()[0] + " = ? ",
|
||||
docPO.get_ID());
|
||||
if (!docStatusOriginal.equals(currentStatus) && currentStatus != null) {
|
||||
throw new IllegalStateException("Document status have been change by other session, please refresh your window and try again. " + docPO.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DocumentEngine engine = new DocumentEngine(doc, doc.getDocStatus());
|
||||
success = engine.processIt(processAction, doc.getDocAction());
|
||||
|
||||
|
|
|
@ -21,14 +21,18 @@ import java.io.BufferedInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
@ -225,6 +229,27 @@ public class PackIn {
|
|||
return data;
|
||||
}
|
||||
|
||||
public File[] readFilesFromBlob(String fileName) throws IOException {
|
||||
ZipFile zf = new ZipFile(m_packageDirectory+File.separator+"blobs"+File.separator+fileName);
|
||||
Enumeration<?> e = zf.entries();
|
||||
ArrayList<File> files = new ArrayList<File>();
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry ze = (ZipEntry) e.nextElement();
|
||||
File file = new File(ze.getName());
|
||||
FileOutputStream fout = new FileOutputStream(file);
|
||||
InputStream in = zf.getInputStream(ze);
|
||||
for (int c = in.read(); c != -1; c = in.read()) {
|
||||
fout.write(c);
|
||||
}
|
||||
in.close();
|
||||
fout.close();
|
||||
files.add(file);
|
||||
}
|
||||
File[] retValue = new File[files.size()];
|
||||
files.toArray(retValue);
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return package name
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.adempiere.pipo2;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
|
@ -7,6 +8,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.model.MAttachment;
|
||||
import org.compiere.model.MAttachmentEntry;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.PO;
|
||||
|
@ -285,25 +288,54 @@ public class PoFiller{
|
|||
private void setBlob(String qName) {
|
||||
Element pe = element.properties.get(qName);
|
||||
String value = pe != null ? pe.contents.toString() : null;
|
||||
Object data = null;
|
||||
if (value != null && value.trim().length() > 0) {
|
||||
String[] component = value.split("[|]");
|
||||
if (component.length == 2) {
|
||||
String fileName = component[0];
|
||||
String dataType = component[1];
|
||||
if (po instanceof MAttachment && "BinaryData".equals(qName)) {
|
||||
PackIn packIn = ctx.packIn;
|
||||
try {
|
||||
byte[] bytes = packIn.readBlob(fileName);
|
||||
if ("byte[]".equals(dataType)) {
|
||||
data = bytes;
|
||||
} else {
|
||||
data = new String(bytes, "UTF-8");
|
||||
String fileName = null;
|
||||
String[] component = value.split("[|]");
|
||||
if (component.length == 2) {
|
||||
fileName = component[0];
|
||||
File[] files;
|
||||
try {
|
||||
files = packIn.readFilesFromBlob(fileName);
|
||||
} catch (IOException e) {
|
||||
throw new AdempiereException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
MAttachment attach = ((MAttachment)po);
|
||||
for (File file : files) {
|
||||
boolean found = false;
|
||||
for (MAttachmentEntry entry : attach.getEntries()) {
|
||||
if (entry.getName().equals(file.getName())) {
|
||||
found = true;
|
||||
attach.updateEntry(entry.getIndex(), file);
|
||||
}
|
||||
}
|
||||
if (! found)
|
||||
attach.addEntry(file);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AdempiereException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
} else {
|
||||
Object data = null;
|
||||
byte[] bytes = null;
|
||||
String fileName = null;
|
||||
String[] component = value.split("[|]");
|
||||
if (component.length == 2) {
|
||||
fileName = component[0];
|
||||
String dataType = component[1];
|
||||
PackIn packIn = ctx.packIn;
|
||||
try {
|
||||
bytes = packIn.readBlob(fileName);
|
||||
if ("byte[]".equals(dataType)) {
|
||||
data = bytes;
|
||||
} else {
|
||||
data = new String(bytes, "UTF-8");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AdempiereException(e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
po.set_ValueNoCheck(qName, data);
|
||||
}
|
||||
}
|
||||
po.set_ValueNoCheck(qName, data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue