1    package com.instantbank.collections.commonQueuing.web;
2    
3    import java.io.IOException;
4    import java.rmi.RemoteException;
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.commonQueuing.ejb.QueueServices;
14   import com.instantbank.collections.commonQueuing.ejb.QueueServicesHome;
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 SetUpQueueTypesController extends HttpServlet {
20     private String debug = "";
21     private QueueServices services;
22     private HttpSession session;
23   
24   
25     public void init(ServletConfig config) throws ServletException {
26       super.init(config);
27       try {
28         QueueServicesHome home = (QueueServicesHome)ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, false);
29         services = home.create();
30       }
31       catch(Exception e) {
32       }
33     }
34   
35   
36     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
37       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       String objectType = "";
45   
46       try {
47         action = request.getParameter("action");
48         objectType = request.getParameter("objectType");
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         }
57         catch(Exception ne) {
58           session.setAttribute("hasException", "1");
59           session.setAttribute("Exception", ne);
60           response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
61           return;
62         }
63         try {
64           if(action.equals("initialize")) {
65             initialize(request, response);
66           }
67           else if(action.equals("save")) {
68             save(request, response);
69           }
70           else {
71             throw new InstantbankException("112001", "Action " + action + " not supported");
72           }
73         }
74         catch(Exception e) {
75           throw new InstantbankException(e, "112002", "Failed to execute controller action " + action + " (" + debug + ")");
76         }
77       }
78       catch(InstantbankException e) {
79         session.setAttribute("hasException", "1");
80         session.setAttribute("Exception", e);
81         try {
82           request.setAttribute("Reset", "SetUpQueueTypesController?action=initialize&objectType=" + objectType + "¤tTab=1");
83           initialize(request, response);
84         }
85         catch(Exception ne) {
86           response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
87         }
88       }
89     }
90   
91   
92     public String getServletInfo() {
93       return "com.instantbank.collections.commonQueuing.web.SetUpQueueTypesController Information";
94     }
95   
96   
97     private void initialize(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, RemoteException, ServletException {
98       Long companyId;
99       Integer currentTab;
100      String data = null;
101      String objectType;
102  
103      currentTab = new Integer(request.getParameter("currentTab"));
104      companyId = (Long)session.getAttribute("companyId");
105      objectType = (String)request.getParameter("objectType");
106      data = services.getQueueTypes(companyId, objectType);
107      ServletContext sc = getServletConfig().getServletContext();
108      request.setAttribute("data", data);
109      RequestDispatcher rd = sc.getRequestDispatcher("/commonQueuing_web/SetUpQueueTypesView.jsp?useCase=SetUpQueueTypes¤tTab=" + currentTab + "&title=Set Up Queue Types");
110      rd.forward(request, response);
111    }
112  
113  
114    private void save(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, RemoteException, ServletException {
115      Long userId;
116      String xml;
117  
118      Long companyId = (Long)session.getAttribute("companyId");
119      userId = (Long)session.getAttribute("userId");
120      xml = request.getParameter("data");
121      services.saveQueueTypes(companyId, userId, xml);
122      initialize(request, response);
123    }
124  }
125  
126