Commit cf95ac1c authored by sanashaikh's avatar sanashaikh

Sana S : Added on [19/09/2019]

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@207670 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 6d40d828
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException;
//Created by Sana Shaikh on 11/09/2019 for Grade Wise Perk [START]
public class GradeWisePerkIC extends ValidatorEJB implements GradeWisePerkLocal, GradeWisePerkRemote
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag,
String xtraParams) throws RemoteException, ITMException
{
System.out.println(xmlString);
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = "";
E12GenericUtility genericUtility = null;
try {
genericUtility = new E12GenericUtility();
if (xmlString != null && xmlString.trim().length() != 0)
{
dom = genericUtility.parseString(xmlString);
System.out.println("Print dom>>>> " + dom);
}
if (xmlString1 != null && xmlString1.trim().length() != 0)
{
dom1 = genericUtility.parseString(xmlString1);
}
if (xmlString2 != null && xmlString2.trim().length() != 0)
{
dom2 = genericUtility.parseString(xmlString2);
}
errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
System.out.println("ErrString :" + errString);
}
catch (Exception e)
{
System.out.println("Exception :GradeWisePerkIC :wfValData(String xmlString):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning from GradeWisePerkIC wfvaldata");
return errString;
}
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag,
String xtraParams) throws RemoteException, ITMException
{
StringBuffer errStringXml = null;
PreparedStatement pstmt = null;
ITMDBAccessEJB itmDbAcess = null;
ResultSet rs = null;
Connection conn = null;
NodeList parentList = null;
NodeList childList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
String errString = "",errCode= "";
String userId = "";
String mval1= "",mval= "";
String sql = "",ls_accfilt="";
String effDateStr = "";
String expDateStr = "";
int currentFormNo = 0;
int noOfChilds = 0;
int counter;
int cnt = 0;
double amount = 0.0;
int cycleStart = 0;
int cycleEnd = 0;
int validityPrd = 0;
int cycleTime = 0;
String mtype= "",loginCode="",profileId="";
E12GenericUtility genericUtility = null;
errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
try
{
genericUtility = new E12GenericUtility();
itmDbAcess = new ITMDBAccessEJB();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
conn = getConnection();
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("Line no----");
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
parentList = dom.getElementsByTagName("Detail" + currentFormNo);
parentNode = parentList.item(0);
childList = parentNode.getChildNodes();
noOfChilds = childList.getLength();
System.out.println("noOfChilds--->>>" + noOfChilds);
for (counter = 0; counter < noOfChilds; counter++)
{
childNode = childList.item(counter);
childNodeName = childNode.getNodeName();
System.out.println("childNodeName>>>>>" + childNodeName);
System.out.println("childNode>>>>>>" + childNode);
System.out.println("counter>>>" + counter);
switch (currentFormNo)
{
case 1:
NodeList parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
NodeList childNodeList = parentNode.getChildNodes();
int childNodeListLength = childNodeList.getLength();
System.out.println("child Node List Length::::::" + childNodeListLength);
for (int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
System.out.println("childNode" + childNode);
if (childNode.getNodeType() != Node.ELEMENT_NODE)
{
continue;
}
childNodeName = childNode.getNodeName();
System.out.println("childNodeName.editFlag." + childNodeName + "" + editFlag);
System.out.println("@V@ Edit flag :- [" + editFlag + "");
if ("ad_code".equalsIgnoreCase(childNodeName))
{
mval = checkNull(genericUtility.getColumnValue("ad_code", dom));
mval1 = checkNull(genericUtility.getColumnValue("ad_code__main", dom));
cnt = 0;
sql = "select count(1) as cnt from allwdedn where ad_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt("cnt");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(cnt == 0)
{
errCode="VMADC1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else if(mval.equalsIgnoreCase(mval1))
{
sql="select payable from allwdedn where ad_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
mtype = rs.getString("payable");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(!"P".equals(mtype))
{
errCode="VTADTYP";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
if(errCode==null || errCode.trim().length()==0)
{
loginCode=genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.print("loginCode:"+loginCode);
sql="select profile_id from users where code= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginCode);
rs = pstmt.executeQuery();
if (rs.next())
{
profileId = rs.getString("profile_id");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
sql="select ACC_FILT as ls_accfilt from user_rights where profile_id= ? and obj_name = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, profileId);
pstmt.setString(2, "grade_perk");
rs = pstmt.executeQuery();
if (rs.next())
{
ls_accfilt = rs.getString("ls_accfilt");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.print("ls_accfilt:"+ls_accfilt);
if(ls_accfilt != null && ls_accfilt.trim().length() > 0)
{
System.out.print("U R IN");
sql="select count(1) as cnt from allwdedn where ad_code = ? and " + ls_accfilt;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt=rs.getInt("cnt");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(cnt==0)
{
errCode="VEADN1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
}
else if ("ad_code__main".equalsIgnoreCase(childNodeName))
{
mval = checkNull(genericUtility.getColumnValue("ad_code__main",dom));
sql="select count(1) as cnt from allwdedn where ad_code= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt("cnt");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(cnt==0)
{
errCode="VMADC1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if ("eff_date".equalsIgnoreCase(childNodeName))
{
effDateStr = checkNull(genericUtility.getColumnValue("eff_date",dom));
if(effDateStr == null || effDateStr.trim().length() == 0)
{
errCode="VTDATE11";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if ("exp_date".equalsIgnoreCase(childNodeName))
{
effDateStr = checkNull(genericUtility.getColumnValue("eff_date",dom));
expDateStr = checkNull(genericUtility.getColumnValue("exp_date",dom));
Date effDate = sdf.parse( effDateStr );
Date expDate = sdf.parse( expDateStr );
if(expDateStr == null || expDateStr.trim().length() == 0)
{
errCode="VTDATE11";
errList.add("VTDATE11");
errFields.add(childNodeName.toLowerCase());
}
if(effDate.after(expDate))
{
errCode="VMEXPDATE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if ("cycle_start".equalsIgnoreCase(childNodeName))
{
mval = checkNull(genericUtility.getColumnValue("ad_code",dom));
mval1 = checkNull(genericUtility.getColumnValue("ad_code__main",dom));
cycleStart=Integer.parseInt(checkNull(genericUtility.getColumnValue("cycle_start", dom)));
if(mval.equalsIgnoreCase(mval1))
{
if(cycleStart < 0 || cycleStart > 12 || cycleStart == 0)
{
errCode="VMCYCLE1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
else if ("cycle_end".equalsIgnoreCase(childNodeName))
{
mval = checkNull(genericUtility.getColumnValue("ad_code",dom));
mval1 = checkNull(genericUtility.getColumnValue("ad_code__main",dom));
cycleEnd=Integer.parseInt(checkNull(genericUtility.getColumnValue("cycle_end", dom)));
if(mval.equalsIgnoreCase(mval1))
{
if(cycleEnd < 0 || cycleEnd > 12 || cycleEnd == 0)
{
errCode="VMCYCLE1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
else if ("validity_period".equalsIgnoreCase(childNodeName))
{
validityPrd = Integer.parseInt(checkInt(genericUtility.getColumnValue("validity_period",dom)));
if(validityPrd <= 0)
{
errCode="VTVALPRD";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if ("amount".equalsIgnoreCase(childNodeName))
{
amount = Double.parseDouble(checkInt(genericUtility.getColumnValue("amount",dom)));
if(amount <= 0)
{
errCode="VTPAMT1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if ("cycle_time".equalsIgnoreCase(childNodeName))
{
cycleTime = Integer.parseInt(checkInt(genericUtility.getColumnValue("cycle_time",dom)));
if(genericUtility.getColumnValue("cycle_time",dom) == null || cycleTime <= 0)
{
errCode="VMCYCLE1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
break;
}
}
System.out.println("errStringXml.toString()---1= "+errStringXml.toString());
if (errList != null && errList.size() > 0)
{
System.out.println("errList==[" + errList + "]");
int errListSize = errList.size();
System.out.println("errListSize:::::::[" + errListSize + "]");
System.out.println("in error::::::::::");
for (int i = 0; i < errListSize; i++)
{
System.out.println("in error For:::::::::::::::");
String errCode1 = (String) errList.get(i);
String errFldName = (String) errFields.get(i);
System.out.println("errCode .........." + errCode1);
errString = itmDbAcess.getErrorString(errFldName, errCode1, userId, "", conn);
System.out.println("errString is : ::::>>>> " + errString);
String msgType = errorType(conn, errCode);
if (errString.length() > 0)
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8,errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
System.out.println("errStringXml .........." + errStringXml);
errString = "";
}
if (msgType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errFields.clear();
}
errStringXml.append("</Errors></Root>\r\n");
System.out.println("errStringXml.toString()---2= "+errStringXml.toString());
}
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 (conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception e)
{
System.out.println("Exception ::" + e);
e.printStackTrace();
throw new ITMException(e);
}
}
errString = errStringXml.toString();
return errString;
}
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext,
String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
Document dom1 = null;
Document dom = null;
Document dom2 = null;
String valueXmlString = "";
E12GenericUtility genericUtility = null;
try
{
System.out.println("xmlString==["+xmlString+"]");
genericUtility = new E12GenericUtility();
if (xmlString != null && xmlString.trim().length() != 0)
{
dom = genericUtility.parseString(xmlString);
}
if (xmlString1 != null && xmlString1.trim().length() != 0)
{
dom1 = genericUtility.parseString(xmlString1);
}
if (xmlString2 != null && xmlString2.trim().length() != 0)
{
dom2 = genericUtility.parseString(xmlString2);
}
valueXmlString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
} catch (Exception e) {
System.out.println("Exception :CadreWisePerkIC :itemChanged(String,String):" + e.getMessage() + ":");
valueXmlString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning from CadreWisePerkIC itemChanged");
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn,
String editFlag, String xtraParams) throws RemoteException, ITMException
{
StringBuffer valueXmlString = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
E12GenericUtility genericUtility = new E12GenericUtility();
int currentFormNo = 0;
String payTable = "";
String gradeCode = "";
String adEffDate = "";
String adExpDate = "";
String adCode = "";
String sql = "";
String descr = "";
AdmCommon admCommon = new AdmCommon();
String lastProcFor="";
int cycleTime = 0;
Date proccFor=null,nextProcDate=null;
String nextProcDate1=null;
UtilMethods utilMethods=new UtilMethods();
SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yy");
try
{
genericUtility = new E12GenericUtility();
System.out.println("currentFormNo...." + currentFormNo);
conn = getConnection();
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n<Header>\r\n<editFlag>");
valueXmlString.append(editFlag).append("</editFlag>\r\n</Header>\r\n");
System.out.println("current form no: " + currentFormNo);
switch (currentFormNo)
{
case 1:
{
System.out.println("=========================================Case1============================");
valueXmlString.append("<Detail1>\r\n");
if ("itm_default".equalsIgnoreCase(currentColumn))
{
System.out.print("Profile ID:::"+genericUtility.getValueFromXTRA_PARAMS(xtraParams, "profile_id"));
payTable = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "pay_table");
valueXmlString.append("<pay_table ><![CDATA[").append(payTable).append("]]></pay_table>\r\n");
AdmCommon.setNodeValue(dom, "pay_table", payTable);
gradeCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "grade_code");
valueXmlString.append("<grade_code ><![CDATA[").append(gradeCode).append("]]></grade_code>\r\n");
AdmCommon.setNodeValue(dom, "grade_code", gradeCode);
adEffDate = admCommon.getEnv("999999", "AD_EFFDATE", conn);
System.out.println("lsVarValue==["+adEffDate+"]");
System.out.println("genericUtility.getApplDateFormat()==["+genericUtility.getApplDateFormat()+"]");
adEffDate = genericUtility.getValidDateString(adEffDate,"dd-MM-yy", genericUtility.getApplDateFormat());
System.out.println("lsVarValue==after["+adEffDate+"]");
adExpDate = admCommon.getEnv("999999", "AD_EXPDATE", conn);
adExpDate = genericUtility.getValidDateString(adExpDate, "dd-MM-yy", genericUtility.getApplDateFormat());
valueXmlString.append("<eff_date ><![CDATA[").append(adEffDate).append("]]></eff_date>\r\n");
AdmCommon.setNodeValue(dom, "eff_date", adEffDate);
valueXmlString.append("<exp_date ><![CDATA[").append(adExpDate).append("]]></exp_date>\r\n");
AdmCommon.setNodeValue(dom, "exp_date", adExpDate);
System.out.println("dom==["+genericUtility.serializeDom(dom)+"]");
}
else if ("ad_code".equalsIgnoreCase(currentColumn))
{
adCode = checkNull(genericUtility.getColumnValue("ad_code", dom));
sql = "Select descr from allwdedn where ad_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, adCode);
rs = pstmt.executeQuery();
if (rs.next())
{
descr = rs.getString("descr");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<allwdedn_descr ><![CDATA[").append(descr).append("]]></allwdedn_descr>\r\n");
AdmCommon.setNodeValue(dom, "allwdedn_descr", descr);
}
else if ("last_proc_for".equalsIgnoreCase(currentColumn))
{
lastProcFor=checkNull(genericUtility.getColumnValue("last_proc_for", dom));
System.out.println("lastProcFor"+lastProcFor);
proccFor=sdf.parse(lastProcFor);
System.out.println("proccFor"+proccFor);
cycleTime=Integer.parseInt(checkNull(genericUtility.getColumnValue("cycle_time", dom)));
nextProcDate=utilMethods.AddMonths(proccFor, cycleTime);
nextProcDate1=sdf.format(nextProcDate);
System.out.println("Date ::::"+nextProcDate1);
valueXmlString.append("<next_proc_date><![CDATA[").append(nextProcDate1).append("]]></next_proc_date>\r\n");
}
else if ("cycle_time".equalsIgnoreCase(currentColumn))
{
lastProcFor=checkNull(genericUtility.getColumnValue("last_proc_for", dom));
proccFor=sdf.parse(lastProcFor);
cycleTime=Integer.parseInt(checkNull(genericUtility.getColumnValue("cycle_time", dom)));
nextProcDate=utilMethods.AddMonths(proccFor, cycleTime);
nextProcDate1 =sdf.format(nextProcDate);
valueXmlString.append("<next_proc_date><![CDATA[").append(nextProcDate1).append("]]></next_proc_date>\r\n");
}
}
valueXmlString.append("</Detail1>");
break;
}
valueXmlString.append("</Root>");
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
conn.close();
conn = null;
}
}
catch (Exception e)
{
System.out.println("Exception ::" + e);
e.printStackTrace();
throw new ITMException(e);
}
}
return valueXmlString.toString();
}
private String errorType(Connection conn, String errorCode) throws ITMException
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
if (conn == null)
{
System.out.println("Connection is null");
} else
{
System.out.println("Connection is not null");
}
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
if (rs.next())
{
msgType = rs.getString("MSG_TYPE");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception ex)
{
ex.printStackTrace();
throw new ITMException(ex);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return msgType;
}
private String checkNull(String input)
{
if (input == null)
{
input = "";
}
return input;
}
private String checkInt(String input)
{
if (input == null)
{
input = "0";
}
return input;
}
}
//Created by Sana Shaikh on 11/09/2019 for Grade Wise Perk [end]
\ 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