Commit 431a920f authored by Ketan Patil's avatar Ketan Patil

added scheduler code

parents
<Application Id="MarketingInsertSch" Name="MarketingInsertSch">
<FormalParameters>
<FormalParameter Id="TRANS_DB" Index="1" Mode="IN" Name="TRANS_DB">
<DataType>
<BasicType Type="STRING"/>
</DataType>
</FormalParameter>
</FormalParameters>
<ExtendedAttributes>
<ExtendedAttribute Name="APPLN_TYPE" Value="JB"/>
<ExtendedAttribute Name="METHOD_NAME" Value="schedule"/>
<ExtendedAttribute Name="COMP_NAME" Value="ibase.webitm.ejb.marketingsch.MarketingInsertSch"/>
<ExtendedAttribute Name="EXEC_MODE" Value="ASYNC"/>
<ExtendedAttribute Name="INPUT_EDITOR" Value="../../scheduler/jsp/Argument.jsp?APPLICATION_NAME=MarketingInsertSch"/>
<ExtendedAttribute Name="SCHEDULABLE" Value="1"/>
</ExtendedAttributes>
</Application>
\ No newline at end of file
package ibase.webitm.ejb.marketingsch;
import ibase.utility.BaseException;
import java.sql.Statement;
import java.io.StringWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import java.io.FileOutputStream;
import ibase.webitm.applAdmin.bean.DocumentPrint;
import java.io.ByteArrayInputStream;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import com.lowagie.text.pdf.PdfReader;
import java.sql.ResultSetMetaData;
import java.util.HashMap;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.sql.Timestamp;
import ibase.webitm.utility.TransIDGenerator;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
import java.sql.ResultSet;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.FileInputStream;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import ibase.utility.UserInfoBean;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.io.ByteArrayOutputStream;
import java.io.BufferedInputStream;
import java.sql.SQLException;
import java.io.FileFilter;
import ibase.utility.CommonConstants;
import ibase.webitm.ejb.DocumentHandlerEJB;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import java.io.File;
import java.util.ArrayList;
import ibase.utility.E12GenericUtility;
import javax.ejb.Stateless;
@Stateless
public class AttachmentHandlerEJB implements AttachmentHandlerEJBRemote, AttachmentHandlerEJBLocal {
E12GenericUtility genericUtility;
public AttachmentHandlerEJB() {
this.genericUtility = new E12GenericUtility();
}
public String handleAttachment(String objName, final String tranIdFrom, final String tranIdTo,
final String loginCode) throws RemoteException, ITMException {
String attachmentDirPath = "";
String toBeLoadedDirPath = "";
String unAllocatedDirPath = "";
String loadedDirPath = "";
String toBeLoadedSubDirPath = "";
ArrayList<File> directoryList = new ArrayList<File>();
final BufferedInputStream bfr = null;
final ByteArrayOutputStream bout = null;
final StringBuffer retXMLStringBuff = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
final byte[] byteArray = {0};
String retString = null;
PreparedStatement unalPstmt = null;
try {
System.out.println("@ Amit Inside AttachmentHandler Ejb ");
objName = objName.replace("w_", "");
System.out.println("objName>>>> " + objName);
UserInfoBean userInfoBean = this.createUserInfo(loginCode);
conn = connDriver.getConnectDB(userInfoBean.getTransDB());
conn.setAutoCommit(false);
connDriver = null;
final AppConnectParm appConnect = new AppConnectParm();
final DocumentHandlerEJB docHandler = new DocumentHandlerEJB();
//attachmentDirPath = String.valueOf(CommonConstants.JBOSSHOME) + File.separator + "attachment";
//System.out.println("attachmentDirPath>>> " + attachmentDirPath);
//toBeLoadedDirPath = String.valueOf(attachmentDirPath) + File.separator + "to_be_loaded";
//System.out.println("toBeLoadedDirPath>>> " + toBeLoadedDirPath);
//loadedDirPath = String.valueOf(attachmentDirPath) + File.separator + "loaded";
//System.out.println("loadedDirPath>>> " + loadedDirPath);
//unAllocatedDirPath = String.valueOf(attachmentDirPath) + File.separator + "unAllocated";
//System.out.println("unAllocatedDirPath>>> " + unAllocatedDirPath);
FinCommon finCommon = new FinCommon();
toBeLoadedDirPath = finCommon.getFinparams("999999", "MKT_TBLD_PTH", conn);
attachmentDirPath = finCommon.getFinparams("999999", "MKT_ATCH_PTH", conn);
unAllocatedDirPath = finCommon.getFinparams("999999", "MKT_UNAL_PTH", conn);
loadedDirPath = finCommon.getFinparams("999999", "MKT_LOAD_PTH", conn);
System.out.println("toBeLoadedDirPath>>>> " + toBeLoadedDirPath);
System.out.println("attachmentDirPath>>>> " + attachmentDirPath);
System.out.println("loadedDirPath>>>> " + loadedDirPath);
System.out.println("unAllocatedDirPath>>>> " + unAllocatedDirPath);
File path = new File(toBeLoadedDirPath);
if(!path.exists())
{
path.mkdirs();
}
path = new File(attachmentDirPath);
if(!path.exists())
{
path.mkdirs();
}
path = new File(unAllocatedDirPath);
if(!path.exists())
{
path.mkdirs();
}
path = new File(loadedDirPath);
if(!path.exists())
{
path.mkdirs();
}
if (objName != null && objName.trim().length() > 0) {
toBeLoadedSubDirPath = String.valueOf(toBeLoadedDirPath) + File.separator + objName;
System.out.println("toBeLoadedSubDirPath>> " + toBeLoadedSubDirPath);
final File subDir = new File(toBeLoadedSubDirPath);
System.out.println("subDir>>>> " + subDir);
if (subDir.exists()) {
System.out.println("inside the sub dir");
directoryList.add(subDir);
}
} else {
System.out.println("inside the else sub dir");
directoryList = this.getDirectoryNamesForAttachment(toBeLoadedDirPath);
}
final int directoryListLen = directoryList.size();
System.out.println("directoryListLen = [" + directoryListLen + "] directoryList = " + directoryList);
for (int i = 0; i < directoryListLen; ++i) {
objName = directoryList.get(i).getName();
toBeLoadedSubDirPath = String.valueOf(toBeLoadedDirPath) + File.separator + objName;
System.out.println("toBeLoadedSubDirPath>>> " + toBeLoadedSubDirPath);
final String refSer = this.getRefSer(conn, objName);
final String loginSite = this.getLoginSite(loginCode, conn);
final FileFilter fileFilter = new FileFilter() {
@Override
public boolean accept(final File file) {
return !file.isDirectory();
}
};
final File toBeLoadedSubDir = new File(toBeLoadedSubDirPath);
System.out.println("File toBeLoadedSubDir>>>> " + toBeLoadedSubDir);
File[] fileArray = new File[0];
if (toBeLoadedSubDir.isDirectory()) {
fileArray = toBeLoadedSubDir.listFiles(fileFilter);
System.out.println("fileArray>>>>>> " + fileArray);
}
System.out.println("fileArray.length = [" + fileArray.length + "], objName = [" + objName + "]");
for (int j = 0; j < fileArray.length; ++j) {
final File fileToBeAttached = fileArray[j];
final String fileName = fileToBeAttached.getName();
String tranID = "";
if (fileName.contains("_")) {
tranID = fileName.substring(0, fileName.indexOf("_"));
} else if (fileName.contains(".")) {
tranID = fileName.substring(0, fileName.indexOf("."));
}
System.out.println("fileName = [" + fileName + "], tranID = [" + tranID + "]");
final boolean isFileToBeAttach = this.getTransactionsBetweenRange(objName, tranIdFrom, tranIdTo,
tranID, conn);
System.out.println("isFileToBeAttach = [" + isFileToBeAttach + "]");
retString = this.uploadAttachments(objName, refSer, tranID, loginCode, loginSite, fileToBeAttached,
conn, docHandler, loadedDirPath, unAllocatedDirPath, toBeLoadedSubDirPath,
isFileToBeAttach);
}
}
} catch (Exception ex) {
ex.printStackTrace();
try {
if (unalPstmt != null) {
try {
unalPstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
unalPstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return retString;
} finally {
try {
if (unalPstmt != null) {
try {
unalPstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
unalPstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
try {
if (unalPstmt != null) {
try {
unalPstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
unalPstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return retString;
}
private String uploadAttachments(final String objName, final String refSer, String tranID, final String loginCode,
final String loginSite, final File fileTobeAttached, Connection conn, final DocumentHandlerEJB docHandler,
final String loadedDirPath, final String unAllocatedDirPath, final String toBeLoadedSubDirPath,
final boolean isFileToBeAttach) throws Exception {
String retString = null;
byte[] byteArray = {0};
ConnDriver connDriver = new ConnDriver();
final StringBuffer retXMLStringBuff = new StringBuffer();
PreparedStatement unalPstmt = null;
boolean localConn = false;
ResultSet rs = null;
String MktRefSer = "";
final StringBuffer uploadFileLog = new StringBuffer();
String doc_id = "";
Label_3514 : {
try {
System.out
.println("Inside uploadAttachments - tranID = [" + tranID + "] - objName = [" + objName + "]");
uploadFileLog
.append("Inside uploadAttachments - tranID = [" + tranID + "] - objName = [" + objName + "]\n");
if (conn == null) {
final UserInfoBean userInfoBean = this.createUserInfo(loginCode);
conn = connDriver.getConnectDB(userInfoBean.getTransDB());
conn.setAutoCommit(false);
localConn = true;
}
connDriver = null;
final String fileName = fileTobeAttached.getName();
final String filePath = fileTobeAttached.toString();
System.out.println("fileName = [" + fileName + "] - filePath = [" + filePath + "]");
uploadFileLog.append("fileName = [" + fileName + "] - filePath = [" + filePath + "]\n");
final File file = new File(filePath);
System.out.println("@ Amit file>>>>>>" + file);
final String fileType = filePath.substring(filePath.lastIndexOf(".") + 1);
System.out.println("@ Amit fileType>>>>>>" + fileType);
if (!isFileToBeAttach) {
if (fileName.contains(".")) {
tranID = fileName.substring(0, fileName.lastIndexOf("."));
}
if (tranID.length() > 50) {
tranID = tranID.substring(0, 49);
}
}
uploadFileLog.append("isFileToBeAttach : [" + isFileToBeAttach + "]\n");
uploadFileLog.append("tranID : [" + tranID + "]\n");
final FileInputStream input = new FileInputStream(file);
final BufferedInputStream bfr = new BufferedInputStream(input);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
int readCount = 0;
while ((readCount = bfr.read()) != -1) {
bout.write(readCount);
}
byteArray = bout.toByteArray();
System.out.println("byteArray>>>>>" + byteArray);
retXMLStringBuff.append("<?xml version=\"1.0\" encoding=\"" + CommonConstants.ENCODING + "\"?>");
retXMLStringBuff.append("<DocumentRoot>");
retXMLStringBuff.append("<description>Datawindow Root</description>");
retXMLStringBuff.append("<group0>");
retXMLStringBuff.append("<description>Group0 description</description>");
retXMLStringBuff.append("<Header0>");
retXMLStringBuff.append("<description>Header0 members</description>");
retXMLStringBuff.append("<header>");
retXMLStringBuff.append("<ref_id><![CDATA[" + tranID + "]]></ref_id>");
retXMLStringBuff.append("<ref_ser><![CDATA[" + refSer + "]]></ref_ser>");
retXMLStringBuff.append("<doc_name><![CDATA[" + fileName + "]]></doc_name>");
retXMLStringBuff.append("<doc_type><![CDATA[" + fileType + "]]></doc_type>");
retXMLStringBuff.append("<obj_name><![CDATA[" + objName + "]]></obj_name>");
retXMLStringBuff.append("<created_by><![CDATA[" + loginCode + "]]></created_by>");
retXMLStringBuff
.append("<doc_pages><![CDATA[" + this.getPageCount(fileTobeAttached) + "]]></doc_pages>");
retXMLStringBuff.append("</header>");
retXMLStringBuff.append("</Header0>");
retXMLStringBuff.append("</group0>");
retXMLStringBuff.append("</DocumentRoot>");
System.out.println("retXMLStringBuff = [" + retXMLStringBuff.toString() + "]");
uploadFileLog.append("retXMLStringBuff = [" + retXMLStringBuff.toString() + "]\n");
try {
docHandler.ejbCreate();
//UserInfoBean userInfo = new UserInfoBean(scheduleParamXML);
UserInfoBean userInfo = this.createUserInfo(loginCode);
retString = docHandler.addDocument(retXMLStringBuff.toString(), byteArray,(byte[]) null, userInfo);
uploadFileLog.append("retString after upload : [" + retString + "]\n");
} catch (Exception e1) {
uploadFileLog.append("Exception while addDocument : [" + this.getStackTrace(e1) + "]\n");
e1.printStackTrace();
throw new ITMException(e1);
}
bfr.close();
bout.close();
System.out.println("retString = [" + retString + "]");
if (isFileToBeAttach) {
final File objNameFolder = new File(String.valueOf(loadedDirPath) + File.separator + objName);
if (!objNameFolder.exists()) {
final File ObjNameFold = new File(String.valueOf(loadedDirPath) + File.separator + objName);
if (!ObjNameFold.mkdir()) {
break Label_3514;
}
final boolean success = file.renameTo(new File(objNameFolder, file.getName()));
if (!success) {
System.out.print("this file [" + file.getName() + "] is not moved to the [" + objNameFolder
+ "] Folder");
uploadFileLog.append("File : [" + file.getName() + "] is not moved to the [" + objNameFolder
+ "] folder.\n");
break Label_3514;
}
uploadFileLog.append(
"File : [" + file.getName() + "] is moved to the [" + objNameFolder + "] folder.\n");
} else {
final boolean success2 = file.renameTo(new File(objNameFolder, file.getName()));
if (!success2) {
System.out.print("file " + file.getName() + " is not moved");
uploadFileLog.append("File : [" + file.getName() + "] is not moved to the [" + objNameFolder
+ "] folder.\n");
break Label_3514;
}
uploadFileLog.append(
"File : [" + file.getName() + "] is moved to the [" + objNameFolder + "] folder.\n");
}
} else {
final Document dom = this.genericUtility.parseString(retString);
final Node node = dom.getElementsByTagName("ID").item(0);
if (node == null || node.getAttributes() == null
|| node.getAttributes().getNamedItem("Document_Id") == null) {
break Label_3514;
}
doc_id = node.getAttributes().getNamedItem("Document_Id").getNodeValue();
System.out.println("doc_id - [" + doc_id + "]");
uploadFileLog.append("doc_id : [" + doc_id + "]\n");
final String UDF_STR3 = "M-BILL";
String sql = "SELECT UDF_STR3 FROM SSCBARCODE_TRAN WHERE UDF_STR3 = ? ";
unalPstmt = conn.prepareStatement(sql);
unalPstmt.setString(1, UDF_STR3);
rs = unalPstmt.executeQuery();
if (rs.next()) {
MktRefSer = rs.getString("UDF_STR3");
}
if (unalPstmt != null) {
unalPstmt.close();
unalPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
int updatecnt = 0;
final String uniqueTranIdGenerator = this.generateTranId("W_UNALLOCATED", loginSite, loginCode,
conn);
sql = "INSERT INTO UNALLOCATED_ATTACH (TRAN_ID,REF_ID,REF_SER,DOC_ID,OBJ_NAME,STATUS,ADDED_BY,ADDED_TO_MAP,ADDED_ON) VALUES ( ?,?,?,?,?,?,?,?,sysdate )";
try {
unalPstmt = conn.prepareStatement(sql);
unalPstmt.setString(1, uniqueTranIdGenerator);
unalPstmt.setString(2, tranID);
unalPstmt.setString(3, MktRefSer);
unalPstmt.setString(4, doc_id);
unalPstmt.setString(5, objName);
unalPstmt.setString(6, "N");
unalPstmt.setString(7, loginCode);
unalPstmt.setString(8, "0");
updatecnt = unalPstmt.executeUpdate();
uploadFileLog.append("uniqueTranIdGenerator - [" + uniqueTranIdGenerator + "]\n");
uploadFileLog.append("documentId - [" + doc_id + "] : updatecnt - [" + updatecnt + "]\n");
} catch (SQLException e2) {
uploadFileLog.append("Exception while inserting into UNALLOCATED_ATTACH - ["
+ this.getStackTrace(e2) + "]\n");
e2.printStackTrace();
throw new ITMException((Exception) e2);
}
boolean isError = false;
try {
if (updatecnt > 0) {
final File unAllocatedFile = new File(
String.valueOf(unAllocatedDirPath) + File.separator + objName);
if (!unAllocatedFile.exists()) {
final File ObjNameFold2 = new File(
String.valueOf(unAllocatedDirPath) + File.separator + objName);
if (ObjNameFold2.mkdir()) {
final boolean success3 = file.renameTo(new File(unAllocatedFile, file.getName()));
if (!success3) {
System.out.print("this file [" + file.getName() + "] is not moved to the "
+ ObjNameFold2 + " Folder");
uploadFileLog.append("File : [" + file.getName() + "] is not moved to the ["
+ unAllocatedFile + "] folder.\n");
} else {
uploadFileLog.append("File : [" + file.getName() + "] is moved to the ["
+ unAllocatedFile + "] folder.\n");
}
}
} else {
final boolean success4 = file.renameTo(new File(unAllocatedFile, file.getName()));
if (!success4) {
System.out.print("file " + file.getName() + " is not moved");
uploadFileLog.append("File : [" + file.getName() + "] is not moved to the ["
+ unAllocatedFile + "] folder.\n");
} else {
uploadFileLog.append("File : [" + file.getName() + "] is moved to the ["
+ unAllocatedFile + "] folder.\n");
}
}
}
} catch (Exception e3) {
isError = true;
uploadFileLog.append("Exception while moving file into Unallocated folder - ["
+ this.getStackTrace(e3) + "]\n");
e3.printStackTrace();
throw new ITMException(e3);
} finally {
try {
if (isError) {
final int deleteCnt = this.deleteUnallocRec(uniqueTranIdGenerator, conn, loginCode);
uploadFileLog.append(
"[" + deleteCnt + "] record deleted from Unallocated_attach for tranId - ["
+ uniqueTranIdGenerator + "] "
+ " due to error while moving file to Unallocated Folder\n");
}
} catch (Exception e4) {
e4.printStackTrace();
throw new ITMException(e4);
}
}
try {
if (isError) {
final int deleteCnt = this.deleteUnallocRec(uniqueTranIdGenerator, conn, loginCode);
uploadFileLog.append("[" + deleteCnt
+ "] record deleted from Unallocated_attach for tranId - [" + uniqueTranIdGenerator
+ "] " + " due to error while moving file to Unallocated Folder\n");
}
} catch (Exception e4) {
e4.printStackTrace();
throw new ITMException(e4);
}
}
} catch (FileNotFoundException e5) {
retString = e5.getMessage();
retString = this.getStackTrace(e5);
e5.printStackTrace();
} catch (RemoteException e6) {
retString = e6.getMessage();
retString = this.getStackTrace(e6);
e6.printStackTrace();
} catch (ITMException e7) {
retString = e7.getMessage();
retString = this.getStackTrace((Throwable) e7);
e7.printStackTrace();
} catch (IOException e8) {
retString = e8.getMessage();
retString = this.getStackTrace(e8);
e8.printStackTrace();
} finally {
try {
uploadFileLog.append("In Finally - [" + retString + "]\n");
if (!this.isFileUploaded(doc_id, refSer, objName, conn, loginCode)) {
final String fileName2 = String.valueOf(doc_id) + "_" + System.currentTimeMillis() + ".txt";
this.createUploadFileLog(
"------------------------ : In AttachmentHandlerEJB :------------------- \n"
+ uploadFileLog.toString(),
fileName2);
}
if (unalPstmt != null) {
try {
unalPstmt.close();
} catch (SQLException e9) {
e9.printStackTrace();
}
unalPstmt = null;
}
if (localConn && conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
try {
uploadFileLog.append("In Finally - [" + retString + "]\n");
if (!this.isFileUploaded(doc_id, refSer, objName, conn, loginCode)) {
final String fileName2 = String.valueOf(doc_id) + "_" + System.currentTimeMillis() + ".txt";
this.createUploadFileLog(
"------------------------ : In AttachmentHandlerEJB :------------------- \n"
+ uploadFileLog.toString(),
fileName2);
}
if (unalPstmt != null) {
try {
unalPstmt.close();
} catch (SQLException e9) {
e9.printStackTrace();
}
unalPstmt = null;
}
if (localConn && conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
return retString;
}
private String getLoginSite(final String loginCode, final Connection conn) {
PreparedStatement lstmt = null;
ResultSet lrs = null;
String loginSite = "";
final String sql = "select emp_site from employee where emp_code = ?";
try {
lstmt = conn.prepareStatement(sql);
lstmt.setString(1, loginCode);
lrs = lstmt.executeQuery();
if (lrs.next()) {
loginSite = lrs.getString("emp_site");
}
lrs.close();
lrs = null;
lstmt.close();
lstmt = null;
} catch (SQLException e) {
e.printStackTrace();
return loginSite;
} finally {
if (lstmt != null) {
try {
lstmt.close();
} catch (SQLException e2) {
e2.printStackTrace();
}
lstmt = null;
}
}
if (lstmt != null) {
try {
lstmt.close();
} catch (SQLException e2) {
e2.printStackTrace();
}
lstmt = null;
}
return loginSite;
}
private String generateTranId(final String winName, final String xsiteCode, final String userID,
final Connection conn) throws Exception {
PreparedStatement lstmt = null;
ResultSet lrs = null;
String tranId = null;
try {
String keyStringQuery = null;
String tranDate = null;
String tranSer = "";
String keyString = "";
String keyCol = "";
keyStringQuery = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE UPPER(TRAN_WINDOW) = ?";
System.out.println("keyStringQuery :: " + keyStringQuery);
lstmt = conn.prepareStatement(keyStringQuery);
lstmt.setString(1, winName);
lrs = lstmt.executeQuery();
if (lrs.next()) {
keyString = lrs.getString("KEY_STRING");
keyCol = lrs.getString("TRAN_ID_COL");
tranSer = lrs.getString("REF_SER");
} else {
if (lrs != null) {
lrs.close();
}
lrs = null;
if (lstmt != null) {
lstmt.close();
}
final String sqlStr = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE TRAN_WINDOW = 'GENERAL' ";
System.out.println(" sqlStr : " + sqlStr);
lstmt = conn.prepareStatement(sqlStr);
lrs = lstmt.executeQuery();
if (lrs.next()) {
keyString = lrs.getString("KEY_STRING");
keyCol = lrs.getString("TRAN_ID_COL");
tranSer = lrs.getString("REF_SER");
}
}
lrs.close();
lrs = null;
lstmt.close();
lstmt = null;
tranDate = this.getCurrdateAppFormat();
final StringBuffer xmlValues = new StringBuffer("<?xml version=\"1.0\" encoding=\"")
.append(CommonConstants.ENCODING).append("\"?><Root>");
xmlValues.append("<Header></Header><Detail1><site_code>").append(xsiteCode).append("</site_code>");
xmlValues.append("<tran_date>").append(tranDate).append("</tran_date></Detail1></Root>");
final TransIDGenerator tg = new TransIDGenerator(xmlValues.toString(), userID, CommonConstants.DB_NAME);
tranId = tg.generateTranSeqID(tranSer, keyCol, keyString, conn);
} catch (SQLException se) {
se.printStackTrace();
throw new ITMException((Exception) se);
} catch (Exception ex) {
ex.printStackTrace();
throw new ITMException(ex);
} finally {
if (lstmt != null) {
lstmt.close();
lstmt = null;
}
}
if (lstmt != null) {
lstmt.close();
lstmt = null;
}
return tranId;
}
private String getCurrdateAppFormat() {
String currAppdate = "";
try {
Timestamp currDate = new Timestamp(System.currentTimeMillis());
final SimpleDateFormat sdf = new SimpleDateFormat(this.genericUtility.getDBDateFormat());
final Object date = sdf.parse(currDate.toString());
currDate = Timestamp.valueOf(String.valueOf(sdf.format(date).toString()) + " 00:00:00.0");
currAppdate = new SimpleDateFormat(this.genericUtility.getApplDateFormat()).format(currDate).toString();
} catch (Exception e) {
e.printStackTrace();
}
return currAppdate;
}
public ArrayList<File> getDirectoryNamesForAttachment(final String toBeLoadedDirPath) {
File[] directoryArray = new File[0];
final ArrayList<File> directoryList = new ArrayList<File>();
File toBeLoadedDir = null;
try {
final FileFilter directotyFilter = new FileFilter() {
@Override
public boolean accept(final File pathname) {
return pathname.isDirectory();
}
};
toBeLoadedDir = new File(toBeLoadedDirPath);
if (toBeLoadedDir.isDirectory()) {
directoryArray = toBeLoadedDir.listFiles(directotyFilter);
}
for (int i = 0; i < directoryArray.length; ++i) {
directoryList.add(directoryArray[i]);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return directoryList;
}
private HashMap<String, ArrayList<File>> getTransactionWiseFileMap(final String toBeLoadedDirPath,
final String objName, final String tranIdFrom, final String tranIdTo, final Connection conn) {
File[] fileArray = new File[0];
final HashMap<String, ArrayList<File>> transactionWiseFileMap = new HashMap<String, ArrayList<File>>();
File toBeLoadedSubDir = null;
ArrayList<File> transactionWiseFileList = null;
String fileName = "";
final String toBeLoadedSubDirPath = String.valueOf(toBeLoadedDirPath) + File.separator + objName;
try {
final FileFilter fileFilter = new FileFilter() {
@Override
public boolean accept(final File file) {
return !file.isDirectory();
}
};
toBeLoadedSubDir = new File(toBeLoadedSubDirPath);
if (toBeLoadedSubDir.isDirectory()) {
fileArray = toBeLoadedSubDir.listFiles(fileFilter);
}
for (int i = 0; i < fileArray.length; ++i) {
final File filesToBeAttached = fileArray[i];
fileName = filesToBeAttached.getName();
String tranID = "";
if (fileName.contains(".")) {
tranID = fileName.substring(0, fileName.lastIndexOf("."));
}
if (tranID.length() > 50) {
tranID = tranID.substring(0, 49);
}
final boolean isFileToBeAttach = this.getTransactionsBetweenRange(objName, tranIdFrom, tranIdTo, tranID,
conn);
if (isFileToBeAttach) {
if (transactionWiseFileMap.containsKey(tranID)) {
transactionWiseFileList = transactionWiseFileMap.get(tranID);
transactionWiseFileList.add(filesToBeAttached);
} else {
transactionWiseFileList = new ArrayList<File>();
transactionWiseFileList.add(filesToBeAttached);
transactionWiseFileMap.put(tranID, transactionWiseFileList);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return transactionWiseFileMap;
}
private boolean getTransactionsBetweenRange(String objName, final String tranIdFrom, final String tranIdTo,
final String tranId, Connection conn) {
final ArrayList<String> transactionList = new ArrayList<String>();
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
ConnDriver connDriver = null;
String tableName = "";
String columnName = "";
boolean localConn = false;
try {
System.out.println("Inside getTransactionsBetweenRange( objName - [" + objName + "], tranIdFrom - ["
+ tranIdFrom + "], tranIdTo - [" + tranIdTo + "], tranId - [" + tranId + "] )");
connDriver = new ConnDriver();
if (conn == null) {
conn = connDriver.getConnectDB("Driver");
conn.setAutoCommit(false);
localConn = true;
}
connDriver = null;
objName = (objName.contains("w_") ? objName : ("w_" + objName));
sql = "SELECT TABLE_NAME,TRAN_ID_COL FROM TRANSETUP WHERE TRAN_WINDOW = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, objName);
rs = pstmt.executeQuery();
if (rs.next()) {
tableName = ((rs.getString("TABLE_NAME") == null) ? "" : rs.getString("TABLE_NAME"));
columnName = ((rs.getString("TRAN_ID_COL") == null) ? "" : rs.getString("TRAN_ID_COL"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (tableName != null && tableName.trim().length() > 0) {
boolean isRangeSpecified = true;
if ((tranIdFrom == null || tranIdFrom.trim().length() == 0)
&& (tranIdTo == null || tranIdTo.trim().length() == 0)) {
isRangeSpecified = false;
}
if (columnName.contains(":")) {
System.out.println("columnName containing colonnnn : [ " + columnName + " ]");
final String[] columns = columnName.split(":");
final int columnsLength = columns.length;
System.out.println("Length of column name = [ " + columnsLength + " ]");
columnName = "";
String tmpColumnName = "";
for (int i = 0; i < columnsLength; ++i) {
if (i == columnsLength - 1) {
tmpColumnName = String.valueOf(tmpColumnName) + columns[i];
} else {
tmpColumnName = String.valueOf(tmpColumnName) + columns[i] + ",";
}
}
columnName = tmpColumnName;
System.out.println(
"Column Name containing comma [" + columnName + " ] tmpColumnName = " + tmpColumnName);
System.out.println("DBDateFormat : [" + this.genericUtility.getDBDateFormat() + "]");
sql = "SELECT " + columnName + " FROM " + tableName + " WHERE 1 = 2";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
final ResultSetMetaData md = rs.getMetaData();
String columnNames = "";
for (int j = 1; j <= md.getColumnCount(); ++j) {
if (md.getColumnTypeName(j).toUpperCase().indexOf("DATE") != -1
|| md.getColumnTypeName(j).toUpperCase().indexOf("TIMESTAMP") != -1) {
columnNames = String.valueOf(columnNames) + "TO_CHAR(" + md.getColumnName(j) + ", '"
+ this.genericUtility.getDBDateFormat() + "') AS " + md.getColumnName(j) + ", ";
} else {
columnNames = String.valueOf(columnNames) + md.getColumnName(j) + ", ";
}
}
if (columnNames != null && columnNames.trim().length() > 1) {
columnName = columnNames.substring(0, columnNames.trim().length() - 1);
}
System.out.println("columnNames = " + columnName);
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (isRangeSpecified) {
sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + columnName + " BETWEEN '"
+ tranIdFrom + "' AND '" + tranIdTo + "' ";
} else {
sql = "SELECT " + columnName + " FROM " + tableName;
}
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
String tmp = "";
String tmpExcludeAfterSpace = "";
String st = "";
while (rs.next()) {
tmp = "";
for (int k = 0; k < columnsLength; ++k) {
tmpExcludeAfterSpace = "";
st = "";
tmpExcludeAfterSpace = rs.getString(columns[k]);
if (tmpExcludeAfterSpace.contains("-") && tmpExcludeAfterSpace.contains(" ")) {
final String[] tmpColumns = tmpExcludeAfterSpace.split(" ");
st = tmpColumns[0];
} else {
st = tmpExcludeAfterSpace;
}
if (k == columnsLength - 1) {
tmp = String.valueOf(tmp) + st;
} else {
tmp = String.valueOf(tmp) + st + "~";
}
}
transactionList.add(tmp);
if (tmp.equalsIgnoreCase(tranId)) {
System.out.println(" Inside colon - tmp - " + tmp + " tranId - " + tranId);
return true;
}
}
} else {
System.out.println("DBDateFormat : [" + this.genericUtility.getDBDateFormat() + "]");
sql = "SELECT " + columnName + " FROM " + tableName + " WHERE 1 = 2";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
final ResultSetMetaData md2 = rs.getMetaData();
String columnNames2 = "";
for (int l = 1; l <= md2.getColumnCount(); ++l) {
if (md2.getColumnTypeName(l).toUpperCase().indexOf("DATE") != -1
|| md2.getColumnTypeName(l).toUpperCase().indexOf("TIMESTAMP") != -1) {
columnNames2 = String.valueOf(columnNames2) + "TO_CHAR(" + md2.getColumnName(l) + ", '"
+ this.genericUtility.getDBDateFormat() + "') AS " + md2.getColumnName(l) + ", ";
} else {
columnNames2 = String.valueOf(columnNames2) + md2.getColumnName(l) + ", ";
}
}
if (columnNames2 != null && columnNames2.trim().length() > 1) {
columnName = columnNames2.substring(0, columnNames2.trim().length() - 1);
}
System.out.println("columnNames = " + columnName);
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (isRangeSpecified) {
sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + columnName + " BETWEEN '"
+ tranIdFrom + "' AND '" + tranIdTo + "' " + " AND " + columnName + " = '" + tranId
+ "' ";
} else {
sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + columnName + " = '" + tranId
+ "' ";
}
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
final String value = rs.getString(columnName);
transactionList.add(value);
if (value.equalsIgnoreCase(tranId)) {
System.out.println(" Inside colon - value - " + value + " tranId - " + tranId);
return true;
}
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
} catch (Exception ex) {
ex.printStackTrace();
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (localConn && conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return false;
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (localConn && conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (localConn && conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return false;
}
public boolean isRecordExist(String objName, final String refId, final String userCode) {
final ArrayList<String> transactionList = new ArrayList<String>();
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn = null;
ConnDriver connDriver = null;
String tableName = "";
String columnName = "";
int cnt = 0;
boolean status = false;
try {
connDriver = new ConnDriver();
final UserInfoBean userInfoBean = this.createUserInfo(userCode);
conn = connDriver.getConnectDB(userInfoBean.getTransDB());
conn.setAutoCommit(false);
connDriver = null;
objName = (objName.contains("w_") ? objName : ("w_" + objName));
sql = "SELECT TABLE_NAME,TRAN_ID_COL FROM TRANSETUP WHERE TRAN_WINDOW = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, objName);
rs = pstmt.executeQuery();
if (rs.next()) {
tableName = ((rs.getString("TABLE_NAME") == null) ? "" : rs.getString("TABLE_NAME"));
columnName = ((rs.getString("TRAN_ID_COL") == null) ? "" : rs.getString("TRAN_ID_COL"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (tableName != null && tableName.trim().length() > 0) {
sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + columnName + " = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if (rs.next()) {
cnt = rs.getInt(1);
}
if (cnt == 1) {
status = true;
} else if (cnt == 0) {
status = false;
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
} catch (Exception ex) {
ex.printStackTrace();
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return status;
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return status;
}
public int getPageCount(final File fileTobeAttached) {
final String filePath = fileTobeAttached.toString();
final String fileName = fileTobeAttached.getName();
final String fileType = fileName.substring(fileName.indexOf(".") + 1);
int pageCount = 0;
try {
if ("pdf".equalsIgnoreCase(fileType)) {
final PdfReader reader = new PdfReader(filePath);
pageCount = reader.getNumberOfPages();
} else if ("doc".equalsIgnoreCase(fileType)) {
try {
final POIFSFileSystem fis = new POIFSFileSystem(
(InputStream) new FileInputStream(fileTobeAttached));
final HWPFDocument wdDoc = new HWPFDocument(fis);
pageCount = wdDoc.getSummaryInformation().getPageCount();
} catch (Exception e) {
System.out.println("In getPageCount Exception [" + e.getMessage() + "]");
e.printStackTrace();
}
} else if ("docx".equalsIgnoreCase(fileType)) {
byte[] inputBytePDF = null;
try {
final FileInputStream fin = new FileInputStream(fileTobeAttached);
inputBytePDF = new byte[(int) fileTobeAttached.length()];
fin.read(inputBytePDF);
final ByteArrayInputStream docxInputStream = new ByteArrayInputStream(inputBytePDF);
final com.aspose.words.Document wordDoc = new com.aspose.words.Document(
(InputStream) docxInputStream);
pageCount = wordDoc.getPageCount();
} catch (Exception e2) {
System.out.println("In docx type Exception [" + e2.getMessage() + "]");
e2.printStackTrace();
}
}
} catch (IOException e3) {
System.out.println("In doc type Exception [" + e3.getMessage() + "]");
e3.printStackTrace();
}
return pageCount;
}
public String getRefSer(String objName, final String LoginEmpCode) {
PreparedStatement pStmt = null;
ResultSet rs = null;
String sql = "";
String refSer = "";
Connection conn = null;
ConnDriver connDriver = null;
try {
connDriver = new ConnDriver();
final UserInfoBean userInfo = this.createUserInfo(LoginEmpCode);
conn = connDriver.getConnectDB(userInfo.getTransDB());
objName = (objName.contains("w_") ? objName : ("w_" + objName));
sql = "SELECT REF_SER FROM TRANSETUP WHERE TRAN_WINDOW = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, objName);
rs = pStmt.executeQuery();
if (rs.next()) {
System.out.println("Inside if ");
refSer = ((rs.getString("REF_SER") == null) ? "" : rs.getString("REF_SER"));
}
System.out.println(" refSer : " + refSer);
} catch (Exception ex) {
System.out.println("[AttachmentHandlerEJB] :: [getRefSer ()] :: " + ex.getMessage());
ex.printStackTrace();
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pStmt != null) {
pStmt.close();
pStmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException ex2) {
System.out.println("[AttachmentHandlerEJB] :: [getRefSer ()] :finally: " + ex2.getMessage());
ex2.printStackTrace();
}
return refSer;
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pStmt != null) {
pStmt.close();
pStmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException ex2) {
System.out.println("[AttachmentHandlerEJB] :: [getRefSer ()] :finally: " + ex2.getMessage());
ex2.printStackTrace();
}
}
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pStmt != null) {
pStmt.close();
pStmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException ex2) {
System.out.println("[AttachmentHandlerEJB] :: [getRefSer ()] :finally: " + ex2.getMessage());
ex2.printStackTrace();
}
return refSer;
}
public String getRefSer(final Connection conn, String objName) throws ITMException, RemoteException {
PreparedStatement pStmt = null;
ResultSet rs = null;
String sql = "";
String refSer = "";
try {
objName = (objName.contains("w_") ? objName : ("w_" + objName));
sql = "SELECT REF_SER FROM TRANSETUP WHERE TRAN_WINDOW = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, objName);
rs = pStmt.executeQuery();
if (rs.next()) {
refSer = ((rs.getString("REF_SER") == null) ? "" : rs.getString("REF_SER"));
}
} catch (Exception ex) {
System.out.println("[AttachmentHandlerEJB] :: [getRefSer ()] :: " + ex.getMessage());
throw new ITMException(ex);
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pStmt != null) {
pStmt.close();
pStmt = null;
}
} catch (SQLException ex2) {
System.out.println("[AttachmentHandlerEJB] :: [getRefSer ()] :finally: " + ex2.getMessage());
throw new ITMException((Exception) ex2);
}
}
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pStmt != null) {
pStmt.close();
pStmt = null;
}
} catch (SQLException ex2) {
System.out.println("[AttachmentHandlerEJB] :: [getRefSer ()] :finally: " + ex2.getMessage());
throw new ITMException((Exception) ex2);
}
return refSer;
}
public String getAttachmentDetail(String objName, final String fromTranId, final String toTranId,
final String userCode) {
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
String tranId = "";
final StringBuffer xmlStringBuff = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Root>\r\n");
Connection conn = null;
ConnDriver connDriver = null;
String docName = "";
String docType = "";
String docPages = "";
String docId = "";
long countId = 0L;
try {
objName = (objName.contains("w_") ? objName : ("w_" + objName));
connDriver = new ConnDriver();
final UserInfoBean userInfoBean = this.createUserInfo(userCode);
conn = connDriver.getConnectDB(userInfoBean.getTransDB());
conn.setAutoCommit(false);
connDriver = null;
sql = " SELECT DT_LINK.REF_ID,DC.DOC_NAME,DC.DOC_TYPE,DC.DOC_PAGES,DC.DOC_ID FROM DOC_CONTENTS DC , DOC_TRANSACTION_LINK DT_LINK WHERE DC.DOC_ID = DT_LINK.DOC_ID AND DT_LINK.REF_ID BETWEEN ? AND ? AND TRIM (DT_LINK.REF_SER) in (SELECT TRIM (REF_SER) FROM TRANSETUP WHERE TRAN_WINDOW = ?) ORDER BY REF_ID,DOC_ID,DOC_NAME";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, fromTranId);
pstmt.setString(2, toTranId);
pstmt.setString(3, objName);
rs = pstmt.executeQuery();
while (rs.next()) {
++countId;
tranId = ((rs.getString("REF_ID") == null) ? "" : rs.getString("REF_ID"));
docName = ((rs.getString("DOC_NAME") == null) ? "" : rs.getString("DOC_NAME"));
docType = ((rs.getString("DOC_TYPE") == null) ? "" : rs.getString("DOC_TYPE"));
docPages = ((rs.getString("DOC_PAGES") == null) ? "" : rs.getString("DOC_PAGES"));
docId = ((rs.getString("DOC_ID") == null) ? "" : rs.getString("DOC_ID"));
xmlStringBuff.append("<Detail>\r\n");
xmlStringBuff.append("<count_id>").append("<![CDATA[").append(countId).append("]]>")
.append("</count_id>\r\n ");
xmlStringBuff.append("<tran_id>").append("<![CDATA[").append(tranId).append("]]>")
.append("</tran_id>\r\n ");
xmlStringBuff.append("<doc_id>").append("<![CDATA[").append(docId).append("]]>")
.append("</doc_id>\r\n ");
xmlStringBuff.append("<doc_name>").append("<![CDATA[").append(docName).append("]]>")
.append("</doc_name>\r\n ");
xmlStringBuff.append("<doc_type>").append("<![CDATA[").append(docType).append("]]>")
.append("</doc_type>\r\n ");
xmlStringBuff.append("<doc_pages>").append("<![CDATA[").append(docPages).append("]]>")
.append("</doc_pages>\r\n ");
xmlStringBuff.append("</Detail>\r\n");
}
xmlStringBuff.append("<Detail1>\r\n");
xmlStringBuff.append("<max_id>").append("<![CDATA[").append(countId).append("]]>").append("</max_id>\r\n ");
xmlStringBuff.append("</Detail1>\r\n");
xmlStringBuff.append("</Root>\r\n");
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception ex) {
ex.printStackTrace();
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
return xmlStringBuff.toString();
} finally {
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
}
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
return xmlStringBuff.toString();
}
public String getPrintLog(String objName, final String fromTranId, final String toTranId, final String printStatus,
final String userCode) {
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
String tranId = "";
String docName = "";
String docType = "";
String docPages = "";
String docId = "";
String docPrintStatus = "";
String docPrintDate = "";
String docPrintBy = "";
final StringBuffer xmlStringBuff = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Root>\r\n");
Connection conn = null;
ConnDriver connDriver = null;
long countId = 0L;
try {
objName = (objName.contains("w_") ? objName : ("w_" + objName));
connDriver = new ConnDriver();
final UserInfoBean userInfo = this.createUserInfo(userCode);
conn = connDriver.getConnectDB(userInfo.getTransDB());
conn.setAutoCommit(false);
connDriver = null;
final SimpleDateFormat simpleDf = new SimpleDateFormat(this.genericUtility.getDBDateFormat());
final SimpleDateFormat simpleDisp = new SimpleDateFormat("dd-MMM-yy");
if ("A".equalsIgnoreCase(printStatus)) {
sql = " SELECT TRAN_ID, DOC_NAME, DOC_TYPE, DOC_ID, PRINT_STATUS, CHG_DATE, CHG_USER FROM PRINT_LOG WHERE TRAN_ID BETWEEN ? AND ? AND OBJ_NAME like '%"
+ objName + "%' AND CHG_USER = ? " + " ORDER BY TRAN_ID,DOC_ID,DOC_NAME";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, fromTranId);
pstmt.setString(2, toTranId);
pstmt.setString(3, userCode);
} else {
sql = " SELECT TRAN_ID, DOC_NAME, DOC_TYPE, DOC_ID, PRINT_STATUS, CHG_DATE, CHG_USER FROM PRINT_LOG WHERE TRAN_ID BETWEEN ? AND ? AND OBJ_NAME like '%"
+ objName + "%' AND PRINT_STATUS = ? AND CHG_USER = ? " + " ORDER BY TRAN_ID,DOC_ID,DOC_NAME";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, fromTranId);
pstmt.setString(2, toTranId);
pstmt.setString(3, printStatus);
pstmt.setString(4, userCode);
}
rs = pstmt.executeQuery();
while (rs.next()) {
++countId;
tranId = ((rs.getString("TRAN_ID") == null) ? "" : rs.getString("TRAN_ID"));
docName = ((rs.getString("DOC_NAME") == null) ? "" : rs.getString("DOC_NAME"));
docType = ((rs.getString("DOC_TYPE") == null) ? "" : rs.getString("DOC_TYPE"));
docId = ((rs.getString("DOC_ID") == null) ? "" : rs.getString("DOC_ID"));
docPrintStatus = ((rs.getString("PRINT_STATUS") == null) ? "" : rs.getString("PRINT_STATUS"));
docPrintDate = ((rs.getString("CHG_DATE") == null) ? "" : rs.getString("CHG_DATE"));
docPrintBy = ((rs.getString("CHG_USER") == null) ? "" : rs.getString("CHG_USER"));
docPages = String.valueOf(this.getNoOfPages(docId));
docPrintDate = simpleDf.format(simpleDf.parse(docPrintDate));
xmlStringBuff.append("<Detail>\r\n");
xmlStringBuff.append("<count_id>").append("<![CDATA[").append(countId).append("]]>")
.append("</count_id>\r\n ");
xmlStringBuff.append("<tran_id>").append("<![CDATA[").append(tranId).append("]]>")
.append("</tran_id>\r\n ");
xmlStringBuff.append("<doc_id>").append("<![CDATA[").append(docId).append("]]>")
.append("</doc_id>\r\n ");
xmlStringBuff.append("<doc_name>").append("<![CDATA[").append(docName).append("]]>")
.append("</doc_name>\r\n ");
xmlStringBuff.append("<doc_type>").append("<![CDATA[").append(docType).append("]]>")
.append("</doc_type>\r\n ");
xmlStringBuff.append("<doc_pages>").append("<![CDATA[").append(docPages).append("]]>")
.append("</doc_pages>\r\n ");
xmlStringBuff.append("<print_status>").append("<![CDATA[").append(docPrintStatus).append("]]>")
.append("</print_status>\r\n ");
xmlStringBuff.append("<print_date>").append("<![CDATA[").append(docPrintDate).append("]]>")
.append("</print_date>\r\n ");
xmlStringBuff.append("<print_by>").append("<![CDATA[").append(docPrintBy).append("]]>")
.append("</print_by>\r\n ");
xmlStringBuff.append("</Detail>\r\n");
}
xmlStringBuff.append("<Detail1>\r\n");
xmlStringBuff.append("<max_id>").append("<![CDATA[").append(countId).append("]]>").append("</max_id>\r\n ");
xmlStringBuff.append("</Detail1>\r\n");
xmlStringBuff.append("</Root>\r\n");
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception ex) {
ex.printStackTrace();
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
return xmlStringBuff.toString();
} finally {
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
}
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
return xmlStringBuff.toString();
}
public String printAttachments(final String[] chkValues, final String printerName, String objName,
final String userCode, final HashMap<String, String> noOfCopiesMap) {
objName = (objName.contains("w_") ? objName : ("w_" + objName));
final DocumentHandlerEJB docHandler = new DocumentHandlerEJB();
final DocumentPrint documentPrint = new DocumentPrint();
byte[] byteArray = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
String result = "";
String docId = "";
String docName = "";
String docType = "";
String tranId = "";
int noOfCopies = 0;
int rowsInserted = 0;
Connection conn = null;
ConnDriver connDriver = null;
try {
connDriver = new ConnDriver();
final UserInfoBean userInfo = this.createUserInfo(userCode);
conn = connDriver.getConnectDB(userInfo.getTransDB());
conn.setAutoCommit(false);
connDriver = null;
sql = " INSERT INTO PRINT_LOG (PRINTLOG_ID,OBJ_NAME,TRAN_ID,PRINT_DATE,PRINT_BY,DOC_NAME,DOC_TYPE, PRINT_STATUS,CHG_DATE,CHG_USER,CHG_TERM,DOC_ID) VALUES (PRINTLOG_ID.nextval,?,?,sysdate,?,?,?,?,sysdate,?,?,?)";
pstmt = conn.prepareStatement(sql);
for (int i = 0; i < chkValues.length; ++i) {
byteArray = null;
rowsInserted = 0;
result = "";
final UserInfoBean userInfoBean = this.createUserInfo(userCode);
docId = chkValues[i];
byteArray = docHandler.getDocument(docId,userInfoBean);
docName = docHandler.getDocumentName(docId,userInfoBean.getTransDB());
tranId = this.getTranId(docId, userInfoBean);
docType = docHandler.getDocumentFile(docId,userInfoBean.getTransDB());
noOfCopies = Integer.parseInt((noOfCopiesMap.get(docId) == null) ? "1" : noOfCopiesMap.get(docId));
System.out.println("No Of Copies are [ " + noOfCopies + " ]");
if (docType.contains(".")) {
docType = docType.substring(docType.lastIndexOf(".") + 1, docType.length());
}
if (byteArray != null) {
try {
final String strDirectoy = String.valueOf(CommonConstants.APPLICATION_CONTEXT) + "Downloads";
File outFile = new File(strDirectoy);
if (!outFile.exists()) {
outFile.mkdir();
}
outFile = new File(String.valueOf(CommonConstants.APPLICATION_CONTEXT) + "Downloads"
+ File.separator + docName);
final FileOutputStream fout = new FileOutputStream(outFile);
IOUtils.write(byteArray, (OutputStream) fout);
result = documentPrint.doPrint(outFile, docType, printerName, noOfCopies);
fout.close();
outFile.delete();
if ("true".equalsIgnoreCase(result)) {
pstmt.setString(1, objName);
pstmt.setString(2, tranId);
pstmt.setString(3, userCode);
pstmt.setString(4, docName);
pstmt.setString(5, docType);
pstmt.setString(6, "Y");
pstmt.setString(7, userCode);
pstmt.setString(8, "");
pstmt.setString(9, docId);
System.out.println("Printing done successfully!!!");
} else {
pstmt.setString(1, objName);
pstmt.setString(2, tranId);
pstmt.setString(3, userCode);
pstmt.setString(4, docName);
pstmt.setString(5, docType);
pstmt.setString(6, "N");
pstmt.setString(7, userCode);
pstmt.setString(8, "");
pstmt.setString(9, docId);
System.out.println("error occured in Printing!!!");
}
rowsInserted = pstmt.executeUpdate();
System.out.println("rows Inserted [" + rowsInserted + "]");
if (rowsInserted > 0) {
conn.commit();
} else {
conn.rollback();
}
} catch (Exception e) {
result = e.getMessage();
}
}
}
if ("true".equalsIgnoreCase(result)) {
result = "Printing Done Successfully!!!";
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex) {
System.out.println("inside try==" + ex.getMessage());
ex.printStackTrace();
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
return result;
} finally {
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
}
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex2) {
ex2.printStackTrace();
}
return result;
}
public String getTranId(final String docId, final UserInfoBean userInfo) {
String retTranId = "";
Connection conn = null;
ConnDriver connDriver = null;
PreparedStatement mPstmt = null;
ResultSet rs = null;
try {
connDriver = new ConnDriver();
conn = connDriver.getConnectDB(userInfo.getTransDB());
conn.setAutoCommit(false);
connDriver = null;
final String selQry = "SELECT REF_ID FROM DOC_TRANSACTION_LINK WHERE DOC_ID =?";
mPstmt = conn.prepareStatement(selQry);
mPstmt.setString(1, docId);
rs = mPstmt.executeQuery();
if (rs.next()) {
retTranId = ((rs.getString(1) == null) ? "" : rs.getString(1));
}
conn.commit();
if (mPstmt != null) {
mPstmt.close();
mPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception e) {
System.out.println("Exception :AttachmentDetailEJB :getTranId :==>" + e);
e.printStackTrace();
try {
if (mPstmt != null) {
mPstmt.close();
mPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
return retTranId;
} finally {
try {
if (mPstmt != null) {
mPstmt.close();
mPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
try {
if (mPstmt != null) {
mPstmt.close();
mPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
return retTranId;
}
public int getNoOfPages(final String docId) {
int retNoOfPages = 0;
Connection conn = null;
ConnDriver connDriver = null;
PreparedStatement mPstmt = null;
ResultSet rs = null;
try {
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("Driver");
conn.setAutoCommit(false);
connDriver = null;
final String selQry = "SELECT DOC_PAGES FROM DOC_CONTENTS WHERE DOC_ID =?";
mPstmt = conn.prepareStatement(selQry);
mPstmt.setString(1, docId);
rs = mPstmt.executeQuery();
if (rs.next()) {
retNoOfPages = rs.getInt(1);
}
conn.commit();
if (mPstmt != null) {
mPstmt.close();
mPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception e) {
System.out.println("Exception :AttachmentDetailEJB :getTranId :==>" + e);
e.printStackTrace();
try {
if (mPstmt != null) {
mPstmt.close();
mPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
return retNoOfPages;
} finally {
try {
if (mPstmt != null) {
mPstmt.close();
mPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
try {
if (mPstmt != null) {
mPstmt.close();
mPstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
return retNoOfPages;
}
private void createUploadFileLog(final String log, final String fileName) {
try {
final String logDir = String.valueOf(CommonConstants.JBOSSHOME) + File.separator + "log" + File.separator
+ "attachments" + File.separator + fileName;
final File outFile = new File(String.valueOf(CommonConstants.JBOSSHOME) + File.separator + "log"
+ File.separator + "attachments");
if (!outFile.exists()) {
outFile.mkdir();
}
final PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(logDir, true)));
out.println(log);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private String getStackTrace(final Throwable throwable) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw, true);
throwable.printStackTrace(pw);
return sw.getBuffer().toString();
}
private boolean isFileUploaded(final String docId, final String refSer, final String objName, Connection conn,
final String loginCode) {
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection mConnection = conn;
boolean isLocalConnection = false;
boolean isFileUploaded = false;
Label_0299 : {
try {
int resultCnt = 0;
if (mConnection == null) {
final UserInfoBean userInfoBean = this.createUserInfo(loginCode);
ConnDriver mConnDriver = new ConnDriver();
conn = mConnDriver.getConnectDB(userInfoBean.getTransDB());
mConnDriver = null;
isLocalConnection = true;
}
final String sql = "SELECT COUNT(*) FROM UNALLOCATED_ATTACH WHERE DOC_ID = ? AND REF_SER = ? AND OBJ_NAME = ?";
pstmt = mConnection.prepareStatement(sql);
pstmt.setString(1, docId);
pstmt.setString(2, refSer);
pstmt.setString(3, objName);
rs = pstmt.executeQuery();
if (rs.next()) {
resultCnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("resultCnt - [" + resultCnt + "]");
if (resultCnt > 0) {
isFileUploaded = true;
}
} catch (Exception e) {
isFileUploaded = false;
e.printStackTrace();
try {
if (isLocalConnection && mConnection != null) {
mConnection.close();
mConnection = null;
}
} catch (SQLException e2) {
e2.printStackTrace();
}
break Label_0299;
} finally {
try {
if (isLocalConnection && mConnection != null) {
mConnection.close();
mConnection = null;
}
} catch (SQLException e2) {
e2.printStackTrace();
}
}
try {
if (isLocalConnection && mConnection != null) {
mConnection.close();
mConnection = null;
}
} catch (SQLException e2) {
e2.printStackTrace();
}
}
System.out.println("isFileUploaded : [" + isFileUploaded + "]");
return isFileUploaded;
}
private int deleteUnallocRec(final String tranId, Connection conn, final String loginCode) {
PreparedStatement pstmt = null;
Connection mConnection = conn;
boolean isLocalConnection = false;
int deleteCnt = 0;
Label_0202 : {
try {
if (mConnection == null) {
final UserInfoBean userInfoBean = this.createUserInfo(loginCode);
ConnDriver mConnDriver = new ConnDriver();
conn = mConnDriver.getConnectDB(userInfoBean.getTransDB());
mConnDriver = null;
isLocalConnection = true;
}
final String sql = "DELETE FROM UNALLOCATED_ATTACH WHERE TRAN_ID = ?";
pstmt = mConnection.prepareStatement(sql);
pstmt.setString(1, tranId);
deleteCnt = pstmt.executeUpdate();
pstmt.close();
pstmt = null;
} catch (Exception e) {
e.printStackTrace();
try {
if (isLocalConnection && mConnection != null) {
mConnection.close();
mConnection = null;
}
} catch (SQLException e2) {
e2.printStackTrace();
}
break Label_0202;
} finally {
try {
if (isLocalConnection && mConnection != null) {
mConnection.close();
mConnection = null;
}
} catch (SQLException e2) {
e2.printStackTrace();
}
}
try {
if (isLocalConnection && mConnection != null) {
mConnection.close();
mConnection = null;
}
} catch (SQLException e2) {
e2.printStackTrace();
}
}
System.out.println("deleteCnt : [" + deleteCnt + "]");
return deleteCnt;
}
public UserInfoBean createUserInfo(final String userId) throws BaseException, Exception {
final UserInfoBean userInfoBean = new UserInfoBean();
ConnDriver connDriver = null;
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
userInfoBean.setLoginCode(userId);
connDriver = new ConnDriver();
connection = connDriver.getConnectDB("Driver");
statement = connection.createStatement();
final String sql = "select EMP_CODE,ENTITY_CODE,PROFILE_ID,USER_TYPE,CHG_TERM,USER_THEME,USER_COUNTRY,USER_LANG,TRANS_DB,SITE_CODE__DEF from users where code='"
+ userId + "'";
resultSet = statement.executeQuery(sql);
if (resultSet.next()) {
userInfoBean.setEmpCode(E12GenericUtility.checkNull(resultSet.getString("EMP_CODE")));
userInfoBean.setEntityCode(E12GenericUtility.checkNull(resultSet.getString("ENTITY_CODE")));
userInfoBean.setProfileId(E12GenericUtility.checkNull(resultSet.getString("PROFILE_ID")));
userInfoBean.setUserType(E12GenericUtility.checkNull(resultSet.getString("USER_TYPE")));
userInfoBean.setRemoteHost(E12GenericUtility.checkNull(resultSet.getString("CHG_TERM")));
userInfoBean.setUserTheme(E12GenericUtility.checkNull(resultSet.getString("USER_THEME")));
userInfoBean.setUserCountry(E12GenericUtility.checkNull(resultSet.getString("USER_COUNTRY")));
userInfoBean.setUserLanguage(E12GenericUtility.checkNull(resultSet.getString("USER_LANG")));
userInfoBean.setTransDB(E12GenericUtility.checkNull(resultSet.getString("TRANS_DB")));
userInfoBean.setSiteCode(E12GenericUtility.checkNull(resultSet.getString("SITE_CODE__DEF")));
System.out.println("CommonDBAccessEjb createUserInfo()::::::" + userInfoBean.toString());
}
} catch (Exception e) {
System.out.println("Exception in CommonDBAccessEJB createUserInfo()........." + e);
return userInfoBean;
} finally {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
}
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
return userInfoBean;
}
}
\ No newline at end of file
package ibase.webitm.ejb.marketingsch;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.util.HashMap;
import javax.ejb.Local;
@Local
public interface AttachmentHandlerEJBLocal {
String handleAttachment(String paramString1, String paramString2, String paramString3, String paramString4)
throws RemoteException, ITMException;
String getAttachmentDetail(String paramString1, String paramString2, String paramString3, String paramString4)
throws RemoteException, ITMException;
String printAttachments(String[] paramArrayOfString, String paramString1, String paramString2, String paramString3,
HashMap<String, String> paramHashMap) throws RemoteException, ITMException;
String getPrintLog(String paramString1, String paramString2, String paramString3, String paramString4,
String paramString5) throws RemoteException, ITMException;
boolean isRecordExist(String paramString1, String paramString2, String paramString3);
String getRefSer(String paramString1, String paramString2);
}
package ibase.webitm.ejb.marketingsch;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.util.HashMap;
import javax.ejb.Remote;
@Remote
public interface AttachmentHandlerEJBRemote {
String handleAttachment(String paramString1, String paramString2, String paramString3, String paramString4)
throws RemoteException, ITMException;
String getAttachmentDetail(String paramString1, String paramString2, String paramString3, String paramString4)
throws RemoteException, ITMException;
String printAttachments(String[] paramArrayOfString, String paramString1, String paramString2, String paramString3,
HashMap<String, String> paramHashMap) throws RemoteException, ITMException;
String getPrintLog(String paramString1, String paramString2, String paramString3, String paramString4,
String paramString5) throws RemoteException, ITMException;
boolean isRecordExist(String paramString1, String paramString2, String paramString3);
String getRefSer(String paramString1, String paramString2);
}
package ibase.webitm.ejb.marketingsch;
import java.util.HashMap;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.AppConnectParm;
import ibase.utility.GenericUtility;
import java.util.HashMap;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class MarketingInsertSch implements Schedule
{
public void attachFiles(String inputString) {
System.out.println("in attach Files");
String tranDB = "";
String objName = "";
String tranIdFrom = "";
String tranIdTo = "";
Document dom = null;
GenericUtility genUtility = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int childNodeLength = 0;
String loginCode = "";
String var14 = "";
try {
genUtility = GenericUtility.getInstance();
dom = genUtility.parseString(inputString);
loginCode = dom.getElementsByTagName("loginCode").item(0).getFirstChild().getNodeValue();
parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeLength = childNodeList.getLength();
for (int i = 0; i < childNodeLength; ++i) {
childNode = childNodeList.item(i);
if (childNode.getFirstChild() != null) {
if (i == 0) {
tranDB = childNode.getFirstChild().getNodeValue();
}
else if (i == 1) {
objName = childNode.getFirstChild().getNodeValue();
} else if (i == 2) {
tranIdFrom = childNode.getFirstChild().getNodeValue();
} else if (i == 3) {
tranIdTo = childNode.getFirstChild().getNodeValue();
}
}
}
if (objName != null && objName.length() != 0 && !"null".equalsIgnoreCase(objName)) {
if (objName.contains("w_")) {
objName = objName.replace("w_", "");
}
} else {
objName = "";
}
if (tranIdFrom == null || tranIdFrom.length() == 0 || "null".equalsIgnoreCase(tranIdFrom)) {
tranIdFrom = "";
}
if (tranIdTo == null || tranIdTo.length() == 0 || "null".equalsIgnoreCase(tranIdTo)) {
tranIdTo = "";
}
AppConnectParm appConnect = new AppConnectParm();
new InitialContext(appConnect.getProperty());
AttachmentHandlerEJB attachHandler = new AttachmentHandlerEJB();
attachHandler.handleAttachment(objName, tranIdFrom, tranIdTo, loginCode);
} catch (NamingException var17) {
var17.printStackTrace();
} catch (Exception var18) {
var18.printStackTrace();
}
}
public String schedule(HashMap inputHashMap) throws Exception {
System.out.println("schedule HashMap inputHashMap[" + inputHashMap + "]");
this.attachFiles(inputHashMap.toString());
return null;
}
public String schedule(String inputString) throws Exception {
System.out.println("schedule inputString[" + inputString + "]");
this.attachFiles(inputString);
return null;
}
public String schedulePriority(String inputString) throws Exception {
System.out.println("schedulePriority inputString[" + inputString + "]");
this.attachFiles(inputString);
return null;
}
}
package ibase.webitm.ejb.marketingsch;
import com.itextpdf.text.pdf.PdfReader;
import ibase.planner.utility.ITMException;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.utility.EMail;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.DocumentHandlerWrapperEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.utility.TransIDGenerator;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
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.Date;
import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.io.FilenameUtils;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class MarketingInsertSchOld extends ValidatorEJB implements Schedule {
UserInfoBean userInfo = null;
String xmlpath = "";
String movePath = "";
String attachmentPath = "";
String logPath = "";
String xmlName = "";
String chgUser = "";
String chgTerm = "";
String loginSiteCode = "";
String logFilePath = "";
String winId = "";
public String schedulePriority(String wrkflwPriority) throws Exception {
return "";
}
public String schedule(HashMap map) throws Exception {
return "";
}
public String schedule(String scheduleParamXML) throws ITMException, Exception {
String flag = "PWC";
String reultString = "";
Connection conn = null;
try {
System.out.println("MarketingSchBean.java.schedule()");
ConnDriver connDriver = new ConnDriver();
this.userInfo = new UserInfoBean(scheduleParamXML);
String transDB = this.userInfo.getTransDB();
String loginEmpCode = this.userInfo.getEmpCode();
System.out.println("get TransDB & login code connection in updateStatus : " + transDB + "::loginEmpCode::"
+ loginEmpCode);
if (transDB != null && transDB.trim().length() > 0) {
conn = connDriver.getConnectDB(transDB);
} else {
conn = connDriver.getConnectDB("DriverITM");
}
conn.setAutoCommit(false);
connDriver = null;
reultString = this.schedule(scheduleParamXML, flag, conn);
this.sendIntimation("ITM", this.logFilePath, loginEmpCode, conn);
} catch (Exception var11) {
var11.printStackTrace();
} finally {
if (conn != null) {
conn.commit();
conn.close();
conn = null;
}
}
return reultString;
}
private String schedule(String scheduleParamXML, String flag, Connection conn) throws ITMException, Exception {
int ctr = 0;
String companyCode = "";
String companyName = "";
double invAmt = 0.0D;
String invDate = "";
String invNo = "";
String metisVendorCode = "";
String orderRefNo = "";
String orderRefNoDateTime = "";
String remarks = "";
String vcode = "";
String vendorName = "";
String winame = "";
String acctCode = "";
String cctrCode = "";
String childNodeName = "";
String orderRefNodesName = "";
String errMsg = "";
Document dom = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
Node orderRefNodes = null;
Node orderRefNodesChildNode = null;
NodeList orderRefNodesList = null;
NodeList orderRefNodesChildList = null;
int childNodeListLength = 0;
String xtraParams = "";
File loadXmlfolder = null;
File[] loadAllXml = null;
File checkFile = null;
FinCommon finCommon = null;
MarketingSchBeanOld vendorSchBean = null;
try {
System.out.println("MarketingSchBean.java.schedule()2]");
System.out.println("scheduleParamXML]" + scheduleParamXML);
finCommon = new FinCommon();
this.userInfo = new UserInfoBean(scheduleParamXML);
xtraParams = "loginEmpCode=" + this.userInfo.getEmpCode() + "~~termId=" + this.userInfo.getRemoteHost()
+ "~~loginSiteCode=" + this.userInfo.getSiteCode() + "~loginCode=" + this.userInfo.getLoginCode();
System.out.println("xtraParams]" + xtraParams);
String transDB = this.userInfo.getTransDB();
String loginCode = this.userInfo.getLoginCode();
System.out.println(
"get TransDB & login code connection in updateStatus : " + transDB + "::loginCode::" + loginCode);
this.xmlpath = finCommon.getFinparams("999999", "MKT_XML_PATH", conn);
this.attachmentPath = finCommon.getFinparams("999999", "MKT_ATTACH_PATH", conn);
this.movePath = finCommon.getFinparams("999999", "MKT_MOVE_PATH", conn);
this.logPath = finCommon.getFinparams("999999", "MKT_LOG_PATH", conn);
System.out.println("xmlpath>>>> " + this.xmlpath);
System.out.println("attachmentPath>>>> " + this.attachmentPath);
System.out.println("movePath>>>> " + this.movePath);
System.out.println("logPath>>>> " + this.logPath);
File path = new File(this.xmlpath);
if(!path.exists())
{
path.mkdirs();
}
path = new File(this.attachmentPath);
if(!path.exists())
{
path.mkdirs();
}
path = new File(this.movePath);
if(!path.exists())
{
path.mkdirs();
}
path = new File(this.logPath);
if(!path.exists())
{
path.mkdirs();
}
loadXmlfolder = new File(this.xmlpath);
loadAllXml = loadXmlfolder.listFiles();
File[] var44 = loadAllXml;
int var43 = loadAllXml.length;
for (int var42 = 0; var42 < var43; ++var42) {
File xmlfile = var44[var42];
this.xmlName = xmlfile.getName();
System.out.println("xmlName==>" + this.xmlName);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
dom = docBuilder.parse(xmlfile);
parentNodeList = dom.getElementsByTagName("workitem");
System.out.println("parentNodeList@]" + parentNodeList.getLength());
for (int i = 0; i < parentNodeList.getLength(); ++i) {
parentNode = parentNodeList.item(i);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("childNodeListLength " + childNodeListLength);
for (ctr = 0; ctr < childNodeListLength; ++ctr) {
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equalsIgnoreCase("companyCode")) {
if (childNode.getFirstChild() != null) {
companyCode = childNode.getFirstChild().getNodeValue();
} else {
companyCode = "";
}
System.out.println("[companyCode@1]+" + companyCode);
}
if (childNodeName.equalsIgnoreCase("companyName")) {
if (childNode.getFirstChild() != null) {
companyName = childNode.getFirstChild().getNodeValue();
} else {
companyName = "";
}
System.out.println("[companyName@1]+" + companyName);
}
if (childNodeName.equalsIgnoreCase("invAmt")) {
if (childNode.getFirstChild() != null) {
invAmt = Double.parseDouble(childNode.getFirstChild().getNodeValue() == null
? "0.0"
: childNode.getFirstChild().getNodeValue());
} else {
invAmt = 0.0D;
}
System.out.println("[invAmt@1]+" + invAmt);
}
if (childNodeName.equalsIgnoreCase("invDate")) {
if (childNode.getFirstChild() != null) {
invDate = childNode.getFirstChild().getNodeValue();
} else {
invDate = "";
}
System.out.println("[invDate@1]+" + invDate);
}
if (childNodeName.equalsIgnoreCase("invNo")) {
if (childNode.getFirstChild() != null) {
invNo = childNode.getFirstChild().getNodeValue();
} else {
invNo = "";
}
System.out.println("[invNo@1]+" + invNo);
}
if (childNodeName.equalsIgnoreCase("metisVendorCode")) {
if (childNode.getFirstChild() != null) {
metisVendorCode = childNode.getFirstChild().getNodeValue();
} else {
metisVendorCode = "";
}
System.out.println("[metisVendorCode@1]+" + metisVendorCode);
}
if (childNodeName.equalsIgnoreCase("orderRefNoTbl")) {
Element e = (Element) childNode;
orderRefNodesList = e.getElementsByTagName("orderRefNoDetails");
System.out.println(orderRefNodesList.getLength());
for (int j = 0; j < orderRefNodesList.getLength(); ++j) {
orderRefNodes = orderRefNodesList.item(j);
orderRefNodesChildList = orderRefNodes.getChildNodes();
System.out.println("lenth" + orderRefNodesChildList.getLength());
for (int k = 0; k < orderRefNodesChildList.getLength(); ++k) {
orderRefNodesChildNode = orderRefNodesChildList.item(k);
orderRefNodesName = orderRefNodesChildNode.getNodeName();
if (orderRefNodesName.equalsIgnoreCase("orderRefNo")) {
if (orderRefNodesChildNode.getFirstChild() != null) {
orderRefNo = orderRefNodesChildNode.getFirstChild().getNodeValue();
} else {
orderRefNo = "";
}
System.out.println("[orderRefNo@1]+" + orderRefNo);
}
if (orderRefNodesName.equalsIgnoreCase("orderRefNoDateTime")) {
if (orderRefNodesChildNode.getFirstChild() != null) {
orderRefNoDateTime = orderRefNodesChildNode.getFirstChild().getNodeValue();
} else {
orderRefNoDateTime = "";
}
System.out.println("[orderRefNoDateTime@1]+" + orderRefNoDateTime);
}
}
}
}
if (childNodeName.equalsIgnoreCase("remarks")) {
if (childNode.getFirstChild() != null) {
remarks = childNode.getFirstChild().getNodeValue();
} else {
remarks = "";
}
System.out.println("[remarks@1]+" + remarks);
}
if (childNodeName.equalsIgnoreCase("vcode")) {
if (childNode.getFirstChild() != null) {
vcode = childNode.getFirstChild().getNodeValue();
} else {
vcode = "";
}
System.out.println("[vcode@1]+" + vcode);
}
if (childNodeName.equalsIgnoreCase("vendorName")) {
if (childNode.getFirstChild() != null) {
vendorName = childNode.getFirstChild().getNodeValue();
} else {
vendorName = "";
}
System.out.println("[vendorName@1]+" + vendorName);
}
if (childNodeName.equalsIgnoreCase("winame")) {
if (childNode.getFirstChild() != null) {
winame = childNode.getFirstChild().getNodeValue();
} else {
winame = "";
}
System.out.println("[winame@1]+" + winame);
}
if (childNodeName.equalsIgnoreCase("costCenterCode")) {
if (childNode.getFirstChild() != null
&& !childNode.getFirstChild().getNodeValue().equalsIgnoreCase("NA")) {
cctrCode = childNode.getFirstChild().getNodeValue();
cctrCode = cctrCode.trim().length() > 4
? cctrCode.trim().substring(cctrCode.trim().length() - 4)
: cctrCode.trim();
System.out.println("INSIDE CCTR VJ" + cctrCode);
} else {
cctrCode = "";
}
System.out.println("[cctrCode@1]+" + cctrCode);
}
if (childNodeName.equalsIgnoreCase("glCode")) {
if (childNode.getFirstChild() != null
&& !childNode.getFirstChild().getNodeValue().equalsIgnoreCase("NA")) {
acctCode = childNode.getFirstChild().getNodeValue();
acctCode = acctCode.trim().length() > 4
? acctCode.trim().substring(acctCode.trim().length() - 4)
: acctCode.trim();
System.out.println("INSIDE GLCODE VJ" + acctCode);
} else {
acctCode = "";
System.out.println("[acctCode@1]+" + acctCode);
}
}
this.winId = winame.length() >= 13 ? winame.substring(3, 13) : winame;
vendorSchBean = new MarketingSchBeanOld(companyCode, companyName, invAmt, invDate, invNo,
metisVendorCode, orderRefNo, orderRefNoDateTime, remarks, vcode, vendorName, winame,
cctrCode, acctCode);
System.out.println("winId>>>> " + this.winId);
System.out.println("winame>>>> " + winame);
if (winame != null && winame.trim().length() > 0) {
checkFile = new File(this.attachmentPath);
File[] files = checkFile.listFiles();
boolean isFileExists = false;
File[] var53 = files;
int var52 = files.length;
for (int var51 = 0; var51 < var52; ++var51) {
File file = var53[var51];
if (file.getName().toLowerCase().indexOf(winame.toLowerCase()) >= 0) {
System.out.println("Parth==>" + file.getName());
isFileExists = true;
break;
}
}
System.out.println("isFileExists>>>> " + isFileExists);
if (isFileExists)
{
System.out.println("checkFile.exists()>>>> " + checkFile.exists());
errMsg = this.supplierBillInsert(vendorSchBean, xtraParams, transDB, conn);
} else
{
this.printLog("win_id==> checkFile.exists() " + this.winId,
"attachment does not exixts", this.xmlName);
}
} else {
this.printLog("win_id==>" + this.winId, "attachment does not exixts", this.xmlName);
}
}
System.out.println("<===errMsg===>" + errMsg);
Path temp = Files.move(Paths.get(xmlfile.getAbsolutePath()),
Paths.get(this.movePath + "/" + xmlfile.getName()));
if (temp != null) {
this.printLog("xmlName==>" + this.xmlName, " successfully to move", this.xmlName);
System.out.println("vj xml moved>>>> " + temp);
} else {
this.printLog("xmlName==>" + this.xmlName, "failed to move", this.xmlName);
System.out.println("vj xml moved failed>>>> " + temp);
}
}
}
} catch (Exception var54) {
var54.printStackTrace();
System.out.println("Exception@123]" + var54.getMessage());
this.printLog("win_id==>" + this.winId, var54.getMessage(), this.xmlName);
}
return errMsg;
}
private String supplierBillInsert(MarketingSchBeanOld vendorSchBean, String xtraParams, String tranDb, Connection conn)
throws ITMException {
String errMsg = "";
String sql = "";
String trandId = "";
String chgDate = "";
String docId = "";
int count = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
E12GenericUtility genericUtility = null;
try {
System.out.println("MarketingSchBean.java.supplierBillInsert()");
genericUtility = new E12GenericUtility();
this.chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
this.chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId");
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
chgDate = sdf.format(new Date());
this.loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
trandId = this.generateTranID("marketing_bill", this.loginSiteCode, "", conn);
System.out.println("MarketingSchBean.java.supplierBillInsert().tranId==>" + trandId);
/*sql = "insert into supplier_bill (tran_id,bill_no,bill_amt,bill_date,supp_code,document_ref_no,remarks,sundry_code,ref_ser,chg_date ,chg_user,chg_term,tran_date,status,sundry_type,acct_code,cctr_code,new_gen_ref_no) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, trandId);
pstmt.setString(2, vendorSchBean.getInvNo());
pstmt.setDouble(3, vendorSchBean.getInvAmt());
pstmt.setTimestamp(4, Timestamp.valueOf(vendorSchBean.getInvDate()));
pstmt.setString(5, vendorSchBean.getMetisVendorCode());
pstmt.setString(6, vendorSchBean.getOrderRefNo());
pstmt.setString(7, vendorSchBean.getRemarks());
pstmt.setString(8, vendorSchBean.getVcode());
pstmt.setString(9, "M-BILL");
pstmt.setTimestamp(10, Timestamp.valueOf(genericUtility.getValidDateString(chgDate,
genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0"));
pstmt.setString(11, this.chgUser);
pstmt.setString(12, this.chgTerm);
pstmt.setTimestamp(13, Timestamp.valueOf(genericUtility.getValidDateString(chgDate,
genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0"));
pstmt.setString(14, "O");
pstmt.setString(15, "S");
pstmt.setString(16, vendorSchBean.getAcctCode());
pstmt.setString(17, vendorSchBean.getCctrCode());
pstmt.setString(18, vendorSchBean.getWiname());
System.out.println("inside supplier_bill vijay");
count = pstmt.executeUpdate();
pstmt.close();
pstmt = null;
if (count > 0) {*/
System.out.println("tranId = "+trandId+"\nvendorSchBean.getWiname() = "+vendorSchBean.getWiname()
+"\ntranDb = "+tranDb);
errMsg = this.uploadAttachment(trandId, vendorSchBean.getWiname(), tranDb, conn);
this.printLog("win_id==>" + this.winId, " trandId==>" + trandId + " transaction generate successfully",
this.xmlName);
System.out.println("MarketingSchBean.java.supplierBillInsert().errMsg]" + errMsg);
//}
return errMsg;
} catch (Exception var15) {
System.out.println("MarketingSchBean.java.supplierBillInsert().Exception" + var15);
this.printLog("win_id==>" + this.winId, var15.getMessage(), this.xmlName);
var15.printStackTrace();
throw new ITMException(var15);
}
}
private String uploadAttachment(String tranId, String fileName, String transDB, Connection conn)
throws ITMException {
String retString = "";
PreparedStatement pstmt = null;
StringBuffer retXMLStringBuff = null;
StringBuffer uploadFileLog = null;
String fileType = "";
File filess = null;
String attachment = "";
byte[] byteArray = new byte[1];
BufferedInputStream bfr = null;
ByteArrayOutputStream bout = null;
FileInputStream input = null;
boolean var16 = false;
try {
E12GenericUtility genericUtility = new E12GenericUtility();
DocumentHandlerWrapperEJB documentHandlerWrapperEJB = new DocumentHandlerWrapperEJB();
attachment = this.attachmentPath;
filess = new File(attachment);
File[] files = filess.listFiles();
File[] var23 = files;
int var22 = files.length;
int var21 = 0;
while (true) {
label207 : {
if (var21 < var22) {
File file = var23[var21];
System.out.println("fileName12==>" + file.getName());
System.out.println("fileName1234==>" + fileName);
if (file.getName().toLowerCase().indexOf(fileName.toLowerCase()) < 0) {
break label207;
}
input = new FileInputStream(file);
bfr = new BufferedInputStream(input);
bout = new ByteArrayOutputStream();
int readCount;
while ((readCount = bfr.read()) != -1) {
bout.write(readCount);
}
byteArray = bout.toByteArray();
fileType = FilenameUtils.getExtension(attachment);
System.out.println("attachment>>>> " + attachment);
System.out.println("fileType]" + fileType);
retXMLStringBuff = new StringBuffer();
retXMLStringBuff
.append("<?xml version=\"1.0\" encoding=\"" + CommonConstants.ENCODING + "\"?>");
retXMLStringBuff.append("<DocumentRoot>");
retXMLStringBuff.append("<description>Datawindow Root</description>");
retXMLStringBuff.append("<group0>");
retXMLStringBuff.append("<description>Group0 description</description>");
retXMLStringBuff.append("<Header0>");
retXMLStringBuff.append("<description>Header0 members</description>");
retXMLStringBuff.append("<header>");
retXMLStringBuff.append("<ref_id><![CDATA[" + tranId + "]]></ref_id>");
retXMLStringBuff.append("<ref_ser><![CDATA[M-BILL]]></ref_ser>");
retXMLStringBuff.append("<doc_name><![CDATA[" + file.getName() + "]]></doc_name>");
retXMLStringBuff.append("<doc_type><![CDATA[" + fileType + "]]></doc_type>");
retXMLStringBuff.append("<obj_name><![CDATA[marketing_bill]]></obj_name>");
retXMLStringBuff.append("<created_by><![CDATA[" + this.chgUser + "]]></created_by>");
retXMLStringBuff.append("</header>");
retXMLStringBuff.append("</Header0>");
retXMLStringBuff.append("</group0>");
retXMLStringBuff.append("</DocumentRoot>");
System.out.println("retXMLStringBuff = [" + retXMLStringBuff.toString() + "]");
System.out.println(retXMLStringBuff.toString());
try {
System.out.println("retXMLStringBuff = "+retXMLStringBuff.toString()+"\nbyteArray = "+byteArray.toString()
+"\nthis.userInfo = "+this.userInfo);
retString = documentHandlerWrapperEJB.addDocument(retXMLStringBuff.toString(), byteArray,
(byte[]) null, this.userInfo);
} catch (Exception var47) {
this.printLog("win_id==>" + this.winId, var47.getMessage(), this.xmlName);
System.out.println(var47.getMessage());
var47.printStackTrace();
throw new ITMException(var47);
}
System.out.println("addDocument@adnan[" + retString + "]");
Document dom = genericUtility.parseString(retString);
Node node = dom.getElementsByTagName("ID").item(0);
if (node == null || node.getAttributes() == null
|| node.getAttributes().getNamedItem("Document_Id") == null) {
break label207;
}
String docid = node.getAttributes().getNamedItem("Document_Id").getNodeValue();
System.out.println("doc_id - [" + docid + "]");
String uniqueTranIdGenerator = this.generateTranID("unallocated", this.loginSiteCode, "", conn);
String sql = "INSERT INTO UNALLOCATED_ATTACH (TRAN_ID,REF_ID,REF_SER,DOC_ID,OBJ_NAME,STATUS,ADDED_BY,ADDED_TO_MAP,ADDED_ON) VALUES ( ?,?,?,?,?,?,?,?,sysdate )";
int updatecnt;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, uniqueTranIdGenerator);
pstmt.setString(2, tranId);
pstmt.setString(3, "M-BILL");
pstmt.setString(4, docid);
pstmt.setString(5, "marketing_bill");
pstmt.setString(6, "N");
pstmt.setString(7, this.loginSiteCode);
pstmt.setString(8, "0");
updatecnt = pstmt.executeUpdate();
System.out.println("inside unallocated vijay");
pstmt.close();
pstmt = null;
} catch (SQLException var46) {
this.printLog("win_id==>" + this.winId, var46.getMessage(), this.xmlName);
System.out.println("insiden exception==>[" + var46.getMessage() + "]");
var46.printStackTrace();
throw new ITMException(var46);
}
if (updatecnt != 0) {
break label207;
}
conn.rollback();
}
System.out.println("attachment>>>> " + attachment);
return retString;
}
++var21;
}
} catch (Exception var48) {
this.printLog("win_id==>" + this.winId, var48.getMessage(), this.xmlName);
var48.printStackTrace();
System.out.println("MarketingSchBean.java.uploadAttachment()Exception" + var48.getMessage());
throw new ITMException(var48);
} finally {
filess = null;
byteArray = null;
if (bfr != null) {
try {
bfr.close();
} catch (IOException var45) {
var45.printStackTrace();
throw new ITMException(var45);
}
}
if (bout != null) {
try {
bout.close();
} catch (IOException var44) {
var44.printStackTrace();
throw new ITMException(var44);
}
}
if (input != null) {
try {
input.close();
} catch (IOException var43) {
var43.printStackTrace();
throw new ITMException(var43);
}
}
}
}
private String generateTranID(String objName, String loginSiteCode, String itemSer, Connection conn)
throws ITMException {
String retString = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String keyString = "";
String refSer = "";
String sysDate = "";
E12GenericUtility genericUtility = new E12GenericUtility();
try {
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
sysDate = sdf.format(new Date());
System.out.println(" objName =>" + objName);
new HashMap();
HashMap<String, String> transetupMap = this.getTransetup("w_" + objName, conn);
keyString = (String) transetupMap.get("key_string");
refSer = (String) transetupMap.get("ref_ser");
String xmlValues = "";
xmlValues = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
xmlValues = xmlValues + "<Header></Header>";
xmlValues = xmlValues + "<Detail1>";
xmlValues = xmlValues + "<TRAN_ID></TRAN_ID>";
xmlValues = xmlValues + "<TRAN_DATE>" + sysDate + "</TRAN_DATE>";
xmlValues = xmlValues + "<SITE_CODE>" + loginSiteCode + "</SITE_CODE>";
xmlValues = xmlValues + "<ITEM_SER>" + itemSer + "</ITEM_SER>";
xmlValues = xmlValues + "</Detail1></Root>";
System.out.println("xmlValues :[" + xmlValues + "]");
System.out.println("keyString>>>>" + keyString + ">>>refSer>>>" + refSer);
TransIDGenerator tranIdGenerator = new TransIDGenerator(xmlValues, "SYSTEM", CommonConstants.DB_NAME);
String tranIdGenerated = tranIdGenerator.generateTranSeqID(refSer, "tran_id", keyString, conn);
System.out.println("tranIdGenerated => " + tranIdGenerated);
retString = tranIdGenerated;
} catch (Exception var23) {
var23.printStackTrace();
throw new ITMException(var23);
} finally {
try {
if (rs != null) {
((ResultSet) rs).close();
rs = null;
}
if (pstmt != null) {
((PreparedStatement) pstmt).close();
pstmt = null;
}
} catch (Exception var24) {
var24.printStackTrace();
throw new ITMException(var24);
}
}
return retString;
}
private HashMap<String, String> getTransetup(String winName, Connection conn) throws ITMException {
String keyString = "";
String refSer = "";
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
HashMap transetupMap = null;
try {
sql = "SELECT KEY_STRING, REF_SER FROM TRANSETUP WHERE TRAN_WINDOW = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, winName);
rs = pstmt.executeQuery();
if (rs.next()) {
keyString = rs.getString("KEY_STRING");
refSer = rs.getString("REF_SER");
}
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
System.out.println("ITWizardBean :: getKeyString :: keyString =>" + keyString);
System.out.println("ITWizardBean :: getKeyString :: refSer =>" + refSer);
transetupMap = new HashMap();
transetupMap.put("key_string", keyString);
transetupMap.put("ref_ser", refSer);
} catch (Exception var17) {
this.printLog("win_id==>" + this.winId, var17.getMessage(), this.xmlName);
var17.printStackTrace();
throw new ITMException(var17);
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
} catch (Exception var16) {
var16.printStackTrace();
throw new ITMException(var16);
}
}
return transetupMap;
}
private void printLog(String msg, String text, String fileName) throws ITMException {
String logFile = "";
String logDir = "";
File logFileDir = null;
FileWriter fileWriter = null;
try {
String logFileName = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
logFileName = "marketing_bill_" + fileName + "_" + sdf.format(new Date());
System.out.println("Inside the print log method");
logDir = this.logPath + File.separator + "marketingScan";
System.out.println("Log direction: " + logDir);
logFileDir = new File(logDir);
if (!logFileDir.exists()) {
logFileDir.mkdirs();
}
logFile = logDir + File.separator + logFileName + ".log";
System.out.println("FIle path::" + logFile);
this.logFilePath = logFile;
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date now = new Date();
String strDate = sdfDate.format(now);
fileWriter = new FileWriter(logFile, true);
fileWriter.write("\r\n");
fileWriter.write(strDate + " " + "[" + text + "] " + msg);
} catch (Exception var20) {
this.printLog("win_id==>" + this.winId, var20.getMessage(), this.xmlName);
var20.printStackTrace();
throw new ITMException(var20);
} finally {
try {
if (fileWriter != null) {
fileWriter.flush();
fileWriter.close();
}
} catch (Exception var19) {
var19.printStackTrace();
}
}
}
public int getPageCount(File fileTobeAttached) {
String filePath = fileTobeAttached.toString();
String fileName = fileTobeAttached.getName();
String fileType = fileName.substring(fileName.indexOf(".") + 1);
int pageCount = 0;
try {
if ("pdf".equalsIgnoreCase(fileType)) {
PdfReader reader = new PdfReader(filePath);
pageCount = reader.getNumberOfPages();
} else if ("doc".equalsIgnoreCase(fileType)) {
try {
POIFSFileSystem fis = new POIFSFileSystem(new FileInputStream(fileTobeAttached));
HWPFDocument wdDoc = new HWPFDocument(fis);
pageCount = wdDoc.getSummaryInformation().getPageCount();
} catch (Exception var10) {
System.out.println("In getPageCount Exception [" + var10.getMessage() + "]");
var10.printStackTrace();
}
} else if ("docx".equalsIgnoreCase(fileType)) {
byte[] inputBytePDF = (byte[]) null;
try {
FileInputStream fin = new FileInputStream(fileTobeAttached);
inputBytePDF = new byte[(int) fileTobeAttached.length()];
fin.read(inputBytePDF);
new ByteArrayInputStream(inputBytePDF);
} catch (Exception var9) {
System.out.println("In docx type Exception [" + var9.getMessage() + "]");
var9.printStackTrace();
}
}
} catch (IOException var11) {
System.out.println("In doc type Exception [" + var11.getMessage() + "]");
var11.printStackTrace();
}
return pageCount;
}
private void sendIntimation(String infoType, String logFileName, String loginEmpCode, Connection conn)
throws ITMException {
String formatCode = "VENDOR_ATT_LOG";
System.out.println("in send mail activity");
System.out.println("info type::" + infoType);
System.out.println("logFileName::" + logFileName);
System.out.println("loginCode::" + loginEmpCode);
StringBuffer valueXmlString = null;
valueXmlString = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><ROOT><TRANS_INFO>");
valueXmlString.append("</TRANS_INFO>");
valueXmlString.append("<MAIL>");
valueXmlString.append("<EMAIL_TYPE>").append("<![CDATA[page]]>").append("</EMAIL_TYPE>");
valueXmlString.append("<ENTITY_TYPE>").append("<![CDATA[E]]>").append("</ENTITY_TYPE>");
valueXmlString.append("<ENTITY_CODE>").append("<![CDATA[" + loginEmpCode + "]]>").append("</ENTITY_CODE>");
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[" + formatCode + "]]>").append("</FORMAT_CODE>");
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + logFileName + "]]>")
.append("</XML_DATA_FILE_PATH>");
valueXmlString.append("</MAIL>");
valueXmlString.append("</ROOT>");
String mailXmlString = valueXmlString.toString();
EMail em = new EMail();
try {
String mail_status = em.sendMail(mailXmlString, infoType, conn);
System.out.println("mail_status==" + mail_status);
} catch (Exception var10) {
var10.printStackTrace();
}
}
}
\ No newline at end of file
package ibase.webitm.ejb.marketingsch;
public class MarketingSchBeanOld {
private String companyCode = "";
private String companyName = "";
private double invAmt = 0.0D;
private String invDate = "";
private String invNo = "";
private String metisVendorCode = "";
String orderRefNo = "";
String orderRefNoDateTime = "";
private String remarks = "";
private String vcode = "";
private String vendorName = "";
private String winame = "";
private String acctCode = "";
private String cctrCode = "";
public MarketingSchBeanOld() {
}
public MarketingSchBeanOld(String companyCode, String companyName, double invAmt, String invDate, String invNo,
String metisVendorCode, String orderRefNo, String orderRefNoDateTime, String remarks, String vcode,
String vendorName, String winame, String cctrCode, String acctCode) {
this.companyCode = companyCode;
this.companyName = companyName;
this.invAmt = invAmt;
this.invDate = invDate;
this.invNo = invNo;
this.metisVendorCode = metisVendorCode;
this.orderRefNo = orderRefNo;
this.orderRefNoDateTime = orderRefNoDateTime;
this.remarks = remarks;
this.vcode = vcode;
this.vendorName = vendorName;
this.winame = winame;
this.acctCode = acctCode;
this.cctrCode = cctrCode;
}
public String getCompanyCode() {
return this.companyCode;
}
public void setCompanyCode(String companyCode) {
this.companyCode = companyCode;
}
public String getCompanyName() {
return this.companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public double getInvAmt() {
return this.invAmt;
}
public void setInvAmt(double invAmt) {
this.invAmt = invAmt;
}
public String getInvDate() {
return this.invDate;
}
public void setInvDate(String invDate) {
this.invDate = invDate;
}
public String getInvNo() {
return this.invNo;
}
public void setInvNo(String invNo) {
this.invNo = invNo;
}
public String getMetisVendorCode() {
return this.metisVendorCode;
}
public void setMetisVendorCode(String metisVendorCode) {
this.metisVendorCode = metisVendorCode;
}
public String getOrderRefNo() {
return this.orderRefNo;
}
public void setOrderRefNo(String orderRefNo) {
this.orderRefNo = orderRefNo;
}
public String getOrderRefNoDateTime() {
return this.orderRefNoDateTime;
}
public void setOrderRefNoDateTime(String orderRefNoDateTime) {
this.orderRefNoDateTime = orderRefNoDateTime;
}
public String getRemarks() {
return this.remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getVcode() {
return this.vcode;
}
public void setVcode(String vcode) {
this.vcode = vcode;
}
public String getVendorName() {
return this.vendorName;
}
public void setVendorName(String vendorName) {
this.vendorName = vendorName;
}
public String getWiname() {
return this.winame;
}
public void setWiname(String winame) {
this.winame = winame;
}
public String getCctrCode() {
return this.cctrCode;
}
public void setCctrCode(String cctrCode) {
this.cctrCode = cctrCode;
}
public String getAcctCode() {
return this.acctCode;
}
public void setAcctCode(String acctCode) {
this.acctCode = acctCode;
}
}
\ No newline at end of file
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