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)
|
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_message = null;
|
||||||
m_action = null;
|
m_action = null;
|
||||||
// Std User Workflows - see MWFNodeNext.isValidFor
|
// Std User Workflows - see MWFNodeNext.isValidFor
|
||||||
|
@ -1270,21 +1285,6 @@ public class DocumentEngine implements DocAction
|
||||||
public static boolean processIt(DocAction doc, String processAction) {
|
public static boolean processIt(DocAction doc, String processAction) {
|
||||||
boolean success = false;
|
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());
|
DocumentEngine engine = new DocumentEngine(doc, doc.getDocStatus());
|
||||||
success = engine.processIt(processAction, doc.getDocAction());
|
success = engine.processIt(processAction, doc.getDocAction());
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,18 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
import javax.xml.parsers.SAXParser;
|
import javax.xml.parsers.SAXParser;
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
@ -225,6 +229,27 @@ public class PackIn {
|
||||||
return data;
|
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
|
* @return package name
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.adempiere.pipo2;
|
package org.adempiere.pipo2;
|
||||||
|
|
||||||
|
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;
|
||||||
|
@ -7,6 +8,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.adempiere.exceptions.AdempiereException;
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.compiere.model.MAttachment;
|
||||||
|
import org.compiere.model.MAttachmentEntry;
|
||||||
import org.compiere.model.MColumn;
|
import org.compiere.model.MColumn;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.model.PO;
|
import org.compiere.model.PO;
|
||||||
|
@ -285,15 +288,43 @@ public class PoFiller{
|
||||||
private void setBlob(String qName) {
|
private void setBlob(String qName) {
|
||||||
Element pe = element.properties.get(qName);
|
Element pe = element.properties.get(qName);
|
||||||
String value = pe != null ? pe.contents.toString() : null;
|
String value = pe != null ? pe.contents.toString() : null;
|
||||||
Object data = null;
|
|
||||||
if (value != null && value.trim().length() > 0) {
|
if (value != null && value.trim().length() > 0) {
|
||||||
|
if (po instanceof MAttachment && "BinaryData".equals(qName)) {
|
||||||
|
PackIn packIn = ctx.packIn;
|
||||||
|
String fileName = null;
|
||||||
String[] component = value.split("[|]");
|
String[] component = value.split("[|]");
|
||||||
if (component.length == 2) {
|
if (component.length == 2) {
|
||||||
String fileName = component[0];
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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];
|
String dataType = component[1];
|
||||||
PackIn packIn = ctx.packIn;
|
PackIn packIn = ctx.packIn;
|
||||||
try {
|
try {
|
||||||
byte[] bytes = packIn.readBlob(fileName);
|
bytes = packIn.readBlob(fileName);
|
||||||
if ("byte[]".equals(dataType)) {
|
if ("byte[]".equals(dataType)) {
|
||||||
data = bytes;
|
data = bytes;
|
||||||
} else {
|
} else {
|
||||||
|
@ -303,7 +334,8 @@ public class PoFiller{
|
||||||
throw new AdempiereException(e.getLocalizedMessage(), e);
|
throw new AdempiereException(e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
po.set_ValueNoCheck(qName, data);
|
po.set_ValueNoCheck(qName, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue