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 AccommodationStatusesMaintenanceController 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
41 doPost(request, response);
42 }
43
44
45 public void doPost(HttpServletRequest request, HttpServletResponse response) throws
46 ServletException, IOException {
47 com.instantbank.collections.util.FilterChain chain;
48 String action;
49
50 try {
51 session = request.getSession(false);
52 action = request.getParameter("action");
53
54 try {
55 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
56 if(chain.processFilter(request, response)) {
57 return;
58 }
59 if(action.equals("initialize")) {
60 initialize(request, response);
61 }
62 else if(action.equals("save")) {
63 save(request, response);
64 }
65 else {
66 throw new InstantbankException("112001", "Action " + action + " not supported");
67 }
68 }
69 catch(Exception e) {
70 throw new InstantbankException(e, "112002", "Failed to execute controller action " + action);
71 }
72 }
73 catch(InstantbankException e) {
74 session.setAttribute("Exception", e);
75 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
76 }
77 }
78
79
80 public String getServletInfo() {
81 return "com.instantbank.collections.basicInfo.web.AccomodationStatusesMaintenanceController Information";
82 }
83
84
85 private void initialize(HttpServletRequest request, HttpServletResponse response) throws
86 ServletException, IOException, InstantbankException {
87
88 String xml;
89
90 xml = services.getAccommodationStatuses();
91 ServletContext sc = getServletConfig().getServletContext();
92 request.setAttribute("title", "Accomodation Statuses Maintenance");
93 request.setAttribute("data", xml);
94 RequestDispatcher rd = sc.getRequestDispatcher("/basicInfo_web/AccommodationStatusesView.jsp");
95 rd.forward(request, response);
96 }
97
98
99 private void save(HttpServletRequest request, HttpServletResponse response) throws
100 ServletException, IOException, InstantbankException {
101 String xml;
102
103 userId = (Long)session.getAttribute("userId");
104 xml = request.getParameter("data");
105 services.saveAccommodationStatuses(userId, xml);
106 initialize(request, response);
107 }
108 }
109
110