Commit a7a9fb5b authored by Ketan Patil's avatar Ketan Patil

Replace ReportCreationSchedulerSfa.java

parent 4fd1a7fe
/* */ package ibase.webitm.ejb.sc;
/* */
/* */ import ibase.scheduler.utility.interfaces.Schedule;
/* */ import ibase.system.config.ConnDriver;
/* */ import ibase.utility.CommonConstants;
/* */ import ibase.utility.E12GenericUtility;
/* */ import ibase.utility.EMail;
/* */ import ibase.utility.MailInfo;
/* */ import ibase.utility.UserInfoBean;
/* */ import ibase.webitm.reports.utility.JasperReportGenerator;
/* */ import ibase.webitm.reports.utility.ResourceConstants;
/* */ import ibase.webitm.reports.utility.XSDParser;
/* */ import ibase.webitm.utility.ITMException;
/* */ import java.io.File;
/* */ import java.io.FileWriter;
/* */ import java.io.PrintStream;
/* */ import java.io.PrintWriter;
/* */ import java.io.StringWriter;
/* */ import java.sql.Connection;
/* */ import java.sql.PreparedStatement;
/* */ import java.sql.ResultSet;
/* */ import java.sql.ResultSetMetaData;
/* */ import java.sql.SQLException;
/* */ import java.text.DateFormat;
/* */ import java.text.SimpleDateFormat;
/* */ import java.util.ArrayList;
/* */ import java.util.HashMap;
/* */ import java.util.TreeMap;
/* */ import java.util.regex.Matcher;
/* */ import java.util.regex.Pattern;
package ibase.webitm.ejb.sc;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
/* */ import org.w3c.dom.Document;
/* */ import org.w3c.dom.Node;
/* */ import org.w3c.dom.NodeList;
/* */
/* */ public class ReportCreationSchedulerSfa
/* */ implements Schedule
/* */ {
/* 41 */ String mailAddress = "";
/* 42 */ String userInfoXml = "";
/* */
/* 45 */ UserInfoBean userInfo = null;
/* */
/* */ public String schedule(HashMap arg0)
/* */ throws Exception
/* */ {
/* 50 */ return null;
/* */ }
/* */
/* */ public String schedule(String arg0) throws Exception
/* */ {
/* 55 */ System.out.println("Inside schedule " + arg0);
/* 56 */ return performOp(arg0);
/* */ }
/* */
/* */ public String schedulePriority(String arg0)
/* */ throws Exception
/* */ {
/* 63 */ System.out.println("Inside schedule priority " + arg0);
/* 64 */ return performOp(arg0);
/* */ }
/* */
/* */ public String performOp(String scheduleParamXML)
/* */ throws ITMException
/* */ {
/* 70 */ String retString = "";
/* */
/* 73 */ ConnDriver connDriver = new ConnDriver();
/* 74 */ Connection conn = null;
/* 75 */ PreparedStatement pstmt = null; PreparedStatement pstmt1 = null;
/* 76 */ ResultSet rs = null;
/* */
/* 78 */ boolean isError = false;
/* */ try
/* */ {
/* 89 */ this.userInfoXml = scheduleParamXML;
/* 90 */ System.out.println("userInfoXml:::[" + this.userInfoXml + "]" + "scheduleParamXML>> " + scheduleParamXML);
/* 91 */ this.userInfo = new UserInfoBean(this.userInfoXml);
/* 92 */ System.out.println("userInfo > Amit > " + this.userInfo);
/* 93 */ String transDB = this.userInfo.getTransDB();
/* 94 */ System.out.println("get TransDB connection in updateStatus : " + transDB);
/* 95 */ if ((transDB != null) && (transDB.trim().length() > 0))
/* */ {
/* 97 */ conn = connDriver.getConnectDB(transDB);
/* */ }
/* */ else
/* */ {
/* 101 */ conn = connDriver.getConnectDB("DriverITM");
/* */ }
/* */
/* 105 */ retString = performOp(scheduleParamXML, conn);
/* */ }
/* */ catch (Exception e)
/* */ {
/* 109 */ isError = true;
/* 110 */ e.printStackTrace();
/* 111 */ throw new ITMException(e);
/* */ }
/* */ finally
/* */ {
/* */ try
/* */ {
/* 117 */ if (conn != null)
/* */ {
/* 119 */ if (isError)
/* */ {
/* 121 */ conn.rollback();
/* */ }
/* */ else
/* */ {
/* 125 */ conn.commit();
/* */ }
/* 127 */ conn.close();
/* 128 */ conn = null;
/* */ }
/* */ }
/* */ catch (Exception e)
/* */ {
/* 133 */ e.printStackTrace();
/* 134 */ throw new ITMException(e);
/* */ }
/* */ }
/* 137 */ return retString;
/* */ }
/* */
/* */ public String performOp(String scheduleParamXML, Connection conn) throws ITMException, Exception
/* */ {
/* 142 */ String retString = "";
/* 143 */ String sql = ""; String objName = ""; String argumentString = ""; String jrxmlName = "";
/* 144 */ String sqlExpr = ""; String sqlExpr1 = ""; String sqlExpr2 = ""; String sqlExpr3 = ""; String sqlExpr4 = ""; String sqlExpr5 = ""; String sqlExpr6 = ""; String errfilePath = "";
/* 145 */ String compSql = "";
/* 146 */ PreparedStatement pstmt = null;
/* 147 */ ResultSet rs = null;
/* 148 */ ArrayList objtNamelist = new ArrayList();
/* 149 */ String objtNames = "";
/* 150 */ String stateCode = ""; String reportGroup = null;
/* */
/* 152 */ E12GenericUtility genericUtility = new E12GenericUtility();
/* 153 */ ArrayList valueContainer = new ArrayList();
/* 154 */ boolean mailSent = false;
/* 155 */ String transInfo = "";
/* */
/* 157 */ String mailFormat = "";
/* */
/* 159 */ System.out.println("scheduler xml content:" + scheduleParamXML);
/* */
/* 161 */ String transDB = "";
/* 162 */ ConnDriver connDriver = new ConnDriver();
/* */ try
/* */ {
/* 166 */ Document dom = genericUtility.parseString(scheduleParamXML);
/* 167 */ System.out.println(" before add parameter userInfo>>>>>" + this.userInfo);
/* 168 */ String chgUser = genericUtility.getColumnValue("empName", dom);
/* 169 */ String chgTerm = genericUtility.getColumnValue("hostIP", dom);
/* 170 */ String loginCode = genericUtility.getColumnValue("loginCode", dom);
/* 171 */ String loginEmpCode = genericUtility.getColumnValue("empCode", dom);
/* 172 */ String loginSiteCode = genericUtility.getColumnValue("siteCode", dom);
/* 173 */ System.out.println("chgUser>> " + chgUser + "chgTerm>>>" + chgTerm + "loginCode>>>" + loginCode + "loginEmpCode>>>" + loginEmpCode + "loginSiteCode>>>" + loginSiteCode);
/* 174 */ this.userInfo.setEmpCode(loginEmpCode);
/* 175 */ this.userInfo.setRemoteHost(chgTerm);
/* 176 */ this.userInfo.setSiteCode(loginSiteCode);
/* 177 */ this.userInfo.setLoginCode(loginCode);
/* 178 */ this.userInfo.setEntityCode(loginEmpCode);
/* 179 */ System.out.println(" add parameter userInfo>>>>>" + this.userInfo);
/* */
/* 181 */ NodeList paramList = dom.getElementsByTagName("SCHEDULE");
/* 182 */ Node currDetail = null;
/* 183 */ int noOfParam = paramList.getLength();
/* 184 */ NodeList parentNodeList = null; NodeList childNodeList = null;
/* 185 */ Node parentNode = null; Node childNode = null;
/* 186 */ String DisparmSites = "";
/* 187 */ int childNodeListLength = 0;
/* 188 */ String childNodeName = null;
/* 189 */ int index = 0;
/* */
/* 191 */ parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
/* */
/* 193 */ parentNode = parentNodeList.item(0);
/* 194 */ childNodeList = parentNode.getChildNodes();
/* 195 */ childNodeListLength = childNodeList.getLength();
/* */
/* 197 */ for (int ctr = 0; ctr < childNodeListLength; ctr++)
/* */ {
/* 199 */ childNode = childNodeList.item(ctr);
/* 200 */ childNodeName = childNode.getNodeName();
/* */
/* 202 */ if ((childNodeName == null) || ("#text".equalsIgnoreCase(childNodeName)))
/* */ continue;
/* 204 */ if (ctr == 0)
/* */ {
/* 206 */ stateCode = checkNull(childNode.getFirstChild().getNodeValue());
/* 207 */ System.out.println("StateCode::" + stateCode);
/* */ }
/* 209 */ else if (ctr == 1)
/* */ {
/* 211 */ reportGroup = checkNull(childNode.getFirstChild().getNodeValue());
/* 212 */ System.out.println("ReportGroup::" + reportGroup);
/* */ }
/* 215 */ else if (ctr == 2)
/* */ {
/* 217 */ mailFormat = checkNull(childNode.getFirstChild().getNodeValue());
/* 218 */ System.out.println("@ MailFormat::" + mailFormat);
/* */ } else {
/* 220 */ if (ctr != 3)
/* */ continue;
/* 222 */ transDB = checkNull(childNode.getFirstChild().getNodeValue());
/* 223 */ System.out.println("@ transDB::" + transDB);
/* */ }
/* */
/* */ }
/* */
/* 230 */ this.userInfo.setTransDB(transDB);
/* 231 */ if ((transDB != null) && (transDB.trim().length() > 0))
/* */ {
/* 233 */ conn = connDriver.getConnectDB(transDB);
/* */ }
/* */ else
/* */ {
/* 237 */ conn = connDriver.getConnectDB("DriverITM");
/* */ }
/* 239 */ sql = "select line_no,sql_expr,sql_input,sql_expr1,sql_expr2,sql_expr3,sql_expr4, sql_expr5,sql_expr6 from tax_bal_grp_det where bal_group=? ";
/* */
/* 241 */ pstmt = conn.prepareStatement(sql);
/* 242 */ pstmt.setString(1, reportGroup);
/* 243 */ rs = pstmt.executeQuery();
/* 244 */ while (rs.next()) {
/* 245 */ sqlExpr = checkNull(rs.getString("sql_expr"));
/* 246 */ sqlExpr1 = checkNull(rs.getString("sql_expr1"));
/* 247 */ sqlExpr2 = checkNull(rs.getString("sql_expr2"));
/* 248 */ sqlExpr3 = checkNull(rs.getString("sql_expr3"));
/* 249 */ sqlExpr4 = checkNull(rs.getString("sql_expr4"));
/* 250 */ sqlExpr5 = checkNull(rs.getString("sql_expr5"));
/* 251 */ sqlExpr6 = checkNull(rs.getString("sql_expr6"));
/* 252 */ objtNames = checkNull(rs.getString("sql_input"));
/* */ }
/* 254 */ rs.close();
/* 255 */ rs = null;
/* 256 */ pstmt.close();
/* 257 */ pstmt = null;
/* */
/* 259 */ compSql = sqlExpr + " " + sqlExpr1 + " " + sqlExpr2 + " " + sqlExpr3 + " " + sqlExpr4 + " " + sqlExpr5 + " " + sqlExpr6;
/* 260 */ System.out.println("Combine SQL::::" + compSql);
/* */
/* 262 */ String[] obj = objtNames.split(",");
/* 263 */ for (String s : obj) {
/* 264 */ objtNamelist.add(s);
/* */ }
/* 266 */ System.out.println("@narendra Obj name " + (String)objtNamelist.get(0) + " Jrxml Name: " + (String)objtNamelist.get(1));
/* 267 */ objName = (String)objtNamelist.get(0);
/* 268 */ jrxmlName = (String)objtNamelist.get(1);
/* */
/* 271 */ int count = 0;
/* 272 */ if ((compSql != null) && (compSql.trim().length() > 0))
/* */ {
/* 275 */ pstmt = conn.prepareStatement(compSql);
/* 276 */ rs = pstmt.executeQuery();
/* */
/* 278 */ while (rs.next()) {
/* 279 */ ResultSetMetaData rsmd = rs.getMetaData();
/* 280 */ for (int i = 1; i <= rsmd.getColumnCount(); i++) {
/* 281 */ int type = rsmd.getColumnType(i);
/* 282 */ if ((type == 12) || (type == 1)) {
/* 283 */ System.out.print("VARCHAR field:" + rs.getString(i));
/* 284 */ if (checkEmailAddress(rs.getString(i)))
/* 285 */ System.out.println("Mail id found");
/* */ else {
/* 287 */ valueContainer.add(rs.getString(i));
/* */ }
/* */ }
/* 290 */ else if (type == 91) {
/* 291 */ System.out.print("DATE field:" + rs.getDate(i));
/* 292 */ String dateAsString = rs.getDate(i).toString();
/* 293 */ DateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd");
/* 294 */ SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yy");
/* 295 */ java.util.Date date = sourceFormat.parse(dateAsString);
/* 296 */ System.out.println(formatter.format(date));
/* 297 */ valueContainer.add(formatter.format(date));
/* */ }
/* 299 */ else if (type == 93) {
/* 300 */ System.out.print("TIMESTAMP field:" + rs.getDate(i));
/* 301 */ valueContainer.add(rs.getTimestamp(i));
/* */ }
/* */ else {
/* 304 */ System.out.println("Exceptional case where data type may be different");
/* */ }
/* */
/* */ }
/* */
/* 309 */ System.out.println("Value container size:::" + valueContainer.size());
/* */
/* 311 */ count++;
/* */
/* 313 */ XSDParser xsdParser = new XSDParser(objName, this.userInfo);
/* */
/* 315 */ argumentString = new ArgumentListGenerator().getDynamicArgumentList(xsdParser, valueContainer);
/* */
/* 317 */ valueContainer.clear();
/* 318 */ System.out.println("argumentString from dynamic ::==> [" + argumentString + "]");
/* */
/* 320 */ JasperReportGenerator jasperReport = new JasperReportGenerator(this.userInfo);
/* 321 */ TreeMap argMap = jasperReport.createArgMap(argumentString);
/* 322 */ System.out.println("Value Of argMap >>>> " + argMap);
/* 323 */ String allType = (String)argMap.get("report_save_type");
/* 324 */ allType = allType == null ? "" : allType.trim();
/* 325 */ System.out.println("allType>>> Amit" + allType);
/* 326 */ if ("PDF".equalsIgnoreCase(allType))
/* */ {
/* 328 */ allType = "pdf";
/* */ }
/* 330 */ else if (("EXCEL".equalsIgnoreCase(allType)) || ("EXCELDATA".equalsIgnoreCase(allType)) || ("EXCEL-DATA".equalsIgnoreCase(allType)) || ("EXCEL DATA".equalsIgnoreCase(allType)) || ("ODS".equalsIgnoreCase(allType)))
/* */ {
/* 332 */ allType = "xls";
/* */ }
/* 334 */ else if (("CSV".equalsIgnoreCase(allType)) || ("CSVDATA".equalsIgnoreCase(allType)))
/* */ {
/* 336 */ allType = "csv";
/* */ }
/* 338 */ else if ("HTML".equalsIgnoreCase(allType))
/* */ {
/* 340 */ allType = "html";
/* */ }
/* 342 */ else if ("TEXT".equalsIgnoreCase(allType))
/* */ {
/* 344 */ allType = "txt";
/* */ }
/* 346 */ else if ("EXCEL(XLSX)".equalsIgnoreCase(allType))
/* */ {
/* 348 */ allType = "xlsx";
/* */ }
/* 350 */ else if ("DOCX".equalsIgnoreCase(allType))
/* */ {
/* 352 */ allType = "docx";
/* */ }
/* 354 */ else if ("RTF".equalsIgnoreCase(allType))
/* */ {
/* 356 */ allType = "rtf";
/* */ }
/* 358 */ else if ("ODT".equalsIgnoreCase(allType))
/* */ {
/* 360 */ allType = "odt";
/* */ }
/* 362 */ System.out.println("allType>>> ::" + allType);
/* 363 */ System.out.println("Getting argument metadata::" + xsdParser.getArgumentMetaDataString());
/* 364 */ System.out.println("xsdParser::---->" + xsdParser);
/* */
/* 374 */ System.out.println(" add parameter userInfo>>>>>" + this.userInfo);
/* */
/* 376 */ jasperReport.createReport(jrxmlName, argMap, xsdParser, rs.getString("site_code"), rs.getString("tran_id") + "_" + count);
/* */
/* 378 */ String reportOutputFileName = jasperReport.getOutputFileName();
/* 379 */ System.out.println("[reportOutputFileName]:" + reportOutputFileName);
/* 380 */ String reportDestination = ResourceConstants.REPORTDESTINATION + File.separator + rs.getString("site_code") + File.separator +
/* 381 */ reportOutputFileName + "." + allType;
/* */
/* 383 */ transInfo = getDomString(rs.getString("email_addr"));
/* */
/* 386 */ String copyPath = ResourceConstants.REPORTDESTINATION + File.separator + "TempFolder";
/* */ try
/* */ {
/* 389 */ File copyFilePath = new File(copyPath);
/* 390 */ if (!copyFilePath.exists()) {
/* 391 */ copyFilePath.mkdir();
/* */ }
/* 393 */ else if (copyFilePath.exists())
/* */ {
/* */ try
/* */ {
/* 397 */ if (count <= 1)
/* */ {
/* 399 */ FileUtils.cleanDirectory(copyFilePath);
/* */ }
/* */ }
/* */ catch (Exception exp)
/* */ {
/* 404 */ exp.printStackTrace();
/* */ }
/* */ }
/* 407 */ File reportDestPath = new File(reportDestination);
/* 408 */ FileUtils.copyFileToDirectory(reportDestPath, copyFilePath);
/* */ try
/* */ {
/* 411 */ mailSent = sendMail(reportDestination, transInfo, mailFormat, conn);
/* */ }
/* */ catch (Exception e)
/* */ {
/* 415 */ System.out.println("Mail sending failed");
/* */ }
/* */ }
/* */ catch (Exception e)
/* */ {
/* 420 */ e.printStackTrace();
/* */ }
/* */
/* 424 */ if (mailSent) {
/* 425 */ printLog(rs.getString("email_addr"), rs.getString("tran_id"), reportOutputFileName, mailSent);
/* 426 */ System.out.println("Succesfully send the mail");
/* */ } else {
/* 428 */ printLog(rs.getString("email_addr"), rs.getString("tran_id"), reportOutputFileName, mailSent);
/* 429 */ System.out.println("failure while sending the mail");
/* */ }
/* 431 */ index++;
/* */ }
/* 433 */ if (index == 0) {
/* 434 */ printLog("No Data Found", "Please Enter Valid Query to Return data");
/* */ }
/* */
/* 437 */ rs.close();
/* 438 */ rs = null;
/* 439 */ pstmt.close();
/* 440 */ pstmt = null;
/* */ }
/* */ }
/* */ catch (SQLException e1)
/* */ {
/* 445 */ System.out.println("Error_Code::::" + e1.getErrorCode());
/* 446 */ System.out.println(e1);
/* 447 */ String err = String.valueOf(e1.getErrorCode());
/* 448 */ printLog("STDERR", "GENERIC REPORTS :: FAIL_SQL ==>" + compSql);
/* 449 */ printLog("STDERR", "GENERIC REPORTS :: FAIL_SQL ==>" + e1);
/* */ }
/* */ catch (Exception e)
/* */ {
/* 454 */ throw new Exception(e);
/* */ }
/* */ finally
/* */ {
/* 458 */ if (rs != null)
/* */ {
/* 460 */ rs.close();
/* 461 */ rs = null;
/* */ }
/* 463 */ if (pstmt != null)
/* */ {
/* 465 */ pstmt.close();
/* 466 */ pstmt = null;
/* */ }
/* */ }
/* 469 */ return retString;
/* */ }
/* */
/* */ private void printLog(String title, String msg)
/* */ {
/* 480 */ String logFile = "";
/* 481 */ String logDir = "";
/* 482 */ File logFileDir = null;
/* 483 */ FileWriter fileWriter = null;
/* */ try
/* */ {
/* 487 */ String logFileName = "";
/* 488 */ SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
/* 489 */ logFileName = "ReportScheduler_" + sdf.format(new java.util.Date());
/* */
/* 491 */ System.out.println("Inside the print log method");
/* */
/* 493 */ logDir = CommonConstants.JBOSSHOME + File.separator + "applnlog" + File.separator + "ReportScheduler_";
/* 494 */ System.out.println("Log direction: " + logDir);
/* */
/* 496 */ logFileDir = new File(logDir);
/* */
/* 498 */ if (!logFileDir.exists())
/* */ {
/* 500 */ logFileDir.mkdirs();
/* */ }
/* */
/* 503 */ logFile = logDir + File.separator + logFileName + ".log";
/* */
/* 505 */ SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
/* 506 */ java.util.Date now = new java.util.Date();
/* 507 */ String strDate = sdfDate.format(now);
/* */
/* 509 */ fileWriter = new FileWriter(logFile, true);
/* */
/* 511 */ fileWriter.write("\r\n");
/* 512 */ fileWriter.write("[ERROR] " + msg);
/* */ }
/* */ catch (Exception ex)
/* */ {
/* 516 */ ex.printStackTrace();
/* 517 */ printLog("STDERR", ex);
/* 518 */ printLog("STDOUT", "Inside Exception [getLog]>>" + ex.toString());
/* */ try
/* */ {
/* 524 */ if (fileWriter != null)
/* */ {
/* 526 */ fileWriter.flush();
/* 527 */ fileWriter.close();
/* */ }
/* */ }
/* */ catch (Exception e)
/* */ {
/* 532 */ e.printStackTrace();
/* 533 */ printLog("STDERR", e);
/* */ }
/* */ }
/* */ finally
/* */ {
/* */ try
/* */ {
/* 524 */ if (fileWriter != null)
/* */ {
/* 526 */ fileWriter.flush();
/* 527 */ fileWriter.close();
/* */ }
/* */ }
/* */ catch (Exception e)
/* */ {
/* 532 */ e.printStackTrace();
/* 533 */ printLog("STDERR", e);
/* */ }
/* */ }
/* */ }
/* */
/* */ private void printLog(String maildId, String tranId, String fileName, boolean mailSent)
/* */ {
/* 540 */ String logFile = "";
/* 541 */ String logDir = "";
/* 542 */ File logFileDir = null;
/* 543 */ FileWriter fileWriter = null;
/* */ try
/* */ {
/* 547 */ String logFileName = "";
/* 548 */ SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
/* 549 */ logFileName = "ReportScheduler_" + sdf.format(new java.util.Date());
/* */
/* 551 */ System.out.println("Inside the print log method");
/* */
/* 553 */ logDir = CommonConstants.JBOSSHOME + File.separator + "applnlog" + File.separator + "ReportScheduler_";
/* 554 */ System.out.println("Log direction: " + logDir);
/* */
/* 556 */ logFileDir = new File(logDir);
/* */
/* 558 */ if (!logFileDir.exists())
/* */ {
/* 560 */ logFileDir.mkdirs();
/* */ }
/* */
/* 563 */ logFile = logDir + File.separator + logFileName + ".log";
/* */
/* 565 */ SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
/* 566 */ java.util.Date now = new java.util.Date();
/* 567 */ String strDate = sdfDate.format(now);
/* */
/* 569 */ fileWriter = new FileWriter(logFile, true);
/* */
/* 571 */ fileWriter.write("\r\n");
/* 572 */ if (mailSent) {
/* 573 */ fileWriter.write("Succesfully Sent mail to [" + tranId + "] " + "With File Name" + " [" + fileName + "] on Mail Id " + "[" + maildId + "]");
/* */ }
/* */ else {
/* 576 */ fileWriter.write("Mail is not Sent to [" + tranId + "] " + "With File Name" + " [" + fileName + "] on Mail Id " + "[" + maildId + "]");
/* */ }
/* */ }
/* */ catch (Exception ex)
/* */ {
/* 581 */ ex.printStackTrace();
/* 582 */ printLog("STDERR", ex);
/* 583 */ printLog("STDOUT", "Inside Exception [getLog]>>" + ex.toString());
/* */ try
/* */ {
/* 589 */ if (fileWriter != null)
/* */ {
/* 591 */ fileWriter.flush();
/* 592 */ fileWriter.close();
/* */ }
/* */ }
/* */ catch (Exception e)
/* */ {
/* 597 */ e.printStackTrace();
/* 598 */ printLog("STDERR", e);
/* */ }
/* */ }
/* */ finally
/* */ {
/* */ try
/* */ {
/* 589 */ if (fileWriter != null)
/* */ {
/* 591 */ fileWriter.flush();
/* 592 */ fileWriter.close();
/* */ }
/* */ }
/* */ catch (Exception e)
/* */ {
/* 597 */ e.printStackTrace();
/* 598 */ printLog("STDERR", e);
/* */ }
/* */ }
/* */ }
/* */
/* */ private void printLog(String title, Exception e)
/* */ {
/* */ try
/* */ {
/* 608 */ StringWriter strError = new StringWriter();
/* 609 */ e.printStackTrace(new PrintWriter(strError));
/* 610 */ String err = strError.toString();
/* 611 */ printLog(title, err);
/* */ }
/* */ catch (Exception ex)
/* */ {
/* 615 */ ex.printStackTrace();
/* 616 */ printLog("STDERR", "Inside Exception [getLog]>>" + ex.toString());
/* */ }
/* */ }
/* */
/* */ private String checkNull(String input)
/* */ {
/* 622 */ if (input == null) {
/* 623 */ input = "";
/* */ }
/* 625 */ return input.trim();
/* */ }
/* */
/* */ public boolean sendMail(String reportFilePath, String transInfo, String mailFormat, Connection conn)
/* */ throws ITMException
/* */ {
/* 635 */ boolean sentMail = false;
/* */
/* 637 */ String lineNo = "1";
/* 638 */ String emailType = "page";
/* 639 */ StringBuffer valueXmlString = null;
/* 640 */ String retValue = "";
/* */ try
/* */ {
/* 644 */ valueXmlString = new StringBuffer("<ROOT>");
/* */
/* 667 */ valueXmlString.append("<MAILINFO>");
/* 668 */ valueXmlString.append("<EMAIL_TYPE>").append("page").append("</EMAIL_TYPE>");
/* */
/* 670 */ if ((mailFormat != null) && (mailFormat.trim().length() > 0))
/* */ {
/* 672 */ valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[" + mailFormat + "]]>").append("</FORMAT_CODE>");
/* */ }
/* */ else {
/* 675 */ valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[GEN_REPORT]]>").append("</FORMAT_CODE>");
/* */ }
/* */
/* 680 */ valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + reportFilePath + "]]>").append("</XML_DATA_FILE_PATH>");
/* 681 */ valueXmlString.append("</MAILINFO>");
/* 682 */ valueXmlString.append("<XML_DATA>").append(transInfo).append("</XML_DATA>");
/* 683 */ valueXmlString.append("</ROOT>");
/* */
/* 686 */ String mailDomStr = valueXmlString.toString();
/* */
/* 688 */ System.out.println("@@## [Generic Report] :sendMail mailDomStr :-->" + mailDomStr);
/* 689 */ EMail email = new EMail();
/* 690 */ MailInfo info = new MailInfo();
/* 691 */ retValue = email.sendMail(mailDomStr, "ITM", conn);
/* 692 */ if ("S".equalsIgnoreCase(retValue))
/* */ {
/* 695 */ sentMail = true;
/* */ }
/* 697 */ System.out.println("[Pdf] mail delivered successfully");
/* */ }
/* */ catch (ITMException itme)
/* */ {
/* 701 */ System.out.println("@@## ITMException [[Generic Report]] :sendMail :sendMail :sendMail() :==>\n");
/* 702 */ throw itme;
/* */ }
/* */ catch (Exception e)
/* */ {
/* 706 */ System.out.println("Exception :[[Generic Report]] :sendMail() :==>\n" + e.getMessage());
/* 707 */ throw new ITMException(e);
/* */ }
/* 709 */ return sentMail;
/* */ }
/* */
/* */ public boolean checkEmailAddress(String emailValue)
/* */ {
/* 716 */ Pattern pattern = Pattern.compile("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}");
/* 717 */ Matcher mat = pattern.matcher(emailValue);
/* 718 */ return mat.matches();
/* */ }
/* */
/* */ private String getDomString(String emailIdPer) throws ITMException
/* */ {
/* 723 */ String retString = "";
/* 724 */ StringBuffer valueXmlString = new StringBuffer();
/* */ try
/* */ {
/* 727 */ valueXmlString.append("<ROOT>");
/* 728 */ valueXmlString.append("<Detail1>");
/* 729 */ valueXmlString.append("<email_id_cust>").append("<![CDATA[" + emailIdPer + "]]>").append("</email_id_cust>");
/* 730 */ valueXmlString.append("</Detail1>");
/* 731 */ valueXmlString.append("</ROOT>");
/* 732 */ retString = valueXmlString.toString();
/* */ }
/* */ catch (Exception e)
/* */ {
/* 736 */ e.printStackTrace();
/* 737 */ printLog("ERROR", e);
/* */ }
/* 739 */ return retString;
/* */ }
/* */ }
/* Location: C:\Users\pravin.nevage\Desktop\ibase3-webitm-sc2-0-1-5.jar
* Qualified Name: ibase.webitm.ejb.sc.ReportCreationSchedulerSfa
* JD-Core Version: 0.6.0
*/
\ No newline at end of file
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.utility.EMail;
import ibase.utility.MailInfo;
import ibase.utility.UserInfoBean;
import ibase.webitm.reports.utility.JasperReportGenerator;
import ibase.webitm.reports.utility.ResourceConstants;
import ibase.webitm.reports.utility.XSDParser;
import ibase.webitm.utility.ITMException;
public class ReportCreationSchedulerSfa implements Schedule{
String mailAddress="";
String userInfoXml = "";
//String userInfoXml = "";
UserInfoBean userInfo = null;
@Override
public String schedule(HashMap arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public String schedule(String arg0) throws Exception {
System.out.println("Inside schedule "+arg0);
return this.performOp(arg0);
}
@Override
public String schedulePriority(String arg0) throws Exception {
// TODO Auto-generated method stub
System.out.println("Inside schedule priority "+arg0);
return this.performOp(arg0);
}
public String performOp(String scheduleParamXML)throws ITMException
{
String retString = "";
//Added By Amit Shrivastava [Start][11/08/20]
/*Connection conn = null;*/
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pstmt = null,pstmt1=null;
ResultSet rs=null;
//Added By Amit Shrivastava [End...][11/08/20]
boolean isError = false;
try
{
//printLog("STDOUT","ReportCreationScheduler : performOp => Scheduler Started");
//printLog("STDOUT","ReportCreationScheduler : performOp : =>" + scheduleParamXML);
//Added By Amit Shrivastava[Start][11/08/20]
/*ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB();*/
this.userInfoXml = scheduleParamXML;
System.out.println("userInfoXml:::[" + this.userInfoXml + "]"+"scheduleParamXML>> "+scheduleParamXML);
userInfo = new UserInfoBean(this.userInfoXml);
System.out.println("userInfo > Amit > " +userInfo);
String transDB = userInfo.getTransDB();
System.out.println("get TransDB connection in updateStatus : " + transDB);
if ((transDB != null) && (transDB.trim().length() > 0))
{
conn = connDriver.getConnectDB(transDB);
}
else
{
conn = connDriver.getConnectDB("DriverITM");
}
//Added By Amit Shrivastava[End....][11/08/20]
retString = performOp(scheduleParamXML, conn);
}
catch(Exception e)
{
isError = true;
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(conn != null)
{
if(isError)
{
conn.rollback();
}
else
{
conn.commit();
}
conn.close();
conn = null;
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return retString;
}
public String performOp(String scheduleParamXML,Connection conn)throws ITMException, Exception
{
String retString="";
String sql="",objName="",argumentString="",jrxmlName="";
String sqlExpr="",sqlExpr1="",sqlExpr2="",sqlExpr3="",sqlExpr4="",sqlExpr5="",sqlExpr6="",errfilePath="";
String compSql="";
PreparedStatement pstmt = null;
ResultSet rs = null ;
ArrayList<String> objtNamelist=new ArrayList<String>();
String objtNames="";
String stateCode="",reportGroup = null;
//ibase.utility.UserInfoBean userInfo = null;
E12GenericUtility genericUtility = new E12GenericUtility();
ArrayList<Object> valueContainer=new ArrayList<Object>();
boolean mailSent = false;
String transInfo = "";
//Added By Amit Shrivastava on 04/16/19 for create a variable [Start]
String mailFormat="";
//Added By Amit Shrivastava on 04/16/19 for create a variable [End]
System.out.println("scheduler xml content:"+scheduleParamXML);
//String reportGroup=scheduleParamXML.substring(scheduleParamXML.indexOf("<reportGroup>")+22, scheduleParamXML.indexOf("</reportGroup>")-3);
String transDB = "";
ConnDriver connDriver = new ConnDriver();
try{
//userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
Document dom=genericUtility.parseString(scheduleParamXML);
System.out.println(" before add parameter userInfo>>>>>" + userInfo);
String chgUser = genericUtility.getColumnValue("empName", dom);
String chgTerm = genericUtility.getColumnValue("hostIP", dom);
String loginCode = genericUtility.getColumnValue("loginCode", dom);
String loginEmpCode = genericUtility.getColumnValue("empCode", dom);
String loginSiteCode = genericUtility.getColumnValue("siteCode", dom);
System.out.println("chgUser>> " + chgUser + "chgTerm>>>" + chgTerm + "loginCode>>>" + loginCode + "loginEmpCode>>>" + loginEmpCode + "loginSiteCode>>>" + loginSiteCode);
userInfo.setEmpCode(loginEmpCode);
userInfo.setRemoteHost(chgTerm);
userInfo.setSiteCode(loginSiteCode);
userInfo.setLoginCode(loginCode);
userInfo.setEntityCode(loginEmpCode);
System.out.println(" add parameter userInfo>>>>>" + userInfo);
//Dom related stuff goes here.....
NodeList paramList = dom.getElementsByTagName( "SCHEDULE" );
Node currDetail = null ;
int noOfParam = paramList.getLength();
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
String DisparmSites = "";
int childNodeListLength = 0;
String childNodeName = null;
int index=0;
parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName!=null && !"#text".equalsIgnoreCase(childNodeName))
{
if(ctr==0)
{
stateCode=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("StateCode::"+stateCode);
}
else if(ctr==1)
{
reportGroup=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("ReportGroup::"+reportGroup);
}
//Added By amit SHrivasatava on 04/06/19 for get the maol format value [Start]
else if(ctr==2)
{
mailFormat=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("@ MailFormat::"+mailFormat);
}
else if(ctr==3)
{
transDB=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("@ transDB::"+transDB);
}
//Added By amit SHrivasatava on 04/06/19 for get the maol format value [end]
}
}
userInfo.setTransDB(transDB);
if ((transDB != null) && (transDB.trim().length() > 0))
{
conn = connDriver.getConnectDB(transDB);
}
else
{
conn = connDriver.getConnectDB("DriverITM");
}
sql="select line_no,sql_expr,sql_input,sql_expr1,sql_expr2,sql_expr3,sql_expr4,"
+ " sql_expr5,sql_expr6 from tax_bal_grp_det where bal_group=? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, reportGroup);
rs=pstmt.executeQuery();
while(rs.next()){
sqlExpr= checkNull(rs.getString("sql_expr"));
sqlExpr1= checkNull(rs.getString("sql_expr1"));
sqlExpr2= checkNull(rs.getString("sql_expr2"));
sqlExpr3= checkNull( rs.getString("sql_expr3"));
sqlExpr4= checkNull(rs.getString("sql_expr4"));
sqlExpr5= checkNull(rs.getString("sql_expr5"));
sqlExpr6= checkNull(rs.getString("sql_expr6"));
objtNames=checkNull(rs.getString("sql_input"));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
compSql= sqlExpr+" "+sqlExpr1+" "+sqlExpr2+" "+sqlExpr3+" "+sqlExpr4+" "+sqlExpr5+" "+sqlExpr6;
System.out.println("Combine SQL::::"+compSql);
String[] obj=objtNames.split(",");
for(String s:obj){
objtNamelist.add(s);
}
System.out.println("@narendra Obj name "+objtNamelist.get(0)+" Jrxml Name: "+objtNamelist.get(1));
objName=objtNamelist.get(0);
jrxmlName=objtNamelist.get(1);
int count=0;
if(compSql!=null && compSql.trim().length() > 0 )
{
pstmt=conn.prepareStatement(compSql);
rs=pstmt.executeQuery();
while(rs.next()){
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
int type = rsmd.getColumnType(i);
if (type == Types.VARCHAR || type == Types.CHAR) {
System.out.print("VARCHAR field:"+rs.getString(i));
if(checkEmailAddress(rs.getString(i))){
System.out.println("Mail id found");
}else{
valueContainer.add(rs.getString(i));
}
}
else if(type==Types.DATE){
System.out.print("DATE field:"+rs.getDate(i));
String dateAsString = rs.getDate(i).toString();
DateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yy");
Date date = sourceFormat.parse(dateAsString);
System.out.println(formatter.format(date));
valueContainer.add(formatter.format(date));
}
else if(type==Types.TIMESTAMP){
System.out.print("TIMESTAMP field:"+rs.getDate(i));
valueContainer.add(rs.getTimestamp(i));
}
else {
System.out.println("Exceptional case where data type may be different");
//System.out.print(rs.getLong(i));
}
}
System.out.println("Value container size:::"+valueContainer.size());
count++;
//argumentString=new ArgumentListGenerator().getArgumentList(objtNamelist.get(1),rs.getString(1));
XSDParser xsdParser=new XSDParser(objName, userInfo);
//argumentString=new ArgumentListGenerator().getDynamicArgumentList(xsdParser,rs.getString(1));
argumentString=new ArgumentListGenerator().getDynamicArgumentList(xsdParser,valueContainer);
valueContainer.clear();
System.out.println("argumentString from dynamic ::==> ["+argumentString+"]");
JasperReportGenerator jasperReport=new JasperReportGenerator(userInfo);
TreeMap argMap = jasperReport.createArgMap(argumentString);
System.out.println("Value Of argMap >>>> "+argMap);
String allType=(String) argMap.get("report_save_type");
allType = allType == null ? "" : allType.trim();
System.out.println("allType>>> Amit"+allType);
if("PDF".equalsIgnoreCase(allType))
{
allType = "pdf";
}
else if("EXCEL".equalsIgnoreCase(allType) || "EXCELDATA".equalsIgnoreCase(allType) || "EXCEL-DATA".equalsIgnoreCase(allType) || "EXCEL DATA".equalsIgnoreCase(allType) || "ODS".equalsIgnoreCase(allType))
{
allType = "xls";
}
else if("CSV".equalsIgnoreCase(allType) || "CSVDATA".equalsIgnoreCase(allType))
{
allType = "csv";
}
else if("HTML".equalsIgnoreCase(allType))
{
allType = "html";
}
else if("TEXT".equalsIgnoreCase(allType))
{
allType = "txt";
}
else if("EXCEL(XLSX)".equalsIgnoreCase(allType))
{
allType = "xlsx";
}
else if("DOCX".equalsIgnoreCase(allType))
{
allType = "docx";
}
else if("RTF".equalsIgnoreCase(allType))
{
allType = "rtf";
}
else if("ODT".equalsIgnoreCase(allType))
{
allType = "odt";
}
System.out.println("allType>>> ::"+allType);
System.out.println("Getting argument metadata::"+xsdParser.getArgumentMetaDataString());
System.out.println("xsdParser::---->"+xsdParser);
//argumnetMap get report_save_type value if report save type -- pdf ,xsl,//Amit
/*
if (argNodes.getLength() > 0) {
Element err = (Element)argNodes.item(0);
System.out.println(err.getAttribute("value")+" "+err.getAttribute("name"));
} else {
// success
}*/
System.out.println(" add parameter userInfo>>>>>" + userInfo);
jasperReport.createReport(jrxmlName, argMap, xsdParser, rs.getString("site_code"), rs.getString("tran_id")+"_"+count);
String reportOutputFileName = jasperReport.getOutputFileName();
System.out.println("[reportOutputFileName]:"+reportOutputFileName);
String reportDestination = ResourceConstants.REPORTDESTINATION + File.separator + rs.getString("site_code") + File.separator
+ reportOutputFileName + "." +allType;
transInfo = getDomString(rs.getString("email_addr"));
//comment by amit shrivastava on 04/06/19 [Start]
/*mailSent= sendMail(reportDestination,transInfo);*/
String copyPath = ResourceConstants.REPORTDESTINATION + File.separator + "TempFolder";
try
{
File copyFilePath = new File(copyPath);
if(!copyFilePath.exists()) {
copyFilePath.mkdir();
}
else if(copyFilePath.exists())
{
try
{
if(count <= 1)
{
FileUtils.cleanDirectory(copyFilePath);
}
}
catch(Exception exp)
{
exp.printStackTrace();
}
}
File reportDestPath = new File(reportDestination);
FileUtils.copyFileToDirectory(reportDestPath, copyFilePath);
try
{
mailSent= sendMail(reportDestination,transInfo ,mailFormat, conn);
}
catch(Exception e)
{
System.out.println("Mail sending failed");
}
}
catch(Exception e)
{
e.printStackTrace();
}
//comment by amit shrivastava on 04/06/19 [End]
if(mailSent){
printLog(rs.getString("email_addr"), rs.getString("tran_id"), reportOutputFileName,mailSent);//GENERATE LOG
System.out.println("Succesfully send the mail");
}else{
printLog(rs.getString("email_addr"), rs.getString("tran_id"), reportOutputFileName,mailSent);//GENERATE LOG
System.out.println("failure while sending the mail");
}
index++;
}
if(index==0){
printLog("No Data Found", "Please Enter Valid Query to Return data");
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
}
catch(SQLException e1)
{
System.out.println("Error_Code::::"+e1.getErrorCode());
System.out.println(e1);
String err=String.valueOf(e1.getErrorCode());
printLog("STDERR", "GENERIC REPORTS :: FAIL_SQL ==>"+compSql);
printLog("STDERR", "GENERIC REPORTS :: FAIL_SQL ==>"+e1);
}
catch(Exception e)
{
throw new Exception(e);
}
finally
{
if(rs!=null)
{
rs.close();
rs = null;
}
if(pstmt !=null)
{
pstmt.close();
pstmt = null;
}
}
return retString;
}
/**
* @param title
* @param msg
* This method is used for printing the logs in log file
*/
private void printLog(String title, String msg)
{
String logFile = "";
String logDir = "";
File logFileDir = null;
FileWriter fileWriter = null;
try
{
String logFileName = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
logFileName = "ReportScheduler_"+sdf.format(new Date());
System.out.println("Inside the print log method");
logDir = CommonConstants.JBOSSHOME + File.separator + "applnlog" + File.separator + "ReportScheduler_";
System.out.println("Log direction: "+logDir);
logFileDir = new File(logDir);
if (!logFileDir.exists())
{
logFileDir.mkdirs();
}
logFile = logDir + File.separator + logFileName + ".log";
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
java.util.Date now = new java.util.Date();
String strDate = sdfDate.format(now);
fileWriter = new FileWriter(logFile, true);
fileWriter.write("\r\n");
fileWriter.write("[ERROR] "+msg);
}
catch (Exception ex)
{
ex.printStackTrace();
printLog("STDERR", ex);
printLog("STDOUT","Inside Exception [getLog]>>" + ex.toString());
}
finally
{
try
{
if (fileWriter != null)
{
fileWriter.flush();
fileWriter.close();
}
}
catch (Exception e)
{
e.printStackTrace();
printLog("STDERR", e);
}
}
}
private void printLog(String maildId, String tranId,String fileName,boolean mailSent)
{
String logFile = "";
String logDir = "";
File logFileDir = null;
FileWriter fileWriter = null;
try
{
String logFileName = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
logFileName = "ReportScheduler_"+sdf.format(new Date());
System.out.println("Inside the print log method");
logDir = CommonConstants.JBOSSHOME + File.separator + "applnlog" + File.separator + "ReportScheduler_";
System.out.println("Log direction: "+logDir);
logFileDir = new File(logDir);
if (!logFileDir.exists())
{
logFileDir.mkdirs();
}
logFile = logDir + File.separator + logFileName + ".log";
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
java.util.Date now = new java.util.Date();
String strDate = sdfDate.format(now);
fileWriter = new FileWriter(logFile, true);
fileWriter.write("\r\n");
if(mailSent){
fileWriter.write("Succesfully Sent mail to ["+tranId + "] " + "With File Name" + " ["+ fileName+"] on Mail Id "+"["+maildId+"]");
}
else{
fileWriter.write("Mail is not Sent to ["+tranId + "] " + "With File Name" + " ["+ fileName+"] on Mail Id "+"["+maildId+"]");
}
}
catch (Exception ex)
{
ex.printStackTrace();
printLog("STDERR", ex);
printLog("STDOUT","Inside Exception [getLog]>>" + ex.toString());
}
finally
{
try
{
if (fileWriter != null)
{
fileWriter.flush();
fileWriter.close();
}
}
catch (Exception e)
{
e.printStackTrace();
printLog("STDERR", e);
}
}
}
private void printLog(String title, Exception e)
{
try
{
StringWriter strError = new StringWriter();
e.printStackTrace(new PrintWriter(strError));
String err = strError.toString();
printLog(title, err);
}
catch(Exception ex)
{
ex.printStackTrace();
printLog("STDERR","Inside Exception [getLog]>>" + ex.toString());
}
}
private String checkNull(String input) {
if (input == null) {
input = "";
}
return input.trim();
}
//Send mail method will send the mail to stockiest person
//Comment by amit shrivastava on 04/06/19 [start]
/*public boolean sendMail(String reportFilePath, String transInfo)throws ITMException*/
public boolean sendMail(String reportFilePath, String transInfo, String mailFormat, Connection conn)throws ITMException
///Comment by amit shrivastava on 04/06/19 [end]
{
boolean sentMail = false;
String lineNo = "1";
String emailType = "page";
StringBuffer valueXmlString=null;
String retValue="";
try{
valueXmlString = new StringBuffer("<ROOT>");
/*valueXmlString = new StringBuffer("<ROOT><TRANS_INFO>");
valueXmlString.append("<OBJ_NAME>").append("<![CDATA[" + "" + "]]>").append("</OBJ_NAME>");
valueXmlString.append("<REF_SER>").append("<![CDATA[" + "" + "]]>").append("</REF_SER>");
valueXmlString.append("<REF_ID>").append("<![CDATA[" + "" + "]]>").append("</REF_ID>");
valueXmlString.append("<LINE_NO>").append("<![CDATA[" + lineNo + "]]>").append("</LINE_NO>");
valueXmlString.append("</TRANS_INFO>");
valueXmlString.append("<MAIL>");
valueXmlString.append("<EMAIL_TYPE>").append("<![CDATA[" + emailType + "]]>").append("</EMAIL_TYPE>");
valueXmlString.append("<ENTITY_CODE>").append("<![CDATA[" + "SUN" + "]]>").append("</ENTITY_CODE>");
valueXmlString.append("<ENTITY_TYPE>").append("<![CDATA[" + "" + "]]>").append("</ENTITY_TYPE>");
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[" + "E" +"]]>").append("</FORMAT_CODE>");
valueXmlString.append("<TO_ADD>").append("<![CDATA[" +mailAddress +"]]>").append("</TO_ADD>");
valueXmlString.append("<CC_ADD>").append("<![CDATA[" + mailAddress+"]]>").append("</CC_ADD>");
valueXmlString.append("<SUBJECT>").append("<![CDATA[" + "Reports" +"]]>").append("</SUBJECT>");
valueXmlString.append("<BODY_TEXT>").append("<![CDATA[" + "PFA of Report(s)" +"]]>").append("</BODY_TEXT>");
valueXmlString.append("<MESSAGE>").append("<![CDATA[" + "PFA of Report(s)" +"]]>").append("</MESSAGE>");
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + reportFilePath + "]]>").append("</XML_DATA_FILE_PATH>");
valueXmlString.append("</MAIL>");
valueXmlString.append("</ROOT>");*/
//valueXmlString.append("<ROOT>");
valueXmlString.append("<MAILINFO>");
valueXmlString.append("<EMAIL_TYPE>").append("page").append("</EMAIL_TYPE>");
//Added By amit Shrivastava on 04/06/19 for add mail format in send mail method.[Start]
if(mailFormat !=null && mailFormat.trim().length()>0)
{
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA["+mailFormat+"]]>").append("</FORMAT_CODE>");
}else
{
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[GEN_REPORT]]>").append("</FORMAT_CODE>");
}
/*valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[GEN_REPORT]]>").append("</FORMAT_CODE>");*/
//Added By amit Shrivastava on 04/06/19 for add mail format in send mail method.[End]
//commInfo.append("<TO_ADD>").append("<![CDATA[" + emailTo + "]]>").append("</TO_ADD>");
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + reportFilePath + "]]>").append("</XML_DATA_FILE_PATH>");
valueXmlString.append("</MAILINFO>");
valueXmlString.append("<XML_DATA>").append(transInfo).append("</XML_DATA>");
valueXmlString.append("</ROOT>");
String mailDomStr = valueXmlString.toString();
System.out.println("@@## [Generic Report] :sendMail mailDomStr :-->" + mailDomStr);
EMail email = new EMail();
MailInfo info=new MailInfo();
retValue=email.sendMail(mailDomStr, "ITM", conn);
if("S".equalsIgnoreCase(retValue))
{
//printLog("STDOUT","ReportCreationScheduler : sendMail => Mail sent successfully" );
sentMail = true;
}
System.out.println("[Pdf] mail delivered successfully" );
}
catch (ITMException itme)
{
System.out.println("@@## ITMException [[Generic Report]] :sendMail :sendMail :sendMail() :==>\n");
throw itme;
}
catch (Exception e)
{
System.out.println("Exception :[[Generic Report]] :sendMail() :==>\n" + e.getMessage());
throw new ITMException(e);
}
return sentMail;
}
/**
* boolean method which will check whether string contains mail address or not
*/
public boolean checkEmailAddress(String emailValue){
Pattern pattern = Pattern.compile("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}");
Matcher mat = pattern.matcher(emailValue);
return mat.matches();
}
private String getDomString(String emailIdPer) throws ITMException
{
String retString = "";
StringBuffer valueXmlString = new StringBuffer();
try
{
valueXmlString.append("<ROOT>");
valueXmlString.append("<Detail1>");
valueXmlString.append("<email_id_cust>").append("<![CDATA[" + emailIdPer + "]]>").append("</email_id_cust>");
valueXmlString.append("</Detail1>");
valueXmlString.append("</ROOT>");
retString = valueXmlString.toString();
}
catch(Exception e)
{
e.printStackTrace();
printLog("ERROR", e);
}
return retString;
}
}
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