1    package com.instantbank.collections.collectionsQueuing.web;
2    
3    import java.io.IOException;
4    import javax.ejb.FinderException;
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.collectionsQueuing.ejb.CollectionsQueuingServices;
14   import com.instantbank.collections.collectionsQueuing.ejb.CollectionsQueuingServicesHome;
15   import com.instantbank.collections.commonQueuing.ejb.QueueServices;
16   import com.instantbank.collections.commonQueuing.ejb.QueueServicesHome;
17   import com.instantbank.collections.util.FilterChain;
18   import com.instantbank.collections.util.InstantbankException;
19   import com.instantbank.collections.util.ServiceLocator;
20   
21   public class SetUpStopperQueueController extends HttpServlet {
22     private String debug = "";
23     private QueueServices queueServices;
24     private CollectionsQueuingServices services;
25     private HttpSession session;
26   
27   
28     public void init(ServletConfig config) throws ServletException {
29       super.init(config);
30       try {
31         CollectionsQueuingServicesHome home = (CollectionsQueuingServicesHome)ServiceLocator.instance().createEJB("CollectionsQueuingServicesHome", CollectionsQueuingServicesHome.class, false);
32         services = home.create();
33         QueueServicesHome qsHome = (QueueServicesHome)ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, false);
34         queueServices = qsHome.create();
35       }
36       catch(Exception e) {
37       }
38     }
39   
40   
41     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
42       doPost(request, response);
43     }
44   
45   
46     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
47       String action = "";
48       com.instantbank.collections.util.FilterChain chain;
49   
50       try {
51         action = request.getParameter("action");
52         session = request.getSession(false);
53         session.setAttribute("hasException", "0");
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             saveQueue(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 + " (" + debug + ")");
71         }
72       }
73       catch(InstantbankException e) {
74         session.setAttribute("hasException", "1");
75         session.setAttribute("Exception", e);
76         if(response.isCommitted()) {
77           return;
78         }
79         response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
80       }
81     }
82   
83   
84     private void initialize(HttpServletRequest request, HttpServletResponse response) throws ServletException, InstantbankException, IOException, FinderException {
85       Long companyId;
86       Long queue;
87       String xml = null;
88   
89       companyId = (Long)session.getAttribute("companyId");
90       xml = services.getStopperQueue(companyId);
91       request.setAttribute("data", xml);
92       ServletContext sc = getServletConfig().getServletContext();
93       RequestDispatcher rd = sc.getRequestDispatcher("/collectionsQueuing_web/StopperQueueView.jsp?useCase=SetUpStopperQueue");
94       rd.forward(request, response);
95     }
96   
97   
98     public void saveQueue(HttpServletRequest request, HttpServletResponse response) throws ServletException, InstantbankException, IOException, FinderException {
99       Long companyId = (Long)session.getAttribute("companyId");
100      String data = request.getParameter("data");
101      Long queueId = new Long(0);
102      Long userId = (Long)session.getAttribute("userId");
103      String xml = "";
104  
105      try {
106        queueId = queueServices.saveQueue(companyId, userId, data);
107        xml = queueServices.getQueue(queueId, companyId);
108        request.setAttribute("data", xml);
109      }
110      catch(Exception e) {
111        session.setAttribute("hasException", "1");
112        session.setAttribute("Exception", e);
113        request.setAttribute("data", data);
114      }
115      finally {
116        ServletContext sc = getServletConfig().getServletContext();
117        RequestDispatcher rd = sc.getRequestDispatcher("/collectionsQueuing_web/StopperQueueView.jsp?useCase=SetUpStopperQueue&title=Set Up Stopper Queues");
118        request.setAttribute("Reset", "SetUpStopperQueueController?action=initialize");
119        rd.forward(request, response);
120      }
121    }
122  
123  
124    public String getServletInfo() {
125      return "com.instantbank.collections.collectionsQueuing.web.SetUpStopperQueueController Information";
126    }
127  }
128  
129