IDEMPIERE-645 Fitnesse Recorder / peer review
This commit is contained in:
parent
722537e0f5
commit
9243e6453d
|
@ -16,8 +16,6 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.idempiere.fitrecorder;
|
package org.idempiere.fitrecorder;
|
||||||
|
|
||||||
import groovy.swing.factory.WidgetFactory;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -27,21 +25,17 @@ import java.io.Writer;
|
||||||
import java.math.BigDecimal;
|
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.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.codehaus.groovy.control.messages.Message;
|
|
||||||
import org.compiere.model.MClient;
|
import org.compiere.model.MClient;
|
||||||
import org.compiere.model.MColumn;
|
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.MProcessPara;
|
||||||
import org.compiere.model.MSearchDefinition;
|
|
||||||
import org.compiere.model.MSession;
|
import org.compiere.model.MSession;
|
||||||
import org.compiere.model.MSysConfig;
|
import org.compiere.model.MSysConfig;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
|
@ -58,9 +52,7 @@ import org.compiere.util.Ini;
|
||||||
|
|
||||||
public class FitRecorder implements ModelValidator {
|
public class FitRecorder implements ModelValidator {
|
||||||
|
|
||||||
private static FileOutputStream FileOr = null;
|
private HashMap<Integer, Writer> writersPerSession;
|
||||||
private static Writer writer;
|
|
||||||
private HashMap<Integer, Writer> files;
|
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger log = CLogger.getCLogger(FitRecorder.class);
|
private static CLogger log = CLogger.getCLogger(FitRecorder.class);
|
||||||
|
@ -112,7 +104,7 @@ public class FitRecorder implements ModelValidator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ModelValidationEngine engine, MClient client) {
|
public void initialize(ModelValidationEngine engine, MClient client) {
|
||||||
files=new HashMap<Integer, Writer>();
|
writersPerSession=new HashMap<Integer, Writer>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -178,7 +170,7 @@ public class FitRecorder implements ModelValidator {
|
||||||
try {
|
try {
|
||||||
if (type == TYPE_AFTER_NEW ) {
|
if (type == TYPE_AFTER_NEW ) {
|
||||||
|
|
||||||
if(po instanceof MSession){
|
if (po instanceof MSession) {
|
||||||
loginFixture(po);
|
loginFixture(po);
|
||||||
}
|
}
|
||||||
if (dontLogTables.contains(po.get_TableName().toUpperCase()))
|
if (dontLogTables.contains(po.get_TableName().toUpperCase()))
|
||||||
|
@ -305,18 +297,15 @@ public class FitRecorder implements ModelValidator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (po instanceof MSession){
|
if (po instanceof MSession) {
|
||||||
if (type == TYPE_AFTER_CHANGE) {
|
if (type == TYPE_AFTER_CHANGE) {
|
||||||
MSession session =(MSession) po;
|
MSession session = (MSession) po;
|
||||||
if(session.isProcessed()){
|
if (session.isProcessed()) {
|
||||||
String msg=closefile();
|
closefile();
|
||||||
if (msg != null){
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return e.getLocalizedMessage();
|
return e.getLocalizedMessage();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -490,58 +479,56 @@ public class FitRecorder implements ModelValidator {
|
||||||
String msg=null;
|
String msg=null;
|
||||||
String preference = Env.getPreference(Env.getCtx(), 0, "FitRecorder", false);
|
String preference = Env.getPreference(Env.getCtx(), 0, "FitRecorder", false);
|
||||||
if (preference.equals("Y")) {
|
if (preference.equals("Y")) {
|
||||||
int Session_ID = po.get_ID();
|
int session_ID = po.get_ID();
|
||||||
int User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
|
int user_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID");
|
||||||
int AD_Org_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Org_ID");
|
int org_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Org_ID");
|
||||||
MUser user = new MUser(Env.getCtx(), User_ID, null);
|
MUser user = new MUser(Env.getCtx(), user_ID, null);
|
||||||
String name = Ini.getAdempiereHome() + "/log/fit_test_" + Session_ID+ user.getName() + ".txt";
|
String name = Ini.getAdempiereHome() + "/log/fit_test_" + session_ID+ user.getName() + ".txt";
|
||||||
File fileNameOr;
|
|
||||||
try {
|
try {
|
||||||
fileNameOr = new File(name);
|
File file = new File(name);
|
||||||
FileOr = new FileOutputStream(fileNameOr, true);
|
FileOutputStream fos = new FileOutputStream(file, true);
|
||||||
writer = new BufferedWriter(new OutputStreamWriter(FileOr,
|
Writer writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF8"));
|
||||||
"UTF8"));
|
Env.setContext(Env.getCtx(), "#AD_Session_ID", session_ID);
|
||||||
files.put(Session_ID, writer);
|
writersPerSession.put(session_ID, writer);
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
writer.append("LOGIN");
|
writeFile("LOGIN");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
writer.append("!");
|
writeFile("!");
|
||||||
writer.append("|Login|");
|
writeFile("|Login|");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
writer.append("|User|");
|
writeFile("|User|");
|
||||||
if (MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN,
|
if (MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN,
|
||||||
false))
|
false))
|
||||||
writer.append(user.getEMail() + "|");
|
writeFile(user.getEMail() + "|");
|
||||||
else if (user.getLDAPUser() != null)
|
else if (user.getLDAPUser() != null)
|
||||||
writer.append(user.getLDAPUser() + "|");
|
writeFile(user.getLDAPUser() + "|");
|
||||||
else
|
else
|
||||||
writer.append(user.getName() + "|");
|
writeFile(user.getName() + "|");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
writer.append("|Password|");
|
writeFile("|Password|");
|
||||||
writer.append(" |");
|
writeFile(" |");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
writer.append("|AD_Client_ID|");
|
writeFile("|AD_Client_ID|");
|
||||||
MClient client = MClient.get(Env.getCtx(),Env.getContextAsInt(Env.getCtx(), "#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|");
|
writeFile("@Ref=AD_Client[Name='" + client.getName() + "'].AD_Client_ID|");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
writer.append("|AD_Org_ID|");
|
writeFile("|AD_Org_ID|");
|
||||||
String orgName = DB.getSQLValueString(null,"SELECT Name FROM AD_Org WHERE AD_Org_ID=?", AD_Org_ID);
|
String orgName = DB.getSQLValueString(null,"SELECT Name FROM AD_Org WHERE AD_Org_ID=?", org_ID);
|
||||||
writer.append("@Ref=AD_Org[Name='" + orgName + "'].AD_Org_ID|");
|
writeFile("@Ref=AD_Org[Name='" + orgName + "'].AD_Org_ID|");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
writer.append("|AD_Role_ID|");
|
writeFile("|AD_Role_ID|");
|
||||||
writer.append("@Ref=AD_Role[Name='"+ Env.getContext(Env.getCtx(), "#AD_Role_Name")+ "'].AD_Role_ID|");
|
writeFile("@Ref=AD_Role[Name='"+ Env.getContext(Env.getCtx(), "#AD_Role_Name")+ "'].AD_Role_ID|");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
int warehouseid = Env.getContextAsInt(Env.getCtx(),Env.M_WAREHOUSE_ID);
|
int warehouseid = Env.getContextAsInt(Env.getCtx(),Env.M_WAREHOUSE_ID);
|
||||||
if (warehouseid > 0) {
|
if (warehouseid > 0) {
|
||||||
MWarehouse warehouse = MWarehouse.get(Env.getCtx(),warehouseid);
|
MWarehouse warehouse = MWarehouse.get(Env.getCtx(),warehouseid);
|
||||||
writer.append("|M_Warehouse_ID|");
|
writeFile("|M_Warehouse_ID|");
|
||||||
writer.append("@Ref=M_Warehouse[Name='" + warehouse.getName()+ "'].M_Warehouse_ID|");
|
writeFile("@Ref=M_Warehouse[Name='" + warehouse.getName()+ "'].M_Warehouse_ID|");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
}
|
}
|
||||||
writer.append("|*Login*|");
|
writeFile("|*Login*|");
|
||||||
writer.append("\n");
|
writeFile("\n");
|
||||||
files.put(Session_ID, writer);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return e.getLocalizedMessage();
|
return e.getLocalizedMessage();
|
||||||
}
|
}
|
||||||
|
@ -550,27 +537,24 @@ public class FitRecorder implements ModelValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeFile(String msg){
|
public void writeFile(String msg){
|
||||||
int Session_ID=Env.getContextAsInt(Env.getCtx(), "#AD_Session_ID");
|
int session_ID=Env.getContextAsInt(Env.getCtx(), "#AD_Session_ID");
|
||||||
Writer writerOr=(Writer) files.get(Session_ID);
|
Writer writer = (Writer) writersPerSession.get(session_ID);
|
||||||
try{
|
if (writer != null) {
|
||||||
writerOr.append(msg);
|
try{
|
||||||
writerOr.flush();
|
writer.append(msg);
|
||||||
|
writer.flush();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String closefile(){
|
public void closefile(){
|
||||||
String msg=null;
|
|
||||||
int Session_ID=Env.getContextAsInt(Env.getCtx(), "#AD_Session_ID");
|
int Session_ID=Env.getContextAsInt(Env.getCtx(), "#AD_Session_ID");
|
||||||
Writer writerOr=(Writer) files.get(Session_ID);
|
Writer writer = (Writer) writersPerSession.get(Session_ID);
|
||||||
try {
|
if (writer != null) {
|
||||||
writerOr.close();
|
try {
|
||||||
} catch (IOException e) {
|
writer.close();
|
||||||
// TODO Auto-generated catch block
|
writersPerSession.remove(Session_ID);
|
||||||
return e.getLocalizedMessage();
|
} catch (IOException e) {}
|
||||||
}
|
}
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue