1 package com.instantbank.collections.basicInfo.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.basicInfo.ejb.BasicInfoServices;
13 import com.instantbank.collections.basicInfo.ejb.BasicInfoServicesHome;
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 CustomerRolesMaintenanceController extends HttpServlet {
19 private String debug;
20 private BasicInfoServices services;
21 private HttpSession session;
22 private Long userId;
23
24
25 public void init(ServletConfig config) throws ServletException {
26 super.init(config);
27 try {
28 BasicInfoServicesHome home = (BasicInfoServicesHome)
29 ServiceLocator.instance().createEJB("BasicInfoServicesHome", BasicInfoServicesHome.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
39 ServletException, IOException {
40 doPost(request, response);
41 }
42
43
44 public void doPost(HttpServletRequest request, HttpServletResponse response) throws
45 ServletException, IOException {
46 String action;
47 com.instantbank.collections.util.FilterChain chain;
48
49 try {
50 action = request.getParameter("action");
51 session = request.getSession(false);
52 try {
53
54 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
55 if(chain.processFilter(request, response)) {
56 return;
57 }
58 if(action.equals("initialize")) {
59 initialize(request, response);
60 }
61 else if(action.equals("save")) {
62 save(request, response);
63 }
64 else {
65 throw new InstantbankException("112001", "Action " + action + " not supported");
66 }
67 }
68 catch(Exception e) {
69 throw new InstantbankException(e, "112002", "Failed to execute controller action " + action);
70 }
71 }
72 catch(InstantbankException e) {
73 session.setAttribute("Exception", e);
74 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
75 }
76 }
77
78
79 public String getServletInfo() {
80 return "com.instantbank.collections.basicInfo.web.CustomerRolesMaintenanceController Information";
81 }
82
83
84 private void initialize(HttpServletRequest request, HttpServletResponse response) throws
85 ServletException, IOException, InstantbankException {
86
87 String xml;
88
89 xml = services.getCustomerRoles();
90 ServletContext sc = getServletConfig().getServletContext();
91 request.setAttribute("title", "Customer Roles Maintenance");
92 request.setAttribute("data", xml);
93 RequestDispatcher rd = sc.getRequestDispatcher("/basicInfo_web/CustomerRolesView.jsp");
94 rd.forward(request, response);
95 }
96
97
98 private void save(HttpServletRequest request, HttpServletResponse response) throws
99 ServletException, IOException, InstantbankException {
100
101 String xml;
102
103 userId = (Long)session.getAttribute("userId");
104 xml = request.getParameter("data");
105 services.saveCustomerRoles(userId, xml);
106 initialize(request, response);
107 }
108 }
109