Commit 008d487c authored by sanashaikh's avatar sanashaikh

Sana S: Added on 17/02/20

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@216733 ce508802-f39f-4f6c-b175-0d175dae99d5
parent abb28e49
package ibase.webitm.ejb.adm.adv;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.E12GenericUtility;
import ibase.utility.EMail;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.adm.AdmCommon;
import ibase.webitm.utility.ITMException;
@Stateless
public class PayStruChgReqSubmit extends ValidatorEJB implements PayStruChgReqSubmitLocal,PayStruChgReqSubmitRemote
{
AdmCommon admCommon = new AdmCommon();
ITMDBAccessEJB itmDbAcess = new ITMDBAccessEJB();
E12GenericUtility genericUtility = new E12GenericUtility();
@SuppressWarnings("resource")
public String postSave(String Tranid,String forcedFlag,String xtraParams,Connection conn,String xmlString) throws RemoteException, ITMException
{
String errString = "";
String userId = "";
String sql = "";
//String workSite = "";
String empCodeHr = "";
String loginEmpCode = "";
String deptCode = "";
String siteCode = "";
String finEntity = "";
String geoLoc = "";
String appType = "";
String email = "";
String employeeMail = "";
//Document dom = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
ArrayList<String> empList = new ArrayList<>();
int cnt = 0 , MailCnt = 0;
boolean isMailSend = false;
try
{
System.out.println(":::Inside PayStruChgReqSubmit : postLogic():::");
// userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"));
userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode"));
System.out.println("Login Emp Code::"+userId);
loginEmpCode=userId;
//workSite = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
sql = "UPDATE PAY_STRU_CHG_REQ_HDR SET WF_STATUS = 'S' where TRAN_ID = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,Tranid);
cnt = pstmt.executeUpdate();
System.out.println("update count:::" +cnt);
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
//mail
sql = "SELECT EMAIL_ID_OFF FROM EMPLOYEE WHERE EMP_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginEmpCode);
rs = pstmt.executeQuery();
if(rs.next())
{
employeeMail = rs.getString("EMAIL_ID_OFF");
System.out.println("employeeMail generated " +employeeMail);
}
/**calling send mail method*/
if (rs != null)
{
rs.close();
rs = null;
}
pstmt.clearParameters();
if(cnt>0)
{
empList=getHREmpCode(loginEmpCode, conn);
System.out.println("empList getting is ::::" +empList.toString());
System.out.println("length of empList::::" +empList.toString().length());
if( empList.size() > 0 )
{
System.out.println("empList size "+empList.size());
for(int i = 0 ; i < empList.size(); i++)
{
empCodeHr = empList.get(i).toString();
System.out.println("EMPCODE FROM EMPLIST...."+empCodeHr);
pstmt.setString(1, empCodeHr);
rs = pstmt.executeQuery();
if(rs.next())
{
email = rs.getString("EMAIL_ID_OFF");
System.out.println("email generated from mailList:::::::" +email);
}
/**calling send mail method*/
if (rs != null)
{
rs.close();
rs = null;
}
pstmt.clearParameters();
isMailSend = sendMail(xmlString, "PYALOC","pay_stru_chg_req_wiz",Tranid,"PYALCHRAPR", "E", empCodeHr,email,employeeMail, conn);
if(isMailSend)
{
MailCnt++;
System.out.println("Mail send successfully >> "+MailCnt);
}
}
}
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try {
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(isMailSend)
{
conn.commit();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println("errString inside postLogic of PayStruChgReqSubmit-->"+errString);
return errString;
}
private boolean sendMail(String transInfo, String refSer, String objName, String refId, String formatCode, String entityType, String entityCode,String empCodeMailId, String mailIdCcAdd, Connection conn)
throws ITMException
{
System.out.println("@@## [PayStruChgReqSubmit] :sendMail ...........");
boolean emailFlag = false;
try
{
if (formatCode != null)
{
String lineNo = "1";
StringBuffer valueXmlString = null;
valueXmlString = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><ROOT><TRANS_INFO>");
valueXmlString.append("<OBJ_NAME>").append("<![CDATA[" + objName + "]]>").append("</OBJ_NAME>");
valueXmlString.append("<REF_SER>").append("<![CDATA[" + refSer + "]]>").append("</REF_SER>");
valueXmlString.append("<REF_ID>").append("<![CDATA[" + refId + "]]>").append("</REF_ID>");
valueXmlString.append("<LINE_NO>").append("<![CDATA[" + lineNo + "]]>").append("</LINE_NO>");
valueXmlString.append("</TRANS_INFO>");
valueXmlString.append("<MAIL>");
valueXmlString.append("<ENTITY_TYPE>").append("<![CDATA[" + entityType + "]]>").append("</ENTITY_TYPE>");
valueXmlString.append("<ENTITY_CODE>").append("<![CDATA[" + entityCode + "]]>").append("</ENTITY_CODE>");
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[" + formatCode +"]]>").append("</FORMAT_CODE>");
valueXmlString.append("<TO_ADD>").append("<![CDATA[" + empCodeMailId +"]]>").append("</TO_ADD>");
valueXmlString.append("<CC_ADD>").append("<![CDATA[" + mailIdCcAdd +"]]>").append("</CC_ADD>");
valueXmlString.append("<LINK_ADDR>").append("<![CDATA[" + "" + "]]>").append("</LINK_ADDR>");
valueXmlString.append("</MAIL>");
valueXmlString.append("<XML_DATA>").append(transInfo).append("</XML_DATA>");
valueXmlString.append("<EMAIL_TYPE>").append("<![CDATA[" + "link" + "]]>").append("</EMAIL_TYPE>");
valueXmlString.append("</ROOT>");
String mailDomStr = valueXmlString.toString();
System.out.println(" [PayStruChgReqSubmit] :sendMail mailDomStr :-->" + mailDomStr);
EMail email = new EMail();
email.sendMail(mailDomStr, "ITM", conn);
System.out.println("PayStruChgReqSubmit mail delivered successfully" );
emailFlag = true;
}
}
catch (Exception e)
{
System.out.println("Exception :[PayStruChgReqSubmit] :sendMail() :==>\n" + e.getMessage());
throw new ITMException(e);
}
return emailFlag;
}
private String checkNull(String input)
{
if (input == null)
{
input = "";
}
else
{
input = input.trim();
}
return input;
}
private ArrayList<String> getHREmpCode (String empCode, Connection conn) throws ITMException
{
String hrEmpCode = "", hrEmpCode1 = "", hrEmpCode2 = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList<String> empCodeList=new ArrayList<>();
int hrCnt=0;
try
{
hrCnt++;
String sql = "SELECT FN_GET_HR_EMP_CODE( ?, 'PYALC', 1) AS HR_EMP_CODE, FN_GET_HR_EMP_CODE( ?, 'PYALC', 2) AS HR_EMP_CODE_1, FN_GET_HR_EMP_CODE( ?, 'PYALC', 3) AS HR_EMP_CODE_2 FROM DUAL";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCode);
pstmt.setString(2, empCode);
pstmt.setString(3, empCode);
rs = pstmt.executeQuery();
if(rs.next())
{
hrEmpCode = checkNull(rs.getString("HR_EMP_CODE"));
hrEmpCode1 = checkNull(rs.getString("HR_EMP_CODE_1"));
hrEmpCode2 = checkNull(rs.getString("HR_EMP_CODE_2"));
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(hrEmpCode.trim().length()>0)
{
empCodeList.add(hrEmpCode);
}
if(hrEmpCode1.trim().length()>0)
{
empCodeList.add(hrEmpCode1);
}
if(hrEmpCode2.trim().length()>0)
{
empCodeList.add(hrEmpCode2);
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt =null;
}
}
catch(SQLException sqle)
{
sqle.printStackTrace();
throw new ITMException(sqle);
}
}
return empCodeList;
}
}
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