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
@ -291,4 +291,23 @@ public class MProcessPara extends X_AD_Process_Para
return true;
} // 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

View File

@ -565,20 +565,21 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
warehouseKNPair = new KeyNamePair(warehouseId, lstItemWarehouse.getLabel());
}
String msg = login.validateLogin(orgKNPair);
Timestamp date = (Timestamp)lstDate.getValue();
String msg = login.loadPreferences(orgKNPair, warehouseKNPair, date, null);
if(!(msg == null || msg.length() == 0))
{
throw new WrongValueException(msg);
}
msg = login.validateLogin(orgKNPair);
if (msg != null && msg.length() > 0)
{
throw new WrongValueException(msg);
}
Timestamp date = (Timestamp)lstDate.getValue();
msg = login.loadPreferences(orgKNPair, warehouseKNPair, date, null);
if(!(msg == null || msg.length() == 0))
{
throw new WrongValueException(msg);
}
wndLogin.loginCompleted();
// 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;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
@ -18,8 +34,11 @@ import org.compiere.model.MColumn;
import org.compiere.model.MPInstance;
import org.compiere.model.MPInstancePara;
import org.compiere.model.MProcess;
import org.compiere.model.MProcessPara;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
import org.compiere.model.MUser;
import org.compiere.model.MWarehouse;
import org.compiere.model.ModelValidationEngine;
import org.compiere.model.ModelValidator;
import org.compiere.model.PO;
@ -29,160 +48,166 @@ import org.compiere.util.DisplayType;
import org.compiere.util.Env;
public class FitRecorder implements ModelValidator {
private static FileOutputStream tempFile = null;
private static Writer writer;
/** Logger */
private static CLogger log = CLogger.getCLogger(FitRecorder.class);
private static ArrayList<String> dontLogTables = new ArrayList<String>(Arrays.asList(
"AD_ACCESSLOG",
"AD_SESSION",
"AD_ALERTPROCESSORLOG",
"AD_CHANGELOG",
"AD_DOCUMENT_ACTION_ACCESS",
"AD_FORM_ACCESS",
"AD_ISSUE",
"AD_LDAPPROCESSORLOG",
"AD_PACKAGE_IMP",
"AD_PACKAGE_IMP_BACKUP",
"AD_PACKAGE_IMP_DETAIL",
"AD_PACKAGE_IMP_INST",
"AD_PACKAGE_IMP_PROC",
"AD_PINSTANCE",
"AD_PINSTANCE_LOG",
"AD_PINSTANCE_PARA",
"AD_PROCESS_ACCESS",
"AD_RECENTITEM",
"AD_REPLICATION_LOG",
"AD_SCHEDULERLOG",
"AD_SESSION",
"AD_WINDOW_ACCESS",
"AD_WORKFLOW_ACCESS",
"AD_WORKFLOWPROCESSORLOG",
"CM_WEBACCESSLOG",
"C_ACCTPROCESSORLOG",
"K_INDEXLOG",
"R_REQUESTPROCESSORLOG",
"T_AGING",
"T_ALTER_COLUMN",
"T_DISTRIBUTIONRUNDETAIL",
"T_INVENTORYVALUE",
"T_INVOICEGL",
"T_REPLENISH",
"T_REPORT",
"T_REPORTSTATEMENT",
"T_SELECTION",
"T_SELECTION2",
"T_SPOOL",
"T_TRANSACTION",
"T_TRIALBALANCE"));
private String ignoreTrx = null;
private static FileOutputStream tempFileOr = null;
private static Writer writerOr;
/** Logger */
private static CLogger log = CLogger.getCLogger(ModelValidator.class);
private static ArrayList<String> dontLogTables = new ArrayList<String>(Arrays.asList(
"AD_ACCESSLOG",
"AD_SESSION",
"AD_ALERTPROCESSORLOG",
"AD_CHANGELOG",
"AD_DOCUMENT_ACTION_ACCESS",
"AD_FORM_ACCESS",
"AD_ISSUE",
"AD_LDAPPROCESSORLOG",
"AD_PACKAGE_IMP",
"AD_PACKAGE_IMP_BACKUP",
"AD_PACKAGE_IMP_DETAIL",
"AD_PACKAGE_IMP_INST",
"AD_PACKAGE_IMP_PROC",
"AD_PINSTANCE",
"AD_PINSTANCE_LOG",
"AD_PINSTANCE_PARA",
"AD_PROCESS_ACCESS",
"AD_RECENTITEM",
"AD_REPLICATION_LOG",
"AD_SCHEDULERLOG",
"AD_SESSION",
"AD_WINDOW_ACCESS",
"AD_WORKFLOW_ACCESS",
"AD_WORKFLOWPROCESSORLOG",
"CM_WEBACCESSLOG",
"C_ACCTPROCESSORLOG",
"K_INDEXLOG",
"R_REQUESTPROCESSORLOG",
"T_AGING",
"T_ALTER_COLUMN",
"T_DISTRIBUTIONRUNDETAIL",
"T_INVENTORYVALUE",
"T_INVOICEGL",
"T_REPLENISH",
"T_REPORT",
"T_REPORTSTATEMENT",
"T_SELECTION",
"T_SELECTION2",
"T_SPOOL",
"T_TRANSACTION",
"T_TRIALBALANCE"));
@Override
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 sql="SELECT ta.TableName"
+" FROM AD_Table ta"
+" WHERE ta.IsActive='Y'"
+" AND ta.IsView='N'"
+" AND ta.EntityType='D'"
+" ORDER BY ta.TableName";
String sql1="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 ta.EntityType='D'"
+" AND cl.AD_Element_ID=287"
+" ORDER BY ta.TableName";
try{
File fileNameOr = File.createTempFile("fit_test_"+dateTimeText, ".txt");
tempFileOr = new FileOutputStream(fileNameOr, true);
writerOr = new BufferedWriter(new OutputStreamWriter(tempFileOr, "UTF8"));
PreparedStatement pstmt=null,pstmt1=null;
ResultSet rs=null,rs1=null;
try{
pstmt=DB.prepareStatement(sql, null);
rs=pstmt.executeQuery();
while (rs.next()) {
if (!dontLogTables.contains(rs.getString(1).toUpperCase().trim()))
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
}
try {
File fileNameOr = File.createTempFile("fit_test_" + dateTimeText + "_", ".txt");
tempFile = new FileOutputStream(fileNameOr, true);
writer = new BufferedWriter(new OutputStreamWriter(tempFile, "UTF8"));
String sql = "SELECT ta.TableName"
+" FROM AD_Table ta"
+" WHERE ta.IsActive='Y'"
+" AND ta.IsView='N'"
+" ORDER BY ta.TableName";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next()) {
engine.addModelChange(rs.getString(1), this);
}
} catch(Exception e) {
log.info(e.getLocalizedMessage());
} finally {
DB.close(rs, pstmt);
pstmt = null; rs = null;
}
}
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() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String login(int AD_Org_ID, int AD_Role_ID, int AD_User_ID) {
try {
writerOr.append("\n");
writerOr.append("\n");
writerOr.append("LOGIN");
writerOr.append("\n");
writerOr.append("!");
writerOr.append("| Login |");
writerOr.append("\n");
writer.append("\n");
writer.append("\n");
writer.append("LOGIN");
writer.append("\n");
writer.append("!");
writer.append("|Login|");
writer.append("\n");
MUser user = MUser.get(Env.getCtx(), AD_User_ID);
writerOr.append("| User |");
writerOr.append(user.getName() + " |");
writerOr.append("\n");
writerOr.append("| Password |");
writerOr.append(user.getPassword() + " |");
writerOr.append("\n");
writerOr.append("| AD_ClIEnT_id |");
writerOr.append(user.getAD_Client_ID() + " |");
writerOr.append("\n");
writerOr.append("| AD_Role_id |");
writerOr.append(AD_Role_ID + " |");
writerOr.append("\n");
writerOr.append("| *Login* |");
writerOr.flush();
}catch (Exception e) {
writer.append("|User|");
if (MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN, false))
writer.append(user.getEMail() + "|");
else
if (user.getLDAPUser() != null)
writer.append(user.getLDAPUser() + "|");
else
writer.append(user.getName() + "|");
writer.append("\n");
writer.append("|Password|");
writer.append(user.getPassword() + "|");
writer.append("\n");
writer.append("|AD_Client_ID|");
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) {
return e.getLocalizedMessage();
}
return null;
@ -190,70 +215,133 @@ public class FitRecorder implements ModelValidator {
@Override
public String modelChange(PO po, int type) throws Exception {
try {
if(type == TYPE_AFTER_NEW ){
writerOr.append("\n");
writerOr.append("\n");
writerOr.append("CREATE RECORD");
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());
MColumn[] columns=table.getColumns(true);
for(int i = 0 ; i < columns.length ; i++){
String colName=columns[i].getColumnName();
String value=po.get_ValueAsString(colName);
if(value != null && value.length() > 0){
writerOr.append("\n");
writerOr.append("| "+colName+" |");
writerOr.append(value+" | ");
}
if (type == TYPE_AFTER_NEW ) {
if (dontLogTables.contains(po.get_TableName().toUpperCase()))
return null;
// Ignore records created within a process
if (po.get_TrxName().startsWith("SvrProcess_"))
return null;
// Ignore records created within a workflow process
if (po.get_TrxName().startsWith("WFP_"))
return null;
writer.append("\n");
writer.append("\n");
writer.append("CREATE RECORD");
writer.append("\n");
writer.append("!");
writer.append("|Create Record||");
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");
writerOr.append("| *Save* |");
writerOr.flush();
writer.append("\n");
writer.append("|*Save*|");
writer.append("\n");
writer.flush();
}
if(po instanceof MPInstance){
if(type == TYPE_AFTER_CHANGE){
MProcess pro= MProcess.get(Env.getCtx(), po.get_ValueAsInt("AD_Process_ID"));
MPInstance pint=(MPInstance)po;
writerOr.append("\n");
writerOr.append("\n");
writerOr.append("RUN PROCESS");
writerOr.append("\n");
writerOr.append("!");
writerOr.append("| Run Process |");
writerOr.append("\n");
writerOr.append("| *ProcessValue* |");
writerOr.append(pro.getValue()+" |");
MPInstancePara[] para=pint.getParameters();
if(para.length>0){
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* |");
}
if (po instanceof MPInstance) {
if (type == TYPE_AFTER_CHANGE) {
MProcess pro = MProcess.get(Env.getCtx(), po.get_ValueAsInt("AD_Process_ID"));
MPInstance pint = (MPInstance)po;
writer.append("\n");
writer.append("\n");
writer.append("RUN PROCESS");
writer.append("\n");
writer.append("!");
writer.append("|Run Process|");
writer.append("\n");
writer.append("|*ProcessValue*|");
writer.append(pro.getValue() + "|");
MPInstancePara[] iparas = pint.getParameters();
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();
}
}
}catch (Exception e) {
return e.getLocalizedMessage();
@ -261,57 +349,168 @@ public class FitRecorder implements ModelValidator {
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
public String docValidate(PO po, int timing) {
try{
if(timing == TIMING_AFTER_COMPLETE ){
writerOr.append("\n");
writerOr.append("\n");
writerOr.append("RUN PROCESS");
writerOr.append("\n");
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(timing == TIMING_AFTER_PREPARE || timing == TIMING_AFTER_VOID
|| timing == TIMING_AFTER_CLOSE || timing == TIMING_AFTER_REACTIVATE || timing == TIMING_AFTER_REVERSECORRECT
|| timing == TIMING_AFTER_REVERSEACCRUAL || timing == TIMING_AFTER_POST ){
writerOr.append("\n");
writerOr.append("\n");
writerOr.append("SET DOC ACTION");
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();
}
}catch (Exception e) {
try {
if ( timing == TIMING_BEFORE_PREPARE || timing == TIMING_BEFORE_VOID
|| timing == TIMING_BEFORE_CLOSE || timing == TIMING_BEFORE_REACTIVATE || timing == TIMING_BEFORE_REVERSECORRECT
|| timing == TIMING_BEFORE_REVERSEACCRUAL || timing == TIMING_BEFORE_COMPLETE || timing == TIMING_BEFORE_POST ) {
if (po.get_TrxName().equals(ignoreTrx))
return null;
ignoreTrx = po.get_TrxName();
String action = po.get_ValueAsString("DocAction");
if (timing == TIMING_BEFORE_POST)
action = "PO";
writer.append("\n");
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());
}
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;
}
}