From 78285506d124c46e3e655e995309946371f9be21 Mon Sep 17 00:00:00 2001 From: Diego Ruiz Date: Wed, 7 Oct 2015 08:13:01 -0500 Subject: [PATCH] IDEMPIERE-2878 Allow single trx in CSV Importer --- .../adempiere/impexp/GridTabCSVImporter.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java index f19d000be2..8d6551dcbc 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java @@ -120,6 +120,7 @@ public class GridTabCSVImporter implements IGridTabImporter //Trx private Trx trx; private String trxName; + private boolean isSingleTrx = false; /** Logger */ private static CLogger log = CLogger.getCLogger(GridTabCSVImporter.class); @@ -228,8 +229,11 @@ public class GridTabCSVImporter implements IGridTabImporter rowsTmpResult.add(rawLine); continue; } + + if( isSingleTrx() && trx == null ) + createTrx(gridTab); - if( !isDetail ){ + if( !isDetail && !isSingleTrx() ){ manageMasterTrx(gridTab, null); createTrx(gridTab); } @@ -240,6 +244,9 @@ public class GridTabCSVImporter implements IGridTabImporter // write rawLine = rawLine + delimiter + quoteChar + rowResult.toString().replaceAll(delimiter, "") + quoteChar + "\n"; rowsTmpResult.add(rawLine); + + if( isSingleTrx() && isError() ) + break; } @@ -808,7 +815,11 @@ public class GridTabCSVImporter implements IGridTabImporter if(isKey){ if(headName.indexOf("/") > 0){ if(headName.endsWith("K")) - headName = headName.substring(0,headName.length()-2); + headName = headName.substring(0,headName.length()-2); + else if (headName.endsWith("KT")){ + setSingleTrx(true); + headName = headName.substring(0,headName.length()-3); + } else throw new AdempiereException(Msg.getMsg(Env.getCtx(), "ColumnKey")+" "+headName); } @@ -1303,7 +1314,7 @@ public class GridTabCSVImporter implements IGridTabImporter List parentColumns = new ArrayList(); //Process columnKeys + Foreign to add restrictions. for (int i = startindx ; i < endindx + 1 ; i++){ - boolean isKeyColumn = header.get(i).indexOf("/") > 0 && header.get(i).endsWith("K"); + boolean isKeyColumn = header.get(i).indexOf("/") > 0 && ( header.get(i).endsWith("K") || header.get(i).endsWith("KT")); if(isKeyColumn && !header.get(i).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID))){ boolean isForeing = header.get(i).indexOf("[") > 0 && header.get(i).indexOf("]")>0; boolean isDetail = header.get(i).indexOf(">") > 0; @@ -1522,6 +1533,14 @@ public class GridTabCSVImporter implements IGridTabImporter return error; } + public boolean isSingleTrx() { + return isSingleTrx; + } + + public void setSingleTrx(boolean isSingleTrx) { + this.isSingleTrx = isSingleTrx; + } + public void setError(boolean error) { this.error = error; }