1 package com.instantbank.collections.customerInfo.web;
2
3 import javax.servlet.RequestDispatcher;
4 import javax.servlet.ServletConfig;
5 import javax.servlet.ServletContext;
6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10 import javax.servlet.http.HttpSession;
11 import java.io.IOException;
12 import com.instantbank.collections.customerInfo.ejb.CustomerInfoServices;
13 import com.instantbank.collections.customerInfo.ejb.CustomerInfoServicesHome;
14 import com.instantbank.collections.util.FilterChain;
15 import com.instantbank.collections.util.InstantbankException;
16 import com.instantbank.collections.util.ServiceLocator;
17
18 public class CustomerStatusesMaintenanceController extends HttpServlet {
19 private CustomerInfoServices services;
20 private HttpSession session;
21 private Long userId;
22 private Long companyId;
23
24
25 public void init(ServletConfig config) throws ServletException {
26 super.init(config);
27 try {
28 CustomerInfoServicesHome home = (CustomerInfoServicesHome)
29 ServiceLocator.instance().createEJB("CustomerInfoServicesHome", CustomerInfoServicesHome.class, false);
30 services = home.create();
31 }
32 catch(Exception e) {
33 throw new ServletException(e);
34 }
35 }
36
37
38 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
39 doPost(request, response);
40 }
41
42
43 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
44 String action;
45 com.instantbank.collections.util.FilterChain chain;
46
47 try {
48 action = request.getParameter("action");
49 session = request.getSession(false);
50 session.setAttribute("hasException", "0");
51 try {
52 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
53 if(chain.processFilter(request, response)) {
54 return;
55 }
56 if(action.equals("initialize")) {
57 initialize(request, response);
58 }
59 else if(action.equals("save")) {
60 save(request, response);
61 }
62 else {
63 throw new InstantbankException("232001", "Action " + action + " not supported");
64 }
65 }
66 catch(Exception e) {
67 throw new InstantbankException(e, "232002", "Failed to execute controller action " + action);
68 }
69 }
70 catch(InstantbankException e) {
71 session.setAttribute("hasException", "1");
72 session.setAttribute("Exception", e);
73 if(response.isCommitted()) {
74 return;
75 }
76 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
77 }
78 }
79
80
81 public String getServletInfo() {
82 return "com.instantbank.collections.customerInfo.web.CustomerStatusesMaintenanceController Information";
83 }
84
85
86 private void initialize(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, ServletException {
87 String xml = null;
88 companyId = (Long)session.getAttribute("companyId");
89 xml = services.getCustomerStatuses(companyId);
90 ServletContext sc = getServletConfig().getServletContext();
91 request.setAttribute("title", "Customer Statuses Maintenance");
92 request.setAttribute("data", xml);
93 RequestDispatcher rd = sc.getRequestDispatcher("/customerInfo_web/CustomerStatusesView.jsp");
94 rd.forward(request, response);
95 }
96
97
98 private void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
99 String xml;
100
101 userId = (Long)session.getAttribute("userId");
102 companyId = (Long)session.getAttribute("companyId");
103 xml = request.getParameter("data");
104 services.saveCustomerStatuses(companyId, userId, xml);
105 initialize(request, response);
106 }
107 }
108