Commit a442154e authored by ysawant's avatar ysawant

*Added HRLogWriter component

HRLogWriter.java


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@205761 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 7793afaa
package ibase.webitm.ejb.adm;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.w3c.dom.Document;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException;
public class HRLogWriter
{
//HRLogWriter hrLogWriter = null;
private String jobID = "", objName = "", statusDetail = "", statusType = "", currentProcess = "", logFileName = "",
wsrLogFileName = "", LogLocationType ="", LogServerAddress ="", activity = "", errorCode = "",processId = "",
logFileCreatedBy = "", jobTerminateRequested = "",transactionCreatedBy = "", inetCreatedBy = "", userId ="",
termId = "", returnUpdError = "", fileNameStartWith = "", filePrefix = "", logFilePath = "", overWrite = ""
, loginSite = "";
private int rowsRejected = 0,rowsIgnored = 0,rowsProcessed = 0,totalRows = 0;
private int lineNo = 0, filePointer = -1, logLineNo = 0, logWriterFlag;
private Timestamp startDateTime = null;
private boolean isJobIdCreated = false;
FileOutputStream fileWriterLog = null;
public String getTermId() {
return termId;
}
public void setTermId(String termId) {
this.termId = termId;
}
public String getLogFilePath() {
return logFilePath;
}
public void setLogFilePath(String logFilePath) {
this.logFilePath = logFilePath;
}
public String getFilePrefix() {
return filePrefix;
}
public void setFilePrefix(String filePrefix) {
this.filePrefix = filePrefix;
}
public String getOverWrite() {
return overWrite;
}
public void setOverWrite(String overWrite) {
this.overWrite = overWrite;
}
public String getJobID() {
return jobID;
}
public void setJobID(String jobID) {
this.jobID = jobID;
}
public String getObjName() {
return objName;
}
public void setObjName(String objName) {
this.objName = objName;
}
public String getStatusDetail() {
return statusDetail;
}
public void setStatusDetail(String statusDetail) {
this.statusDetail = statusDetail;
}
public String getStatusType() {
return statusType;
}
public void setStatusType(String statusType) {
this.statusType = statusType;
}
public String getCurrentProcess() {
return currentProcess;
}
public void setCurrentProcess(String currentProcess) {
this.currentProcess = currentProcess;
}
public String getLogFileName() {
return logFileName;
}
public void setLogFileName(String logFileName) {
this.logFileName = logFileName;
}
public String getWsrLogFileName() {
return wsrLogFileName;
}
public void setWsrLogFileName(String wsrLogFileName) {
this.wsrLogFileName = wsrLogFileName;
}
public String getLogLocationType() {
return LogLocationType;
}
public void setLogLocationType(String logLocationType) {
LogLocationType = logLocationType;
}
public String getLogServerAddress() {
return LogServerAddress;
}
public void setLogServerAddress(String logServerAddress) {
LogServerAddress = logServerAddress;
}
public String getActivity() {
return activity;
}
public void setActivity(String activity) {
this.activity = activity;
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public String getProcessId() {
return processId;
}
public void setProcessId(String processId) {
this.processId = processId;
}
public String getLogFileCreatedBy() {
return logFileCreatedBy;
}
public void setLogFileCreatedBy(String logFileCreatedBy) {
this.logFileCreatedBy = logFileCreatedBy;
}
public String getJobTerminateRequested() {
return jobTerminateRequested;
}
public void setJobTerminateRequested(String jobTerminateRequested) {
this.jobTerminateRequested = jobTerminateRequested;
}
public String getTransactionCreatedBy() {
return transactionCreatedBy;
}
public void setTransactionCreatedBy(String transactionCreatedBy) {
this.transactionCreatedBy = transactionCreatedBy;
}
public String getInetCreatedBy() {
return inetCreatedBy;
}
public void setInetCreatedBy(String inetCreatedBy) {
this.inetCreatedBy = inetCreatedBy;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getReturnUpdError() {
return returnUpdError;
}
public void setReturnUpdError(String returnUpdError) {
this.returnUpdError = returnUpdError;
}
public String getFileNameStartWith() {
return fileNameStartWith;
}
public void setFileNameStartWith(String fileNameStartWith) {
this.fileNameStartWith = fileNameStartWith;
}
public int getRowsRejected() {
return rowsRejected;
}
public void setRowsRejected(int rowsRejected) {
this.rowsRejected = rowsRejected;
}
public int getRowsIgnored() {
return rowsIgnored;
}
public void setRowsIgnored(int rowsIgnored) {
this.rowsIgnored = rowsIgnored;
}
public int getRowsProcessed() {
return rowsProcessed;
}
public void setRowsProcessed(int rowsProcessed) {
this.rowsProcessed = rowsProcessed;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public int getLineNo() {
return lineNo;
}
public void setLineNo(int lineNo) {
this.lineNo = lineNo;
}
public int getFilePointer() {
return filePointer;
}
public void setFilePointer(int filePointer) {
this.filePointer = filePointer;
}
public int getLogLineNo() {
return logLineNo;
}
public void setLogLineNo(int logLineNo) {
this.logLineNo = logLineNo;
}
public int getLogWriterFlag() {
return logWriterFlag;
}
public void setLogWriterFlag(int logWriterFlag) {
this.logWriterFlag = logWriterFlag;
}
public Timestamp getStartDateTime() {
return startDateTime;
}
public void setStartDateTime(Timestamp startDateTime) {
this.startDateTime = startDateTime;
}
public boolean isJobIdCreated() {
return isJobIdCreated;
}
public void setJobIdCreated(boolean isJobIdCreated) {
this.isJobIdCreated = isJobIdCreated;
}
public FileOutputStream getFileWriterLog() {
return fileWriterLog;
}
public void setFileWriterLog(FileOutputStream fileWriterLog) {
this.fileWriterLog = fileWriterLog;
}
public String getLoginSite() {
return loginSite;
}
public void setLoginSite(String loginSite) {
this.loginSite = loginSite;
}
private String createHrJobId(Connection logConn) throws RemoteException, ITMException
{
String lsRetVal = "";
long llJobId = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
UtilMethods utilmethod = new UtilMethods();
try
{
System.out.println("Inside HRLogWriter.createHrJobId()");
sql = "select hrbackgroundjobseq.nextval as nextval from dual";
pstmt = logConn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
llJobId = rs.getInt("nextval");
System.out.println("llJobId == "+llJobId);
lsRetVal = "HMS" + utilmethod.right("000000000000000" + String.valueOf(llJobId), 12);
return lsRetVal;
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
System.out.println("Exception : AttendanceProcess.gbfAutoAttdProc() : " + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return lsRetVal;
}
public void initializeHRLogWriter(String argStrObjName ,String argStrJobId, String argStrUserId, String argStrTermID, String argStrActivity, String argStrFilePrefix , String argsLoginSite, Connection logConn) throws RemoteException, ITMException
{
System.out.println("Inside HRLogWriter.initializeHRLogWriter method");
String filePath = "", isCurrentLine = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
StringBuffer xmlFileData = new StringBuffer();
E12GenericUtility genericUtility = new E12GenericUtility();
UtilMethods utilMethod = new UtilMethods();
String logLocationType = "", logServerAddress = "";
int cnt = 0;
int liRet = 0;
Timestamp ldtCurrent = null;
SimpleDateFormat sdf = null;
try
{
Timestamp timestamp = null;
timestamp = new Timestamp(System.currentTimeMillis());
sdf = new SimpleDateFormat(genericUtility.getApplDateTimeFormat());
String currDateStr = sdf.format(timestamp);
System.out.println("currDateStr--["+currDateStr+"]");
currDateStr = genericUtility.getValidDateTimeString(currDateStr, genericUtility.getApplDateTimeFormat(), genericUtility.getDBDateTimeFormat());
System.out.println("currDateStr--["+currDateStr+"]");
ldtCurrent = Timestamp.valueOf(currDateStr);
setUserId(argStrUserId);
setLoginSite(argsLoginSite);
setObjName(argStrObjName);
setTermId(argStrTermID);
if(argStrFilePrefix == null || argStrFilePrefix.trim().length() == 0)
{
argStrFilePrefix = "HRLOG";
}
setFilePrefix(argStrFilePrefix);
filePath = CommonConstants.JBOSSHOME + File.separator + "server" + File.separator + "default" + File.separator + "deploy" + File.separator + "ibase.ear" + File.separator + "ibase.war" + File.separator + "setting" + File.separator +"init.xml";
File file = new File(filePath);
try
{
BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath));
while ((isCurrentLine = bufferedReader.readLine()) != null)
{
System.out.println("isCurrentLine =" + isCurrentLine.trim());
if (isCurrentLine.trim().length() > 0)
{
xmlFileData.append(isCurrentLine.trim());
}
}
}
catch (FileNotFoundException e)
{
System.out.println("getMetaData in ParentMetaDataServlet ********* ");
} catch (IOException e)
{
e.printStackTrace();
}
System.out.println(" xmlFileData.toString().replace :=" + xmlFileData.toString().replace("//", "").trim());
String xmlMetadata = xmlFileData.toString().replace("//", "").trim();
xmlMetadata = xmlMetadata.replace('"', ' ').trim();
Document domInitData = genericUtility.parseString(xmlMetadata);
System.out.println("xmlMetadata ==> "+xmlMetadata);
System.out.println("domInitData == > "+domInitData);
logLocationType = getLogLocationType();
logServerAddress = getLogServerAddress();
if(logLocationType == null || logLocationType.trim().length() == 0)
{
logLocationType = checkNull(genericUtility.getColumnValue("Log_Location_Type", domInitData));
if(logLocationType == null || logLocationType.trim().length() == 0)
{
logLocationType = "N";
}
else
{
if(logLocationType.trim().equalsIgnoreCase("B") || logLocationType.trim().equalsIgnoreCase("S"))
{
logServerAddress = checkNull(genericUtility.getColumnValue("Log_Server_Address", domInitData));
if(logServerAddress == null || logServerAddress.trim().length() == 0 )
{
logServerAddress = "";
logLocationType = "N";
}
}
else if(!(logLocationType.trim().equalsIgnoreCase("D")))
{
logLocationType = "N";
getFileName(logConn);
System.out.println("Log file name after calling getFileName()"+getLogFileName());
}
}
}
//logWriter.setLogLocationType(logLocationType);
//logWriter.setLogServerAddress(logServerAddress);
setLogLocationType(logLocationType);
setLogServerAddress(logServerAddress);
//logWriter.setlogWriterFlag(liRet);
setLogWriterFlag(liRet);
if(!file.exists())
{
System.out.println("File does not exist");
setLogLocationType("N");
}
if(argStrJobId != null && argStrJobId.trim().length() > 0)
{
setLogLocationType("D");
}
else
{
System.out.println("getLogLocationType::: ["+getLogLocationType()+"] ");
if("D".equalsIgnoreCase(getLogLocationType()))
{
System.out.println("Calling createHrJobId()");
argStrJobId = createHrJobId(logConn);
sql = "insert into Background_Job (job_id, created_date, obj_name, obj_type, job_stat, user_id, exec_date, login_site)" +
" values (?, ?, ?, 'P', 'P', ?, ?, ?)";
//" values (:ls_job_id, sysdate, :istr_log_writer.obj_name, 'P', 'P', :userid, sysdate, :login_site)";
pstmt = logConn.prepareStatement(sql);
pstmt.setString(1, argStrJobId);
pstmt.setTimestamp(2, ldtCurrent);
pstmt.setString(3, argStrObjName);
pstmt.setString(4, argStrUserId);
pstmt.setTimestamp(5, ldtCurrent);
pstmt.setString(6, argsLoginSite);
int updCnt = pstmt.executeUpdate();
if(updCnt == 0)
{
setJobID(null);
setLogLocationType("N");
}
else
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
setJobID(argStrJobId);
logConn.commit();
}
System.out.println("Created Job Id is :: ["+getJobID()+"]");
}
}
if("N".equalsIgnoreCase(getLogLocationType()))
{
System.out.println("Log file name : "+getLogFileName());
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
private void getFileName(Connection logConn) throws RemoteException, ITMException
{
System.out.println("Inside HRLogWriter.getFileName method");
String lsPath = "", lsOvWrt = "N", lsFileName = "";
int liRet = 0;
E12GenericUtility genericUtility = new E12GenericUtility();
UtilMethods utilmethod = new UtilMethods();
try
{
System.out.println("Inside HRLogWriter : getFileName method");
///home/base/wildfly/applnlog/Payroll Process-To-Track-Exceptions
lsPath = CommonConstants.JBOSSHOME + File.separator + "applnlog" + File.separator + getFilePrefix();
setLogFilePath(lsPath);
setOverWrite("N");
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
String todayDateTime = sdf.format(cal.getTime());
System.out.println("todayDateTime::::: " + todayDateTime);
if(getOverWrite() == "N")
{
lsFileName = getLogFilePath() + getFilePrefix().toUpperCase() + "_" + getUserId().toUpperCase() + "_"
+ getTermId().toUpperCase() + "_" + todayDateTime + ".LOG";
System.out.println("lsFileName:::: " + lsFileName);
}
else
{
lsFileName = getLogFilePath() + getFilePrefix() + ".LOG";
System.out.println("lsFileName of else :::: " + lsFileName);
}
setLogFileName(lsFileName);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
public void gbfErrWrite(String asPrdCode, String asEmpCode, String asType, String asErrCode, String asSeverity, Connection logConn) throws ITMException
{
System.out.println("Inside HRLogWriter.gbfErrWrite method with 5 parameters....");
E12GenericUtility genericUtility = new E12GenericUtility();
String lsStr = "" , lsErr = "" , lsErrCode = "";
String userInfoStr = "",chgTerm = "",argloginSite = "",xtraParams = "",userId = "";
try
{
/*userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"));
chgTerm = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId"));
loginSite = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));*/
userId = getUserId();
chgTerm = getTermId();
argloginSite = getLoginSite();
System.out.println("userId :: ["+userId+"] chgTerm :: ["+chgTerm+"] argloginSite :: ["+argloginSite+"]");
if(asPrdCode != null && asPrdCode.trim().length() > 0)
{
lsErr = lsErr + "Prd : " + asPrdCode;
}
if(asEmpCode != null && asEmpCode.trim().length() > 0)
{
lsErr = lsErr + " Emp : " + asEmpCode + " - ";
}
if(asErrCode != null && asErrCode.trim().length() > 0)
{
lsStr = asErrCode;
asErrCode = getToken(lsStr,"~t");
}
setStatusDetail(lsErr + getCurrentProcess().trim() + " " + lsStr);
setErrorCode(asErrCode);
setStatusType(asSeverity);
gfLogWriter(logConn);
lsErrCode = getReturnUpdError();
System.out.println("lsErrCode coming from gfLogWriter Method:::: " + lsErrCode);
if(lsErrCode != null && lsErrCode.trim().length() > 0)
{
setReturnUpdError(lsErrCode);
setLogWriterFlag(-1);
}
else
{
setLogWriterFlag(1);
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
public void gbfErrWrite(String asPrdCode, String asEmpCode, String asType, String asErrCode, String asSeverity,int Num,Connection logConn) throws ITMException
{
System.out.println("Inside HRLogWriter.gbfErrWrite method with 6 parameters....");
try
{
setTotalRows(getTotalRows() + 1);
if(Num == 1)
{
setRowsProcessed(getRowsProcessed() + 1);
gbfErrWrite(asPrdCode, asEmpCode, asType, asErrCode, asSeverity,logConn);
}
else if(Num == 2)
{
setRowsRejected(getRowsRejected() + 1);
gbfErrWrite(asPrdCode, asEmpCode, asType, asErrCode, asSeverity,logConn);
}
else if(Num == 3)
{
setRowsIgnored(getRowsIgnored() + 1);
gbfErrWrite(asPrdCode, asEmpCode, asType, asErrCode, asSeverity,logConn);
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
public void gfLogWriter(Connection logConn) throws ITMException, IOException
{
System.out.println("Inside HRLogWriter.gfLogWriter method....");
ResultSet rs = null;
PreparedStatement pstmt = null;
FileOutputStream output = null;
String sql = "";
String lsStr = "", lsMsg = "", lsErr = "", lsReturnErrcode = "", lsSeverity = "I" , lsErrorCode = "", lsErrorCode1 = "";
String lsMsgStr = "",lsDescr = "", lsCurrentProcess = "", lsActivity = "" , lsMsgType = "",jobId = "",logLocationType = "";
String lsTempData = "", lsUrl = "", lsKey = "";
try
{
lsSeverity = getStatusType();
lsCurrentProcess = getCurrentProcess();
lsActivity = getActivity();
lsErrorCode = getErrorCode();
lsErrorCode1 = getErrorCode();
System.out.println("lsSeverity::: " + lsSeverity + " lsCurrentProcess::: " + lsCurrentProcess + " lsActivity:::: " + lsActivity +
" lsErrorCode:::" + lsErrorCode + " lsErrorCode1::: " + lsErrorCode1);
if(lsSeverity == null || lsSeverity.trim().length() == 0)
{
lsSeverity = "I";
}
lsStr = lsStr + " " + getStatusDetail();
System.out.println("lsStr::: " + lsStr);
if(lsErrorCode != null && lsErrorCode.trim().length() > 0)
{
lsErrorCode1 = getToken(lsErrorCode1 , "~t");
sql = "select case when msg_str is null then ' ' else msg_str end as msg_str, case when msg_descr is null then ' '"+
" else msg_descr end as msg_descr, case when msg_type is null then 'E' else msg_type end as msg_type "+
"from messages where msg_no = ? ";
pstmt = logConn.prepareStatement(sql);
pstmt.setString(1, lsErrorCode1);
rs = pstmt.executeQuery();
if(rs.next())
{
lsMsgStr = checkNull(rs.getString("msg_str"));
lsDescr = checkNull(rs.getString("msg_descr"));
lsMsgType = checkNull(rs.getString("msg_type"));
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("lsMsgStr::: " + lsMsgStr + " lsDescr::: " + lsDescr + " lsMsgType::: " + lsMsgType);
if(lsMsgStr == null || lsMsgStr.trim().length() == 0)
{
lsMsgStr = "";
}
else
{
lsMsgStr = lsMsgStr.trim();
lsMsg = lsMsg + lsMsgStr;
}
if(lsDescr == null || lsDescr.trim().length() == 0)
{
lsDescr = "";
}
else
{
if(lsMsgStr.trim().length() > 0)
{
lsMsg = lsMsg + "-" + lsDescr.trim();
}
else
{
lsMsg = lsMsg + lsDescr.trim();
}
}
lsMsg = "(" + lsErrorCode1 + ") " + lsMsg;
lsStr = lsStr + " " + lsMsg;
}
System.out.println("lsStr::: " + lsStr + " lsMsg::: " + lsMsg);
if("E".equalsIgnoreCase(lsSeverity) || (lsMsgType != null && "E".equalsIgnoreCase(lsMsgType)))
{
lsStr = "(ERROR$)-" + lsStr;
}
else
{
lsStr = "(INFORMATION$)-" + lsStr;
}
if(lsStr != null && lsStr.trim().length() > 0)
{
lsStr = lsStr.replace( '"' , ' ');
}
System.out.println("lsStr got replaced::: " + lsStr);
jobId = getJobID();
System.out.println("jobId:::: " + jobId);
if(jobId != null && jobId.trim().length() > 0)
{
setStatusType(lsSeverity);
setStatusDetail(lsStr);
setLineNo(getLineNo() + 1);
lsReturnErrcode = gfUpdBackgroundPrcStatus(logConn);
setReturnUpdError(lsReturnErrcode);
System.out.println("lsReturnErrcode coming from gfUpdBackgroundPrcStatus::::: " + lsReturnErrcode);
}
else
{
int liInetRet = 0;
setLineNo(getLineNo() + 1);
logLocationType = getLogLocationType();
if("N".equalsIgnoreCase(logLocationType) || "B".equalsIgnoreCase(logLocationType))
{
//this need to be done
//filewrite(astr_log_writer.file_pointer , trim(string(astr_log_writer.line_no)) + "~t" + string(datetime(today() , now()) , "dd/mm/yy hh:mm:ss.fff") + " - " + ls_str + "~r~n")
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
String todayDateTime = sdf.format(cal.getTime());
output = new FileOutputStream(getLogFileName(), true);
System.out.println("FileOutputStream output path:::: " + output);
output.write((getLineNo() + "\t" + todayDateTime +" - "+ lsStr + "\r\n").getBytes());
}
if("B".equalsIgnoreCase(logLocationType) || "S".equalsIgnoreCase(logLocationType))
{
String tomcatHome = CommonConstants.TOMCAT_HOME;
String url = ""+tomcatHome+"/ibase/rest/E12LogFileRestService/writeLog?";
System.out.println("url is===>" + url);
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("hhmmss");
SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MMM-yyyy");
String todayDateTime = sdf.format(cal.getTime());
String startDate = sdf1.format(cal.getTime());
System.out.println("todayDateTime:::: " + todayDateTime + " startDate:::: " + startDate);
lsKey = lsActivity + String.valueOf(getLineNo()).trim() + "_" + todayDateTime;
System.out.println("lsKey:::: " + lsKey);
String query = "key=" + URLEncoder.encode(lsKey, "UTF-8") +
"&date=" + URLEncoder.encode(startDate, "UTF-8") +
"&userCode=" + URLEncoder.encode(getUserId(), "UTF-8") +
"&objName=" + URLEncoder.encode(getObjName(), "UTF-8") +
"&activity=" + URLEncoder.encode(lsActivity, "UTF-8") +
"&logMessage=" + URLEncoder.encode(lsStr, "UTF-8") +
"&logDetails=&procId=" + URLEncoder.encode(getProcessId(), "UTF-8") +
"&fileName=" + URLEncoder.encode(getWsrLogFileName(), "UTF-8") +
"&severity=" + URLEncoder.encode(lsSeverity, "UTF-8");
System.out.println("query:::: [" + query + "]");
String webServiceValue = callE12ExtService(url, query);
System.out.println("webServiceValue>>" + webServiceValue);
//this need to be done
/*
lsKey = string(now() , "hhmmssfff");
lsKey = lsActivity + "_" + String.valueOf(logWriter1.getLineNo()).trim() + "_" + lsKey;
lsUrl = "http://" + logWriter1.getLogServerAddress() + "/ibase/rest/E12LogFileRestService/writeLog?" +
"key=" + lsKey + "&date=" + string(astr_log_writer.start_date , "dd-MMM-yyyy") + "&userCode=" + logWriter1.getUserId() +
"&objName=" + logWriter1.getObjName() + "&activity=" + lsActivity + "&logMessage=" + lsStr +
"&logDetails=&procId=" + logWriter1.getProcessId() + "&fileName=" + astr_log_writer.wsr_log_file_name + "&severity=" + lsSeverity;
string ls_t1 = ""
SELECT 'LOG SERVICE URL = ' || :ls_url into :ls_t1 from dual;
li_inet_ret = astr_log_writer.io_inet.getUrl(ls_url , astr_log_writer.inet_ret)
ls_temp_data = astr_log_writer.inet_ret.is_return*/
}
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(output != null)
{
output.close();
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (SQLException e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
}
public String gfUpdBackgroundPrcStatus(Connection logConn) throws ITMException, RemoteException
{
System.out.println("Inside HRLogWriter.gfUpdBackgroundPrcStatus method....");
String userId = "", lsReturn = "" , lsStatusDet = "" , processID = "" , currentProcess = "" , statusDetail = "",todayDate = "";
Timestamp ldtCurrent = null;
E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
UtilMethods utilMethod = new UtilMethods();
SimpleDateFormat sdf = null;
PreparedStatement pstmt = null;
String sql = "";
int cnt = 0;
try
{
processID = getProcessId().trim().toUpperCase();
currentProcess = getCurrentProcess().trim().toUpperCase();
statusDetail = getStatusDetail().trim().toUpperCase();
System.out.println("processID:::: " + processID + " currentProcess:::: " + currentProcess + " statusDetail:::: " + statusDetail);
if(!(processID.equalsIgnoreCase(currentProcess)))
{
lsStatusDet = "[" + processID + " - " + currentProcess + "] " + statusDetail;
}
else
{
lsStatusDet = "[" + processID + "] " + statusDetail;
}
if(lsStatusDet.length() > 1024)
{
lsStatusDet = utilMethod.left(lsStatusDet,1024);
}
System.out.println("lsStatusDet:::: " + lsStatusDet);
// Modified by Azhar to print sysdate with time in background_status table field STATUS_TIME on 29-03-2019 [Start]
Timestamp timestamp = null;
timestamp = new Timestamp(System.currentTimeMillis());
sdf = new SimpleDateFormat(genericUtility.getApplDateTimeFormat());
String val = sdf.format(timestamp);
System.out.println("val--["+val+"]");
val = genericUtility.getValidDateTimeString(val, genericUtility.getApplDateTimeFormat(), genericUtility.getDBDateTimeFormat());
System.out.println("val--["+val+"]");
ldtCurrent = Timestamp.valueOf(val);
// Modified by Azhar to print sysdate with time in background_status table field STATUS_TIME on 29-03-2019 [End]
//LocalDateTime now = LocalDateTime.now();
//todayDate = sdf.format(sdf);
//ldtCurrent= utilMethod.dateTime(utilMethod.todaySqlDate(),utilMethod.now());
//System.out.println("todayDate==>" + todayDate);
//ldtCurrent = Timestamp.valueOf(genericUtility.getValidDateString(todayDate,
//genericUtility.getApplDateTimeFormat(), genericUtility.getDBDateTimeFormat()));
System.out.println("ldtCurrent==>" + ldtCurrent);
sql = "insert into background_status(job_id , obj_name , line_no , status_det , status_time, status_type)" +
"values (? , ? , ? , ? , ?, ? )";
pstmt = logConn.prepareStatement(sql);
pstmt.setString(1, getJobID());
pstmt.setString(2, getObjName());
pstmt.setLong(3, getLineNo());
pstmt.setString(4, lsStatusDet);
pstmt.setTimestamp(5, ldtCurrent);
pstmt.setString(6, getStatusType());
cnt = pstmt.executeUpdate();
logConn.commit();
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
userId = getUserId();
}
catch(Exception e)
{
lsReturn = itmDBAccessEJB.getErrorString("", "DS0000", userId, "", logConn);
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return lsReturn;
}
public String callE12ExtService(String urlStr, String paramStr) throws ITMException {
String output = "";
try
{
System.out.println("Inside callE12ExtService Method....!!!!");
URL url = new URL(urlStr + paramStr);
System.out.println("URL: " + url);
String urlTest = url.toString();
System.out.println("@S@urlTest[" + urlTest + "");
urlTest = urlTest.replaceAll(" ", "%20");
System.out.println("@S@ urlTest using %20[" + urlTest + "]");
url = new URL(urlTest);
System.out.println("@S@ url using %20[" + url + "]");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
System.out.println("RequestMethod- " + conn.getRequestMethod());
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setUseCaches(false);
conn.setRequestProperty("Accept", "application/json");
conn.connect();
/*
* try { DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
* wr.writeBytes( paramStr ); wr.flush(); } catch (Exception e) {
* System.out.println( "Exception - "+ e.getMessage() ); e.printStackTrace(); }
*/
System.out.println("URL: " + url);
System.out.println("ResponseCode: " + conn.getResponseCode());
System.out.println("ResponseMessage: " + conn.getResponseMessage());
if (conn.getResponseCode() != 200)
{
System.out.println("Failed : HTTP error code : " + conn.getResponseCode());
System.out.println("ErrorStream: "
+ (new BufferedReader(new InputStreamReader(conn.getErrorStream()))).readLine());
}
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((output = br.readLine()) != null)
{
System.out.println(output);
}
conn.disconnect();
System.out.println("Output: " + output);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return output;
}
public boolean gfJobterminateRequested (String jobId, Connection conn) throws ITMException, SQLException
{
System.out.println("Inside HRLogWriter.gfJobterminateRequested method....");
int cnt = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
try {
if(jobId == null || jobId.trim().length() == 0)
{
return false;
}
sql = "select count(1) as cnt from background_job where job_id = ? and "
+ "case when terminate_req is null then 'N' else terminate_req end = 'Y'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, jobId);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(cnt > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
}
public String getToken(String source, String separator)
{
int p = 0;
int lenSource = 0;
int lenSeparator = 0;
int diffstr = 0;
String ret = "";
try
{
p = source.indexOf(separator);
if (p == -1) // if no separator,
{
ret = source; // return the whole source string and
source = ""; // make the original source of zero length
}
else
{
ret = source.substring(0, p);
lenSource = source.length();
lenSeparator = separator.length();
diffstr = lenSource - (p + lenSeparator) + 1;
source = source.substring(diffstr, lenSource);
}
}catch (Exception e)
{
System.out.println("Exception...[getToken] " + e.getMessage());
e.printStackTrace();
}
return ret;
}
public String checkNull(String input)
{
if (input == null || "null".equalsIgnoreCase(input))
{
input= "";
}
return input.trim();
}
}
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