IDEMPIERE-645 Fitnesse Recorder

This commit is contained in:
Carlos Ruiz 2013-02-18 21:20:39 -05:00
parent 8ecca8238f
commit 7cdcc71a41
7 changed files with 535 additions and 258 deletions

View File

@ -37,7 +37,7 @@ public class MProcessPara extends X_AD_Process_Para
/** /**
* *
*/ */
private static final long serialVersionUID = -6254678383726841920L; private static final long serialVersionUID = 4580303034897910371L;
/** /**
* Get MProcessPara from Cache * Get MProcessPara from Cache
@ -291,4 +291,23 @@ public class MProcessPara extends X_AD_Process_Para
return true; return true;
} // beforeSave } // beforeSave
public String getReferenceTableName() {
String foreignTable = null;
if (DisplayType.TableDir == getAD_Reference_ID()
|| (DisplayType.Search == getAD_Reference_ID() && getAD_Reference_Value_ID() == 0)) {
foreignTable = getColumnName().substring(0, getColumnName().length()-3);
} else if (DisplayType.Table == getAD_Reference_ID() || DisplayType.Search == getAD_Reference_ID()) {
X_AD_Reference ref = new X_AD_Reference(getCtx(), getAD_Reference_Value_ID(), get_TrxName());
if (X_AD_Reference.VALIDATIONTYPE_TableValidation.equals(ref.getValidationType())) {
MRefTable rt = new MRefTable(getCtx(), getAD_Reference_Value_ID(), get_TrxName());
if (rt != null)
foreignTable = rt.getAD_Table().getTableName();
}
} else if (DisplayType.List == getAD_Reference_ID()) {
foreignTable = "AD_Ref_List";
}
return foreignTable;
}
} // MProcessPara } // MProcessPara

View File

@ -565,20 +565,21 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
warehouseKNPair = new KeyNamePair(warehouseId, lstItemWarehouse.getLabel()); warehouseKNPair = new KeyNamePair(warehouseId, lstItemWarehouse.getLabel());
} }
String msg = login.validateLogin(orgKNPair);
if (msg != null && msg.length() > 0)
{
throw new WrongValueException(msg);
}
Timestamp date = (Timestamp)lstDate.getValue(); Timestamp date = (Timestamp)lstDate.getValue();
msg = login.loadPreferences(orgKNPair, warehouseKNPair, date, null); String msg = login.loadPreferences(orgKNPair, warehouseKNPair, date, null);
if(!(msg == null || msg.length() == 0)) if(!(msg == null || msg.length() == 0))
{ {
throw new WrongValueException(msg); throw new WrongValueException(msg);
} }
msg = login.validateLogin(orgKNPair);
if (msg != null && msg.length() > 0)
{
throw new WrongValueException(msg);
}
wndLogin.loginCompleted(); wndLogin.loginCompleted();
// Elaine 2009/02/06 save preference to AD_Preference // Elaine 2009/02/06 save preference to AD_Preference

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<idempiere Name="org.idempiere.fitrecorder" Version="1.0" idempiereVersion="" DataBaseVersion="" Description="FitRecorder model validator" Author="" AuthorEmail="" CreatedDate="2013-02-18 14:04:15.072" UpdatedDate="2013-02-18 14:57:03.815" PackOutVersion="100" Client="0-SYSTEM-System">
<AD_ModelValidator type="table">
<AD_Client_ID>0</AD_Client_ID>
<AD_Org_ID>0</AD_Org_ID>
<SeqNo>0</SeqNo>
<Help>Fitnesse Recorder - see output on /tmp/fit_test_*.txt - enable this model validator to record fitnesse actions - disable to stop recording</Help>
<ModelValidationClass>org.idempiere.fitrecorder.FitRecorder</ModelValidationClass>
<EntityType>U</EntityType>
<Description>Fitnesse Recorder</Description>
<Name>FitRecorder</Name>
<AD_ModelValidator_UU>cbe0799e-bbe4-46cd-a2c9-433ecb969325</AD_ModelValidator_UU>
<IsActive>true</IsActive>
</AD_ModelValidator>
<SQLStatement type="custom">
<DBType>ALL</DBType>
<statement><![CDATA[UPDATE AD_ModelValidator SET IsActive='N' WHERE AD_ModelValidator_UU='cbe0799e-bbe4-46cd-a2c9-433ecb969325']]></statement>
</SQLStatement>
</idempiere>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="idempiereDocument.css"?>
<idempiereDocument>
<header>org.idempiere.fitrecorder Package Description</header>
<H1>Package Name:</H1>
<packagename>org.idempiere.fitrecorder</packagename>
<H1>Author:</H1>
<Name:/>
<H1>Email Address:</H1>
<Email/>
<H1>Created:</H1>
<Date>2013-02-18 14:04:15.072</Date>
<H1>Updated:</H1>
<Date>2013-02-18 14:57:03.815</Date>
<H1>Description:</H1>
<description>FitRecorder model validator</description>
<H1>Instructions:</H1>
<instructions/>
<H1>Files in Package:</H1>
<file>File: PackOut.xml</file>
<filedirectory>Directory: \dict\</filedirectory>
<filenotes>Notes: Contains all application/object settings for package</filenotes>
<H1>Client:</H1>
<Client>0-SYSTEM-System</Client>
</idempiereDocument>

Binary file not shown.

View File

@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Fitrecorder
Bundle-SymbolicName: org.idempiere.fitrecorder;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.adempiere.plugin.utils.AdempiereActivator
Import-Package: org.adempiere.base,
org.adempiere.plugin.utils,
org.compiere.model,
org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Service-Component: plugin.xml
Require-Bundle: org.adempiere.base

View File

@ -1,11 +1,27 @@
/******************************************************************************
* Product: iDempiere ERP & CRM Smart Business Solution *
* Copyright (C) Trek Global All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* *
* @author Juliana Corredor, jcorredor@trekglobal.com *
* @author Carlos Ruiz *
*****************************************************************************/
package org.idempiere.fitrecorder; package org.idempiere.fitrecorder;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.math.BigDecimal;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -18,8 +34,11 @@ import org.compiere.model.MColumn;
import org.compiere.model.MPInstance; import org.compiere.model.MPInstance;
import org.compiere.model.MPInstancePara; import org.compiere.model.MPInstancePara;
import org.compiere.model.MProcess; import org.compiere.model.MProcess;
import org.compiere.model.MProcessPara;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.MUser; import org.compiere.model.MUser;
import org.compiere.model.MWarehouse;
import org.compiere.model.ModelValidationEngine; import org.compiere.model.ModelValidationEngine;
import org.compiere.model.ModelValidator; import org.compiere.model.ModelValidator;
import org.compiere.model.PO; import org.compiere.model.PO;
@ -30,127 +49,114 @@ import org.compiere.util.Env;
public class FitRecorder implements ModelValidator { public class FitRecorder implements ModelValidator {
private static FileOutputStream tempFileOr = null; private static FileOutputStream tempFile = null;
private static Writer writerOr; private static Writer writer;
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(ModelValidator.class); private static CLogger log = CLogger.getCLogger(FitRecorder.class);
private static ArrayList<String> dontLogTables = new ArrayList<String>(Arrays.asList( private static ArrayList<String> dontLogTables = new ArrayList<String>(Arrays.asList(
"AD_ACCESSLOG", "AD_ACCESSLOG",
"AD_SESSION", "AD_SESSION",
"AD_ALERTPROCESSORLOG", "AD_ALERTPROCESSORLOG",
"AD_CHANGELOG", "AD_CHANGELOG",
"AD_DOCUMENT_ACTION_ACCESS", "AD_DOCUMENT_ACTION_ACCESS",
"AD_FORM_ACCESS", "AD_FORM_ACCESS",
"AD_ISSUE", "AD_ISSUE",
"AD_LDAPPROCESSORLOG", "AD_LDAPPROCESSORLOG",
"AD_PACKAGE_IMP", "AD_PACKAGE_IMP",
"AD_PACKAGE_IMP_BACKUP", "AD_PACKAGE_IMP_BACKUP",
"AD_PACKAGE_IMP_DETAIL", "AD_PACKAGE_IMP_DETAIL",
"AD_PACKAGE_IMP_INST", "AD_PACKAGE_IMP_INST",
"AD_PACKAGE_IMP_PROC", "AD_PACKAGE_IMP_PROC",
"AD_PINSTANCE", "AD_PINSTANCE",
"AD_PINSTANCE_LOG", "AD_PINSTANCE_LOG",
"AD_PINSTANCE_PARA", "AD_PINSTANCE_PARA",
"AD_PROCESS_ACCESS", "AD_PROCESS_ACCESS",
"AD_RECENTITEM", "AD_RECENTITEM",
"AD_REPLICATION_LOG", "AD_REPLICATION_LOG",
"AD_SCHEDULERLOG", "AD_SCHEDULERLOG",
"AD_SESSION", "AD_SESSION",
"AD_WINDOW_ACCESS", "AD_WINDOW_ACCESS",
"AD_WORKFLOW_ACCESS", "AD_WORKFLOW_ACCESS",
"AD_WORKFLOWPROCESSORLOG", "AD_WORKFLOWPROCESSORLOG",
"CM_WEBACCESSLOG", "CM_WEBACCESSLOG",
"C_ACCTPROCESSORLOG", "C_ACCTPROCESSORLOG",
"K_INDEXLOG", "K_INDEXLOG",
"R_REQUESTPROCESSORLOG", "R_REQUESTPROCESSORLOG",
"T_AGING", "T_AGING",
"T_ALTER_COLUMN", "T_ALTER_COLUMN",
"T_DISTRIBUTIONRUNDETAIL", "T_DISTRIBUTIONRUNDETAIL",
"T_INVENTORYVALUE", "T_INVENTORYVALUE",
"T_INVOICEGL", "T_INVOICEGL",
"T_REPLENISH", "T_REPLENISH",
"T_REPORT", "T_REPORT",
"T_REPORTSTATEMENT", "T_REPORTSTATEMENT",
"T_SELECTION", "T_SELECTION",
"T_SELECTION2", "T_SELECTION2",
"T_SPOOL", "T_SPOOL",
"T_TRANSACTION", "T_TRANSACTION",
"T_TRIALBALANCE")); "T_TRIALBALANCE"));
private String ignoreTrx = null;
@Override @Override
public void initialize(ModelValidationEngine engine, MClient client) { public void initialize(ModelValidationEngine engine, MClient client) {
SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.DateTime); SimpleDateFormat format = new SimpleDateFormat ("yyyyMMddHHmmss");
String dateTimeText = format.format(new Timestamp(System.currentTimeMillis())); String dateTimeText = format.format(new Timestamp(System.currentTimeMillis()));
String sql="SELECT ta.TableName" try {
+" FROM AD_Table ta" File fileNameOr = File.createTempFile("fit_test_" + dateTimeText + "_", ".txt");
+" WHERE ta.IsActive='Y'" tempFile = new FileOutputStream(fileNameOr, true);
+" AND ta.IsView='N'" writer = new BufferedWriter(new OutputStreamWriter(tempFile, "UTF8"));
+" AND ta.EntityType='D'"
+" ORDER BY ta.TableName";
String sql1="SELECT ta.TableName" String sql = "SELECT ta.TableName"
+" FROM AD_Table ta" +" FROM AD_Table ta"
+" INNER JOIN AD_Column cl ON (ta.AD_Table_ID = cl.AD_Table_ID)" +" WHERE ta.IsActive='Y'"
+" WHERE ta.IsActive='Y'" +" AND ta.IsView='N'"
+" AND ta.IsView='N'" +" ORDER BY ta.TableName";
+" AND ta.EntityType='D'"
+" AND cl.AD_Element_ID=287"
+" ORDER BY ta.TableName";
try{ PreparedStatement pstmt = null;
File fileNameOr = File.createTempFile("fit_test_"+dateTimeText, ".txt"); ResultSet rs = null;
tempFileOr = new FileOutputStream(fileNameOr, true); try {
writerOr = new BufferedWriter(new OutputStreamWriter(tempFileOr, "UTF8")); pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
PreparedStatement pstmt=null,pstmt1=null; while (rs.next()) {
ResultSet rs=null,rs1=null; engine.addModelChange(rs.getString(1), this);
}
try{ } catch(Exception e) {
pstmt=DB.prepareStatement(sql, null); log.info(e.getLocalizedMessage());
rs=pstmt.executeQuery(); } finally {
while (rs.next()) { DB.close(rs, pstmt);
if (!dontLogTables.contains(rs.getString(1).toUpperCase().trim())) pstmt = null; rs = null;
engine.addModelChange(rs.getString(1), this);
}
}catch(Exception e){
log.info(e.getLocalizedMessage());
}finally{
pstmt.close();
rs.close();
}
try {
pstmt1=DB.prepareStatement(sql1, null);
rs1=pstmt1.executeQuery();
while (rs1.next()) {
if (!dontLogTables.contains(rs1.getString(1).toUpperCase().trim()))
engine.addDocValidate(rs1.getString(1), this);
}
}catch (Exception e) {
log.info(e.getLocalizedMessage());
}finally{
pstmt1.close();
rs1.close();
}
}catch (Exception e) {
log.info(e.getLocalizedMessage());
}finally{
if (tempFileOr!=null){
try {
tempFileOr.close();
} catch (IOException e){
//TODO
}
} }
sql = "SELECT ta.TableName"
+" FROM AD_Table ta"
+" INNER JOIN AD_Column cl ON (ta.AD_Table_ID = cl.AD_Table_ID)"
+" WHERE ta.IsActive='Y'"
+" AND ta.IsView='N'"
+" AND cl.AD_Element_ID=287"
+" ORDER BY ta.TableName";
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next()) {
engine.addDocValidate(rs.getString(1), this);
}
} catch (Exception e) {
log.info(e.getLocalizedMessage());
} finally {
DB.close(rs, pstmt);
pstmt = null; rs = null;
}
} catch (Exception e) {
log.info(e.getLocalizedMessage());
} }
} }
@Override
public int getAD_Client_ID() { public int getAD_Client_ID() {
// TODO Auto-generated method stub
return 0; return 0;
} }
@ -159,30 +165,49 @@ public class FitRecorder implements ModelValidator {
try { try {
writerOr.append("\n"); writer.append("\n");
writerOr.append("\n"); writer.append("\n");
writerOr.append("LOGIN"); writer.append("LOGIN");
writerOr.append("\n"); writer.append("\n");
writerOr.append("!"); writer.append("!");
writerOr.append("| Login |"); writer.append("|Login|");
writerOr.append("\n"); writer.append("\n");
MUser user = MUser.get(Env.getCtx(), AD_User_ID); MUser user = MUser.get(Env.getCtx(), AD_User_ID);
writerOr.append("| User |"); writer.append("|User|");
writerOr.append(user.getName() + " |"); if (MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN, false))
writerOr.append("\n"); writer.append(user.getEMail() + "|");
writerOr.append("| Password |"); else
writerOr.append(user.getPassword() + " |"); if (user.getLDAPUser() != null)
writerOr.append("\n"); writer.append(user.getLDAPUser() + "|");
writerOr.append("| AD_ClIEnT_id |"); else
writerOr.append(user.getAD_Client_ID() + " |"); writer.append(user.getName() + "|");
writerOr.append("\n"); writer.append("\n");
writerOr.append("| AD_Role_id |"); writer.append("|Password|");
writerOr.append(AD_Role_ID + " |"); writer.append(user.getPassword() + "|");
writerOr.append("\n"); writer.append("\n");
writerOr.append("| *Login* |"); writer.append("|AD_Client_ID|");
writerOr.flush(); MClient client = MClient.get(Env.getCtx(), Env.getContextAsInt(Env.getCtx(), "#AD_Client_ID"));
writer.append("@Ref=AD_Client[Name='" + client.getName() + "'].AD_Client_ID|");
writer.append("\n");
writer.append("|AD_Org_ID|");
String orgName = DB.getSQLValueString(null, "SELECT Name FROM AD_Org WHERE AD_Org_ID=?", AD_Org_ID);
writer.append("@Ref=AD_Org[Name='" + orgName + "'].AD_Org_ID|");
writer.append("\n");
writer.append("|AD_Role_ID|");
writer.append("@Ref=AD_Role[Name='" + Env.getContext(Env.getCtx(), "#AD_Role_Name") + "'].AD_Role_ID|");
writer.append("\n");
int warehouseid = Env.getContextAsInt(Env.getCtx(), Env.M_WAREHOUSE_ID);
if (warehouseid > 0) {
MWarehouse warehouse = MWarehouse.get(Env.getCtx(), warehouseid);
writer.append("|M_Warehouse_ID|");
writer.append("@Ref=M_Warehouse[Name='" + warehouse.getName() + "'].M_Warehouse_ID|");
writer.append("\n");
}
writer.append("|*Login*|");
writer.append("\n");
writer.flush();
}catch (Exception e) { } catch (Exception e) {
return e.getLocalizedMessage(); return e.getLocalizedMessage();
} }
return null; return null;
@ -192,68 +217,131 @@ public class FitRecorder implements ModelValidator {
public String modelChange(PO po, int type) throws Exception { public String modelChange(PO po, int type) throws Exception {
try { try {
if(type == TYPE_AFTER_NEW ){ if (type == TYPE_AFTER_NEW ) {
if (dontLogTables.contains(po.get_TableName().toUpperCase()))
return null;
writerOr.append("\n"); // Ignore records created within a process
writerOr.append("\n"); if (po.get_TrxName().startsWith("SvrProcess_"))
writerOr.append("CREATE RECORD"); return null;
writerOr.append("\n");
writerOr.append("!");
writerOr.append("| Create Record||");
writerOr.append("\n");
writerOr.append("| *Table* |");
writerOr.append(po.get_TableName()+"|");
MTable table=MTable.get(Env.getCtx(),po.get_Table_ID()); // Ignore records created within a workflow process
MColumn[] columns=table.getColumns(true); if (po.get_TrxName().startsWith("WFP_"))
return null;
for(int i = 0 ; i < columns.length ; i++){ writer.append("\n");
String colName=columns[i].getColumnName(); writer.append("\n");
String value=po.get_ValueAsString(colName); writer.append("CREATE RECORD");
if(value != null && value.length() > 0){ writer.append("\n");
writerOr.append("\n"); writer.append("!");
writerOr.append("| "+colName+" |"); writer.append("|Create Record||");
writerOr.append(value+" | "); writer.append("\n");
writer.append("|*Table*|");
writer.append(po.get_TableName() + "|");
MTable table = MTable.get(Env.getCtx(),po.get_Table_ID());
for(MColumn column : table.getColumns(false)) {
String colName = column.getColumnName();
// exclude some columns
if ( colName.equals("Created")
|| colName.equals("CreatedBy")
|| colName.equals("Updated")
|| colName.equals("UpdatedBy")
|| colName.equals("AD_Client_ID")
|| colName.equals(table.getTableName() + "_ID")
|| colName.equals(PO.getUUIDColumnName(table.getTableName()))
|| column.getAD_Reference_ID() == DisplayType.Button
)
continue;
if (po.isActive() && colName.equals("IsActive"))
continue;
// TODO: Exclude read-only fields (read-only is marked on window which is not available here)
String value = po.get_ValueAsString(colName);
if (value != null && value.length() > 0) {
writer.append("\n");
writer.append("|" + colName + "|");
if (DisplayType.isLookup(column.getAD_Reference_ID()) && DisplayType.List != column.getAD_Reference_ID()) {
writer.append(resolveValue(po, table, column) + "|");
} else {
writer.append(value +"|");
}
} }
} }
writerOr.append("\n"); writer.append("\n");
writerOr.append("| *Save* |"); writer.append("|*Save*|");
writerOr.flush(); writer.append("\n");
writer.flush();
} }
if(po instanceof MPInstance){ if (po instanceof MPInstance) {
if(type == TYPE_AFTER_CHANGE){ if (type == TYPE_AFTER_CHANGE) {
MProcess pro= MProcess.get(Env.getCtx(), po.get_ValueAsInt("AD_Process_ID")); MProcess pro = MProcess.get(Env.getCtx(), po.get_ValueAsInt("AD_Process_ID"));
MPInstance pint=(MPInstance)po; MPInstance pint = (MPInstance)po;
writerOr.append("\n"); writer.append("\n");
writerOr.append("\n"); writer.append("\n");
writerOr.append("RUN PROCESS"); writer.append("RUN PROCESS");
writerOr.append("\n"); writer.append("\n");
writerOr.append("!"); writer.append("!");
writerOr.append("| Run Process |"); writer.append("|Run Process|");
writerOr.append("\n"); writer.append("\n");
writerOr.append("| *ProcessValue* |"); writer.append("|*ProcessValue*|");
writerOr.append(pro.getValue()+" |"); writer.append(pro.getValue() + "|");
MPInstancePara[] para=pint.getParameters(); MPInstancePara[] iparas = pint.getParameters();
if(para.length>0){ for (MProcessPara para : pro.getParameters()) {
MPInstancePara ipara = null;
for (MPInstancePara iparat : iparas) {
if (iparat.getParameterName().equals(para.getColumnName())) {
ipara = iparat;
break;
}
}
if (ipara == null) {
continue;
}
String value = null;
String valueTo = null;
if (DisplayType.isDate(para.getAD_Reference_ID())) {
if (ipara.getP_Date() != null)
value = ipara.getP_Date().toString();
if (para.isRange() && ipara.getP_Date_To() != null)
valueTo = ipara.getP_Date_To().toString();
} else if (DisplayType.isNumeric(para.getAD_Reference_ID())) {
if (ipara.getP_Number() != null)
value = ipara.getP_Number().toString();
if (para.isRange() && ipara.getP_Number_To() != null)
valueTo = ipara.getP_Number_To().toString();
} else if (DisplayType.isLookup(para.getAD_Reference_ID()) && DisplayType.List != para.getAD_Reference_ID()) {
// TODO: resolve Ref
if (ipara.get_Value("P_Number") != null)
value = resolveValuePara(ipara.getP_Number(), para);
if (para.isRange() && ipara.get_Value("P_Number_To") != null)
valueTo = resolveValuePara(ipara.getP_Number_To(), para);
} else {
if (ipara.getP_String() != null)
value = ipara.getP_String();
if (para.isRange() && ipara.getP_String_To() != null)
valueTo = ipara.getP_String_To();
}
if (value != null) {
writer.append("\n");
writer.append("|" + para.getColumnName() + "|");
writer.append(value + "|");
}
if (para.isRange() && valueTo != null) {
writer.append("\n");
writer.append("|" + para.getColumnName() + "_2|");
writer.append(valueTo + "|");
}
}
writer.append("\n");
writer.append("|*Run*|");
writer.append("\n");
writer.flush();
for (int i=0 ; i < para.length ; i++){ }
writerOr.append("\n");
String name=para[i].getParameterName();
if(name.contains("to")){
name.replace("to", "_2");
}
writerOr.append("|"+name+"|");
writerOr.append(para[i].get_ValueAsString(para[i].getParameterName())+"|");
}
}
writerOr.append("\n");
writerOr.append("| *Run* |");
}
} }
}catch (Exception e) { }catch (Exception e) {
return e.getLocalizedMessage(); return e.getLocalizedMessage();
@ -261,57 +349,168 @@ public class FitRecorder implements ModelValidator {
return null; return null;
} }
private String resolveValuePara(BigDecimal p_Number, MProcessPara para) {
String value = null;
// resolve to identifier - search for value first, if not search for name - if not use the ID
String foreignTable = para.getReferenceTableName();
String foreignColName = null;
if ( ! ("AD_Language".equals(foreignTable) || "AD_EntityType".equals(foreignTable))) {
MTable fTable = MTable.get(Env.getCtx(), foreignTable);
// Hardcoded / do not check for Value on AD_Org, AD_User and AD_Ref_List, must use name for these two tables
if (! ("AD_Org".equals(foreignTable) || "AD_User".equals(foreignTable) || "AD_Ref_List".equals(foreignTable))
&& fTable.getColumn("Value") != null) {
foreignColName = "Value";
} else if (fTable.getColumn("Name") != null) {
foreignColName = "Name";
} else if (fTable.getColumn("DocumentNo") != null) {
foreignColName = "DocumentNo";
}
}
Object idO = p_Number.intValue();
if (idO != null && foreignColName != null) {
int id = (Integer) idO;
StringBuilder select = new StringBuilder("SELECT ")
.append(foreignColName).append(" FROM ")
.append(foreignTable).append(" WHERE ")
.append(foreignTable).append("_ID=?");
String foreignValue = DB.getSQLValueStringEx(null, select.toString(), id);
value = "@Ref=" + foreignTable + "[" + foreignColName + "='" + foreignValue + "']." + foreignTable + "_ID";
} else {
value = p_Number.toString();
}
return value;
}
private String resolveValue(PO po, MTable table, MColumn column) {
String value = null;
// resolve to identifier - search for value first, if not search for name - if not use the ID
String foreignTable = column.getReferenceTableName();
String foreignColName = null;
if ( ! ("AD_Language".equals(foreignTable) || "AD_EntityType".equals(foreignTable))) {
MTable fTable = MTable.get(Env.getCtx(), foreignTable);
// Hardcoded / do not check for Value on AD_Org, AD_User and AD_Ref_List, must use name for these two tables
if (! ("AD_Org".equals(foreignTable) || "AD_User".equals(foreignTable) || "AD_Ref_List".equals(foreignTable))
&& fTable.getColumn("Value") != null) {
foreignColName = "Value";
} else if (fTable.getColumn("Name") != null) {
foreignColName = "Name";
} else if (fTable.getColumn("DocumentNo") != null) {
foreignColName = "DocumentNo";
}
}
Object idO = po.get_Value(column.getColumnName());
if (idO != null && foreignColName != null) {
int id = (Integer) idO;
StringBuilder select = new StringBuilder("SELECT ")
.append(foreignColName).append(" FROM ")
.append(foreignTable).append(" WHERE ")
.append(foreignTable).append("_ID=?");
String foreignValue = DB.getSQLValueStringEx(null, select.toString(), id);
value = "@Ref=" + foreignTable + "[" + foreignColName + "='" + foreignValue + "']." + foreignTable + "_ID";
} else {
value = po.get_ValueAsString(column.getColumnName());
}
return value;
}
@Override @Override
public String docValidate(PO po, int timing) { public String docValidate(PO po, int timing) {
try{
if(timing == TIMING_AFTER_COMPLETE ){
writerOr.append("\n"); try {
writerOr.append("\n"); if ( timing == TIMING_BEFORE_PREPARE || timing == TIMING_BEFORE_VOID
writerOr.append("RUN PROCESS"); || timing == TIMING_BEFORE_CLOSE || timing == TIMING_BEFORE_REACTIVATE || timing == TIMING_BEFORE_REVERSECORRECT
writerOr.append("\n"); || timing == TIMING_BEFORE_REVERSEACCRUAL || timing == TIMING_BEFORE_COMPLETE || timing == TIMING_BEFORE_POST ) {
writerOr.append("!");
writerOr.append("| Run Process |");
writerOr.append("\n");
writerOr.append("| *ProcessValue* |");
writerOr.append(po.get_ValueAsString("value")+" |");
writerOr.append("\n");
writerOr.append("| *DocAction* |");
writerOr.append("CO |");
writerOr.append("\n");
writerOr.append("| *Run* |");
writerOr.flush();
} if (po.get_TrxName().equals(ignoreTrx))
return null;
if(timing == TIMING_AFTER_PREPARE || timing == TIMING_AFTER_VOID ignoreTrx = po.get_TrxName();
|| timing == TIMING_AFTER_CLOSE || timing == TIMING_AFTER_REACTIVATE || timing == TIMING_AFTER_REVERSECORRECT
|| timing == TIMING_AFTER_REVERSEACCRUAL || timing == TIMING_AFTER_POST ){
writerOr.append("\n"); String action = po.get_ValueAsString("DocAction");
writerOr.append("\n"); if (timing == TIMING_BEFORE_POST)
writerOr.append("SET DOC ACTION"); action = "PO";
writerOr.append("\n");
writerOr.append("!");
writerOr.append("| Set DocAction |");
writerOr.append("\n");
writerOr.append("| *Table* |");
MTable table=new MTable(Env.getCtx(), po.get_Table_ID(), null);
writerOr.append(table.getTableName()+" |");
writerOr.append("\n");
writerOr.append("| *RecordID* |");
writerOr.append(po.get_ID()+"|");
writerOr.append("\n");
writerOr.append("|docAction |");
writerOr.append(po.get_ValueAsString("DocAction")+" |");
writerOr.append("\n");
writerOr.append("| *Save* |");
writerOr.flush();
} writer.append("\n");
}catch (Exception e) { writer.append("\n");
if (action.equals("CO")) {
// run process
String processValue = DB.getSQLValueString(po.get_TrxName(),
"SELECT p.Value FROM AD_Process p JOIN AD_Workflow w ON (p.AD_Workflow_ID=w.AD_Workflow_ID) WHERE w.AD_Table_ID=?", po.get_Table_ID());
writer.append("RUN PROCESS");
writer.append("\n");
writer.append("!");
writer.append("|Run Process|");
writer.append("\n");
writer.append("|*ProcessValue*|");
writer.append(processValue + "|");
writer.append("\n");
writer.append("|*RecordID*|");
writer.append(resolveValueDoc(po.get_ID(), po.get_TableName()) + "|");
writer.append("\n");
writer.append("|*DocAction*|");
writer.append(action + "|");
writer.append("\n");
writer.append("|*Run*|");
} else {
// set doc action
writer.append("SET DOC ACTION");
writer.append("\n");
writer.append("!");
writer.append("|Set DocAction|");
writer.append("\n");
writer.append("|*Table*|");
writer.append(po.get_TableName() + "|");
writer.append("\n");
writer.append("|" + po.get_TableName() + "_ID|");
writer.append(resolveValueDoc(po.get_ID(), po.get_TableName()) + "|");
writer.append("\n");
writer.append("|DocAction|");
writer.append(action + "|");
writer.append("\n");
writer.append("|*Save*|");
}
writer.append("\n");
writer.flush();
}
} catch (Exception e) {
log.info(e.getLocalizedMessage()); log.info(e.getLocalizedMessage());
} }
return null; return null;
} }
private String resolveValueDoc(int id, String tableName) {
String value = null;
// resolve to identifier - search for value first, if not search for name - if not use the ID
String foreignTable = tableName;
String foreignColName = null;
if ( ! ("AD_Language".equals(foreignTable) || "AD_EntityType".equals(foreignTable))) {
MTable fTable = MTable.get(Env.getCtx(), foreignTable);
// Hardcoded / do not check for Value on AD_Org, AD_User and AD_Ref_List, must use name for these two tables
if (! ("AD_Org".equals(foreignTable) || "AD_User".equals(foreignTable) || "AD_Ref_List".equals(foreignTable))
&& fTable.getColumn("Value") != null) {
foreignColName = "Value";
} else if (fTable.getColumn("Name") != null) {
foreignColName = "Name";
} else if (fTable.getColumn("DocumentNo") != null) {
foreignColName = "DocumentNo";
}
}
if (id > 0 && foreignColName != null) {
StringBuilder select = new StringBuilder("SELECT ")
.append(foreignColName).append(" FROM ")
.append(foreignTable).append(" WHERE ")
.append(foreignTable).append("_ID=?");
String foreignValue = DB.getSQLValueStringEx(null, select.toString(), id);
value = "@Ref=" + foreignTable + "[" + foreignColName + "='" + foreignValue + "']." + foreignTable + "_ID";
} else {
value = String.valueOf(id);
}
return value;
}
} }