IDEMPIERE-4373 Bug fixes for CSV Import loader (#174)

close trx in finally block.
m_directNullKey interfere with CSV Import Loader due to trx that's not
committed yet.
insert mode: update window/tab context after save.
This commit is contained in:
hengsin 2020-07-21 06:10:49 +08:00 committed by GitHub
parent dd2b24aafa
commit d3717bc1fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 50 deletions

View File

@ -539,53 +539,52 @@ public class GridTabCSVImporter implements IGridTabImporter
* @param childs * @param childs
*/ */
private void manageMasterTrx(GridTab gridTab, List<GridTab> childs){ private void manageMasterTrx(GridTab gridTab, List<GridTab> childs){
if (trx != null) {
if( trx != null ){ try {
if (isError()) {
if( isError() ) { gridTab.dataDelete();
gridTab.dataDelete(); rollbackTrx();
rollbackTrx(); setError(false);
setError(false); } else {
}else { boolean commit = false;
if (isThereDocAction) {
boolean commit = false;
if( isThereDocAction ){ boolean isError = false;
int AD_Process_ID = MColumn.get(Env.getCtx(), gridTab.getField("DocAction").getAD_Column_ID()).getAD_Process_ID();
boolean isError = false;
int AD_Process_ID = MColumn.get(Env.getCtx(), gridTab.getField("DocAction").getAD_Column_ID()).getAD_Process_ID(); if (AD_Process_ID > 0){
String docResult = processDocAction(masterRecord, AD_Process_ID);
if( AD_Process_ID > 0 ){
String docResult = processDocAction(masterRecord, AD_Process_ID); if (docResult.contains("error"))
isError = true;
if(docResult.contains("error"))
isError = true; rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",docResult + quoteChar + "\n"));
} else {
rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",docResult + quoteChar + "\n")); throwAdempiereException("No Process found for document action.");
}else { }
throwAdempiereException("No Process found for document action.");
} if (isError){
gridTab.dataDelete();
if( isError ){ rollbackTrx();
gridTab.dataDelete(); } else {
rollbackTrx(); commit = true;
}else{ }
} else {
commit = true; commit = true;
} }
}else{ if (commit) {
commit = true; String commitResult = commitTrx();
} if (isError()) {
if (commit) { rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",commitResult + quoteChar + "\n"));
String commitResult = commitTrx(); gridTab.dataDelete();
if (isError()) { rollbackTrx();
rowsTmpResult.set(0,rowsTmpResult.get(0).replace(quoteChar + "\n",commitResult + quoteChar + "\n")); }
gridTab.dataDelete();
rollbackTrx();
} }
} }
} finally {
trx.close();
trx=null;
} }
trx.close();
trx=null;
} }
}//manageMasterTrx }//manageMasterTrx
@ -687,9 +686,17 @@ public class GridTabCSVImporter implements IGridTabImporter
if(currentGridTab.equals(gridTab)) if(currentGridTab.equals(gridTab))
masterRecord = po; masterRecord = po;
if( isInsertMode() ) if( isInsertMode() ) {
logMsg = Msg.getMsg(Env.getCtx(), "Inserted") + " " + po.toString(); logMsg = Msg.getMsg(Env.getCtx(), "Inserted") + " " + po.toString();
else{ if (!Util.isEmpty(currentGridTab.getKeyColumnName()) && currentGridTab.getKeyColumnName().endsWith("_ID")) {
int recordId = currentGridTab.getRecord_ID();
if (recordId > 0) {
if (currentGridTab.getTabNo() == 0)
Env.setContext(Env.getCtx(), currentGridTab.getWindowNo(), currentGridTab.getKeyColumnName(), recordId);
Env.setContext(Env.getCtx(), currentGridTab.getWindowNo(), currentGridTab.getTabNo(), currentGridTab.getKeyColumnName(), Integer.toString(recordId));
}
}
} else {
logMsg = Msg.getMsg(Env.getCtx(), "Updated") + " " + po.toString(); logMsg = Msg.getMsg(Env.getCtx(), "Updated") + " " + po.toString();
if( currentGridTab.equals(gridTab) && sortedtTabMapIndexes.size()>1 ) if( currentGridTab.equals(gridTab) && sortedtTabMapIndexes.size()>1 )
currentGridTab.dataRefresh(true); currentGridTab.dataRefresh(true);

View File

@ -512,8 +512,6 @@ public final class MLookup extends Lookup implements Serializable
/** Save getDirect last return value */ /** Save getDirect last return value */
private HashMap<Object,Object> m_lookupDirect = null; private HashMap<Object,Object> m_lookupDirect = null;
/** Save last unsuccessful */
private Object m_directNullKey = null;
private Future<?> m_loaderFuture; private Future<?> m_loaderFuture;
public NamePair getDirect (Object key, boolean saveInCache, boolean cacheLocal) public NamePair getDirect (Object key, boolean saveInCache, boolean cacheLocal)
@ -533,8 +531,6 @@ public final class MLookup extends Lookup implements Serializable
// Nothing to query // Nothing to query
if (key == null || m_info.QueryDirect == null || m_info.QueryDirect.length() == 0) if (key == null || m_info.QueryDirect == null || m_info.QueryDirect.length() == 0)
return null; return null;
if (key.equals(m_directNullKey))
return null;
if (key.toString().trim().length() == 0) if (key.toString().trim().length() == 0)
return null; return null;
// //
@ -609,7 +605,6 @@ public final class MLookup extends Lookup implements Serializable
} }
else else
{ {
m_directNullKey = key;
directValue = null; directValue = null;
} }