1    package com.instantbank.collections.collectionsActivities.web;
2    
3    import java.io.IOException;
4    import java.io.PrintWriter;
5    import javax.servlet.RequestDispatcher;
6    import javax.servlet.ServletConfig;
7    import javax.servlet.ServletContext;
8    import javax.servlet.ServletException;
9    import javax.servlet.http.HttpServlet;
10   import javax.servlet.http.HttpServletRequest;
11   import javax.servlet.http.HttpServletResponse;
12   import javax.servlet.http.HttpSession;
13   import com.instantbank.collections.creditInfo.ejb.AccountInfoServices;
14   import com.instantbank.collections.creditInfo.ejb.AccountInfoServicesHome;
15   import com.instantbank.collections.util.FilterChain;
16   import com.instantbank.collections.util.InstantbankException;
17   import com.instantbank.collections.util.ServiceLocator;
18   
19   public class ReviewAccountController extends HttpServlet {
20     AccountInfoServices accountInfoServices;
21     private PrintWriter out;
22     private HttpSession session;
23   
24   
25     public void init(ServletConfig config) throws ServletException {
26       try {
27         super.init(config);
28         AccountInfoServicesHome ahome = (AccountInfoServicesHome)ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
29         accountInfoServices = ahome.create();
30       }
31       catch(Exception e) {
32       }
33     }
34   
35   
36     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
37       this.doPost(request, response);
38     }
39   
40   
41     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
42       String action = "";
43       com.instantbank.collections.util.FilterChain chain;
44   
45       try {
46         action = request.getParameter("action");
47         session = request.getSession(false);
48         session.setAttribute("hasException", "0");
49         try {
50           chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
51           if(chain.processFilter(request, response)) {
52             return;
53           }
54           if(action.equals("initialize")) {
55             initialize(request, response);
56           }
57           else if(action.equals("changeTab")) {
58             changeTab(request, response);
59           }
60           else if(action.equals("getAccount")) {
61             getAccount(request, response);
62           }
63           else {
64             throw new InstantbankException("522006", "Action " + action + " not supported");
65           }
66         }
67         catch(Exception e) {
68           throw new InstantbankException(e, "522001", "Failed to execute controller action " + action);
69         }
70       }
71       catch(InstantbankException e) {
72         session.setAttribute("hasException", "1");
73         session.setAttribute("Exception", e);
74         if(response.isCommitted()) {
75           return;
76         }
77         response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
78       }
79     }
80   
81   
82     private void changeTab(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, ServletException, Exception {
83       if(request.getParameter("tab").equals("CurrentQueues")) {
84         try {
85           Long agrmId = new Long(request.getParameter("agrmId"));
86           request.setAttribute("objectId", agrmId);
87         }
88         catch(Exception e) {
89           throw e;
90         }
91       }
92       ServletContext sctx = getServletConfig().getServletContext();
93       RequestDispatcher rd = sctx.getRequestDispatcher("/collectionsActivities_web/ReviewAccountView.jsp");
94       rd.forward(request, response);
95     }
96   
97   
98     private void getAccount(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, ServletException {
99       Long agrmCode;
100      Long agrmId;
101      Long companyId;
102      ServletContext sctx = getServletConfig().getServletContext();
103  
104      companyId = (Long)session.getAttribute("companyId");
105      agrmCode = new Long(request.getParameter("accountNumber"));
106      agrmId = accountInfoServices.getAgreementId(companyId, agrmCode);
107      request.setAttribute("wrki_id", new Long("0"));
108      RequestDispatcher rd = sctx.getRequestDispatcher("/collectionsActivities_web/ReviewAccountView.jsp?mainData=&tab=Details&agrmId=" + agrmId.toString());
109      rd.forward(request, response);
110    }
111  
112  
113    private void initialize(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, ServletException {
114      Long agrmId;
115      String tab;
116      String status;
117      Long firstWorkId;
118      String from;
119      ServletContext sctx = getServletConfig().getServletContext();
120  
121      agrmId = (Long)(request.getAttribute("agrmId"));
122      tab = (String)(request.getAttribute("tab"));
123      status = (String)(request.getAttribute("status"));
124      if(status != null) {
125        session.setAttribute("NextWrkiStatus", status);
126        firstWorkId = (Long)(request.getAttribute("wrki_id"));
127        session.setAttribute("firstWI", firstWorkId);
128      }
129  
130      if(tab == null) {
131        tab = "Details";
132      }
133      RequestDispatcher rd = sctx.getRequestDispatcher("/collectionsActivities_web/ReviewAccountView.jsp?mainData=&tab=" + tab + "&agrmId=" + agrmId.toString());
134      rd.forward(request, response);
135    }
136  
137  
138    public String getServletInfo() {
139      return "com.instantbank.collectionsActions.web.AccountDetailsController Information";
140    }
141  }
142  
143