1    package com.instantbank.collections.collectionsActivities.web;
2    
3    import javax.servlet.RequestDispatcher;
4    import javax.servlet.ServletConfig;
5    import javax.servlet.ServletContext;
6    import javax.servlet.ServletException;
7    import javax.servlet.http.HttpServlet;
8    import javax.servlet.http.HttpServletRequest;
9    import javax.servlet.http.HttpServletResponse;
10   import javax.servlet.http.HttpSession;
11   import java.io.IOException;
12   import java.io.OutputStreamWriter;
13   import java.io.PrintWriter;
14   import java.util.Enumeration;
15   import com.instantbank.collections.collectionsActivities.ejb.CollectionsActivitiesServices;
16   import com.instantbank.collections.collectionsActivities.ejb.CollectionsActivitiesServicesHome;
17   import com.instantbank.collections.creditInfo.ejb.AccountInfoServices;
18   import com.instantbank.collections.creditInfo.ejb.AccountInfoServicesHome;
19   import com.instantbank.collections.util.FilterChain;
20   import com.instantbank.collections.util.InstantbankException;
21   import com.instantbank.collections.util.ServiceLocator;
22   
23   public class PromiseHistoryController extends HttpServlet {
24     private AccountInfoServices accountInfoServices;
25     private AccountInfoServicesHome accountInfoServicesHome;
26     private PrintWriter out;
27     private OutputStreamWriter osw;
28     private HttpSession session;
29     private CollectionsActivitiesServices services;
30   
31   
32     /**
33      * Initialize global variables
34      *
35      * @param config Description of the Parameter
36      * @throws ServletException Description of the Exception
37      */
38     public void init(ServletConfig config) throws ServletException {
39       super.init(config);
40       try {
41         CollectionsActivitiesServicesHome home = (CollectionsActivitiesServicesHome)
42           ServiceLocator.instance().createEJB("CollectionsActivitiesServicesHome", CollectionsActivitiesServicesHome.class, false);
43         services = home.create();
44         accountInfoServicesHome = (AccountInfoServicesHome)ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
45         accountInfoServices = accountInfoServicesHome.create();
46       }
47       catch(Exception e) {
48         throw new ServletException(e);
49       }
50     }
51   
52   
53     /**
54      * Process the HTTP Get request
55      *
56      * @param request Description of the Parameter
57      * @param response Description of the Parameter
58      * @throws ServletException Description of the Exception
59      * @throws IOException Description of the Exception
60      */
61     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
62       doPost(request, response);
63     }
64   
65   
66     /**
67      * Process the HTTP Post request
68      *
69      * @param request Description of the Parameter
70      * @param response Description of the Parameter
71      * @throws ServletException Description of the Exception
72      * @throws IOException Description of the Exception
73      */
74     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
75       String action;
76       com.instantbank.collections.util.FilterChain chain;
77       try {
78         action = request.getParameter("action");
79         session = request.getSession(false);
80         try {
81   
82           chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
83           if(chain.processFilter(request, response)) {
84             return;
85           }
86           if(action.equals("initialize")) {
87             initialize(request, response);
88           }
89           else if(action.equals("searchPromise")) {
90             searchPromise(request, response);
91           }
92           else {
93             throw new InstantbankException("522003", "Action " + action + " not supported");
94           }
95         }
96         catch(Exception e) {
97           throw new InstantbankException(e, "522003", "Failed to execute controller action " + action);
98         }
99       }
100      catch(InstantbankException e) {
101        session.setAttribute("Exception", e);
102        response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
103      }
104  
105    }
106  
107  
108    /**
109     * Get Servlet information
110     *
111     * @return java.lang.String
112     */
113    public String getServletInfo() {
114      return "com.instantbank.collections.collectionsActivities.web.PromiseHistory Information";
115    }
116  
117  
118    private void initialize(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, ServletException, IOException {
119      Long agrmCode;
120      Long agrmId;
121      String attr;
122      Long companyId;
123      String data;
124      Long maxRows;
125      Long row;
126      Boolean isAttr = new Boolean(false);
127  
128      Enumeration AttributeNames = request.getAttributeNames();
129      while(AttributeNames.hasMoreElements()) {
130        attr = (String)AttributeNames.nextElement();
131        if(attr.equals("rowNum")) {
132          isAttr = new Boolean(true);
133        }
134      }
135  
136      if(isAttr.equals(new Boolean(false))) {
137        row = new Long("1");
138      }
139      else {
140        row = new Long((String)request.getAttribute("rowNum"));
141      }
142  
143      companyId = (Long)session.getAttribute("companyId");
144      agrmId = new Long((String)request.getAttribute("agrmId"));
145      data = services.getPromiseHistory(companyId, agrmId, row);
146      maxRows = services.getRowsPromiseHistory(companyId, agrmId);
147  
148      request.setAttribute("data", data);
149      request.setAttribute("rowNum", row);
150      request.setAttribute("maxRows", maxRows);
151  
152      request.setAttribute("controller", "PromiseHistoryController");
153      ServletContext sc = getServletConfig().getServletContext();
154      RequestDispatcher rd = sc.getRequestDispatcher("/collectionsActivities_web/PromiseHistoryView.jsp");
155      rd.forward(request, response);
156    }
157  
158  
159    private void searchPromise(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, ServletException, IOException {
160      Long agrmCode;
161      Long agrmId;
162      Long companyId;
163      Long rowNum;
164      String data;
165      String wrkiId;
166      String mainData;
167  
168      companyId = (Long)session.getAttribute("companyId");
169      agrmCode = new Long((String)request.getParameter("agrmId"));
170      rowNum = new Long((String)request.getParameter("rowNum"));
171      wrkiId = request.getParameter("wrki_id");
172      mainData = request.getParameter("mainData");
173      response.sendRedirect("/Instantbank/collectionsActivities_web/ReviewAccountController?action=changeTab&mainData= " + mainData + "&tab=PromiseHistory&agrmId=" + agrmCode.toString() + "&wrki_id=" + wrkiId + "&rowNum=" + rowNum.toString());
174    }
175  }
176  
177