1 package com.instantbank.collections.collectionsQueuing.web;
2
3 import java.io.IOException;
4 import java.util.Enumeration;
5 import javax.ejb.FinderException;
6 import javax.servlet.RequestDispatcher;
7 import javax.servlet.ServletConfig;
8 import javax.servlet.ServletContext;
9 import javax.servlet.ServletException;
10 import javax.servlet.http.HttpServlet;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13 import javax.servlet.http.HttpSession;
14 import com.instantbank.collections.collectionsQueuing.ejb.CollectionsQueuingServices;
15 import com.instantbank.collections.collectionsQueuing.ejb.CollectionsQueuingServicesHome;
16 import com.instantbank.collections.util.FilterChain;
17 import com.instantbank.collections.util.InstantbankException;
18 import com.instantbank.collections.util.ServiceLocator;
19
20 public class CollectionsQueuingController extends HttpServlet {
21 private String debug = "";
22 private CollectionsQueuingServices services;
23 private HttpSession session;
24
25
26 public void init(ServletConfig config) throws ServletException {
27 super.init(config);
28 try {
29 CollectionsQueuingServicesHome home = (CollectionsQueuingServicesHome)ServiceLocator.instance().createEJB("CollectionsQueuingServicesHome", CollectionsQueuingServicesHome.class, false);
30 services = home.create();
31 }
32 catch(Exception e) {
33 throw new ServletException(e);
34 }
35 }
36
37
38 private void distribute(HttpServletRequest request, HttpServletResponse response) throws ServletException, InstantbankException, IOException, FinderException {
39 Long companyId;
40 Long queue;
41 String xml = null;
42
43 companyId = (Long)session.getAttribute("companyId");
44 queue = new Long(request.getParameter("queueId"));
45 xml = services.distributeWork(queue, companyId);
46 request.setAttribute("data", xml);
47 ServletContext sc = getServletConfig().getServletContext();
48 RequestDispatcher rd = sc.getRequestDispatcher("/collectionsQueuing_web/DistributeWorkView.jsp?title=Distribute Work Result");
49 rd.forward(request, response);
50 }
51
52
53 private void distributeDownload(HttpServletRequest request, HttpServletResponse response) throws ServletException, InstantbankException, IOException, FinderException {
54 Long companyId;
55 Long downloadId;
56 String xml = null;
57
58 companyId = (Long)session.getAttribute("companyId");
59 downloadId = new Long(request.getParameter("downloadId"));
60 xml = services.distributeDownload(downloadId, companyId);
61 request.setAttribute("data", xml);
62 ServletContext sc = getServletConfig().getServletContext();
63 RequestDispatcher rd = sc.getRequestDispatcher("/collectionsQueuing_web/DistributeDownloadView.jsp?title=Distribute Download Result");
64 rd.forward(request, response);
65 }
66
67
68 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
69 doPost(request, response);
70 }
71
72
73 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
74 String action = "";
75 com.instantbank.collections.util.FilterChain chain;
76
77 try {
78 action = request.getParameter("action");
79 session = request.getSession(false);
80 session.setAttribute("hasException", "0");
81 try {
82 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
83 if(chain.processFilter(request, response)) {
84 return;
85 }
86 if(action.equals("preview")) {
87 preview(request, response);
88 }
89 else if(action.equals("searchPreview")) {
90 searchPreview(request, response);
91 }
92 else if(action.equals("generate")) {
93 generate(request, response);
94 }
95 else if(action.equals("distribute")) {
96 distribute(request, response);
97 }
98 else if(action.equals("previewDownload")) {
99 previewDownload(request, response);
100 }
101 else if(action.equals("generateDownload")) {
102 generateDownload(request, response);
103 }
104 else if(action.equals("distributeDownload")) {
105 distributeDownload(request, response);
106 }
107 else {
108 throw new InstantbankException("112001", "Action " + action + " not supported");
109 }
110 }
111 catch(Exception e) {
112 throw new InstantbankException(e, "112002", "Failed to execute controller action " + action + " (" + debug + ")");
113 }
114 }
115 catch(InstantbankException e) {
116 session.setAttribute("hasException", "1");
117 session.setAttribute("Exception", e);
118 if(response.isCommitted()) {
119 return;
120 }
121 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
122 }
123 }
124
125
126 private void generate(HttpServletRequest request, HttpServletResponse response) throws ServletException, InstantbankException, IOException, FinderException {
127 Long companyId;
128 Long queue;
129 String xml = null;
130
131 companyId = (Long)session.getAttribute("companyId");
132 queue = new Long(request.getParameter("queueId"));
133 xml = services.generateWork(queue, companyId);
134 request.setAttribute("data", xml);
135 ServletContext sc = getServletConfig().getServletContext();
136 RequestDispatcher rd = sc.getRequestDispatcher("/collectionsQueuing_web/GenerateWorkView.jsp?title=Generate Work Result");
137 rd.forward(request, response);
138 }
139
140
141 private void generateDownload(HttpServletRequest request, HttpServletResponse response) throws ServletException, InstantbankException, IOException, FinderException {
142 Long companyId;
143 Long downloadId;
144 String xml = null;
145
146 companyId = (Long)session.getAttribute("companyId");
147 downloadId = new Long(request.getParameter("downloadId"));
148 xml = services.generateDownload(downloadId, companyId);
149 request.setAttribute("data", xml);
150 ServletContext sc = getServletConfig().getServletContext();
151 RequestDispatcher rd = sc.getRequestDispatcher("/collectionsQueuing_web/GenerateDownloadView.jsp?title=Generate Download Result");
152 rd.forward(request, response);
153 }
154
155
156 private void preview(HttpServletRequest request, HttpServletResponse response) throws ServletException, InstantbankException, IOException, FinderException {
157 Long companyId;
158 Long queue;
159 Long maxRows;
160 Boolean isAttr = new Boolean(false);
161 String attr = "";
162
163 Enumeration AttributeNames = request.getAttributeNames();
164 while(AttributeNames.hasMoreElements()) {
165 attr = (String)AttributeNames.nextElement();
166 if(attr.equals("maxRows")) {
167 isAttr = new Boolean(true);
168 }
169 }
170
171 companyId = (Long)session.getAttribute("companyId");
172 queue = new Long(request.getParameter("queueId"));
173
174 if(isAttr.equals(new Boolean(false))) {
175 maxRows = services.getRowsQueueAccounts(queue, companyId);
176 }
177 else {
178 maxRows = new Long((String)request.getAttribute("maxRows"));
179 }
180
181 showPage(request, response, maxRows);
182 }
183
184
185 private void previewDownload(HttpServletRequest request, HttpServletResponse response) throws ServletException, InstantbankException, IOException, FinderException {
186 Long companyId;
187 Long downloadId;
188 String xml = null;
189
190 companyId = (Long)session.getAttribute("companyId");
191 downloadId = new Long(request.getParameter("downloadId"));
192 xml = services.getDownloadAccounts(downloadId, companyId);
193 request.setAttribute("data", xml);
194 ServletContext sc = getServletConfig().getServletContext();
195 RequestDispatcher rd = sc.getRequestDispatcher("/collectionsQueuing_web/PreviewDownload.jsp?title=Preview Download Accounts");
196 rd.forward(request, response);
197 }
198
199
200 private void searchPreview(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, ServletException, IOException {
201 Long rowNum;
202 Long queueId;
203 Long maxRows;
204 rowNum = new Long((String)request.getParameter("rowNum"));
205 queueId = new Long((String)request.getParameter("queueId"));
206 maxRows = new Long((String)request.getParameter("maxRows"));
207 response.sendRedirect("/Instantbank/collectionsQueuing_web/CollectionsQueuingDispatcher.jsp?useCase=PreviewWorkGenerated&rowNum=" + rowNum + "&queueId=" + queueId + "&maxRows=" + maxRows);
208 }
209
210
211 private void showPage(HttpServletRequest request, HttpServletResponse response, Long maxRows) throws InstantbankException, ServletException, IOException {
212 String attr = "";
213 Long companyId;
214 Long queue;
215 String xml = null;
216 Long rowNum;
217 Boolean isAttr = new Boolean(false);
218
219 Enumeration AttributeNames = request.getAttributeNames();
220 while(AttributeNames.hasMoreElements()) {
221 attr = (String)AttributeNames.nextElement();
222 if(attr.equals("rowNum")) {
223 isAttr = new Boolean(true);
224 }
225 }
226
227 if(isAttr.equals(new Boolean(false))) {
228 rowNum = new Long("1");
229 }
230 else {
231 rowNum = new Long((String)request.getAttribute("rowNum"));
232 }
233
234 companyId = (Long)session.getAttribute("companyId");
235 queue = new Long(request.getParameter("queueId"));
236 xml = services.getQueueAccounts(queue, companyId, rowNum);
237 request.setAttribute("queueId", queue);
238 request.setAttribute("rowNum", rowNum);
239 request.setAttribute("maxRows", maxRows);
240 request.setAttribute("data", xml);
241 ServletContext sc = getServletConfig().getServletContext();
242 RequestDispatcher rd = sc.getRequestDispatcher("/collectionsQueuing_web/PreviewWork.jsp?title=Preview Work Generated");
243 rd.forward(request, response);
244 }
245
246
247 public String getServletInfo() {
248 return "com.instantbank.collections.collectionsQueuing.web.CollectionsQueuingController Information";
249 }
250 }
251
252