Commit b38836e6 authored by bpandey's avatar bpandey

modify code as per client requirement


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@94225 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 56c0d2fc
...@@ -93,14 +93,14 @@ public class ProductionVsBudgetReportBean ...@@ -93,14 +93,14 @@ public class ProductionVsBudgetReportBean
public void generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException
{ {
String resultString="false";
try try
{ {
budgetReportRemote.generatePDF(hashMap,exportPDFPath,exportImagePath,preyearMonth,rptTitle,userID); resultString= budgetReportRemote.generatePDF(hashMap,exportPDFPath,exportImagePath,preyearMonth,rptTitle,userID);
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -108,7 +108,7 @@ public class ProductionVsBudgetReportBean ...@@ -108,7 +108,7 @@ public class ProductionVsBudgetReportBean
e.printStackTrace(); e.printStackTrace();
} }
return resultString;
} }
......
...@@ -4,17 +4,20 @@ import ibase.scheduler.utility.interfaces.Schedule; ...@@ -4,17 +4,20 @@ import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants; import ibase.utility.CommonConstants;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.awt.Desktop;
import java.net.URI;
public class ProductionVsBudgetReportSchedule implements Schedule public class ProductionVsBudgetReportSchedule implements Schedule
{ {
public String schedule(HashMap map) throws Exception public String schedule(HashMap map) throws Exception
{ {
System.out.println(schedule((String) map.get("PROCESS_NAME"))); System.out.println(schedule((String) map.get("PROCESS_NAME")));
...@@ -35,7 +38,6 @@ public class ProductionVsBudgetReportSchedule implements Schedule ...@@ -35,7 +38,6 @@ public class ProductionVsBudgetReportSchedule implements Schedule
private void runSchedule() throws ITMException private void runSchedule() throws ITMException
{ {
// Add new code on dated 10/01/2013 // Add new code on dated 10/01/2013
String sql = ""; String sql = "";
ResultSet rs = null; ResultSet rs = null;
...@@ -45,25 +47,30 @@ public class ProductionVsBudgetReportSchedule implements Schedule ...@@ -45,25 +47,30 @@ public class ProductionVsBudgetReportSchedule implements Schedule
String userID = ""; String userID = "";
String uri = ""; String uri = "";
String finalURI = ""; String finalURI = "";
List<String> sendFinalURIList = null; List<String> sendFinalURIList = null;
//add new variable on dated1/02/2013
String os = System.getProperty("os.name").toLowerCase();
String browserPathForLinex="";
try try
{ {
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
connDriver = null; connDriver = null;
sendFinalURIList = new ArrayList<String>(); sendFinalURIList = new ArrayList<String>();
sql = " select user_id,uri from dashboard_comp where uri like '%ProductionVsBudgetReportExport.jsp%'"; //sql = " select user_id,uri from dashboard_comp where uri like '%ProductionVsBudgetReportExport.jsp%'";
sql="select user_id,uri from dashboard_comp where uri like '%ExportExample/ProductionVsBudgetReportExport.jsp%'";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
userID = checkNull(rs.getString("user_id")); userID = checkNull(rs.getString("user_id"));
uri = checkNull(rs.getString("uri")); uri = checkNull(rs.getString("uri"));
// finalURI = CommonConstants.TOMCAT_HOME + uri + "&userID ="+userID; finalURI = CommonConstants.TOMCAT_HOME+uri+"&userID="+userID;
finalURI = CommonConstants.TOMCAT_HOME + uri; System.out.println("direct uri from table ="+ uri);
System.out.println("finalURI is =" + finalURI);
sendFinalURIList.add(finalURI);
System.out.println("User id is =" + userID); System.out.println("User id is =" + userID);
System.out.println("modify url is =" + finalURI);
sendFinalURIList.add(finalURI);
} }
...@@ -71,45 +78,68 @@ public class ProductionVsBudgetReportSchedule implements Schedule ...@@ -71,45 +78,68 @@ public class ProductionVsBudgetReportSchedule implements Schedule
rs.close(); rs.close();
pstmt = null; pstmt = null;
rs = null; rs = null;
for (String resourcePath : sendFinalURIList) //This URL comming from table as dashboard_comp as multiple types
{ //CommonConstants.TOMCAT_HOME+ibase/dashboard/mfg/jsp/ProductionVsBudgetReport.jsp?geoLocation=105,110,117,130 &unitForm=TAB,CAP,V01,A01&userID=E04111
if (Desktop.isDesktopSupported()) /* if (os.indexOf( "win" ) >= 0)
{ {
Desktop desktop = Desktop.getDesktop();
try for (String resourcePath : sendFinalURIList)
{ {
desktop.browse(new URI(resourcePath));
} catch (Exception e) Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler"+ resourcePath);
{ Thread.sleep(25000);
// TODO Auto-generated catch block }
e.printStackTrace(); } */
} /*Added new code for windows palform*/
} else
{ if (os.indexOf("win") >= 0)
Runtime runtime = Runtime.getRuntime(); {
try System.out.println("Start Window Section part execution");
{ if (Desktop.isDesktopSupported())
runtime.exec("xdg-open " + resourcePath); {
} catch (IOException e) Desktop desktop = Desktop.getDesktop();
for (String resourcePath : sendFinalURIList)
{
try
{
System.out.println("run on browser through window ");
desktop.browse(new URI(resourcePath));
Thread.sleep(2500);
System.out.println("End run on browser through window ");
}
catch (Exception e)
{
e.printStackTrace();
}
}
//Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler" + resourcePath);
//Thread.sleep(25000L);
}
System.out.println("End of Window Section part execution");
}
/* Ended Added new code for windows palform*/
if (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0)
{
//browserPathForLinex ="/usr/lib/firefox/firefox";
browserPathForLinex ="/usr/lib/firefox/firefox";
for (String resourcePath : sendFinalURIList)
{ {
// TODO Auto-generated catch block callURL(browserPathForLinex,resourcePath); //call synchronized method
e.printStackTrace(); //String[] b = {browserPath, resourcePath};
} }
} }
// String resourcePath = CommonConstants.TOMCAT_HOME + File.separator + "ibase" +File.separator + "dashboard" + File.separator + "mfg" +File.separator+"JSP"+File.separator+"ExportExample"+File.separator +"ProductionVsBudgetReport_export.jsp"; // end forloop
System.out.println("ProductionVsBudgetReportSchedule path =[" + resourcePath + "]");
}// end forloop
}// end try block }// end try block
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
} finally } finally
{ {
try try
...@@ -133,8 +163,23 @@ public class ProductionVsBudgetReportSchedule implements Schedule ...@@ -133,8 +163,23 @@ public class ProductionVsBudgetReportSchedule implements Schedule
} }
} }
} }
synchronized void callURL(String browserPath,String resourcePath)
{
try{
int second = (int)(System.currentTimeMillis() / 1000) % 60 ;
System.out.println("View for Time when next URL are comming==="+second);
Runtime.getRuntime().exec(new String[] {browserPath, resourcePath});
Thread.sleep(35000);
System.out.println("In Linex12");
}catch(Exception e){System.out.println("Exception Inside callURL by synchronization method "+e.getMessage());}
}
// This method call for check null // This method call for check null
private String checkNull(String input) private String checkNull(String input)
{ {
......
package ibase.dashboard.mfg.bean; package ibase.dashboard.mfg.bean;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import javax.servlet.ServletException; import javax.servlet.ServletException;
...@@ -47,9 +52,19 @@ public class ProductionVsBudgetReportServlet extends HttpServlet ...@@ -47,9 +52,19 @@ public class ProductionVsBudgetReportServlet extends HttpServlet
//System.out.println("preyearMonth====="+preyearMonth); //System.out.println("preyearMonth====="+preyearMonth);
//System.out.println("rptTitle====="+rptTitle); //System.out.println("rptTitle====="+rptTitle);
//call EJB method for PDF creation******************* //call EJB method for PDF creation*******************
bean.generatePDF(gridDataMap, exportPDFPath, exportImagePath, preyearMonth, rptTitle,userID);
response.setContentType("text/html"); String resultString= bean.generatePDF(gridDataMap, exportPDFPath, exportImagePath, preyearMonth, rptTitle,userID);
response.getWriter().write("PDF Creation"); response.setContentType("text/html");
System.out.println("resultString is ="+resultString);
if(resultString.equals("false"))
{
response.getWriter().write("false");
}
else
{
response.getWriter().write("true");
}
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -65,7 +80,8 @@ public class ProductionVsBudgetReportServlet extends HttpServlet ...@@ -65,7 +80,8 @@ public class ProductionVsBudgetReportServlet extends HttpServlet
} }
finally finally
{ {
bean=null;
userID="";
} }
} }
......
package ibase.dashboard.mfg.ejb; package ibase.dashboard.mfg.ejb;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.utility.EMail;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import ibase.utility.EMail;
import java.awt.Color; import java.awt.Color;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.MalformedURLException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -21,10 +19,18 @@ import java.util.HashMap; ...@@ -21,10 +19,18 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.processing.FilerException;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*; import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
/** /**
* Session Bean implementation class ProductionVsBudgetReport * Session Bean implementation class ProductionVsBudgetReport
...@@ -569,7 +575,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -569,7 +575,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
//end Role validation //end Role validation
//start method for PDF generate //start method for PDF generate
public void generatePDF(HashMap<String, List<String>> hashMap, String exportPDFPath, String exportImagePath, String preyearMonth, String rptTitle,String userID) throws RemoteException, ITMException public String generatePDF(HashMap<String, List<String>> hashMap, String exportPDFPath, String exportImagePath, String preyearMonth, String rptTitle,String userID) throws RemoteException, ITMException
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
...@@ -589,14 +595,22 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -589,14 +595,22 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
File existImgFile =null; File existImgFile =null;
int seconds =0; int seconds =0;
String pdfFileName =null; String pdfFileName =null;
String toMailId ="";
String ccMailId ="";
String bccAddress ="";
String subject ="";
String userWiseBodytext="";
String resultFlage ="false";
System.out.print("Call for PDF created"); System.out.print("Call for PDF created");
try try
{ {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy");
Calendar calendar = Calendar.getInstance();
String currDate = simpleDateFormat.format(calendar.getTime());
System.out.println("Current date is="+currDate);
document = new Document(); document = new Document();
seconds = (int) (System.currentTimeMillis() / 1000) % 60 ; seconds = (int) (System.currentTimeMillis() / 1000) % 60 ;
pdfFileName = exportPDFPath+"ProductionVsBudget-"+userID+"-"+seconds+".pdf"; pdfFileName = exportPDFPath+"ProductionVsBudgetReport-"+userID+"-"+currDate+".pdf";
file = new FileOutputStream(new File(pdfFileName)); file = new FileOutputStream(new File(pdfFileName));
writer = PdfWriter.getInstance(document, file); writer = PdfWriter.getInstance(document, file);
document.open(); document.open();
...@@ -607,6 +621,8 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -607,6 +621,8 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
preface.add(new Paragraph(" ")); preface.add(new Paragraph(" "));
document.add(preface); document.add(preface);
System.out.println(" size of HashMap is="+hashMap.size());
ArrayList<String> keyList=new ArrayList<String>(); ArrayList<String> keyList=new ArrayList<String>();
ArrayList<List<String>> valueList=new ArrayList<List<String>>(); ArrayList<List<String>> valueList=new ArrayList<List<String>>();
...@@ -659,9 +675,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -659,9 +675,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
System.out.println("Image Deleted after status *******"+imgFilePath ); System.out.println("Image Deleted after status *******"+imgFilePath );
} }
image.scaleAbsolute(320f, 250f);// image width,height image.scaleAbsolute(320f, 250f);// image width,height
image.setAlignment(5); image.setAlignment(5);
...@@ -738,11 +752,8 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -738,11 +752,8 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
cell = new PdfPCell(new Paragraph(gridDataList.get(6),font)); cell = new PdfPCell(new Paragraph(gridDataList.get(6),font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW); cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell); table.addCell(cell);
childtable.addCell(table);
childtable.addCell(table);
cell = new PdfPCell(childtable); cell = new PdfPCell(childtable);
cell.setBorder(Rectangle.NO_BORDER); cell.setBorder(Rectangle.NO_BORDER);
parentTable.addCell(cell); parentTable.addCell(cell);
...@@ -766,24 +777,22 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -766,24 +777,22 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
} }
document.close(); document.close();
file.close(); file.close();
System.out.println("PDF Created succesfully");
System.out.println("System goes to connected database table:users");
System.out.println("PDF Created succesfully");
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
connDriver =null; connDriver =null;
String toMailId =""; toMailId ="";
String ccMailId =""; ccMailId ="";
String bccAddress =""; bccAddress ="";
String subject ="Regarding:ProductionVsBudgetReport as PDF "; subject ="Production Vs Budget Report-PDF ";
String userWiseBodytext = "Plase find attachment of Production Vs BudgetReport PDF"; userWiseBodytext ="Dear Sir, Please find attached herewith is the Production Vs Budget Report in PDF format.";
String sql = "select name,user_type,email_id FROM users WHERE code='"+userID+"'"; String sql = "select name,user_type,email_id FROM users WHERE code='"+userID+"'";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
toMailId = checkNull(rs.getString("email_id")); toMailId = checkNull(rs.getString("email_id"));
System.out.println("EMAIL ID from table :users=="+toMailId); System.out.println("No of Users ="+userID +"AND According to Email ID======="+toMailId);
} }
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
...@@ -805,12 +814,9 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -805,12 +814,9 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
mailInfo.add(userWiseBodytext); mailInfo.add(userWiseBodytext);
mailInfo.add(attachFile.getPath()); mailInfo.add(attachFile.getPath());
this.sendingMail(mailInfo); this.sendingMail(mailInfo);
resultFlage="true";
} }
System.out.println("*********** Pdf and sending mail done succesfully (Final)**************");
System.out.println("All Activity have been completed(PDF,Mail Sending) :Thanks you");
} catch (Exception e) } catch (Exception e)
{ {
System.out.println("Exception :ProductionVsBudgetReport :generatePDF(HashMap<String, List<String>>,String,String,String,String"+e.getMessage()); System.out.println("Exception :ProductionVsBudgetReport :generatePDF(HashMap<String, List<String>>,String,String,String,String"+e.getMessage());
...@@ -831,6 +837,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -831,6 +837,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
} }
} }
return resultFlage;
} }
//end method for PDF generate //end method for PDF generate
...@@ -851,12 +858,11 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -851,12 +858,11 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
commInfo.append("</ROOT>"); commInfo.append("</ROOT>");
EMail email = new EMail(); EMail email = new EMail();
try try
{ {
System.out.println(" calling sendMail method()"); System.out.println(" calling sendMail method()");
email.sendMail(commInfo.toString(), "ITM", null); email.sendMail(commInfo.toString(), "ITM", null);
System.out.println(" Email send succesfully ***********"); System.out.println(" ********Email send succesfully ***********");
} catch (Exception e) } catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
...@@ -865,5 +871,4 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -865,5 +871,4 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
email = null; email = null;
} }
//End method for sending mail******* //End method for sending mail*******
} }
\ No newline at end of file
...@@ -15,6 +15,6 @@ public interface ProductionVsBudgetReportLocal extends ValidatorLocal{ ...@@ -15,6 +15,6 @@ public interface ProductionVsBudgetReportLocal extends ValidatorLocal{
public String getGeoLoCodeXmlData() throws RemoteException, ITMException; public String getGeoLoCodeXmlData() throws RemoteException, ITMException;
public String getUnitFormXmlData() throws RemoteException, ITMException; public String getUnitFormXmlData() throws RemoteException, ITMException;
public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException; public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException;
public void generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException; public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException;
} }
...@@ -16,6 +16,6 @@ public interface ProductionVsBudgetReportRemote extends ValidatorRemote ...@@ -16,6 +16,6 @@ public interface ProductionVsBudgetReportRemote extends ValidatorRemote
public String getGeoLoCodeXmlData() throws RemoteException, ITMException; public String getGeoLoCodeXmlData() throws RemoteException, ITMException;
public String getUnitFormXmlData() throws RemoteException, ITMException; public String getUnitFormXmlData() throws RemoteException, ITMException;
public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException; public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException;
public void generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException; public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException;
} }
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