1 package com.instantbank.collections.collectionsActivities.web;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.PrintWriter;
6 import java.rmi.RemoteException;
7 import javax.ejb.CreateException;
8 import javax.naming.NamingException;
9 import javax.servlet.RequestDispatcher;
10 import javax.servlet.ServletConfig;
11 import javax.servlet.ServletContext;
12 import javax.servlet.ServletException;
13 import javax.servlet.http.HttpServlet;
14 import javax.servlet.http.HttpServletRequest;
15 import javax.servlet.http.HttpServletResponse;
16 import javax.servlet.http.HttpSession;
17 import org.w3c.dom.Element;
18 import org.w3c.dom.NodeList;
19 import oracle.xml.parser.v2.DOMParser;
20 import oracle.xml.parser.v2.XMLDocument;
21 import oracle.xml.parser.v2.XMLNode;
22 import com.instantbank.collections.creditInfo.ejb.AccountInfoServices;
23 import com.instantbank.collections.creditInfo.ejb.AccountInfoServicesHome;
24 import com.instantbank.collections.util.FilterChain;
25 import com.instantbank.collections.util.InstantbankException;
26 import com.instantbank.collections.util.ServiceLocator;
27
28
29 public class SearchAccountController extends HttpServlet {
30
31 AccountInfoServices accountInfoServices;
32 AccountInfoServicesHome ahome;
33 PrintWriter out;
34 HttpSession session;
35
36
37 public void init(ServletConfig config) throws ServletException {
38 super.init(config);
39 try {
40 ahome = (AccountInfoServicesHome)
41 ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
42 accountInfoServices = ahome.create();
43 }
44 catch(Exception e) {
45 }
46 }
47
48
49 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
50 doPost(request, response);
51 }
52
53
54 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
55 String action = "";
56 com.instantbank.collections.util.FilterChain chain;
57
58 try {
59 action = request.getParameter("action");
60 session = request.getSession(false);
61 session.setAttribute("hasException", "0");
62 try {
63 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
64 if(chain.processFilter(request, response)) {
65 return;
66 }
67 if(action.equals("initialize")) {
68 initialize(request, response);
69 }
70 else if(action.equals("search")) {
71 search(request, response);
72 }
73 else {
74 throw new InstantbankException("522007", "Action " + action + " not supported");
75 }
76 }
77 catch(Exception e) {
78 throw new InstantbankException(e, "522007", "Failed to execute controller action " + action);
79 }
80 }
81 catch(InstantbankException e) {
82 session.setAttribute("hasException", "1");
83 session.setAttribute("Exception", e);
84 if(response.isCommitted()) {
85 return;
86 }
87 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
88 }
89 }
90
91
92 private void initialize(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, ServletException {
93 ServletContext sctx = getServletConfig().getServletContext();
94 session.setAttribute("NextWrkiStatus", " ");
95 session.setAttribute("firstWI", new Long("0"));
96 RequestDispatcher rd = sctx.getRequestDispatcher("/collectionsActivities_web/SearchAccountView.jsp");
97 rd.forward(request, response);
98 }
99
100
101 private void search(HttpServletRequest request, HttpServletResponse response) throws Exception, CreateException, NamingException, RemoteException, InstantbankException {
102 Long companyId;
103 String criteria;
104 String data;
105 XMLDocument dataXml;
106 DOMParser docParser = new DOMParser();
107 XMLNode firstNode;
108 String firstNodeAccount;
109 String lastRownum;
110 String nodeAccount;
111 NodeList nodeList;
112 Integer numberOfRows = null;
113 Element root;
114 Long rownum;
115 ServletContext sctx = getServletConfig().getServletContext();
116 boolean showOne;
117 ByteArrayInputStream stream;
118 XMLNode theNode;
119
120 rownum = new Long(request.getParameter("rownum"));
121 criteria = request.getParameter("criteria");
122 lastRownum = request.getParameter("lastRownum");
123 companyId = (Long)session.getAttribute("companyId");
124 numberOfRows = new Integer(request.getParameter("numberOfRows"));
125 data = accountInfoServices.searchAccount(companyId, criteria, rownum, numberOfRows);
126 stream = new ByteArrayInputStream(data.getBytes());
127 docParser.setValidationMode(false);
128 docParser.parse(stream);
129 dataXml = docParser.getDocument();
130
131 root = dataXml.getDocumentElement();
132 nodeList = root.getChildNodes();
133 request.setAttribute("tab", "Details");
134 if(nodeList.getLength() == 0) {
135 RequestDispatcher rd = sctx.getRequestDispatcher("/collectionsActivities_web/SearchAccountView.jsp");
136 request.setAttribute("message", "No Accounts Found.");
137 request.setAttribute("lastRownum", lastRownum);
138 request.setAttribute("criteria", criteria);
139 rd.forward(request, response);
140 }
141 else if((nodeList.getLength() == 1) && (rownum.equals(new Long(0)))) {
142 RequestDispatcher rd = sctx.getRequestDispatcher("/main_web/MainDispatcher?module=searchAccount&useCase=ReviewAccount&optionCollections=0&optionCompany=0&agrmId=" + dataXml.valueOf("Accounts/Account/id"));
143 rd.forward(request, response);
144 }
145 else {
146 showOne = true;
147 firstNode = (XMLNode)nodeList.item(0);
148 firstNodeAccount = firstNode.valueOf("accountnumber");
149 ;
150 for(int i = 1; i < nodeList.getLength(); i++) {
151 theNode = (XMLNode)nodeList.item(i);
152 nodeAccount = theNode.valueOf("accountnumber");
153 if(!firstNodeAccount.equals(nodeAccount)) {
154 showOne = false;
155 i = nodeList.getLength();
156 }
157 }
158 if(showOne) {
159 RequestDispatcher rd = sctx.getRequestDispatcher("/main_web/MainDispatcher?module=searchAccount&useCase=ReviewAccount&optionCollections=0&optionCompany=0&agrmId=" + dataXml.valueOf("Accounts/Account/id"));
160 rd.forward(request, response);
161 }
162 else {
163 RequestDispatcher rd = sctx.getRequestDispatcher("/collectionsActivities_web/SearchAccountView.jsp");
164 request.setAttribute("lastRownum", lastRownum);
165 request.setAttribute("data", data);
166 request.setAttribute("criteria", criteria);
167 rd.forward(request, response);
168 }
169 }
170 }
171
172
173 public String getServletInfo() {
174 return "com.instantbank.collectionsActions.web.SearchAccountController Information";
175 }
176 }
177
178