Commit e121b267 authored by vkadam's avatar vkadam

Change in validation.


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@96753 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 4a85ed6e
......@@ -27,47 +27,53 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryICRemote {
public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryICRemote
{
GenericUtility genericUtility = GenericUtility.getInstance();
String winName = null;
FinCommon finCommon = null;
ValidatorEJB validator = null;
public String wfValData(String xmlString, String xmlString1,String xmlString2,
String objContext, String editFlag,String xtraParams) throws RemoteException, ITMException {
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException
{
String errString = "";
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try {
if (xmlString != null && xmlString.trim().length() > 0) {
try
{
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = parseString(xmlString);
}
if (xmlString1 != null && xmlString1.trim().length() > 0) {
if (xmlString1 != null && xmlString1.trim().length() > 0)
{
dom1 = parseString(xmlString1);
}
if (xmlString2 != null && xmlString2.trim().length() > 0) {
if (xmlString2 != null && xmlString2.trim().length() > 0)
{
dom2 = parseString("<Root>" + xmlString2 + "</Root>");
}
errString = wfValData(dom, dom1, dom2, objContext, editFlag,xtraParams);
} catch (Exception e) {
errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
} catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return errString;
}
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag,
String xtraParams)throws RemoteException, ITMException {
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException
{
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
StringBuffer valueXmlString = new StringBuffer();
String userId = "",sql = "",errCode = "",errorType = "",errString = "",tranId = "",blankVar="";
String countCode="",keyFlag="",descr="",currCode="",transCode="",regCode="",validUpto="",regDate="";
int ctr = 0,currentFormNo = 0,cnt = 0,cnt1=0;
String userId = "", sql = "", errCode = "", errorType = "", errString = "", tranId = "", blankVar = "";
String countCode = "", keyFlag = "", descr = "", currCode = "", transCode = "", regCode = "", validUpto = "", regDate = "";
int ctr = 0, currentFormNo = 0, cnt = 0, cnt1 = 0;
ArrayList errList = new ArrayList();
ArrayList errFields = new ArrayList();
Connection conn = null;
......@@ -75,17 +81,20 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
ResultSet rs = null;
ConnDriver connDriver = new ConnDriver();
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
try {
try
{
this.finCommon = new FinCommon();
this.validator = new ValidatorEJB();
conn = connDriver.getConnectDB("DriverITM");
userId = getValueFromXTRA_PARAMS(xtraParams, "loginCode");
if ((objContext != null) && (objContext.trim().length() > 0)) {
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version = \"1.0\"?> <Root> <header> <editFlag>");
valueXmlString.append(editFlag).append("</editFlag> </header>");
switch (currentFormNo) {
switch (currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
......@@ -93,17 +102,20 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
valueXmlString.append("<Detail1>");
int childNodeListLength = childNodeList.getLength();
tranId = checkNull(this.genericUtility.getColumnValue("tran_id", dom));
for (ctr = 0; ctr < childNodeListLength; ctr++) {
for (ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("CURRENT COLUMN IN VALIDATION ["+ childNodeName + "]");
if (childNodeName.equalsIgnoreCase("count_code")) {
System.out.println("CURRENT COLUMN IN VALIDATION [" + childNodeName + "]");
if (childNodeName.equalsIgnoreCase("count_code"))
{
countCode = this.genericUtility.getColumnValue("count_code", dom);
sql = "select key_flag from transetup where tran_window = 'w_country'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
if (rs.next())
{
keyFlag = rs.getString("key_flag");
}
rs.close();
......@@ -111,20 +123,24 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
pstmt.close();
pstmt = null;
if(keyFlag==null){
keyFlag="M";
if (keyFlag == null)
{
keyFlag = "M";
}
if(keyFlag.equalsIgnoreCase("M") && (countCode==null || countCode.trim().length()<=0)){
if (keyFlag.equalsIgnoreCase("M") && (countCode == null || countCode.trim().length() <= 0))
{
errCode = "VMCODNULL";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}else if(editFlag.equalsIgnoreCase("A")){
cnt=0;
} else if (editFlag.equalsIgnoreCase("A"))
{
cnt = 0;
sql = "select count(*) as cnt from country where count_code =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, countCode);
rs = pstmt.executeQuery();
if (rs.next()) {
if (rs.next())
{
cnt = rs.getInt("cnt");
}
rs.close();
......@@ -132,81 +148,94 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
pstmt.close();
pstmt = null;
if(cnt>0){
if (cnt > 0)
{
errCode = "VMDUPL1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}else if(childNodeName.equalsIgnoreCase("descr")){
} else if (childNodeName.equalsIgnoreCase("descr"))
{
descr = this.genericUtility.getColumnValue("descr", dom);
if(descr==null || descr.trim().length()<=0){
if (descr == null || descr.trim().length() <= 0)
{
errCode = "VMDESCR";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}else{
} else
{
countCode = this.genericUtility.getColumnValue("count_code", dom);
cnt=0;
cnt = 0;
sql = "select count(1) as cnt from country where count_code !=? and descr =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, countCode);
pstmt.setString(2, descr);
rs = pstmt.executeQuery();
if (rs.next()) {
if (rs.next())
{
cnt = rs.getInt("cnt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(cnt>0){
if (cnt > 0)
{
errCode = "VMDUPDESCR";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}else if(childNodeName.equalsIgnoreCase("curr_code")){
} else if (childNodeName.equalsIgnoreCase("curr_code"))
{
currCode = this.genericUtility.getColumnValue("curr_code", dom);
cnt=0;
cnt = 0;
sql = "select count(*) as cnt from currency where curr_code =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, currCode);
rs = pstmt.executeQuery();
if (rs.next()) {
if (rs.next())
{
cnt = rs.getInt("cnt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(cnt==0){
if (cnt == 0)
{
errCode = "VMCUR1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}else if(childNodeName.equalsIgnoreCase("trans_code")){
} else if (childNodeName.equalsIgnoreCase("trans_code"))
{
transCode = this.genericUtility.getColumnValue("trans_code", dom);
if(transCode!=null){
cnt=0;
if (transCode != null)
{
cnt = 0;
sql = "select count(*) as cnt from transporter where tran_code =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, transCode);
rs = pstmt.executeQuery();
if (rs.next()) {
if (rs.next())
{
cnt = rs.getInt("cnt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(cnt==0){
if (cnt == 0)
{
errCode = "VMTRAN1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
......@@ -222,65 +251,72 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail2>");
childNodeListLength = childNodeList.getLength();
for (ctr = 0; ctr < childNodeListLength; ctr++) {
for (ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.trim().equalsIgnoreCase("reg_code")) {
if (childNodeName.trim().equalsIgnoreCase("reg_code"))
{
regCode = this.genericUtility.getColumnValue("reg_code", dom);
if(regCode!=null){
cnt=0;
if (regCode != null)
{
cnt = 0;
sql = "select count(*) as cnt from reg_requirements where reg_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, regCode);
rs = pstmt.executeQuery();
if (rs.next()) {
if (rs.next())
{
cnt = rs.getInt("cnt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(cnt==0){
if (cnt == 0)
{
errCode = "VTRCODEXT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}else {
} else
{
errCode = "VTRCODNULL";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
} else if(childNodeName.trim().equalsIgnoreCase("reg_date")){
} else if (childNodeName.trim().equalsIgnoreCase("reg_date"))
{
regDate = this.genericUtility.getColumnValue("reg_date", dom);
if(regDate==null || regDate.trim().length()<=0){
if (regDate == null)
{
errCode = "VTREGNULL";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if(childNodeName.trim().equalsIgnoreCase("valid_upto")){
} else if (childNodeName.trim().equalsIgnoreCase("valid_upto"))
{
validUpto = this.genericUtility.getColumnValue("valid_upto", dom);
regDate = this.genericUtility.getColumnValue("reg_date", dom);
if(validUpto==null){
errCode = "VTVALNULL";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}else if (regDate != null)
{
Timestamp validUptoDate = Timestamp.valueOf(genericUtility.getValidDateString(validUpto, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
Timestamp regDateNew = Timestamp.valueOf(genericUtility.getValidDateString(regDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
if(validUpto!=null){
Timestamp validUptoDate = Timestamp.valueOf(genericUtility.getValidDateString(validUpto,
genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
Timestamp regDateNew = Timestamp.valueOf(genericUtility.getValidDateString(regDate,
genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
if(validUptoDate.compareTo(regDateNew)<=0)
if (validUptoDate.compareTo(regDateNew) <= 0)
{
errCode = "VTVALREGDT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}else{
errCode = "VTVALNULL";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
}
valueXmlString.append("</Detail1>");
......@@ -288,45 +324,57 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
int errListSize = errList.size();
cnt = 0;
String errFldName = null;
if ((errList != null) && (errListSize > 0)) {
for (cnt = 0; cnt < errListSize; cnt++) {
if ((errList != null) && (errListSize > 0))
{
for (cnt = 0; cnt < errListSize; cnt++)
{
errCode = (String) errList.get(cnt);
errFldName = (String) errFields.get(cnt);
errString = getErrorString(errFldName, errCode, userId);
errorType = 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>"));
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);
errString = "";
}
if (errorType.equalsIgnoreCase("E")) {
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errStringXml.append("</Errors> </Root> \r\n");
} else {
} else
{
errStringXml = new StringBuffer("");
}
} catch (Exception e) {
} catch (Exception e)
{
e.printStackTrace();
errString = e.getMessage();
throw new ITMException(e);
} finally {
try {
if (conn != null) {
if (rs != null) {
} finally
{
try
{
if (conn != null)
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null) {
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
conn.close();
}
conn = null;
} catch (Exception d) {
} catch (Exception d)
{
d.printStackTrace();
throw new ITMException(d);
}
......@@ -335,40 +383,43 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
return errString;
}
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext,
String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException {
Document dom = null,dom1 = null,dom2 = null;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
Document dom = null, dom1 = null, dom2 = null;
String valueXmlString = "";
try {
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0) {
if (xmlString2.trim().length() > 0)
{
dom2 = parseString(xmlString2);
}
valueXmlString = itemChanged(dom, dom1, dom2, objContext,currentColumn, editFlag, xtraParams);
valueXmlString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
System.out.println("valueXmlString[" + valueXmlString + "]");
} catch (Exception e) {
System.out.println("Exception : [MiscVal][itemChanged( String, String )] :==>\n"+ e.getMessage());
} catch (Exception e)
{
System.out.println("Exception : [MiscVal][itemChanged( String, String )] :==>\n" + e.getMessage());
throw new ITMException(e);
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2,String objContext, String currentColumn,
String editFlag,String xtraParams) throws RemoteException, ITMException {
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
String sql = "",sql1 = "",sql2 = "";
String sql = "", sql1 = "", sql2 = "";
Connection conn = null;
PreparedStatement pstmt = null,pstmt1=null,pstmt2=null;
ResultSet rs = null,rs1=null,rs2=null;
String currCode="",currCodeDesr="",regCode="",regDescr="";
int ctr = 0,currentFormNo = 0,childNodeListLength = 0;
java.util.Date reqDate = null,statusDate = null;
PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null;
ResultSet rs = null, rs1 = null, rs2 = null;
String currCode = "", currCodeDesr = "", regCode = "", regDescr = "";
int ctr = 0, currentFormNo = 0, childNodeListLength = 0;
java.util.Date reqDate = null, statusDate = null;
ArrayList errList = new ArrayList();
ArrayList errFields = new ArrayList();
SimpleDateFormat sdf;
......@@ -376,50 +427,57 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
GenericUtility genericUtility = GenericUtility.getInstance();
ConnDriver connDriver = new ConnDriver();
try {
try
{
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver = null;
this.finCommon = new FinCommon();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
if ((objContext != null) && (objContext.trim().length() > 0)) {
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version = \"1.0\"?> <Root> <header> <editFlag>");
valueXmlString.append(editFlag).append("</editFlag> </header>");
switch (currentFormNo) {
switch (currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail1>");
childNodeListLength = childNodeList.getLength();
do {
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equals(currentColumn)) {
if (childNodeName.equals(currentColumn))
{
childNode.getFirstChild();
}
ctr++;
} while ((ctr < childNodeListLength)&& (!childNodeName.equals(currentColumn)));
} while ((ctr < childNodeListLength) && (!childNodeName.equals(currentColumn)));
System.out.println("CURRENT COLUMN [" + currentColumn + "]");
if (currentColumn.trim().equalsIgnoreCase("curr_code")) {
if (currentColumn.trim().equalsIgnoreCase("curr_code"))
{
currCode = checkNull(this.genericUtility.getColumnValue("curr_code", dom));
sql = "Select descr from currency where curr_code =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, currCode);
rs = pstmt.executeQuery();
if (rs.next()) {
if (rs.next())
{
currCodeDesr = checkNull(rs.getString("descr"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
valueXmlString.append("<currency_descr ><![CDATA[" + currCodeDesr + "]]></currency_descr>");
}
valueXmlString.append("</Detail1>");
......@@ -431,43 +489,51 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
valueXmlString.append("<Detail2>");
childNodeListLength = childNodeList.getLength();
do {
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equals(currentColumn)) {
if (childNodeName.equals(currentColumn))
{
childNode.getFirstChild();
}
ctr++;
} while ((ctr < childNodeListLength)&& (!childNodeName.equals(currentColumn)));
} while ((ctr < childNodeListLength) && (!childNodeName.equals(currentColumn)));
System.out.println("CURRENT COLUMN [" + currentColumn + "]");
if (currentColumn.trim().equalsIgnoreCase("reg_code")) {
if (currentColumn.trim().equalsIgnoreCase("reg_code"))
{
regCode = checkNull(this.genericUtility.getColumnValue("reg_code", dom));
sql = "select descr from reg_requirements where reg_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, regCode);
rs = pstmt.executeQuery();
if (rs.next()) {
if (rs.next())
{
regDescr = checkNull(rs.getString("descr"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
valueXmlString.append("<descr ><![CDATA[" + regDescr + "]]></descr>");
}
}
valueXmlString.append("</Detail2>");
}
valueXmlString.append("</Root>");
} catch (Exception e) {
} catch (Exception e)
{
e.printStackTrace();
System.out.println("Exception ::" + e.getMessage());
throw new ITMException(e);
} finally {
try {
if (conn != null) {
} finally
{
try
{
if (conn != null)
{
if (pstmt != null)
pstmt.close();
if (rs != null)
......@@ -477,66 +543,88 @@ public class CountryIC extends ValidatorEJB implements CountryICLocal, CountryIC
conn.close();
conn = null;
}
} catch (Exception d) {
} catch (Exception d)
{
d.printStackTrace();
throw new ITMException(d);
}
}
return valueXmlString.toString();
}
private String checkNull(String str) {
if (str == null) {
private String checkNull(String str)
{
if (str == null)
{
return "";
} else {
} else
{
return str;
}
}
private double checkDoubleNull(String str) {
if (str == null || str.trim().length() == 0) {
private double checkDoubleNull(String str)
{
if (str == null || str.trim().length() == 0)
{
return 0.0;
} else {
} else
{
return Double.parseDouble(str);
}
}
private String errorType(Connection conn, String errorCode)
throws ITMException {
private String errorType(Connection conn, String errorCode) throws ITMException
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
try
{
String sql = "SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
while (rs.next()) {
while (rs.next())
{
msgType = rs.getString("MSG_TYPE");
}
} catch (Exception ex) {
} catch (Exception ex)
{
ex.printStackTrace();
try {
if (rs != null) {
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null) {
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
} catch (Exception e) {
} catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
} finally {
try {
if (rs != null) {
} finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null) {
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
} catch (Exception e) {
} catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
......
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