1    package com.instantbank.collections.creditInfo.web;
2    
3    import java.io.IOException;
4    import javax.servlet.RequestDispatcher;
5    import javax.servlet.ServletConfig;
6    import javax.servlet.ServletContext;
7    import javax.servlet.ServletException;
8    import javax.servlet.http.HttpServlet;
9    import javax.servlet.http.HttpServletRequest;
10   import javax.servlet.http.HttpServletResponse;
11   import javax.servlet.http.HttpSession;
12   import com.instantbank.collections.creditInfo.ejb.CreditInfoServices;
13   import com.instantbank.collections.creditInfo.ejb.CreditInfoServicesHome;
14   import com.instantbank.collections.util.FilterChain;
15   import com.instantbank.collections.util.InstantbankException;
16   import com.instantbank.collections.util.ServiceLocator;
17   
18   
19   public class SetUpStatusController extends HttpServlet {
20     CreditInfoServices creditInfoServices;
21     CreditInfoServicesHome chome;
22     HttpSession session;
23   
24   
25     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
26       this.doPost(request, response);
27     }
28   
29   
30     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
31       String action = "";
32       com.instantbank.collections.util.FilterChain chain;
33       try {
34         action = request.getParameter("action");
35         session = request.getSession(false);
36         session.setAttribute("hasException", "0");
37         try {
38           chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
39           if(chain.processFilter(request, response)) {
40             return;
41           }
42           if(action.equals("initialize")) {
43             initialize(request, response);
44           }
45           else if(action.equals("save")) {
46             save(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 String getServletInfo() {
68       return "com.instantbank.collections.creditInfo.web.SetUpStatusController Information";
69     }
70   
71   
72     public void init(ServletConfig config) throws ServletException {
73       try {
74         super.init(config);
75         chome = (CreditInfoServicesHome)ServiceLocator.instance().createEJB("CreditInfoServicesHome", CreditInfoServicesHome.class, false);
76         creditInfoServices = chome.create();
77       }
78       catch(Exception e) {
79         throw new ServletException(e);
80       }
81     }
82   
83   
84     private void initialize(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
85       Long companyId;
86       String data;
87       ServletContext sctx = getServletConfig().getServletContext();
88   
89       companyId = (Long)session.getAttribute("companyId");
90       data = creditInfoServices.getStatusCategoriesValues(companyId);
91       request.setAttribute("data", data);
92       RequestDispatcher rd = sctx.getRequestDispatcher("/creditInfo_web/StatusCategoriesView.jsp");
93       rd.forward(request, response);
94     }
95   
96   
97     private void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
98       Long companyId;
99       String data;
100      Long userId;
101  
102      data = request.getParameter("data");
103      companyId = (Long)session.getAttribute("companyId");
104      userId = (Long)session.getAttribute("userId");
105      creditInfoServices.saveStatusCategoriesValues(data, companyId, userId);
106      initialize(request, response);
107    }
108  }
109  
110