Commit 56ddd64c authored by Ajit Deshmukh's avatar Ajit Deshmukh

Replace MarketingCampaignPreSend.java

parent b546e501
//Created by Ajit - 13/09/24
package ibase.webitm.ejb.wsfa.transactions; package ibase.webitm.ejb.wsfa.transactions;
import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -12,7 +10,6 @@ import java.util.ArrayList; ...@@ -12,7 +10,6 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import ibase.utility.BaseLogger; import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility; import ibase.utility.E12GenericUtility;
import ibase.utility.EMail; import ibase.utility.EMail;
...@@ -21,11 +18,10 @@ import ibase.webitm.ejb.ActionHandlerEJB; ...@@ -21,11 +18,10 @@ import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.ITMDBAccessEJB; import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.utility.ITMException;
public class MarketingCampaignPreSend extends ActionHandlerEJB { public class MarketingCampaignPreSend extends ActionHandlerEJB {
ValidatorEJB validatorEJB = new ValidatorEJB(); ValidatorEJB validatorEJB = new ValidatorEJB();
E12GenericUtility genericUtility = new E12GenericUtility(); E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
private String buildMailXMLStr(HashMap<String, Object> mailFormatDetails, UserInfoBean userInfo) { private String buildMailXMLStr(HashMap<String, Object> mailFormatDetails, UserInfoBean userInfo) {
...@@ -263,12 +259,12 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB { ...@@ -263,12 +259,12 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql = ""; String sql = "";
String fromEmailId = "",retString = ""; String fromEmailId = "", retString = "";
String status = "";
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB(); ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
List<String> mailListForMailSend; List<String> mailListForMailSend;
boolean updateFlag = false; boolean updateFlag = false;
try { try {
conn = getConnection(); conn = getConnection();
conn.setAutoCommit(false); // Begin transaction conn.setAutoCommit(false); // Begin transaction
...@@ -278,7 +274,7 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB { ...@@ -278,7 +274,7 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB {
if (mailListForMailSend.isEmpty()) { if (mailListForMailSend.isEmpty()) {
updateFlag = true; updateFlag = true;
break; break;
} }
int totalMails = mailListForMailSend.size(); int totalMails = mailListForMailSend.size();
...@@ -307,34 +303,35 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB { ...@@ -307,34 +303,35 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB {
try { try {
emailStatus = email.sendMail(mailXMLStr, "ITM", userInfo); emailStatus = email.sendMail(mailXMLStr, "ITM", userInfo);
BaseLogger.log("3", null, null, "Email status for [" + emailId + "]: " + emailStatus); BaseLogger.log("3", null, null, "Email status for [" + emailId + "]: " + emailStatus);
status = "S";
} catch (Exception e) { } catch (Exception e) {
BaseLogger.log("3", null, null, BaseLogger.log("3", null, null,
"Error sending email to [" + emailId + "]: " + e.getMessage()); "Error sending email to [" + emailId + "]: " + e.getMessage());
continue; // Proceed to the next email status = "E";
} }
// Update the log // Update the log
sql = "UPDATE mktg_campaign_log SET status = 'S' WHERE email_id = ? AND campaign_id = ?"; sql = "UPDATE mktg_campaign_log SET status = ? WHERE email_id = ? AND campaign_id = ?";
try (PreparedStatement updatePstmt = conn.prepareStatement(sql)) { try (PreparedStatement updatePstmt = conn.prepareStatement(sql)) {
updatePstmt.setString(1, emailId); updatePstmt.setString(1, status);
updatePstmt.setString(2, tranId); updatePstmt.setString(2, emailId);
updatePstmt.setString(3, tranId);
int affectedRows = updatePstmt.executeUpdate(); int affectedRows = updatePstmt.executeUpdate();
BaseLogger.log("3", null, null, BaseLogger.log("3", null, null,
"Rows affected by update for emailId [" + emailId + "]: " + affectedRows); "Rows affected by update for emailId [" + emailId + "]: " + affectedRows);
} catch (SQLException e) { } catch (SQLException e) {
BaseLogger.log("3", null, null, BaseLogger.log("3", null, null,
"Error updating log for emailId [" + emailId + "]: " + e.getMessage()); "Error updating log for emailId [" + emailId + "]: " + e.getMessage());
conn.rollback(); // Rollback on error conn.rollback();
} }
conn.commit(); // Commit the transaction conn.commit();
} }
} }
} }
if(updateFlag) if (updateFlag) {
{ retString = itmDBAccessEJB.getErrorString("", "VTMAILSUCC", "", "", conn);
retString = itmDBAccessEJB.getErrorString("","VTMAILSUCC","","",conn);
return retString; return retString;
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -342,7 +339,7 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB { ...@@ -342,7 +339,7 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB {
BaseLogger.log("0", null, null, "Exception during email processing: " + e.getMessage()); BaseLogger.log("0", null, null, "Exception during email processing: " + e.getMessage());
if (conn != null) { if (conn != null) {
try { try {
conn.rollback(); // Rollback on exception conn.rollback();
BaseLogger.log("0", null, null, "Transaction rolled back due to exception."); BaseLogger.log("0", null, null, "Transaction rolled back due to exception.");
} catch (SQLException se) { } catch (SQLException se) {
se.printStackTrace(); se.printStackTrace();
...@@ -364,6 +361,8 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB { ...@@ -364,6 +361,8 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB {
String formatCode = ""; String formatCode = "";
String subject = ""; String subject = "";
String bodyText = ""; String bodyText = "";
// boolean updateFlag = false;
String retString = "";
UserInfoBean userInfo = getUserInfo(); UserInfoBean userInfo = getUserInfo();
System.out.println("********************userinfo****************" + userInfo); System.out.println("********************userinfo****************" + userInfo);
...@@ -388,6 +387,12 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB { ...@@ -388,6 +387,12 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB {
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
} }
//Check weather email id present or not against loged in user
if(userEmail == null) {
BaseLogger.log("3", null, null, "In null condition [" + userEmail + "]");
retString = itmDBAccessEJB.getErrorString("", "NULEMAILID", "", "", conn);
return retString;
}
BaseLogger.log("3", null, null, "user email [" + userEmail + "]"); BaseLogger.log("3", null, null, "user email [" + userEmail + "]");
sql = "select campaign_template from mktg_campaign where campaign_id = ?"; sql = "select campaign_template from mktg_campaign where campaign_id = ?";
...@@ -438,16 +443,21 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB { ...@@ -438,16 +443,21 @@ public class MarketingCampaignPreSend extends ActionHandlerEJB {
String mailXMLStr = buildMailXMLStr(mailFormatDetails, userInfo); String mailXMLStr = buildMailXMLStr(mailFormatDetails, userInfo);
String emailStatus = email.sendMail(mailXMLStr, "ITM", userInfo); String emailStatus = email.sendMail(mailXMLStr, "ITM", userInfo);
System.out.println("emailStatus....::" + emailStatus); System.out.println("emailStatus....::" + emailStatus);
String msg = emailStatus.equals("S") ? "VTMAILSUCC" : "MAILFAILED";
retString = itmDBAccessEJB.getErrorString("", msg, "", "", conn);
return retString;
} 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 {
closeResources(rs, pstmt, conn); closeResources(rs, pstmt, conn);
} }
return "<tran_id>" + tranId + "</tran_id>"; return retString;
} }
private void closeResources(ResultSet rs, PreparedStatement pstmt, Connection conn) { private void closeResources(ResultSet rs, PreparedStatement pstmt, Connection conn) {
if (rs != null) { if (rs != null) {
try { try {
......
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