1    package com.instantbank.collections.creditInfo.web;
2    
3    import java.io.IOException;
4    import java.io.OutputStreamWriter;
5    import java.io.PrintWriter;
6    import javax.servlet.RequestDispatcher;
7    import javax.servlet.ServletConfig;
8    import javax.servlet.ServletContext;
9    import javax.servlet.ServletException;
10   import javax.servlet.http.HttpServlet;
11   import javax.servlet.http.HttpServletRequest;
12   import javax.servlet.http.HttpServletResponse;
13   import javax.servlet.http.HttpSession;
14   import com.instantbank.collections.creditInfo.ejb.AccountInfoServices;
15   import com.instantbank.collections.creditInfo.ejb.AccountInfoServicesHome;
16   import com.instantbank.collections.util.FilterChain;
17   import com.instantbank.collections.util.InstantbankException;
18   import com.instantbank.collections.util.ServiceLocator;
19   import com.instantbank.collections.util.StringFormat;
20   
21   public class AccountDetailsContController extends HttpServlet {
22     AccountInfoServices accountInfoServices;
23     AccountInfoServicesHome ahome;
24     PrintWriter out;
25     HttpSession session;
26   
27   
28     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
29       this.doPost(request, response);
30     }
31   
32   
33     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
34       String action = "";
35       com.instantbank.collections.util.FilterChain chain;
36       try {
37         action = request.getParameter("action");
38         session = request.getSession(false);
39         session.setAttribute("hasException", "0");
40         try {
41           chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
42           if(chain.processFilter(request, response)) {
43             return;
44           }
45           if(action.equals("initialize")) {
46             initialize(request, response);
47           }
48           else {
49             throw new InstantbankException("242001", "Action " + action + " not supported");
50           }
51         }
52         catch(Exception e) {
53           throw new InstantbankException(e, "242002", "Failed to execute controller action " + action);
54         }
55       }
56       catch(InstantbankException e) {
57         session.setAttribute("hasException", "1");
58         session.setAttribute("Exception", e);
59         if(response.isCommitted()) {
60           return;
61         }
62         response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
63       }
64     }
65   
66   
67     public void init(ServletConfig config) throws ServletException {
68       try {
69         super.init(config);
70         ahome = (AccountInfoServicesHome)ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
71         accountInfoServices = ahome.create();
72       }
73       catch(Exception e) {
74         throw new ServletException(e);
75       }
76     }
77   
78   
79     private void initialize(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, ServletException {
80       String agrmDetailsCont;
81       Long agrmId = null;
82       Long agrmCode;
83       String collateral;
84       Long companyId;
85       String data;
86       String fromQueuing = "N";
87       String outXmlString = "";
88       String primary;
89       ServletContext sctx = getServletConfig().getServletContext();
90       String status;
91   
92       try {
93   
94         agrmId = (Long)request.getAttribute("agrmId");
95         companyId = (Long)session.getAttribute("companyId");
96         fromQueuing = request.getParameter("fromQueuing");
97         primary = StringFormat.cleanXml(accountInfoServices.getPrimaryCustomer(companyId, agrmId));
98         collateral = StringFormat.cleanXml(accountInfoServices.getCollateralInfo(companyId, agrmId));
99         agrmDetailsCont = StringFormat.cleanXml(accountInfoServices.getAgreementDetailsCont(companyId, agrmId));
100        status = StringFormat.cleanXml(accountInfoServices.getStatusValues(companyId, agrmId));
101        outXmlString = "<?xml version=\"1.0\" encoding=\"ISO8859-1\"?><AccountDetailsCont>" + primary + collateral + agrmDetailsCont + status + "</AccountDetailsCont>";
102        request.setAttribute("data", outXmlString);
103        RequestDispatcher rd = sctx.getRequestDispatcher("/creditInfo_web/AccountDetailsContView.jsp");
104        rd.forward(request, response);
105      }
106      catch(Exception e) {
107        response.setContentType("text/html");
108        OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
109        PrintWriter out = new PrintWriter(osw);
110        out.println("<html>");
111        out.println("<head><title>Accounts no found</title></head>");
112        out.println("<body>");
113        out.println("<H2>Account number not found.</H2>");
114        out.println("</body></html>");
115        out.println("<script>");
116        out.println("/*");
117        e.printStackTrace(out);
118        out.println("*/");
119        out.println("</script>");
120        out.close();
121      }
122    }
123  }
124  
125