1 package com.instantbank.collections.collectionsActivities.web;
2
3 import java.io.IOException;
4 import java.io.OutputStreamWriter;
5 import java.io.PrintWriter;
6 import java.rmi.RemoteException;
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.collectionsActivities.ejb.ActionResultServices;
15 import com.instantbank.collections.collectionsActivities.ejb.ActionResultServicesHome;
16 import com.instantbank.collections.commonQueuing.ejb.QueueServices;
17 import com.instantbank.collections.commonQueuing.ejb.QueueServicesHome;
18 import com.instantbank.collections.creditInfo.ejb.AccountInfoServices;
19 import com.instantbank.collections.creditInfo.ejb.AccountInfoServicesHome;
20 import com.instantbank.collections.util.FilterChain;
21 import com.instantbank.collections.util.InstantbankException;
22 import com.instantbank.collections.util.ServiceLocator;
23 import com.instantbank.collections.util.StringFormat;
24
25 public class RecordActionResultController extends HttpServlet {
26
27 ActionResultServices actionResultServices;
28 QueueServices queueServices;
29 PrintWriter out;
30 HttpSession session;
31
32
33 public void init(ServletConfig config) throws ServletException {
34 super.init(config);
35 try {
36 ActionResultServicesHome home = (ActionResultServicesHome)
37 ServiceLocator.instance().createEJB("ActionResultServicesHome", ActionResultServicesHome.class, false);
38 actionResultServices = home.create();
39 }
40 catch(Exception e) {
41 throw new ServletException(e);
42 }
43 }
44
45
46 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
47 doPost(request, response);
48 }
49
50
51 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
52 String action = "";
53 com.instantbank.collections.util.FilterChain chain;
54
55 try {
56 action = request.getParameter("action");
57 session = request.getSession(false);
58 try {
59
60 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
61 if(chain.processFilter(request, response)) {
62 return;
63 }
64 if(action.equals("getResultRules")) {
65 getResultRules(request, response);
66 }
67 else if(action.equals("save")) {
68 save(request, response);
69 }
70 else if(action.equals("saveNext")) {
71 saveNext(request, response);
72 }
73 else {
74 throw new InstantbankException("522004", "Action " + action + " not supported");
75 }
76 }
77 catch(Exception e) {
78 throw new InstantbankException(e, "522004", "Failed to execute controller action " + action);
79 }
80 }
81 catch(InstantbankException e) {
82 session.setAttribute("Exception", e);
83 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
84 }
85 }
86
87
88 private void getResultRules(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, RemoteException, IOException {
89 Long resultId;
90 String responseXml;
91 String sessionXml;
92
93 OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
94 PrintWriter out = new PrintWriter(osw);
95 try {
96 sessionXml = "<session><companyId>" + ((Long)session.getAttribute("companyId")).toString() + "</companyId><userId>" + ((Long)session.getAttribute("userId")).toString() + "</userId></session>";
97 resultId = new Long(request.getParameter("resultId"));
98 responseXml = actionResultServices.getResultRules(sessionXml, resultId);
99 responseXml = StringFormat.cleanXml(responseXml);
100 out.println("<script>");
101 out.print("parent.resultXmlStr='");
102 out.print(responseXml);
103 out.println("';");
104 out.println("parent.screenFormat();");
105 out.println("</script>");
106 out.close();
107 }
108 catch(Exception e) {
109 out.println("<script>");
110 out.print("alert (\"Errors found getting the information of the result:\\n\\n " + StringFormat.toSafeJavaString(e.toString()) + "\");");
111 out.println("</script>");
112 out.close();
113 }
114 }
115
116
117 private void save(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, RemoteException, IOException {
118 String activityXmlString;
119 Long agrmId;
120 Long firstWrk;
121 Long agrmCode;
122 int indx = 0;
123 String responseXml = "";
124 Long workItemId = new Long(0);
125 String workXmlString;
126 Long nextWorkItemId;
127 Long userId;
128 String queueType;
129 String status;
130 String toQueueType;
131 boolean cToC;
132
133 OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
134 PrintWriter out = new PrintWriter(osw);
135 try {
136 if(!request.getParameter("workItemId").equals("")) {
137 workItemId = new Long(request.getParameter("workItemId"));
138 }
139 AccountInfoServicesHome ahome = (AccountInfoServicesHome)ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
140 AccountInfoServices accountInfoServices = ahome.create();
141 QueueServicesHome home = (QueueServicesHome)
142 ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, false);
143 queueServices = home.create();
144 agrmId = new Long(request.getParameter("agreementId"));
145 activityXmlString = request.getParameter("activityXmlString");
146 queueType = queueServices.getQueueType(workItemId);
147 toQueueType = queueServices.getToQueueType(activityXmlString);
148 cToC = false;
149 if(toQueueType.equalsIgnoreCase("C") && queueType.equalsIgnoreCase("C")) {
150 out.println("top.navigate('/Instantbank/collectionsActivities_web/CollectionsActivitiesDispatcher.jsp?useCase=ReviewAccount&agrmId=" + agrmId.toString() + "&wrki_id=');");
151 out.println("</script>");
152 cToC = true;
153 }
154
155
156 if(toQueueType.equalsIgnoreCase("C") && !queueType.equalsIgnoreCase("C")) {
157 out.println("<script>");
158 out.println("alert('You can`t transfer to collections from non-collections');");
159 out.println("</script>");
160 }
161 else {
162 firstWrk = (Long)session.getAttribute("firstWI");
163 userId = (Long)session.getAttribute("userId");
164 status = (String)session.getAttribute("NextWrkiStatus");
165 nextWorkItemId = queueServices.getWork((Long)session.getAttribute("companyId"), userId, workItemId, status, firstWrk);
166 responseXml = actionResultServices.recordActivity(activityXmlString, (String)session.getAttribute("sessionXmlStr"), workItemId, agrmId);
167 if((responseXml.indexOf("<Status>OK</Status>") != (-1)) && (workItemId.longValue() != 0)) {
168 responseXml = StringFormat.cleanXml(responseXml);
169 out.println("<script>");
170 if(responseXml.indexOf("<Status>OK</Status>") == (-1)) {
171 out.print("alert(\"");
172 out.print(StringFormat.toSafeJavaString(responseXml));
173 out.println("\");");
174 }
175 out.println("top.resetAll();");
176 out.println("</script>");
177 if(cToC) {
178
179 workItemId = new Long(0);
180 request.setAttribute("workItemIdStr", "0");
181 }
182 if(nextWorkItemId.longValue() == 0) {
183 out.println("<script>");
184 out.println("alert('No more accounts to work.');");
185 out.println("top.navigate('/Instantbank/commonQueuing_web/CommonQueuingDispatcher.jsp?useCase=ReviewQueueAgrm');");
186 out.println("</script>");
187 }
188
189 }
190 else if((responseXml.indexOf("<Status>OK</Status>") != (-1)) && (workItemId.longValue() == 0)) {
191 out.println("<script>");
192 out.println("top.resetAll();");
193 out.println("</script>");
194 }
195 else {
196 out.println("<script>");
197 out.print("alert(\"");
198 out.print(StringFormat.toSafeJavaString(responseXml));
199 out.println("\");");
200 out.println("</script>");
201 out.close();
202 }
203
204 }
205 out.close();
206 }
207 catch(Exception e) {
208 out.println("<script>");
209 out.print("alert (\"Errors found in the saving of the information:\\n\\n " + StringFormat.toSafeJavaString(e.toString()) + "\");");
210 out.println("top.resetAll();");
211 out.println("</script>");
212 out.close();
213 }
214 }
215
216
217 private void saveNext(HttpServletRequest request, HttpServletResponse response) throws
218 InstantbankException, RemoteException, IOException, ServletException {
219
220 String activityXmlString;
221 Long agrmId;
222 Long firstWrk;
223 Long nextAgrmId = null;
224 Long nextWorkItemId;
225 String responseXml;
226 ServletContext sctx = getServletConfig().getServletContext();
227 String status;
228 Long userId;
229 Long workItemId;
230 String queueType;
231 String toQueueType;
232
233 OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
234 PrintWriter out = new PrintWriter(osw);
235 try {
236 QueueServicesHome home = (QueueServicesHome)
237 ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, false);
238 queueServices = home.create();
239 status = (String)session.getAttribute("NextWrkiStatus");
240 if((!request.getParameter("workItemId").equals("")) && (request.getParameter("workItemId") != null)) {
241 workItemId = new Long(request.getParameter("workItemId"));
242 }
243 else {
244 workItemId = new Long(0);
245 }
246 if((!request.getParameter("agreementId").equals("")) && (request.getParameter("agreementId") != null)) {
247 AccountInfoServicesHome ahome = (AccountInfoServicesHome)ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
248 AccountInfoServices accountInfoServices = ahome.create();
249 agrmId = new Long(request.getParameter("agreementId"));
250 }
251 else {
252 agrmId = null;
253 }
254 activityXmlString = request.getParameter("activityXmlString");
255 queueType = queueServices.getQueueType(workItemId);
256 toQueueType = queueServices.getToQueueType(activityXmlString);
257 if(agrmId == null) {
258 toQueueType = " ";
259 }
260
261 if(toQueueType.equalsIgnoreCase("C") && !queueType.equalsIgnoreCase("C")) {
262 out.println("<script>");
263 out.println("alert('You can`t transfer to collections from non-collections');");
264 out.println("</script>");
265 out.close();
266 }
267 else {
268 firstWrk = (Long)session.getAttribute("firstWI");
269 userId = (Long)session.getAttribute("userId");
270 nextWorkItemId = queueServices.getWork((Long)session.getAttribute("companyId"), userId, workItemId, status, firstWrk);
271 if(nextWorkItemId.longValue() != 0) {
272 nextAgrmId = queueServices.getObjectIdOfWorkItem(nextWorkItemId);
273 }
274 responseXml = actionResultServices.recordActivity(activityXmlString, (String)session.getAttribute("sessionXmlStr"), workItemId, agrmId);
275 if((responseXml.indexOf("<Status>OK</Status>") != (-1)) && (workItemId.longValue() != 0)) {
276 if(nextWorkItemId.longValue() != 0) {
277 out.println("<script>");
278 out.println("top.navigate('/Instantbank/collectionsActivities_web/CollectionsActivitiesDispatcher.jsp?useCase=ReviewAccount&agrmId=" + nextAgrmId.toString() + "&wrki_id=" + nextWorkItemId.toString() + "');");
279 out.println("</script>");
280 }
281 else {
282
283 out.println("<script>");
284 out.println("alert('No more accounts to work.');");
285 out.println("top.navigate('/Instantbank/commonQueuing_web/CommonQueuingDispatcher.jsp?useCase=ReviewQueueAgrm');");
286 out.println("</script>");
287
288 }
289 out.close();
290 }
291 else if((responseXml.indexOf("<Status>OK</Status>") != (-1)) && (workItemId.longValue() == 0)) {
292 out.println("<script>");
293 out.println("top.navigate('/Instantbank/collectionsActivities_web/CollectionsActivitiesDispatcher.jsp?useCase=SearchAccount');");
294 out.println("</script>");
295 out.close();
296 }
297 else {
298 out.println("<script>");
299 out.print("alert(\"");
300 out.print(StringFormat.toSafeJavaString(responseXml));
301 out.println("\");");
302 out.println("</script>");
303 out.close();
304 }
305 }
306 }
307 catch(Exception e) {
308 out.println("<script>");
309 out.print("alert (\"Errors found in the saving of the information:\\n\\n " + StringFormat.toSafeJavaString(e.toString()) + "\");");
310 out.println("top.resetAll();");
311 out.println("</script>");
312 out.close();
313 }
314 }
315
316
317 public String getServletInfo() {
318 return "com.instantbank.collectionsActions.web.RecordActionResultController Information";
319 }
320 }
321
322