1    package com.instantbank.collections.creditInfo.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.util.Enumeration;
13   import com.instantbank.collections.creditInfo.ejb.AccountInfoServices;
14   import com.instantbank.collections.creditInfo.ejb.AccountInfoServicesHome;
15   import com.instantbank.collections.util.FilterChain;
16   import com.instantbank.collections.util.InstantbankException;
17   import com.instantbank.collections.util.ServiceLocator;
18   
19   public class AccountMaintenanceHistoryController extends HttpServlet {
20     private AccountInfoServices AccServices;
21     private Long companyId;
22     private String debug;
23     private String typeSel;
24     private Long userId;
25     HttpSession session;
26   
27   
28     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
29       doPost(request, response);
30     }
31   
32   
33     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
34       String action;
35       com.instantbank.collections.util.FilterChain chain;
36   
37       try {
38         debug = "set action";
39         action = request.getParameter("action");
40         try {
41   
42           chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
43           if(chain.processFilter(request, response)) {
44             return;
45           }
46           if(action.equals("initialize")) {
47             initialize(request, response);
48           }
49           else if(action.equals("searchMaintenance")) {
50             searchMaintenance(request, response);
51           }
52           else {
53             throw new InstantbankException("242001", "Action " + action + " not supported");
54           }
55         }
56         catch(Exception e) {
57           throw new InstantbankException(e, "242002", "Failed to execute controller action " + action);
58         }
59       }
60       catch(InstantbankException e) {
61         session.setAttribute("Exception", e);
62         response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
63       }
64     }
65   
66   
67     public String getServletInfo() {
68       return "com.instantbank.collections.creditInfo.web.AccountMaintenanceHistoryController Information";
69     }
70   
71   
72     public void init(ServletConfig config) throws ServletException {
73       super.init(config);
74       try {
75         AccountInfoServicesHome Home = (AccountInfoServicesHome)
76           ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
77         AccServices = Home.create();
78       }
79       catch(Exception e) {
80         throw new ServletException(e);
81       }
82     }
83   
84   
85     private void initialize(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
86       Long agrmId;
87       String attr;
88       String data;
89       String fromDate;
90       Long maxRows;
91       String toDate;
92       String primarySort;
93       String secondarySort;
94       Long rowNum;
95       Boolean isAttr = new Boolean(false);
96   
97       Enumeration AttributeNames = request.getAttributeNames();
98       while(AttributeNames.hasMoreElements()) {
99         attr = (String)AttributeNames.nextElement();
100        if(attr.equals("rowNum")) {
101          isAttr = new Boolean(true);
102        }
103      }
104  
105      if(isAttr.equals(new Boolean(false))) {
106        rowNum = new Long("1");
107      }
108      else {
109        rowNum = new Long((String)request.getAttribute("rowNum"));
110      }
111  
112      session = request.getSession();
113      primarySort = (String)request.getAttribute("primarySort");
114      secondarySort = (String)request.getAttribute("secondarySort");
115      fromDate = (String)request.getAttribute("fromDate");
116      toDate = (String)request.getAttribute("toDate");
117      companyId = new Long(session.getValue("companyId").toString());
118      agrmId = new Long(request.getAttribute("agrmId").toString());
119      data = AccServices.getMaintenanceHistory(companyId, agrmId, primarySort, secondarySort, fromDate, toDate, rowNum);
120      maxRows = AccServices.getRowsMaintenanceHistory(companyId, agrmId, fromDate, toDate);
121  
122      request.setAttribute("data", data);
123      request.setAttribute("rowNum", rowNum);
124      request.setAttribute("maxRows", maxRows);
125  
126      ServletContext sc = getServletConfig().getServletContext();
127      RequestDispatcher rd = sc.getRequestDispatcher("/creditInfo_web/AccountMaintenanceHistoryView.jsp");
128      rd.forward(request, response);
129    }
130  
131  
132    private void searchMaintenance(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, ServletException, IOException {
133      Long agrmCode;
134      Long agrmId;
135      Long companyId;
136      String fromDate;
137      Long rowNum;
138      String data;
139      String toDate;
140      String wrkiId;
141      String mainData;
142      String primarySort;
143      String secondarySort;
144  
145      primarySort = (String)request.getParameter("primarySort");
146      secondarySort = (String)request.getParameter("secondarySort");
147      fromDate = (String)request.getParameter("fromDate");
148      toDate = (String)request.getParameter("toDate");
149      companyId = (Long)session.getAttribute("companyId");
150      agrmCode = new Long((String)request.getParameter("agrmId"));
151      rowNum = new Long((String)request.getParameter("rowNum"));
152      wrkiId = request.getParameter("wrki_id");
153      mainData = request.getParameter("mainData");
154      response.sendRedirect("/Instantbank/collectionsActivities_web/ReviewAccountController?action=changeTab&mainData= " + mainData + "&tab=MaintenanceHistory&agrmId=" + agrmCode.toString() + "&wrki_id=" + wrkiId + "&rowNum=" + rowNum.toString() + "&primarySort=" + primarySort + "&secondarySort=" + secondarySort + "&fromDate=" + fromDate + "&toDate=" + toDate);
155    }
156  }
157