Commit 3f824a67 authored by Omkar Ingale's avatar Omkar Ingale

updated java component for mailingListIC.java

parent 6828f630
...@@ -20,204 +20,182 @@ import ibase.webitm.utility.ITMException; ...@@ -20,204 +20,182 @@ import ibase.webitm.utility.ITMException;
public class MailingListIC extends ValidatorEJB { public class MailingListIC extends ValidatorEJB {
E12GenericUtility genericUtility=new E12GenericUtility(); E12GenericUtility genericUtility = new E12GenericUtility();
@Override @Override
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext,
{ String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException {
Document dom = null; Document dom = null;
Document dom1 = null; Document dom1 = null;
Document dom2 = null; Document dom2 = null;
String errString = null; String errString = null;
try try {
{
if (xmlString != null && xmlString.trim().length()!=0) if (xmlString != null && xmlString.trim().length() != 0) {
{
dom = genericUtility.parseString(xmlString); dom = genericUtility.parseString(xmlString);
} }
if (xmlString1 != null && xmlString1.trim().length()!=0) if (xmlString1 != null && xmlString1.trim().length() != 0) {
{
dom1 = genericUtility.parseString(xmlString1); dom1 = genericUtility.parseString(xmlString1);
} }
if (xmlString2 != null && xmlString2.trim().length()!=0) if (xmlString2 != null && xmlString2.trim().length() != 0) {
{
dom2 = genericUtility.parseString(xmlString2); dom2 = genericUtility.parseString(xmlString2);
} }
// passing the dom to itemchanged method // passing the dom to itemchanged method
errString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams); errString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
System.out.println ("ErrString :" + errString); System.out.println("ErrString :" + errString);
} } catch (Exception e) {
catch (Exception e) System.out.println("Exception :SfaTime :itemChanged(String,String):" + e.getMessage() + ":");
{
System.out.println ("Exception :SfaTime :itemChanged(String,String):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e); errString = genericUtility.createErrorString(e);
} }
System.out.println ("returning from SfaTime itemChanged"); System.out.println("returning from SfaTime itemChanged");
return errString; return errString;
} }
@Override @Override
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn,
String editFlag, String xtraParams) throws RemoteException,ITMException String editFlag, String xtraParams) throws RemoteException, ITMException {
{
System.out.println("Inside itemchange"); System.out.println("Inside itemchange");
//Document headerDom = null; // Document headerDom = null;
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
StringBuffer valueXmlString = null; StringBuffer valueXmlString = null;
String name=""; String name = "";
String email_id=""; String email_id = "";
int currentFormNo = 0; int currentFormNo = 0;
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
try try {
{
conn = getConnection(); conn = getConnection();
if(objContext != null && objContext.trim().length() > 0) if (objContext != null && objContext.trim().length() > 0) {
{
currentFormNo = Integer.parseInt(objContext); currentFormNo = Integer.parseInt(objContext);
} }
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>"); valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>"); valueXmlString.append(editFlag).append("</editFlag></header>");
switch(currentFormNo) switch (currentFormNo)
{ {
case 1: case 1:
valueXmlString.append("<Detail1>"); valueXmlString.append("<Detail1>");
if ("mail_list_type".equalsIgnoreCase(currentColumn.trim())) { if ("mail_list_type".equalsIgnoreCase(currentColumn.trim())) {
String mailListType = checkNull(genericUtility.getColumnValue("mail_list_type", dom)); String mailListType = checkNull(genericUtility.getColumnValue("mail_list_type", dom));
// Check for 'S' or 'P' // Check for 'S' or 'P'
if ("S".equalsIgnoreCase(mailListType) || "D".equalsIgnoreCase(mailListType)) { if ("S".equalsIgnoreCase(mailListType) || "I".equalsIgnoreCase(mailListType)) {
valueXmlString.append("<sql_str protect='0'>").append("<![CDATA[]]>").append("</sql_str>\r\n"); valueXmlString.append("<sql_str protect='0'>").append("<![CDATA[]]>").append("</sql_str>\r\n");
} else if ("P".equalsIgnoreCase(mailListType)) { } else if ("P".equalsIgnoreCase(mailListType)) {
valueXmlString.append("<sql_str protect='1'>").append("<![CDATA[]]>").append("</sql_str>\r\n"); valueXmlString.append("<sql_str protect='1'>").append("<![CDATA[]]>").append("</sql_str>\r\n");
}
}
valueXmlString.append ("</Detail1>\r\n");
break;
case 2:
System.out.println("In Case 2");
valueXmlString.append("<Detail2>");
String sql = checkNull(genericUtility.getColumnValue("sql_str", dom1));
String type = checkNull(genericUtility.getColumnValue("mail_list_type", dom1));
System.out.println(sql);
System.out.println("Sql null checker");
BaseLogger.log("3", null, null, "createProject >> XmlString :: [" + sql + "]");
if ("itm_default".equalsIgnoreCase(currentColumn.trim())) {
if ("S".equalsIgnoreCase(type)) {
String sqltest = sql;
BaseLogger.log("3", null, null, "createProject >> XmlString :: [" + sqltest + "]");
String[] selectParts = sql.toLowerCase().split("from")[0].replace("select", "").trim().split(",");
String firstColumn = selectParts[0].trim();
String secondColumn = selectParts.length > 1 ? selectParts[1].trim() : "";
try {
pstmt = conn.prepareStatement(sqltest);
rs = pstmt.executeQuery();
if (rs.next()) {
name = rs.getString(firstColumn);
email_id =rs.getString(secondColumn);
}
valueXmlString.append("<name protect='1'><![CDATA[").append(name).append("]]></name>\r\n");
valueXmlString.append("<email_id protect='1'><![CDATA[").append(email_id).append("]]></email_id>\r\n");
}catch (SQLException e){
BaseLogger.log("3", null, null, "createProject >> XmlString :: [" + "SQL Exception while executing query." + "]");
} }
} }
else if ("D".equalsIgnoreCase(type)) {
BaseLogger.log("3", null, null, "In dremio databse connection [" + sql + "]"); valueXmlString.append("</Detail1>\r\n");
break;
//Connection code for Dremio Database
// case 2:
try { //
// System.out.println("In Case 2");
// valueXmlString.append("<Detail2>");
conn = connDriver.getConnectDB("APPVIS"+"_IN_MEM",true); // String sql = checkNull(genericUtility.getColumnValue("sql_str", dom1));
BaseLogger.log("3", null, null, "Connected to Dremio!"); // String type = checkNull(genericUtility.getColumnValue("mail_list_type", dom1));
// System.out.println(sql);
// System.out.println("Sql null checker");
// BaseLogger.log("3", null, null, "createProject >> XmlString :: [" + sql + "]");
Statement statement = conn.createStatement(); //
ResultSet resultSet = statement.executeQuery(sql); // if ("itm_default".equalsIgnoreCase(currentColumn.trim())) {
// if ("S".equalsIgnoreCase(type) || "I".equalsIgnoreCase(type) ) {
// String sqltest = sql;
while (resultSet.next()) { // BaseLogger.log("3", null, null, "createProject >> XmlString :: [" + sqltest + "]");
System.out.println(resultSet.getString(1)); //
} // String[] selectParts = sql.toLowerCase().split("from")[0].replace("select", "").trim().split(",");
resultSet.close(); // String firstColumn = selectParts[0].trim();
statement.close(); // String secondColumn = selectParts.length > 1 ? selectParts[1].trim() : "";
conn.close(); //
}catch (SQLException se) { // try {
BaseLogger.log("3", null, null, "Exception in Dremio Connection [" + E12GenericUtility.getStackTrace(se) + "]"); // pstmt = conn.prepareStatement(sqltest);
throw new ITMException(se); // rs = pstmt.executeQuery();
} // if (rs.next()) {
// name = rs.getString(firstColumn);
// email_id =rs.getString(secondColumn);
} // }
// valueXmlString.append("<name protect='0'><![CDATA[").append(name).append("]]></name>\r\n");
} // valueXmlString.append("<email_id protect='0'><![CDATA[").append(email_id).append("]]></email_id>\r\n");
valueXmlString.append ("</Detail2>\r\n"); // }catch (SQLException e){
break; // BaseLogger.log("3", null, null, "createProject >> XmlString :: [" + "SQL Exception while executing query." + "]");
// }
// }
// else if ("D".equalsIgnoreCase(type)) {
// BaseLogger.log("3", null, null, "In dremio databse connection [" + sql + "]");
//
// //Connection code for Dremio Database
//
// try {
//
//
// conn = connDriver.getConnectDB("APPVIS"+"_IN_MEM",true);
// BaseLogger.log("3", null, null, "Connected to Dremio!");
//
//
//
// Statement statement = conn.createStatement();
// ResultSet resultSet = statement.executeQuery(sql);
//
//
// while (resultSet.next()) {
// System.out.println(resultSet.getString(1));
// }
// resultSet.close();
// statement.close();
// conn.close();
// }catch (SQLException se) {
// BaseLogger.log("3", null, null, "Exception in Dremio Connection [" + E12GenericUtility.getStackTrace(se) + "]");
// throw new ITMException(se);
// }
//
//
// }
//
// }
// valueXmlString.append ("</Detail2>\r\n");
// break;
} }
valueXmlString.append("</Root>\r\n"); valueXmlString.append("</Root>\r\n");
} } catch (Exception e) {
catch(Exception e)
{
System.out.println("Exception :SfaTime :itemChanged(Document,String):" + e.getMessage() + ":"); System.out.println("Exception :SfaTime :itemChanged(Document,String):" + e.getMessage() + ":");
e.printStackTrace(); e.printStackTrace();
} } finally {
finally try {
{ if (conn != null) {
try
{
if(conn != null)
{
conn.close(); conn.close();
conn = null; conn = null;
} }
if( rs != null ) if (rs != null) {
{
rs.close(); rs.close();
rs = null; rs = null;
} }
if( pstmt != null ) if (pstmt != null) {
{
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
} }
} } catch (Exception e) {
catch(Exception e)
{
System.out.println("Exception :SfaTime :Exception in SQL" + e.getMessage() + ":"); System.out.println("Exception :SfaTime :Exception in SQL" + e.getMessage() + ":");
e.printStackTrace(); e.printStackTrace();
} }
} }
return valueXmlString.toString(); return valueXmlString.toString();
} }
// For validation
// For validation
@Override @Override
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 {
// Initially dom values are set to null // Initially dom values are set to null
Document dom = null; Document dom = null;
...@@ -227,26 +205,22 @@ public class MailingListIC extends ValidatorEJB { ...@@ -227,26 +205,22 @@ public class MailingListIC extends ValidatorEJB {
// To check what is it printing // To check what is it printing
System.out.println("xmlString["+xmlString+"]"); System.out.println("xmlString[" + xmlString + "]");
System.out.println("xmlString1["+xmlString1+"]"); System.out.println("xmlString1[" + xmlString1 + "]");
System.out.println("xmlString2["+xmlString2+"]"); System.out.println("xmlString2[" + xmlString2 + "]");
// To validate weather the xml is not empty and neither null. // To validate weather the xml is not empty and neither null.
try try {
{
if(xmlString != null && xmlString.trim().length()!=0) if (xmlString != null && xmlString.trim().length() != 0) {
{
// This satisfies both condition so we can convert this xml to dom. // This satisfies both condition so we can convert this xml to dom.
dom = genericUtility.parseString(xmlString); dom = genericUtility.parseString(xmlString);
} }
if(xmlString1 != null && xmlString1.trim().length()!=0) if (xmlString1 != null && xmlString1.trim().length() != 0) {
{
dom1 = genericUtility.parseString(xmlString1); dom1 = genericUtility.parseString(xmlString1);
} }
if(xmlString2 != null && xmlString2.trim().length()!=0) if (xmlString2 != null && xmlString2.trim().length() != 0) {
{
dom2 = genericUtility.parseString(xmlString2); dom2 = genericUtility.parseString(xmlString2);
} }
...@@ -255,8 +229,7 @@ public class MailingListIC extends ValidatorEJB { ...@@ -255,8 +229,7 @@ public class MailingListIC extends ValidatorEJB {
errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams); errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
System.out.println("ErrString: " + errString); System.out.println("ErrString: " + errString);
} } catch (Exception e) // Catch any other exception
catch(Exception e) // Catch any other exception
{ {
System.out.println("Exception: SfaTime: wfValData(String xmlString): " + e.getMessage() + ":"); System.out.println("Exception: SfaTime: wfValData(String xmlString): " + e.getMessage() + ":");
errString = genericUtility.createErrorString(e); errString = genericUtility.createErrorString(e);
...@@ -264,90 +237,131 @@ public class MailingListIC extends ValidatorEJB { ...@@ -264,90 +237,131 @@ public class MailingListIC extends ValidatorEJB {
} }
System.out.println("Returning from SfaTime wfValData"); System.out.println("Returning from SfaTime wfValData");
// If there is no error we return the errString value which will come from consequetive method. // If there is no error we return the errString value which will come from
// consequetive method.
return (errString); return (errString);
} }
@Override @Override
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag,
String xtraParams) throws RemoteException,ITMException String xtraParams) throws RemoteException, ITMException {
{
System.out.println("Inside SfaTime validation"); System.out.println("Inside SfaTime validation");
NodeList parentNodeList = null; NodeList parentNodeList = null;
NodeList childNodeList = null; NodeList childNodeList = null;
Node parentNode = null; Node parentNode = null;
Node childNode = null; Node childNode = null;
Connection conn =null; Connection conn = null;
String childNodeName = null; String childNodeName = null;
String errorString=""; String errorString = "";
String userId=""; String userId = "";
int ctr=0; int ctr = 0;
int currentFormNo=0; int currentFormNo = 0;
int childNodeListLength=0; int childNodeListLength = 0;
try try {
{
conn = getConnection(); conn = getConnection();
userId = getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode"); userId = getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
if(objContext!=null && objContext.trim().length()>0) if (objContext != null && objContext.trim().length() > 0) {
{
currentFormNo = Integer.parseInt(objContext); currentFormNo = Integer.parseInt(objContext);
} }
parentNodeList = dom.getElementsByTagName("Detail" + currentFormNo); parentNodeList = dom.getElementsByTagName("Detail" + currentFormNo);
parentNode = parentNodeList.item(0); parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes(); childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength(); childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++) for (ctr = 0; ctr < childNodeListLength; ctr++) {
{
childNode = childNodeList.item(ctr); childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName(); childNodeName = childNode.getNodeName();
switch(currentFormNo) switch (currentFormNo) {
{
case 1: case 1:
BaseLogger.log( "3", null, null, "In case 1 of validation" ); BaseLogger.log("3", null, null, "In case 1 of validation");
String mailListType = checkNull(genericUtility.getColumnValue("mail_list_type", dom)); String mailListType = checkNull(genericUtility.getColumnValue("mail_list_type", dom));
BaseLogger.log( "3", null, null, "[below mailListType value : ("+ mailListType +") ]" ); BaseLogger.log("3", null, null, "[below mailListType value : (" + mailListType + ") ]");
if ("S".equalsIgnoreCase(mailListType)) { BaseLogger.log("3", null, null, "[New updated from pc : (" + mailListType + ") ]");
if(childNodeName.equalsIgnoreCase("sql_str")) if ("S".equalsIgnoreCase(mailListType)) {
{ if (childNodeName.equalsIgnoreCase("sql_str")) {
if(childNode.getFirstChild()==null) if (childNode.getFirstChild() == null) {
{ errorString = getErrorString("sql_str", "VTBISINTSQ", userId);
errorString= getErrorString("sql_str","VTBISINTSQ",userId); break;
break; }
} }
}
}
case 2:
BaseLogger.log("3", null, null, "In case 2 of validation");
String mailListType1 = checkNull(genericUtility.getColumnValue("mail_list_type", dom));
BaseLogger.log("3", null, null, "MailingListPostSave : DOM :: [" + mailListType1 + "]");
String mailListTypec2 = checkNull(genericUtility.getColumnValue("mail_list_type", dom1));
BaseLogger.log("3", null, null, "MailingListPostSave : DOM :: [" + mailListTypec2 + "]");
String Name = checkNull(genericUtility.getColumnValue("name", dom2));
BaseLogger.log("3", null, null, "MailingListPostSave : DOM :: [" + Name + "]");
String email_id = checkNull(genericUtility.getColumnValue("email_id", dom2));
BaseLogger.log("3", null, null, "MailingListPostSave : DOM :: [" + email_id + "]");
String line_no = checkNull(genericUtility.getColumnValue("name", dom2));
BaseLogger.log("3", null, null, "MailingListPostSave : DOM :: [" + line_no + "]");
if ("S".equalsIgnoreCase(mailListTypec2) || "I".equalsIgnoreCase(mailListTypec2)) {
if (childNodeName.equalsIgnoreCase("name")) {
if (childNode.getFirstChild() == null || Name.length() > 0) {
errorString = getErrorString("name", "SQLIM", userId);
break;
}
}
if (childNodeName.equalsIgnoreCase("email_id")) {
if (childNode.getFirstChild() == null || email_id.length() > 0) {
errorString = getErrorString("email_id", "SQLIM", userId);
break;
}
}
if (childNodeName.equalsIgnoreCase("line_no")) {
if (childNode.getFirstChild() == null || line_no.length() > 0) {
errorString = getErrorString("line_no", "SQLIM", userId);
break;
}
}
}
} if("P".equalsIgnoreCase(mailListTypec2)) {
// String name = checkNull(genericUtility.getColumnValue("name", dom1)); if (childNodeName.equalsIgnoreCase("name")) {
// String Email = checkNull(genericUtility.getColumnValue("email_id", dom1)); if (childNode.getFirstChild() == null) {
// BaseLogger.log( "3", null, null, "[ value from form 2 name : ("+ name +") ]" ); errorString = getErrorString("name", "ALLFIELD", userId);
// BaseLogger.log( "3", null, null, "[ value from form 2 Email : ("+ Email +") ]" ); break;
// }
// if(name == null || name.length() == 0 ) { }
// errorString= getErrorString("name","VTPRCNCP",userId); if (childNodeName.equalsIgnoreCase("email_id")) {
// }else if(Email == null || Email.length() == 0 ) if (childNode.getFirstChild() == null) {
// { errorString = getErrorString("email_id", "ALLFIELD", userId);
// errorString= getErrorString("Email","VTPRCNCP",userId); break;
// } }
}
if (childNodeName.equalsIgnoreCase("line_no")) {
if (childNode.getFirstChild() == null ) {
errorString = getErrorString("line_no", "ALLFIELD", userId);
break;
}
}
}
}
} }
} } catch (Exception e) {
}catch(Exception e) { BaseLogger.log("3", null, null, "MailingListPostSave : DOM :: In catch block");
}
}
return errorString; return errorString;
} }
private String checkNull(String input) private String checkNull(String input) {
{ if (input == null) {
if (input == null)
{
input = ""; input = "";
} } else {
else
{
input = input.trim(); input = input.trim();
} }
return input; return input;
......
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