Commit bb9b125c authored by vdhoble's avatar vdhoble

scheduler for audit trail -REQ ID : S15DSUN002


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@98365 ce508802-f39f-4f6c-b175-0d175dae99d5
parent a67150af
package ibase.webitm.ejb.sys;
/********************************************************
Title :DespatchSchedule[D14LSUN009]
Date : 13/04/15
Developer: Vishakha
********************************************************/
import ibase.scheduler.utility.interfaces.Schedule;
import java.util.*;
import java.sql.*;
import org.w3c.dom.*;
import java.io.File;
import java.io.FileOutputStream;
import javax.naming.InitialContext;
import javax.xml.rpc.ParameterMode;
import ibase.webitm.ejb.DBAccessRemote;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import ibase.system.config.*;
import ibase.utility.CommonConstants;
import java.text.SimpleDateFormat;
import ibase.utility.E12GenericUtility;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class WFAuditTraillScheduler extends ValidatorEJB implements Schedule
{
String chgUser = null;
String chgTerm = null;
static long count_records=0;
boolean isError = false;
String loginSiteCode = "";
String retString="";
E12GenericUtility e12GenericUtility = new E12GenericUtility();
FileOutputStream fos1 = null;
java.util.Date startDate = new java.util.Date(System.currentTimeMillis());
Calendar calendar = Calendar.getInstance();
String startDateStr = null;
public static void main(String args[])
{
WFAuditTraillScheduler ecs=new WFAuditTraillScheduler();
System.out.println("Main Method Calling*************************************Audit Trial");
}
public String schedulePriority( String wrkflwPriority )throws Exception
{
return "";
}
public String schedule(HashMap map)throws Exception
{
return "";
}
public String schedule(String scheduleParamXML)throws Exception
{
String siteCode = "",actualLoginSiteCode="",errString="";
String xtraParams = "";
ibase.utility.UserInfoBean userInfo = null;
try
{
System.out.println("************ ["+scheduleParamXML+"]");
userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
siteCode = userInfo.getSiteCode();
xtraParams = "loginEmpCode="+userInfo.getEmpCode()+"~~termId="+userInfo.getRemoteHost()+"~~loginSiteCode="+loginSiteCode;
GenericUtility genericUtility=GenericUtility.getInstance();
Document dom=genericUtility.parseString(scheduleParamXML);
NodeList paramList = dom.getElementsByTagName( "SCHEDULE" );
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
int childNodeListLength = 0;
String childNodeName = null;
int lineNo = 1;
parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
/*if(childNodeName!=null && !"#text".equalsIgnoreCase(childNodeName))
{
if(ctr==0)
{
actualLoginSiteCode=childNode.getFirstChild().getNodeValue();
}
}*/
}
System.out.println("ActualLoginSiteCode----["+actualLoginSiteCode+"]");
System.out.println("intializingLog$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$........."+ intializingLog("audit_trial_log"));
errString = auditTrialSch(xtraParams);
}
catch(Exception e)
{
throw new Exception(e);
}
System.out.println("errString>>>["+errString+"]");
return errString;
}
public String auditTrialSch(String xtraParams) throws Exception
{
System.out.println("Insiding*****AuditTrialScheduler **************************");
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
PreparedStatement pstmt1 = null,pstmt2=null;
ResultSet rs1 = null,rs2=null;
String sql="";
String refId="",ChgId = "";
String childNodeName = null;
String sql1="";
String errString ="";
String strToWrite = "";
String endDateStr = null;
String objName = "";
String methodName = "",compName = "",compType="",retString = "",serviceCode = "",serviceURI = "",actionURI = "";
String forcedFlag="N",addUser = "",addTerm = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null; int childNodeListLength;int ctr=0;
Document dom = null;
Document formDom = null;
InitialContext ctx = null;
String xmlString = null;
int noForms=0;
String domID="0";
String prcInstWf="";
int lineNo=0;
String refSer="";
String fieldName = "",newValue = "",oldValue = "";int detailsLen = 0;
String processId="",instanceId="",activityId="",seqId="";
E12GenericUtility genericUtility = new E12GenericUtility();
SimpleDateFormat sdf = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
java.util.Date startDate = new java.util.Date(System.currentTimeMillis());
java.util.Date endDate = new java.util.Date(System.currentTimeMillis());
java.sql.Timestamp sysDate = null;
try
{
sysDate = new java.sql.Timestamp(System.currentTimeMillis());
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
conn.setAutoCommit(false);
SimpleDateFormat sdf1 = new SimpleDateFormat(e12GenericUtility.getDBDateFormat());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
java.util.Calendar cal = java.util.Calendar.getInstance();
sql1 = "select chg_id,obj_name,ref_id,chg_user,chg_date,chg_term,tran_id,prc_inst__wf,wf_action from audit_trail where prc_inst__wf is not null and prc_inst__wf not in(select process_id||':'||instance_id||':'||activity_id||':'||seq_id from wf_audit_data) order by ref_id ";
pstmt1 = conn.prepareStatement(sql1);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
lineNo=0;
refId = rs1.getString("ref_id");
ChgId = rs1.getString("chg_id");
objName = rs1.getString("obj_name");
prcInstWf=rs1.getString("prc_inst__wf");
System.out.println("refID is ["+refId+"]ChgId is["+ChgId+"]");
String prcInstWfArr[]=prcInstWf.split(":");
for(int i=0;i<prcInstWfArr.length;i++)
{
processId=prcInstWfArr[0];
instanceId=prcInstWfArr[1];
activityId=prcInstWfArr[2];
seqId=prcInstWfArr[3];
}
sql="select count(1) from obj_forms where win_name=?";
pstmt2=conn.prepareStatement(sql);
pstmt2.setString(1,"w_"+objName);
rs2=pstmt2.executeQuery();
if(rs2.next())
{
noForms=rs2.getInt(1);
}
rs2.close();
rs2=null;
pstmt2.close();
pstmt2=null;
sql="select ref_ser from transetup where tran_window=?";
pstmt2=conn.prepareStatement(sql);
pstmt2.setString(1,"w_"+objName);
rs2=pstmt2.executeQuery();
if(rs2.next())
{
refSer=rs2.getString(1);
}
rs2.close();
rs2=null;
pstmt2.close();
pstmt2=null;
System.out.println("Generating XML String....");
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext(appConnect.getProperty());
DBAccessRemote dbAccess = (DBAccessRemote)ctx.lookup("ibase/DBAccessEJB/remote");
String query = "SELECT CHG_XML FROM AUDIT_TRAIL WHERE CHG_ID = ? AND OBJ_NAME=? AND TRIM(REF_ID)=?";
ArrayList bindVarValues = new ArrayList();
ArrayList bindVarTypes = new ArrayList();
bindVarValues.add(ChgId);
bindVarValues.add(objName);
bindVarValues.add(refId);
System.out.println("query "+query);
System.out.println("chgID ["+ChgId+"]");
System.out.println("recObjName ["+objName+"]");
System.out.println("refID ["+refId+"]");
bindVarTypes.add("String");
bindVarTypes.add("String");
bindVarTypes.add("String");
xmlString = dbAccess.getBlob(query, bindVarValues, bindVarTypes);
System.out.println("xmlString !@! "+xmlString);
xmlString=checkNull(xmlString);
System.out.println(" refId:::::::::" + refId);
strToWrite = refId+",";
startDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
startDateStr = sdf1.format(startDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
strToWrite=strToWrite+startDateStr+",";
if(xmlString.trim().length()>0)
{
dom = parseString(xmlString);// read xmldataAll
for(int formNo=1;formNo<=noForms;formNo++)
{
parentNodeList=dom.getElementsByTagName("Detail"+formNo);
if(parentNodeList.getLength()>0)
{
lineNo++;
newValue=genericUtility.getColumnValueFromNode("new_value",parentNodeList.item(0));
oldValue=genericUtility.getColumnValueFromNode("old_value",parentNodeList.item(0));
fieldName=genericUtility.getColumnValueFromNode("field_name",parentNodeList.item(0));
//domID=parentNodeList.item(0).getAttributes().getNamedItem("domID").getNodeValue();
addUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginEmpCode");
addTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
System.out.println("XTRAPARMS ======"+xtraParams);
System.out.println(" ADD user ==="+addUser);
System.out.println(" ADD Term ==="+addTerm);
System.out.println(" ADD date ==="+sysDate);
System.out.println("lineNo["+lineNo+"]");
//domID=getCurrentdomIDFlag(parentNodeList.item(0));
sql=" INSERT INTO WF_AUDIT_DATA(PROCESS_ID,INSTANCE_ID,"
+ "ACTIVITY_ID,SEQ_ID,FORM_NO,"
+ "LINE_NO,COL_NAME,COL_VALUE,COL_VALUE_O,"
+ "REF_ID,REF_SER,OBJ_NAME,ADD_DATE,ADD_USER,ADD_TERM"
+ ") "
+ " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
pstmt2=conn.prepareStatement(sql);
pstmt2.setString(1,processId);
pstmt2.setString(2,instanceId);
pstmt2.setString(3,activityId);
pstmt2.setString(4,seqId);
pstmt2.setString(5,Integer.toString(formNo));
pstmt2.setInt(6,lineNo);
pstmt2.setString(7,fieldName);
pstmt2.setString(8,newValue);
pstmt2.setString(9,oldValue);
pstmt2.setString(10,refId);
pstmt2.setString(11,refSer);
pstmt2.setString(12,objName);
pstmt2.setTimestamp(13,sysDate);
pstmt2.setString(14,addUser);
pstmt2.setString(15,addTerm);
int retCnt=pstmt2.executeUpdate();
if(retCnt>0)
{
conn.commit();
}
else
{
conn.rollback();
}
}
}
}
/*System.out.println("STARTING DATE"+startDateStr +"STRING TO WRITE"+strToWrite);
endDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
endDateStr = sdf1.format(endDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
System.out.println("**** DESPATCH completed for.....[" + tranId + "] at [" + endDateStr + "]" );
strToWrite=strToWrite+endDateStr+",";
strToWrite = strToWrite + retString+"\r\n\r\n";
fos1.write(strToWrite.getBytes());
System.out.println("End Time for transaction"+endDateStr+"string to write"+strToWrite);*/
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
}
catch(SQLException se)
{
isError = true;
System.out.println("Exception : audit Trial Scheduler" +se.getMessage());
try
{
conn.rollback();
}
catch(Exception se1){}
throw new ITMException(se);
}finally
{
if(conn != null)
{
if(pstmt!=null)
{
pstmt.close();
pstmt=null;
}
if(rs!=null)
{
rs.close();
rs=null;
}
conn.close();
conn= null;
}
}
System.out.println("errString........:: " + errString);
return errString;
}
private String intializingLog(String fileName)
{
String log="intializingLog_Failed";
String strToWrite = "";
String currTime = null;
try{
SimpleDateFormat sdf1 = new SimpleDateFormat(e12GenericUtility.getDBDateFormat());
try
{
currTime = sdf1.format(new Timestamp(System.currentTimeMillis())).toString();
currTime = currTime.replaceAll("-","");
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
fileName = fileName+currTime+calendar.get(Calendar.HOUR)+""+calendar.get(Calendar.MINUTE)+".csv";
fos1 = new FileOutputStream(CommonConstants.JBOSSHOME + File.separator +"EDI"+File.separator+fileName);
}
catch(Exception e)
{
System.out.println("Exception []::"+e.getMessage());
e.printStackTrace();
}
startDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
startDateStr = sdf1.format(startDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
fos1.write(("Fetching Records Started At " + startDateStr +"\r\n").getBytes());
}
catch(Exception e)
{
System.out.println("Exception []::"+e.getMessage());
e.printStackTrace();
}
log ="intializingLog_Successesfull";
return log;
}
public String checkNull(String input)
{
if (input == null)
{
input="";
}
return input.trim();
}
private String getCurrentdomIDFlag(Node currDetail)
{
NodeList currDetailList = null;
String updateStatus = "",nodeName = "";
int currDetailListLength = 0;
currDetailList = currDetail.getChildNodes();
currDetailListLength = currDetailList.getLength();
for (int i=0;i< currDetailListLength;i++)
{
nodeName = currDetailList.item(i).getNodeName();
if (nodeName.equalsIgnoreCase("Attribute"))
{
updateStatus = currDetailList.item(i).getAttributes().getNamedItem("domID").getNodeValue();
break;
}
}
return updateStatus;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment