1    package com.instantbank.collections.creditInfo.web;
2    
3    import java.io.IOException;
4    import java.io.OutputStreamWriter;
5    import java.io.PrintWriter;
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.basicInfo.ejb.BasicInfoServices;
15   import com.instantbank.collections.basicInfo.ejb.BasicInfoServicesHome;
16   import com.instantbank.collections.creditInfo.ejb.AccountInfoServices;
17   import com.instantbank.collections.creditInfo.ejb.AccountInfoServicesHome;
18   import com.instantbank.collections.util.FilterChain;
19   import com.instantbank.collections.util.InstantbankException;
20   import com.instantbank.collections.util.ServiceLocator;
21   import com.instantbank.collections.util.StringFormat;
22   
23   public class DemographicsMaintenanceController extends HttpServlet {
24     private AccountInfoServices accountInfoServices;
25     private AccountInfoServicesHome ahome;
26     private BasicInfoServices basicServices;
27     private PrintWriter out;
28     private HttpSession session;
29   
30   
31     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
32       this.doPost(request, response);
33     }
34   
35   
36     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
37       String action = "";
38       com.instantbank.collections.util.FilterChain chain;
39   
40       try {
41         action = request.getParameter("action");
42         session = request.getSession(false);
43   
44         try {
45   
46           chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
47           if(chain.processFilter(request, response)) {
48             return;
49           }
50           if(action.equals("initialize")) {
51             initialize(request, response);
52           }
53           else if(action.equals("getStates")) {
54             getStates(request, response);
55           }
56           else if(action.equals("save")) {
57             save(request, response);
58           }
59           else {
60             throw new InstantbankException("242001", "Action " + action + " not supported");
61           }
62         }
63         catch(Exception e) {
64           throw new InstantbankException(e, "242002", "Failed to execute controller action " + action);
65         }
66       }
67       catch(InstantbankException e) {
68         session.setAttribute("Exception", e);
69         response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
70       }
71     }
72   
73   
74     private void getStates(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, ServletException, IOException {
75       String countryId = request.getParameter("countryId");
76       OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
77       String xml = null;
78   
79       xml = basicServices.getStates(countryId);
80       PrintWriter out = new PrintWriter(osw);
81       response.setContentType("text/html");
82       out.println("<html>");
83       out.println("<script language=JavaScript>");
84       out.println("parent.statesXML='" + StringFormat.cleanXml(xml) + "';");
85       out.println("parent.loadStates();");
86       out.println("</script></html>");
87       out.close();
88     }
89   
90   
91     public void init(ServletConfig config) throws ServletException {
92       try {
93         super.init(config);
94         ahome = (AccountInfoServicesHome)ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
95         accountInfoServices = ahome.create();
96         BasicInfoServicesHome basicHome = (BasicInfoServicesHome)ServiceLocator.instance().createEJB("BasicInfoServicesHome", BasicInfoServicesHome.class, false);
97         basicServices = basicHome.create();
98       }
99       catch(Exception e) {
100      }
101    }
102  
103  
104    private void initialize(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
105      Long agrmId;
106      Long companyId;
107      String customers;
108      String data;
109      String outXmlString = "";
110  
111      try {
112        ServletContext sctx = getServletConfig().getServletContext();
113        agrmId = new Long(request.getParameter("agrmId"));
114        companyId = (Long)session.getAttribute("companyId");
115        customers = accountInfoServices.getCustomers(companyId, agrmId);
116        request.setAttribute("data", customers);
117        RequestDispatcher rd = sctx.getRequestDispatcher("/creditInfo_web/DemographicsView.jsp");
118        rd.forward(request, response);
119      }
120      catch(Exception e) {
121        e.printStackTrace();
122      }
123    }
124  
125  
126    private void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
127      Long agrmId;
128      Long companyId;
129      String data;
130      String mainData;
131      String outXmlString = "";
132      ServletContext sctx = getServletConfig().getServletContext();
133      Long userId;
134      String wrkiId;
135  
136      agrmId = new Long(request.getParameter("agrmId"));
137      companyId = (Long)session.getAttribute("companyId");
138      userId = (Long)session.getAttribute("userId");
139      data = request.getParameter("data");
140      mainData = request.getParameter("mainData");
141      wrkiId = request.getParameter("wrki_id");
142      accountInfoServices.saveCustomer(data, agrmId, companyId, userId);
143      response.sendRedirect("/Instantbank/collectionsActivities_web/ReviewAccountController?action=changeTab&mainData=" + mainData + "&tab=Demographics&agrmId=" + agrmId + "&wrki_id=" + wrkiId);
144    }
145  }
146  
147