Commit 42e1e50e authored by Ketan Patil's avatar Ketan Patil

Changes done by Pravin

parent df4ba164
...@@ -6,6 +6,7 @@ import ibase.utility.CommonConstants; ...@@ -6,6 +6,7 @@ import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility; import ibase.utility.E12GenericUtility;
import ibase.utility.EMail; import ibase.utility.EMail;
import ibase.utility.UserInfoBean; import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
...@@ -13,12 +14,10 @@ import java.io.PrintStream; ...@@ -13,12 +14,10 @@ import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -35,8 +34,6 @@ import org.w3c.dom.Document; ...@@ -35,8 +34,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
public class CHCReportOtherClusterSch public class CHCReportOtherClusterSch
implements Schedule implements Schedule
{ {
...@@ -67,45 +64,20 @@ public class CHCReportOtherClusterSch ...@@ -67,45 +64,20 @@ public class CHCReportOtherClusterSch
String retString = ""; String retString = "";
Connection conn = null; Connection conn = null;
Connection connection = null; Connection connection = null;
//Connection connDWH = null;
boolean isError = false; boolean isError = false;
try try
{ {
ConnDriver connDriver = new ConnDriver();
ConnDriver connDriver = new ConnDriver(); ConnDriver con = new ConnDriver();
ConnDriver con = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn = connDriver.getConnectDB("DriverITM"); connection = con.getConnectDB("DWH");
connection = con.getConnectDB("DWH"); System.out.println("connection===>" + connection);
System.out.println("connection===>" + connection);
/*ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB();*/
/* String url = "jdbc:oracle:thin:@//oe02-scan.spil.com:1521/dwh11g";
String user = "ES3"; String pass = "z$3RUpHi";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
conn=DriverManager.getConnection(url, user, pass);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
conn.setAutoCommit(false);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/
if (conn != null) { if (conn != null) {
System.out.println("Connected to the database!"); System.out.println("Connected to the database!");
retString = performOp(scheduleParamXML, conn,connection); retString = performOp(scheduleParamXML, conn, connection);
} }
} }
...@@ -136,11 +108,11 @@ public class CHCReportOtherClusterSch ...@@ -136,11 +108,11 @@ public class CHCReportOtherClusterSch
{ {
if (isError) if (isError)
{ {
connection.rollback(); connection.rollback();
} }
else else
{ {
connection.commit(); connection.commit();
} }
connection.close(); connection.close();
connection = null; connection = null;
...@@ -155,18 +127,18 @@ public class CHCReportOtherClusterSch ...@@ -155,18 +127,18 @@ public class CHCReportOtherClusterSch
return retString; return retString;
} }
public String performOp(String scheduleParamXML, Connection conn,Connection connection) public String performOp(String scheduleParamXML, Connection conn, Connection connection)
throws ITMException, Exception throws ITMException, Exception
{ {
String retString = ""; String retString = "";
String zoneEmailId = ""; String zoneEmailId = "";
String zoneTherpyGrp = ""; String zoneTherpyGrp = "";
String siteCity = ""; String regionCode = "",zone=""; String siteCity = ""; String regionCode = ""; String zone = "";
String sql = ""; String objName = ""; String argumentString = ""; String jrxmlName = ""; String sql = ""; String objName = ""; String argumentString = ""; String jrxmlName = "";
String lineNo="",sqlExpr = ""; String sqlExpr1 = ""; String sqlExpr2 = ""; String sqlExpr3 = ""; String sqlExpr4 = ""; String sqlExpr5 = ""; String sqlExpr6 = ""; String errfilePath = ""; String lineNo = ""; String sqlExpr = ""; String sqlExpr1 = ""; String sqlExpr2 = ""; String sqlExpr3 = ""; String sqlExpr4 = ""; String sqlExpr5 = ""; String sqlExpr6 = ""; String errfilePath = "";
String compSql = ""; String compSql = "";
PreparedStatement pstmt = null,pstmt1 = null; PreparedStatement pstmt = null; PreparedStatement pstmt1 = null;
ResultSet rs = null,rs1 = null; ResultSet rs = null; ResultSet rs1 = null;
ArrayList objtNamelist = new ArrayList(); ArrayList objtNamelist = new ArrayList();
String objtNames = ""; String objtNames = "";
String driver = ""; String reportGroup = null; String driver = ""; String reportGroup = null;
...@@ -208,7 +180,7 @@ public class CHCReportOtherClusterSch ...@@ -208,7 +180,7 @@ public class CHCReportOtherClusterSch
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
System.out.println("SQL>>>::::" + sql); System.out.println("SQL>>>::::" + sql);
while (rs.next()) { while (rs.next()) {
lineNo=checkNull(rs.getString("line_no")); lineNo = checkNull(rs.getString("line_no"));
sqlExpr = checkNull(rs.getString("sql_expr")); sqlExpr = checkNull(rs.getString("sql_expr"));
sqlExpr1 = checkNull(rs.getString("sql_expr1")); sqlExpr1 = checkNull(rs.getString("sql_expr1"));
sqlExpr2 = checkNull(rs.getString("sql_expr2")); sqlExpr2 = checkNull(rs.getString("sql_expr2"));
...@@ -217,300 +189,223 @@ public class CHCReportOtherClusterSch ...@@ -217,300 +189,223 @@ public class CHCReportOtherClusterSch
sqlExpr5 = checkNull(rs.getString("sql_expr5")); sqlExpr5 = checkNull(rs.getString("sql_expr5"));
sqlExpr6 = checkNull(rs.getString("sql_expr6")); sqlExpr6 = checkNull(rs.getString("sql_expr6"));
objtNames = checkNull(rs.getString("sql_input")); objtNames = checkNull(rs.getString("sql_input"));
compSql = sqlExpr + " " + sqlExpr1 + " " + sqlExpr2 + " " + sqlExpr3 + " " + sqlExpr4 + " " + sqlExpr5 + " " + sqlExpr6; compSql = sqlExpr + " " + sqlExpr1 + " " + sqlExpr2 + " " + sqlExpr3 + " " + sqlExpr4 + " " + sqlExpr5 + " " + sqlExpr6;
System.out.println("Combine SQL::::" + compSql); System.out.println("Combine SQL::::" + compSql);
int count = 0; int count = 0;
if ((compSql != null) && (compSql.trim().length() > 0)) if ((compSql == null) || (compSql.trim().length() <= 0))
continue;
System.out.println("Combine SQL not null::::" + compSql);
pstmt1 = connection.prepareStatement(compSql);
rs1 = pstmt1.executeQuery();
HashMap<String,List<String>> app = new HashMap<String,List<String>>();
HashMap<String,HashSet<String>> emailApp = new HashMap<String,HashSet<String>>();
StringBuffer emailheaderStr = new StringBuffer();
ResultSetMetaData rsmd= null;
while (rs1.next())
{ {
System.out.println("Combine SQL not null::::" + compSql); StringBuffer emailBodyStr = new StringBuffer();
pstmt1 = connection.prepareStatement(compSql);
rs1 = pstmt1.executeQuery();
HashMap<String,List<String>> app = new HashMap<String,List<String>>(); rsmd = rs1.getMetaData();
HashMap<String,HashSet<String>> emailApp = new HashMap<String,HashSet<String>>();
StringBuffer emailheaderStr = new StringBuffer();
ResultSetMetaData rsmd;
while (rs1.next())
{
StringBuffer emailBodyStr = new StringBuffer();
rsmd = rs1.getMetaData();
emailBodyStr.append("<tr>"); emailBodyStr.append("<tr>");
for (int i = 1; i <= rsmd.getColumnCount(); i++) { for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.println("Inside for::::"); System.out.println("Inside for::::");
System.out.println("count==>"+count); System.out.println("count==>" + count);
JSONObject chcReportJsonObj = new JSONObject(); JSONObject chcReportJsonObj = new JSONObject();
String colName = rsmd.getColumnName(i); String colName = rsmd.getColumnName(i);
System.out.println("col name ::::" + colName); System.out.println("col name ::::" + colName);
if (count < 1) if (count < 1)
{
if (!colName.equalsIgnoreCase("zone_email"))
{ {
if (!colName.equalsIgnoreCase("zone_email")) { System.out.println("emailheaderStr=====>>>" + emailheaderStr.length());
// if(!colName.equalsIgnoreCase("therpy_grp")){ System.out.println("rsmd.getColumnCount()=====>>>" + rsmd.getColumnCount());
System.out.println("emailheaderStr=====>>>" + emailheaderStr.length()); emailheaderStr.append("<th>");
System.out.println("rsmd.getColumnCount()=====>>>" + rsmd.getColumnCount());
emailheaderStr.append("<th>");
if(colName.equalsIgnoreCase("report_dt")){
emailheaderStr.append("Report Date");
}
if(colName.equalsIgnoreCase("therpy_grp")){
emailheaderStr.append("Cluster");
}
if(colName.equalsIgnoreCase("zone")){
emailheaderStr.append("Zone");
}
if(colName.equalsIgnoreCase("region")){
emailheaderStr.append("Region");
}
if(colName.equalsIgnoreCase("site_city")){
emailheaderStr.append("Site City");
}
if(colName.equalsIgnoreCase("stockist_city")){
emailheaderStr.append("Stockist City");
}
if(colName.equalsIgnoreCase("cattegory")){
emailheaderStr.append("Category");
}
if(colName.equalsIgnoreCase("division")){
emailheaderStr.append("Division");
}
if(colName.equalsIgnoreCase("order_date")){
emailheaderStr.append("Order Date");
}
/* if(colName.equalsIgnoreCase("ord_value")){
emailheaderStr.append("Order Value");
}*/
if(colName.equalsIgnoreCase("sale_order")){
emailheaderStr.append("Sale Order");
}
/* if(colName.equalsIgnoreCase("sku")){
emailheaderStr.append("SKU");
}*/
if(colName.equalsIgnoreCase("threshold_limit")){
emailheaderStr.append("Threshold Limit");
}
if(colName.equalsIgnoreCase("purchase_val_till_date")){
emailheaderStr.append("Purchase Val till Date");
}
/* if(colName.equalsIgnoreCase("outstanding_amt")){
emailheaderStr.append("Outstanding Amt");
}*/
if(colName.equalsIgnoreCase("blocked_ord_val")){
emailheaderStr.append("Blocked Order Val");
}
if(colName.equalsIgnoreCase("status")){
emailheaderStr.append("Status");
}
if(colName.equalsIgnoreCase("chg_user")){
emailheaderStr.append("Chg User");
}
if(colName.equalsIgnoreCase("user_name")){
emailheaderStr.append("User Name");
}
emailheaderStr.append("</th>");
}
}
System.out.println("colName=====>>>" + colName);
int type = rsmd.getColumnType(i);
System.out.println("type=====>>>" + type);
if (type == Types.VARCHAR || type == Types.CHAR) {
System.out.print("VARCHAR field varchar==>>:" + rs1.getString(colName));
if (!colName.equalsIgnoreCase("zone_email")) { if (colName.equalsIgnoreCase("therpy_grp")) {
System.out.print("column name>>:" + rs1.getString(colName)); emailheaderStr.append("Cluster");
chcReportJsonObj.put(colName, rs1.getString(colName)); }
if (colName.equalsIgnoreCase("zone")) {
emailBodyStr.append("<td>"); emailheaderStr.append("Zone");
emailBodyStr.append(rs1.getString(colName));
emailBodyStr.append("</td>");
} }
if(colName.equalsIgnoreCase("zone_email")){ if (colName.equalsIgnoreCase("region")) {
zoneEmailId=rs1.getString(colName); emailheaderStr.append("Region");
} }
if(colName.equalsIgnoreCase("therpy_grp")){ if (colName.equalsIgnoreCase("site_city")) {
zoneTherpyGrp=rs1.getString(colName); emailheaderStr.append("Site City");
}
if(colName.equalsIgnoreCase("site_city")){
siteCity=rs1.getString(colName);
} }
if(colName.equalsIgnoreCase("region")){ if (colName.equalsIgnoreCase("stockist_city")) {
regionCode=rs1.getString(colName); emailheaderStr.append("Stockist City");
} }
if(colName.equalsIgnoreCase("zone")){ if (colName.equalsIgnoreCase("cattegory")) {
zone=rs1.getString(colName); emailheaderStr.append("Category");
} }
if (colName.equalsIgnoreCase("division")) {
emailheaderStr.append("Division");
}
if (colName.equalsIgnoreCase("order_date")) {
emailheaderStr.append("Order Date");
}
if (colName.equalsIgnoreCase("sale_order")) {
emailheaderStr.append("Sale Order");
}
if (colName.equalsIgnoreCase("threshold_limit")) {
emailheaderStr.append("Threshold Limit");
}
if (colName.equalsIgnoreCase("purchase_val_till_date")) {
emailheaderStr.append("Purchase Val till Date");
}
if (colName.equalsIgnoreCase("blocked_ord_val")) {
emailheaderStr.append("Blocked Order Val");
}
emailheaderStr.append("</th>");
} }
else if (type == Types.INTEGER || type == Types.BIGINT) { }
System.out.print("VARCHAR field Int:" + rs1.getInt(colName)); System.out.println("colName=====>>>" + colName);
int type = rsmd.getColumnType(i);
System.out.println("type=====>>>" + type);
if ((type == 12) || (type == 1)) {
System.out.print("VARCHAR field varchar==>>:" + rs1.getString(colName));
if (!colName.equalsIgnoreCase("zone_email")) {
System.out.print("column name>>:" + rs1.getString(colName));
chcReportJsonObj.put(colName, rs1.getString(colName));
chcReportJsonObj.put(colName, rs1.getInt(colName));
emailBodyStr.append("<td>"); emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getInt(colName)); emailBodyStr.append(rs1.getString(colName));
emailBodyStr.append("</td>"); emailBodyStr.append("</td>");
} }
else if (type == Types.DOUBLE|| type == Types.FLOAT){ if (colName.equalsIgnoreCase("zone_email")) {
System.out.print("VARCHAR field double:" + rs1.getDouble(colName)); zoneEmailId = rs1.getString(colName);
chcReportJsonObj.put(colName, rs1.getDouble(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getDouble(colName));
emailBodyStr.append("</td>");
} }
else if(type==Types.DATE) { if (colName.equalsIgnoreCase("therpy_grp")) {
System.out.print("DATE field date:" + rs1.getDate(colName)); zoneTherpyGrp = rs1.getString(colName);
String dateAsString = rs1.getDate(colName).toString(); }
DateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd"); if (colName.equalsIgnoreCase("site_city")) {
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yy"); siteCity = rs1.getString(colName);
java.util.Date date = sourceFormat.parse(dateAsString);
System.out.println(formatter.format(date));
chcReportJsonObj.put(colName, formatter.format(date));
emailBodyStr.append("<td>");
emailBodyStr.append(formatter.format(date));
emailBodyStr.append("</td>");
} }
else if(type==Types.TIMESTAMP) { if (colName.equalsIgnoreCase("region")) {
System.out.print("TIMESTAMP field:" + rs1.getDate(colName)); regionCode = rs1.getString(colName);
}
if (colName.equalsIgnoreCase("zone")) {
zone = rs1.getString(colName);
}
}
else if ((type == 4) || (type == -5)) {
System.out.print("VARCHAR field Int:" + rs1.getInt(colName));
chcReportJsonObj.put(colName, rs1.getInt(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getInt(colName));
emailBodyStr.append("</td>");
}
else if ((type == 8) || (type == 6)) {
System.out.print("VARCHAR field double:" + rs1.getDouble(colName));
chcReportJsonObj.put(colName, rs1.getDouble(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getDouble(colName));
emailBodyStr.append("</td>");
}
else if (type == 91) {
System.out.print("DATE field date:" + rs1.getDate(colName));
String dateAsString = rs1.getDate(colName).toString();
DateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yy");
java.util.Date date = sourceFormat.parse(dateAsString);
System.out.println(formatter.format(date));
chcReportJsonObj.put(colName, formatter.format(date));
emailBodyStr.append("<td>");
emailBodyStr.append(formatter.format(date));
emailBodyStr.append("</td>");
}
else if (type == 93) {
System.out.print("TIMESTAMP field:" + rs1.getDate(colName));
chcReportJsonObj.put(colName, rs1.getTimestamp(colName)); chcReportJsonObj.put(colName, rs1.getTimestamp(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getTimestamp(colName));
emailBodyStr.append("</td>");
}
else if (type == 2) {
System.out.print("NUMERIC field:" + rs1.getInt(colName));
if (!colName.equalsIgnoreCase("zone_email")) {
chcReportJsonObj.put(colName, rs1.getInt(colName));
emailBodyStr.append("<td>"); emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getTimestamp(colName)); emailBodyStr.append(rs1.getInt(colName));
emailBodyStr.append("</td>"); emailBodyStr.append("</td>");
} }
/* else if(type==Types.BIT) {
System.out.print("BIT field:" + rs.getDate(colName));
chcReportJsonObj.put(colName, rs.getTimestamp(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs.getTimestamp(colName));
emailBodyStr.append("</td>");
}*/
else if(type==Types.NUMERIC) {
System.out.print("NUMERIC field:" + rs1.getInt(colName));
if (!colName.equalsIgnoreCase("zone_email")) {
chcReportJsonObj.put(colName, rs1.getInt(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getInt(colName));
emailBodyStr.append("</td>");
}
}
else if(type==Types.TINYINT) {
System.out.print("TINYINT field:" + rs1.getInt(colName));
chcReportJsonObj.put(colName, rs1.getInt(colName)); }
emailBodyStr.append("<td>"); else if (type == -6) {
emailBodyStr.append(rs1.getInt(colName)); System.out.print("TINYINT field:" + rs1.getInt(colName));
emailBodyStr.append("</td>");
}
else if(type==Types.SMALLINT) {
System.out.print("SMALLINT field:" + rs1.getInt(colName));
chcReportJsonObj.put(colName, rs1.getInt(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getInt(colName));
emailBodyStr.append("</td>");
}
/* else if(type==Types.REAL) {
System.out.print("REAL field:" + rs.getDate(colName));
chcReportJsonObj.put(colName, rs.getTimestamp(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs.getTimestamp(colName));
emailBodyStr.append("</td>");
}
else if(type==Types.FLOAT) {
System.out.print("FLOAT field:" + rs.getDate(colName));
chcReportJsonObj.put(colName, rs.getTimestamp(colName)); chcReportJsonObj.put(colName, rs1.getInt(colName));
emailBodyStr.append("<td>"); emailBodyStr.append("<td>");
emailBodyStr.append(rs.getTimestamp(colName)); emailBodyStr.append(rs1.getInt(colName));
emailBodyStr.append("</td>"); emailBodyStr.append("</td>");
} }
else if(type==Types.DOUBLE) { else if (type == 5) {
System.out.print("DOUBLE field:" + rs.getDate(colName)); System.out.print("SMALLINT field:" + rs1.getInt(colName));
chcReportJsonObj.put(colName, rs.getTimestamp(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs.getTimestamp(colName));
emailBodyStr.append("</td>");
}*/
/* else if(type==Types.BINARY) {
System.out.print("BINARY field:" + rs.getDate(colName));
chcReportJsonObj.put(colName, rs.getTimestamp(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs.getTimestamp(colName));
emailBodyStr.append("</td>");
}
else if(type==Types.CLOB) {
System.out.print("CLOB field:" + rs.getDate(colName));
chcReportJsonObj.put(colName, rs.getTimestamp(colName)); chcReportJsonObj.put(colName, rs1.getInt(colName));
emailBodyStr.append("<td>"); emailBodyStr.append("<td>");
emailBodyStr.append(rs.getTimestamp(colName)); emailBodyStr.append(rs1.getInt(colName));
emailBodyStr.append("</td>"); emailBodyStr.append("</td>");
} }
else if(type==Types.BLOB) { else if (type == 92) {
System.out.print("BLOB field:" + rs.getDate(colName)); System.out.print("TIME field:" + rs1.getTime(colName));
chcReportJsonObj.put(colName, rs.getTimestamp(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs.getTimestamp(colName));
emailBodyStr.append("</td>");
}*/
else if(type==Types.TIME) {
System.out.print("TIME field:" + rs1.getTime(colName));
chcReportJsonObj.put(colName, rs1.getTime(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getTime(colName));
emailBodyStr.append("</td>");
}
else
{
System.out.println("Exceptional case where data type may be different");
}
chcReportJsonArray.put(chcReportJsonObj); chcReportJsonObj.put(colName, rs1.getTime(colName));
emailBodyStr.append("<td>");
emailBodyStr.append(rs1.getTime(colName));
emailBodyStr.append("</td>");
} }
System.out.println("123456==>"+count); else
{
count++; System.out.println("Exceptional case where data type may be different");
System.out.println("987654==>"+count); }
/* zoneEmailId = rs.getString("zone_email");
siteCity = rs.getString("site_city"); chcReportJsonArray.put(chcReportJsonObj);
regionCode = rs.getString("region_code"); }
zone = rs.getString("zone");*/ System.out.println("123456==>" + count);
System.out.println("zoneEmailId" + zoneEmailId);
System.out.println("zoneTherpyGrp" + zoneTherpyGrp); count++;
System.out.println("siteCity" + siteCity); System.out.println("987654==>" + count);
System.out.println("regionCode" + regionCode);
System.out.println("zone" + zone); System.out.println("zoneEmailId" + zoneEmailId);
System.out.println("zoneTherpyGrp" + zoneTherpyGrp);
String combineKey = siteCity + "," + regionCode+ "," + zone; System.out.println("siteCity" + siteCity);
System.out.println("combineKey" + combineKey); System.out.println("regionCode" + regionCode);
System.out.println("app" + app.toString()); System.out.println("zone" + zone);
String emailbd = (emailBodyStr != null) && (emailBodyStr.length() > 0) ? emailBodyStr.toString().replaceAll("\\[|\\]", "") : ""; String combineKey = siteCity + "," + regionCode+ "," + zone;
System.out.println("emailbd" + emailbd); System.out.println("combineKey" + combineKey);
if (!app.containsKey(combineKey)) { System.out.println("app" + app.toString());
System.out.println("Inside if app not contains key"); String emailbd = (emailBodyStr != null) && (emailBodyStr.length() > 0) ? emailBodyStr.toString().replaceAll("\\[|\\]", "") : "";
System.out.println("emailbd" + emailbd);
if (!app.containsKey(combineKey)) {
System.out.println("Inside if app not contains key");
List<String> ls = new ArrayList(); List<String> ls = new ArrayList();
ls.add(emailbd); ls.add(emailbd);
app.put(combineKey, ls); app.put(combineKey, ls);
HashSet emailSet = new HashSet(); HashSet emailSet = new HashSet();
emailSet.add(zoneEmailId); emailSet.add(zoneEmailId);
emailApp.put(combineKey, emailSet); emailApp.put(combineKey, emailSet);
} }
else if (app.containsKey(combineKey)) else if (app.containsKey(combineKey))
{ {
System.out.println("Inside if app contains key"); System.out.println("Inside if app contains key");
List<String> ls = (List)app.get(combineKey); List<String> ls = (List)app.get(combineKey);
System.out.println("ls=======>"+ls); System.out.println("ls=======>"+ls);
ls.add(emailbd); ls.add(emailbd);
...@@ -518,111 +413,100 @@ public class CHCReportOtherClusterSch ...@@ -518,111 +413,100 @@ public class CHCReportOtherClusterSch
HashSet emailSet = (HashSet)emailApp.get(combineKey); HashSet emailSet = (HashSet)emailApp.get(combineKey);
emailSet.add(zoneEmailId); emailSet.add(zoneEmailId);
emailApp.put(combineKey, emailSet); emailApp.put(combineKey, emailSet);
} }
emailBodyStr.append("</tr>"); emailBodyStr.append("</tr>");
System.out.println("chcReportJsonArray size:::" + chcReportJsonArray.length()); System.out.println("chcReportJsonArray size:::" + chcReportJsonArray.length());
index++; index++;
} }
if (index == 0) { if (index == 0) {
System.out.println("Check index"); System.out.println("Check index");
printLog("No Data Found", "Please Enter Valid Query to Return data"); printLog("No Data Found", "Please Enter Valid Query to Return data");
} }
else else
{
for (Map.Entry emailData : app.entrySet())
{ {
for (Map.Entry emailData : app.entrySet()) System.out.println("Inside for loop to check map entry");
HashSet<String> emailGet = emailApp.get(emailData.getKey());
System.out.println("emailGet==>" + emailGet);
for (String emailD : emailGet)
{ {
System.out.println("Inside for loop to check map entry"); zoneEmailId = emailD;
HashSet<String> emailGet = emailApp.get(emailData.getKey()); StringBuffer emailStr = new StringBuffer();
System.out.println("emailGet==>"+emailGet); emailStr.append("<html><head><style type='text/css'>table, th, td {border:1px solid black;}</style></head><body><table>");
for (String emailD : emailGet)
emailStr.append("<thead>");
emailStr.append("<tr>");
emailStr.append(emailheaderStr.toString());
emailStr.append("</tr>");
emailStr.append("</thead>");
emailStr.append("<tbody>");
String emailbdData = emailData.getValue() != null ? ((List)emailData.getValue()).toString().replaceAll("\\[|\\]|,", "") : "";
emailStr.append(emailbdData);
emailbdData = emailData.getValue() != null ? emailbdData.replaceAll("<tr>|<td>|</tr>", " ") : "";
if (emailbdData != null)
{ {
zoneEmailId = emailD; String[] emailbdDataa = emailbdData.split("</td>");
StringBuffer emailStr = new StringBuffer(); System.out.println("zone>>>==>" + emailbdData);
emailStr.append("<html><head><style type='text/css'>table, th, td {border:1px solid black;}</style></head><body><table>"); zone = emailbdDataa[1];
zoneTherpyGrp = emailbdDataa[0];
emailStr.append("<thead>"); siteCity = emailbdDataa[3];
emailStr.append("<tr>"); }
emailStr.append(emailheaderStr.toString()); else
emailStr.append("</tr>"); {
emailStr.append("</thead>"); zone = "";
emailStr.append("<tbody>"); siteCity = "";
}
String emailbdData = emailData.getValue() != null ? ((List)emailData.getValue()).toString().replaceAll("\\[|\\]|,", "") : "";
emailStr.append(emailbdData);
emailbdData = emailData.getValue() != null ?emailbdData.replaceAll("<tr>|<td>|</tr>"," "):"";
if(emailbdData!=null)
{
String[] emailbdDataa =emailbdData.split("</td>");
System.out.println("zone>>>==>"+emailbdData);
zone= emailbdDataa[1];
zoneTherpyGrp=emailbdDataa[0];
siteCity=emailbdDataa[3];
}
else
{
zone="";
siteCity="";
}
System.out.println("zone>>>==>"+zone);
System.out.println("siteCity>>>==>"+siteCity);
System.out.println("zone>>>==>"+zone);
System.out.println("siteCity>>>==>"+siteCity);
emailStr.append("</tbody>");
emailStr.append("</body>");
emailStr.append("</html>");
String chcReportData = emailStr.toString();
System.out.println("chcReportData====>" + chcReportData);
chcReportData = "Dear All,<br><br>Please find the CHC Deviation Report(Orders Blocked)<br><br> To override the orders through "+"Pragati Order release"+" application login to the mobile app or if you are on a laptop click on below link and login with your Sunpharma Shine credentials:<br><br><b>Laptop link: </b> https://pragati.sunpharma.com/<br><br> \n" + chcReportData + "\n" + "<br>This is autogenerated mail , kindly do not reply to this mail id<br><br> <b style='color:red;'>Disclaimer: This data shows the blocked status as per mentioned date time stamp and may not reflect any changes done on the order release application in the interim.</b> <br><br>Regards,<br>BI team."; System.out.println("zone>>>==>" + zone);
System.out.println("siteCity>>>==>" + siteCity);
//chcReportData = "Dear All,<br><br>Please find the CHC Deviation Report(Orders Blocked)<br><br> To override the orders through "+"Pragati Order release"+" application click on below link and login with your Sunpharma Shine credentials:<br><br> https://pragati.sunpharma.com/<br><br> \n" + chcReportData + "\n" + "<br>This is autogenerated mail , kindly do not reply to this mail id<br><br> <b style='color:red;'>Disclaimer: This data shows the blocked status as per mentioned date time stamp and may not reflect any changes done on the order release application in the interim.</b> <br><br>Regards,<br>BI team."; System.out.println("zone>>>==>" + zone);
//chcReportData = "Dear All,<br><br>Please find the "+zoneTherpyGrp+" Deviation Report(Orders Blocked)<br><br> \n" + chcReportData + "\n" + "<br>This is autogenerated mail , kindly do not reply to this mail id <br><br>Regards,<br>BI team."; System.out.println("siteCity>>>==>" + siteCity);
emailStr.append("</tbody>");
emailStr.append("</body>");
emailStr.append("</html>");
System.out.println("chcReportData222====>" + chcReportData); String chcReportData = emailStr.toString();
System.out.println("chcReportData====>" + chcReportData);
System.out.println("zoneEmailId>>>" + zoneEmailId); chcReportData = "Dear All,<br><br>Please find the " + zoneTherpyGrp + " Deviation Report(Orders Blocked)<br><br> \n" + chcReportData + "\n" + "<br>This is autogenerated mail , kindly do not reply to this mail id <br><br>Regards,<br>BI team.";
mailSent = sendMail(chcReportData, zoneEmailId, transInfo,zone,siteCity,lineNo,zoneTherpyGrp);
// mailSent = sendMail(chcReportData, "ketan.patil@baseinformation.com,Prachi.Joshi@sunpharma.com,prashant.joshi@proteustech.in,ketanpatilketanpatil@gmail.com", transInfo); System.out.println("chcReportData222====>" + chcReportData);
//mailSent = sendMail(chcReportData, "ketan.patil@baseinformation.com,Tejashree.Sawe@sunpharma.com", transInfo,zone,siteCity,lineNo);
if (mailSent) System.out.println("zoneEmailId>>>" + zoneEmailId);
{ mailSent = sendMail(chcReportData, zoneEmailId, transInfo, zone, siteCity, lineNo, zoneTherpyGrp,conn);
printLog(zoneEmailId, "", "", mailSent);
System.out.println("Succesfully send the mail");
}
else {
printLog(zoneEmailId, "", "", mailSent);
System.out.println("failure while sending the mail");
}
if (mailSent)
{
printLog(zoneEmailId, "", "", mailSent);
System.out.println("Succesfully send the mail");
}
else {
printLog(zoneEmailId, "", "", mailSent);
System.out.println("failure while sending the mail");
} }
} }
} }
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
} }
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
} }
rs.close(); rs.close();
rs = null; rs = null;
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
} }
catch (SQLException e1) catch (SQLException e1)
{ {
...@@ -706,6 +590,20 @@ public class CHCReportOtherClusterSch ...@@ -706,6 +590,20 @@ public class CHCReportOtherClusterSch
e.printStackTrace(); e.printStackTrace();
printLog("STDERR", e); printLog("STDERR", e);
} }
try
{
if (fileWriter != null)
{
fileWriter.flush();
fileWriter.close();
}
}
catch (Exception e)
{
e.printStackTrace();
printLog("STDERR", e);
}
} }
finally finally
{ {
...@@ -783,6 +681,20 @@ public class CHCReportOtherClusterSch ...@@ -783,6 +681,20 @@ public class CHCReportOtherClusterSch
e.printStackTrace(); e.printStackTrace();
printLog("STDERR", e); printLog("STDERR", e);
} }
try
{
if (fileWriter != null)
{
fileWriter.flush();
fileWriter.close();
}
}
catch (Exception e)
{
e.printStackTrace();
printLog("STDERR", e);
}
} }
finally finally
{ {
...@@ -826,45 +738,47 @@ public class CHCReportOtherClusterSch ...@@ -826,45 +738,47 @@ public class CHCReportOtherClusterSch
return input.trim(); return input.trim();
} }
public boolean sendMail(String reportFilePath, String emailId, String transInfo, String ZoneStr, String SiteCityStr,String lineNo,String zoneTherpyGrp) public boolean sendMail(String reportFilePath, String emailId, String transInfo, String ZoneStr, String SiteCityStr, String lineNo, String zoneTherpyGrp,Connection conn)
throws ITMException throws ITMException
{ {
System.out.println("Inside sent mail: "); System.out.println("Inside sent mail: ");
boolean sentMail = false; boolean sentMail = false;
//String lineNo = "1";
String emailType = "page"; String emailType = "page";
StringBuffer valueXmlString = null; StringBuffer valueXmlString = null;
String retValue = ""; String retValue = "";
try try
{ {
//String ccId="Rajesh.Sutar@sunpharma.com,Prachi.Joshi@sunpharma.com"; DistCommon disCommon = new DistCommon();
//String toId="Prachi.Joshi@sunpharma.com"; String ccId = disCommon.getDisparams("999999", "CHC_OTHER_CC", conn);
//String ccId="rajeshkumar.sinha@sunpharma.com, Agnivarna.Chaudhary@sunpharma.com, Parthasarathi.Muntha@sunpharma.com,Prachi.joshi@sunpharma.com"; System.out.println("ccId>>>>"+ ccId);
String ccId="ketan.patil@baseinformation.com";
//String bccId="Prashant.Joshi@proteustech.in,ketan.patil@baseinformation.com"; if(ccId == null || ccId.trim().length() == 0 || ccId.trim().equalsIgnoreCase("NULLNOTFOUND"))
{
ccId = "Agnivarna.Chaudhary@sunpharma.com, Parthasarathi.Muntha@sunpharma.com,Prachi.joshi@sunpharma.com";
}
//String ccId="Prachi.Joshi@sunpharma.com";
System.out.println("Inside try: "); System.out.println("Inside try: ");
valueXmlString = new StringBuffer("<ROOT>"); valueXmlString = new StringBuffer("<ROOT>");
valueXmlString.append("<MAILINFO>"); valueXmlString.append("<MAILINFO>");
valueXmlString.append("<EMAIL_TYPE>").append("null").append("</EMAIL_TYPE>"); valueXmlString.append("<EMAIL_TYPE>").append("null").append("</EMAIL_TYPE>");
emailId="pravin.nevage@proteustech.in";
valueXmlString.append("<TO_ADD>").append("<![CDATA[" + emailId + "]]>").append("</TO_ADD>"); valueXmlString.append("<TO_ADD>").append("<![CDATA[" + emailId + "]]>").append("</TO_ADD>");
valueXmlString.append("<CC_ADD>").append("<![CDATA[" + ccId + "]]>").append("</CC_ADD>"); valueXmlString.append("<CC_ADD>").append("<![CDATA[" + ccId + "]]>").append("</CC_ADD>");
// valueXmlString.append("<BCC_ADD>").append("<![CDATA[" + bccId + "]]>").append("</BCC_ADD>");
System.out.println("emailId: " + emailId); System.out.println("emailId: " + emailId);
System.out.println("lineNo: " + lineNo); System.out.println("lineNo: " + lineNo);
if(lineNo.equalsIgnoreCase("1")){ if (lineNo.equalsIgnoreCase("1")) {
valueXmlString.append("<SUBJECT>").append("<![CDATA["+zoneTherpyGrp +" Deviation Report : ZSM - For Zone -" + ZoneStr + "]]>").append("</SUBJECT>"); valueXmlString.append("<SUBJECT>").append("<![CDATA[" + zoneTherpyGrp + " Deviation Report : ZSM - For Zone -" + ZoneStr + "]]>").append("</SUBJECT>");
} }
if(lineNo.equalsIgnoreCase("2")){ if (lineNo.equalsIgnoreCase("2")) {
valueXmlString.append("<SUBJECT>").append("<![CDATA["+zoneTherpyGrp +" Deviation Report : NSM - For Zone -" + ZoneStr + "]]>").append("</SUBJECT>"); valueXmlString.append("<SUBJECT>").append("<![CDATA[" + zoneTherpyGrp + " Deviation Report : NSM - For Zone -" + ZoneStr + "]]>").append("</SUBJECT>");
} }
if(lineNo.equalsIgnoreCase("3")){ if (lineNo.equalsIgnoreCase("3")) {
valueXmlString.append("<SUBJECT>").append("<![CDATA["+zoneTherpyGrp +" Deviation Report : BUHEAD - For Zone -" + ZoneStr + "]]>").append("</SUBJECT>"); valueXmlString.append("<SUBJECT>").append("<![CDATA[" + zoneTherpyGrp + " Deviation Report : BUHEAD - For Zone -" + ZoneStr + "]]>").append("</SUBJECT>");
} }
valueXmlString.append("<BODY_TEXT>").append("<![CDATA[" + reportFilePath + "]]>").append("</BODY_TEXT>"); valueXmlString.append("<BODY_TEXT>").append("<![CDATA[" + reportFilePath + "]]>").append("</BODY_TEXT>");
......
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