Merge b9d4aa7914c7
This commit is contained in:
commit
817f7b0979
|
@ -75,11 +75,14 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
{
|
||||
private static final String ERROR_HEADER = "_ERROR_";
|
||||
private static final String LOG_HEADER = "_LOG_";
|
||||
private String IMPORT_MODE = null;
|
||||
private boolean m_isError = false;
|
||||
private String m_import_mode = null;
|
||||
private static final String IMPORT_MODE_MERGE = "M";
|
||||
private static final String IMPORT_MODE_UPDATE = "U";
|
||||
private static final String IMPORT_MODE_INSERT = "I";
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(GridTabCSVImporter.class);
|
||||
boolean m_isError = false;
|
||||
|
||||
public File fileImport(GridTab gridTab, List<GridTab> childs, InputStream filestream, Charset charset , String importMode) {
|
||||
ICsvMapReader mapReader = null;
|
||||
|
@ -90,9 +93,9 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
CsvPreference csvpref = CsvPreference.STANDARD_PREFERENCE;
|
||||
String delimiter = String.valueOf((char) csvpref.getDelimiterChar());
|
||||
String quoteChar = String.valueOf((char) csvpref.getQuoteChar());
|
||||
IMPORT_MODE = importMode;
|
||||
m_import_mode = importMode;
|
||||
|
||||
if(!gridTab.isInsertRecord() && IMPORT_MODE.equals("I"))
|
||||
if(!gridTab.isInsertRecord() && isInsertMode())
|
||||
throw new AdempiereException("Insert record disabled for Tab");
|
||||
|
||||
try {
|
||||
|
@ -143,7 +146,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
}
|
||||
}
|
||||
|
||||
if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey)
|
||||
if(isUpdateOrMergeMode() && !isThereKey)
|
||||
throw new AdempiereException(gridTab.getTableName()+": "+Msg.getMsg(Env.getCtx(), "NoKeyFound"));
|
||||
|
||||
tabMapIndexes.put(gridTab,indxDetail-1);
|
||||
|
@ -161,7 +164,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
|
||||
if(currentDetailTab!=null){
|
||||
//check out key per Tab
|
||||
if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey){
|
||||
if(isUpdateOrMergeMode() && !isThereKey){
|
||||
throw new AdempiereException(currentDetailTab.getTableName()+": "+Msg.getMsg(Env.getCtx(), "NoKeyFound"));
|
||||
}else{
|
||||
tabMapIndexes.put(currentDetailTab,idx-1);
|
||||
|
@ -207,7 +210,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
}
|
||||
|
||||
if(currentDetailTab!=null){
|
||||
if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey)
|
||||
if(isUpdateOrMergeMode() && !isThereKey)
|
||||
throw new AdempiereException(currentDetailTab.getTableName()+": "+Msg.getMsg(Env.getCtx(), "NoKeyFound"));
|
||||
|
||||
tabMapIndexes.put(currentDetailTab,header.size()-1);
|
||||
|
@ -219,8 +222,11 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
sortedtTabMapIndexes = new TreeMap<GridTab,Integer>(bvc);
|
||||
sortedtTabMapIndexes.putAll(tabMapIndexes);
|
||||
}else{
|
||||
sortedtTabMapIndexes = new TreeMap<GridTab,Integer>();
|
||||
sortedtTabMapIndexes.put(gridTab,header.size()-1);
|
||||
Map<GridTab,Integer> localMapIndexes = new HashMap<GridTab,Integer>();
|
||||
localMapIndexes.put(gridTab, header.size()-1);
|
||||
ValueComparator bvc = new ValueComparator(localMapIndexes);
|
||||
sortedtTabMapIndexes = new TreeMap<GridTab,Integer>(bvc);
|
||||
sortedtTabMapIndexes.putAll(localMapIndexes);
|
||||
}
|
||||
|
||||
CellProcessor[] processors = readProcArray.toArray(new CellProcessor[readProcArray.size()]);
|
||||
|
@ -334,7 +340,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
logMsg = areValidKeysAndColumns(currentGridTab,map,header,currentColumn,j,masterRecord);
|
||||
|
||||
if (logMsg == null){
|
||||
if (IMPORT_MODE.equals("I")){
|
||||
if (isInsertMode()){
|
||||
if(!currentGridTab.getTableModel().isOpen())
|
||||
currentGridTab.getTableModel().open(0);
|
||||
//how to read from status since the warning is coming empty ?
|
||||
|
@ -347,7 +353,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
|
||||
currentColumn = j + 1;
|
||||
if(!(logMsg == null)){
|
||||
IMPORT_MODE =importMode;
|
||||
m_import_mode =importMode;
|
||||
//Ignore row since there is no data
|
||||
if("NO_DATA_TO_IMPORT".equals(logMsg)){
|
||||
logMsg ="";
|
||||
|
@ -367,7 +373,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
if(currentGridTab.equals(gridTab))
|
||||
masterRecord = po;
|
||||
|
||||
if(IMPORT_MODE.equals("I"))
|
||||
if(isInsertMode())
|
||||
logMsg = Msg.getMsg(Env.getCtx(), "Inserted")+" "+ po.toString();
|
||||
else
|
||||
logMsg = Msg.getMsg(Env.getCtx(), "Updated")+" "+ po.toString();
|
||||
|
@ -417,7 +423,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
break;
|
||||
}
|
||||
}
|
||||
IMPORT_MODE = importMode;
|
||||
m_import_mode = importMode;
|
||||
currentGridTab.getTableModel().setImportingMode(false, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -432,7 +438,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
trx.close();
|
||||
trx = null;
|
||||
}
|
||||
IMPORT_MODE =importMode;
|
||||
m_import_mode =importMode;
|
||||
}
|
||||
// write
|
||||
rawLine = rawLine + delimiter + quoteChar + rowResult.toString().replaceAll(delimiter, "") + quoteChar + "\n";
|
||||
|
@ -466,6 +472,22 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
return errFile;
|
||||
}
|
||||
|
||||
private boolean isInsertMode() {
|
||||
return IMPORT_MODE_INSERT.equals(m_import_mode);
|
||||
}
|
||||
|
||||
private boolean isUpdateMode() {
|
||||
return IMPORT_MODE_UPDATE.equals(m_import_mode);
|
||||
}
|
||||
|
||||
private boolean isMergeMode() {
|
||||
return IMPORT_MODE_MERGE.equals(m_import_mode);
|
||||
}
|
||||
|
||||
private boolean isUpdateOrMergeMode() {
|
||||
return isUpdateMode() || isMergeMode();
|
||||
}
|
||||
|
||||
private String getColumnName(boolean isKey ,boolean isForeing ,boolean isDetail , String headName){
|
||||
|
||||
if(isKey){
|
||||
|
@ -591,7 +613,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
|
||||
if(idS == null && id < 0){
|
||||
//it could be that record still doesn't exist if import mode is inserting or merging
|
||||
if(IMPORT_MODE.equals("U"))
|
||||
if(isUpdateMode())
|
||||
return new StringBuilder(Msg.getMsg(Env.getCtx(),"ForeignNotResolved",new Object[]{header.get(i),value}));
|
||||
}
|
||||
} else {
|
||||
|
@ -689,7 +711,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
if(header.get(i).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID))){
|
||||
|
||||
if(address == null){
|
||||
if(IMPORT_MODE.equals("I")){
|
||||
if(isInsertMode()){
|
||||
address = new MLocation (Env.getCtx(),0,masterRecord.get_TrxName());
|
||||
}else{
|
||||
Object location = gridTab.getValue("C_Location_ID")==null?0:gridTab.getValue("C_Location_ID").toString();
|
||||
|
@ -709,7 +731,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
}
|
||||
address.set_ValueOfColumn(columnName,setValue);
|
||||
}else{
|
||||
if(isKeyColumn && IMPORT_MODE.equals("U"))
|
||||
if(isKeyColumn && isUpdateMode())
|
||||
continue;
|
||||
|
||||
GridField field = gridTab.getField(columnName);
|
||||
|
@ -762,7 +784,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
if(!field.isDisplayed(true))
|
||||
continue;
|
||||
|
||||
if (!IMPORT_MODE.equals("I") && !field.isEditable(true) && value!=null) {
|
||||
if (!isInsertMode() && !field.isEditable(true) && value!=null) {
|
||||
logMsg = Msg.getMsg(Env.getCtx(), "FieldNotEditable", new Object[] {header.get(i)}) + "{" + value + "}";
|
||||
break;
|
||||
}
|
||||
|
@ -997,13 +1019,13 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
}
|
||||
gridTab.getTableModel().dataRequery(pquery.getWhereClause(),false,0);
|
||||
gridTab.setCurrentRow(0,true);
|
||||
if (IMPORT_MODE.equals("I")){
|
||||
if (isInsertMode()){
|
||||
if(gridTab.getTableModel().getRowCount()>=1)
|
||||
logMsg = Msg.getMsg(Env.getCtx(), "AlreadyExists")+" "+pquery;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
if (IMPORT_MODE.equals("U")){
|
||||
if (isUpdateMode()){
|
||||
if(gridTab.getTableModel().getRowCount()==1)
|
||||
return null;
|
||||
else if(gridTab.getTableModel().getRowCount()<=0)
|
||||
|
@ -1011,11 +1033,11 @@ public class GridTabCSVImporter implements IGridTabImporter
|
|||
else if(gridTab.getTableModel().getRowCount()>1)
|
||||
logMsg = Msg.getMsg(Env.getCtx(),"TooManyRows")+" "+pquery;
|
||||
}
|
||||
if (IMPORT_MODE.equals("M")){
|
||||
if (isMergeMode()){
|
||||
if(gridTab.getTableModel().getRowCount()==1)
|
||||
IMPORT_MODE = "U";
|
||||
m_import_mode = IMPORT_MODE_UPDATE;
|
||||
else if(gridTab.getTableModel().getRowCount()<=0)
|
||||
IMPORT_MODE = "I";
|
||||
m_import_mode = IMPORT_MODE_INSERT;
|
||||
else if(gridTab.getTableModel().getRowCount()>1)
|
||||
logMsg = Msg.getMsg(Env.getCtx(),"TooManyRows")+" "+pquery;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class ProcessInfo implements Serializable
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1426147857271483561L;
|
||||
private static final long serialVersionUID = 1371812474929601477L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -137,6 +137,9 @@ public class ProcessInfo implements Serializable
|
|||
/** Export File */
|
||||
private File m_exportFile = null;
|
||||
|
||||
/** Row count */
|
||||
private int m_rowCount;
|
||||
|
||||
/**
|
||||
* String representation
|
||||
* @return String representation
|
||||
|
@ -761,4 +764,13 @@ public class ProcessInfo implements Serializable
|
|||
{
|
||||
m_Record_IDs = Record_IDs;
|
||||
}
|
||||
|
||||
public void setRowCount(int rowCount) {
|
||||
m_rowCount = rowCount;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return m_rowCount;
|
||||
}
|
||||
|
||||
} // ProcessInfo
|
||||
|
|
|
@ -53,8 +53,8 @@ import net.sf.jasperreports.engine.JRExporterParameter;
|
|||
import net.sf.jasperreports.engine.JRParameter;
|
||||
import net.sf.jasperreports.engine.JRPropertiesUtil;
|
||||
import net.sf.jasperreports.engine.JRQuery;
|
||||
import net.sf.jasperreports.engine.JRVariable;
|
||||
import net.sf.jasperreports.engine.JasperCompileManager;
|
||||
import net.sf.jasperreports.engine.JasperFillManager;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
import net.sf.jasperreports.engine.JasperReport;
|
||||
import net.sf.jasperreports.engine.design.JRDesignQuery;
|
||||
|
@ -67,6 +67,8 @@ import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter;
|
|||
import net.sf.jasperreports.engine.export.JRTextExporter;
|
||||
import net.sf.jasperreports.engine.export.JRXlsExporter;
|
||||
import net.sf.jasperreports.engine.export.JRXmlExporter;
|
||||
import net.sf.jasperreports.engine.fill.JRBaseFiller;
|
||||
import net.sf.jasperreports.engine.fill.JRFiller;
|
||||
import net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer;
|
||||
import net.sf.jasperreports.engine.util.JRLoader;
|
||||
import net.sf.jasperreports.engine.util.JRSwapFile;
|
||||
|
@ -351,6 +353,8 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
|||
private boolean startProcess0(Properties ctx, ProcessInfo pi, Trx trx)
|
||||
{
|
||||
processInfo = pi;
|
||||
int nrows = 0;
|
||||
Object onrows = null;
|
||||
String Name=pi.getTitle();
|
||||
int AD_PInstance_ID=pi.getAD_PInstance_ID();
|
||||
int Record_ID=pi.getRecord_ID();
|
||||
|
@ -606,7 +610,9 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
|||
params.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
|
||||
DefaultJasperReportsContext jasperContext = DefaultJasperReportsContext.getInstance();
|
||||
JRPropertiesUtil.getInstance(jasperContext).setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
|
||||
JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, params, conn);
|
||||
JRBaseFiller filler = JRFiller.createFiller(jasperContext, jasperReport);
|
||||
JasperPrint jasperPrint = filler.fill(params, conn);
|
||||
onrows = filler.getVariableValue(JRVariable.REPORT_COUNT);
|
||||
|
||||
if (!processInfo.isExport())
|
||||
{
|
||||
|
@ -737,6 +743,10 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
|||
}
|
||||
}
|
||||
|
||||
if (onrows != null && onrows instanceof Integer) {
|
||||
nrows = (Integer) onrows;
|
||||
processInfo.setRowCount(nrows);
|
||||
}
|
||||
reportResult( AD_PInstance_ID, null, trxName);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.adempiere.util.IProcessUI;
|
|||
import org.adempiere.util.ProcessUtil;
|
||||
import org.compiere.db.CConnection;
|
||||
import org.compiere.interfaces.Server;
|
||||
import org.compiere.model.MPInstance;
|
||||
import org.compiere.model.MRule;
|
||||
import org.compiere.print.ReportCtl;
|
||||
import org.compiere.process.ClientProcess;
|
||||
|
@ -37,6 +38,7 @@ import org.compiere.util.Env;
|
|||
import org.compiere.util.Ini;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Trx;
|
||||
import org.compiere.util.Util;
|
||||
import org.compiere.wf.MWFProcess;
|
||||
|
||||
/**
|
||||
|
@ -268,6 +270,14 @@ public abstract class AbstractProcessCtl implements Runnable
|
|||
m_pi.setReportingProcess(true);
|
||||
m_pi.setClassName(ProcessUtil.JASPER_STARTER_CLASS);
|
||||
startProcess();
|
||||
MPInstance pinstance = new MPInstance(Env.getCtx(), m_pi.getAD_PInstance_ID(), null);
|
||||
String errmsg = pinstance.getErrorMsg();
|
||||
if (Util.isEmpty(errmsg, true))
|
||||
errmsg = "Rows=" + String.valueOf(m_pi.getRowCount());
|
||||
else
|
||||
errmsg += " Rows=" + m_pi.getRowCount();
|
||||
pinstance.setErrorMsg(errmsg);
|
||||
pinstance.saveEx();
|
||||
unlock();
|
||||
return;
|
||||
}
|
||||
|
@ -278,6 +288,14 @@ public abstract class AbstractProcessCtl implements Runnable
|
|||
// Start Report -----------------------------------------------
|
||||
boolean ok = ReportCtl.start(m_processUI, windowno, m_pi, IsDirectPrint);
|
||||
m_pi.setSummary("Report", !ok);
|
||||
MPInstance pinstance = new MPInstance(Env.getCtx(), m_pi.getAD_PInstance_ID(), null);
|
||||
String errmsg = pinstance.getErrorMsg();
|
||||
if (Util.isEmpty(errmsg, true))
|
||||
errmsg = "Rows=" + String.valueOf(m_pi.getRowCount());
|
||||
else
|
||||
errmsg += " Rows=" + m_pi.getRowCount();
|
||||
pinstance.setErrorMsg(errmsg);
|
||||
pinstance.saveEx();
|
||||
unlock ();
|
||||
}
|
||||
/**********************************************************************
|
||||
|
|
|
@ -16,6 +16,16 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.print;
|
||||
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_C_DUNNING;
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_C_INVOICE;
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_C_ORDER;
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_C_PAYMENT;
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_C_PROJECT;
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_C_RFQRESPONSE;
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_FINREPORT;
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_FINSTATEMENT;
|
||||
import static org.compiere.model.SystemIDs.PROCESS_RPT_M_INOUT;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
@ -27,7 +37,6 @@ import org.compiere.model.MProcess;
|
|||
import org.compiere.model.MQuery;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.PrintInfo;
|
||||
import static org.compiere.model.SystemIDs.*;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
|
@ -66,6 +75,7 @@ public class ReportCtl
|
|||
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (ReportCtl.class);
|
||||
private volatile static ProcessInfo m_pi;
|
||||
|
||||
/**
|
||||
* Create Report.
|
||||
|
@ -113,6 +123,7 @@ public class ReportCtl
|
|||
{
|
||||
if (s_log.isLoggable(Level.INFO)) s_log.info("start - " + pi);
|
||||
|
||||
m_pi = pi;
|
||||
/**
|
||||
* Order Print
|
||||
*/
|
||||
|
@ -363,6 +374,8 @@ public class ReportCtl
|
|||
|
||||
private static void createOutput(ReportEngine re, boolean printPreview, String printerName)
|
||||
{
|
||||
if (m_pi != null)
|
||||
m_pi.setRowCount(re.getPrintData().getRowCount());
|
||||
if (printPreview)
|
||||
preview(re);
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue