1    package com.instantbank.collections.documents.web;
2    
3    import java.io.IOException;
4    import java.rmi.RemoteException;
5    import javax.servlet.RequestDispatcher;
6    import javax.servlet.ServletConfig;
7    import javax.servlet.ServletContext;
8    import javax.servlet.ServletException;
9    import javax.servlet.http.HttpServlet;
10   import javax.servlet.http.HttpServletRequest;
11   import javax.servlet.http.HttpServletResponse;
12   import javax.servlet.http.HttpSession;
13   import com.instantbank.collections.commonQueuing.ejb.QueueServices;
14   import com.instantbank.collections.commonQueuing.ejb.QueueServicesHome;
15   import com.instantbank.collections.companyInfo.ejb.CompanyServices;
16   import com.instantbank.collections.companyInfo.ejb.CompanyServicesHome;
17   import com.instantbank.collections.documents.ejb.DocumentServices;
18   import com.instantbank.collections.documents.ejb.DocumentServicesHome;
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 DocumentSetupController extends HttpServlet {
24     private CompanyServices companyServices;
25     private DocumentServices docServices;
26     private QueueServices queueServices;
27     private HttpSession session;
28   
29   
30     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
31       doPost(request, response);
32     }
33   
34   
35     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
36   
37       String action;
38       com.instantbank.collections.util.FilterChain chain;
39   
40       try {
41         session = request.getSession(false);
42         action = request.getParameter("action");
43         try {
44   
45           chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
46           if(chain.processFilter(request, response)) {
47             return;
48           }
49           if(action.equals("initialize")) {
50             initialize(request, response);
51           }
52           else if(action.equals("save")) {
53             save(request, response);
54           }
55           else if(action.equals("saveRules")) {
56             saveRules(request, response);
57           }
58           else if(action.equals("selection")) {
59             selection(request, response);
60           }
61           else {
62             throw new InstantbankException("122001", "Action " + action + " not supported");
63           }
64         }
65         catch(Exception e) {
66           throw new InstantbankException(e, "122002", "Failed to execute controller action " + action);
67         }
68       }
69       catch(InstantbankException e) {
70         session.setAttribute("Exception", e);
71         response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
72       }
73     }
74   
75   
76     public String getServletInfo() {
77       return "com.instantbank.collections.companyInfo.web.CompanyMaintenanceController Information";
78     }
79   
80   
81     public void init(ServletConfig config) throws ServletException {
82       super.init(config);
83       try {
84         CompanyServicesHome home = (CompanyServicesHome)ServiceLocator.instance().createEJB("CompanyServicesHome", CompanyServicesHome.class, false);
85         companyServices = home.create();
86         DocumentServicesHome dochome = (DocumentServicesHome)ServiceLocator.instance().createEJB("DocumentServicesHome", DocumentServicesHome.class, false);
87         docServices = dochome.create();
88         QueueServicesHome queuehome = (QueueServicesHome)ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, false);
89         queueServices = queuehome.create();
90       }
91       catch(Exception e) {
92         throw new ServletException(e);
93       }
94     }
95   
96   
97     private void initialize(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, RemoteException, ServletException {
98       Long companyId;
99       String xmlDoc;
100      String xmlLocations;
101      String xmlTrigger;
102  
103      companyId = (Long)session.getAttribute("companyId");
104      xmlLocations = companyServices.getCompanyLocations(companyId);
105      xmlDoc = docServices.getDocuments(companyId);
106      xmlTrigger = docServices.getTrigger();
107      request.setAttribute("title", "Document Setup");
108      request.setAttribute("locations", xmlLocations);
109      request.setAttribute("documents", xmlDoc);
110      request.setAttribute("triggerlist", xmlTrigger);
111      request.setAttribute("objectType", "A");
112      ServletContext sc = getServletConfig().getServletContext();
113      RequestDispatcher rd = sc.getRequestDispatcher("/documents_web/DocumentSetup.jsp");
114      rd.forward(request, response);
115    }
116  
117  
118    private void save(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, RemoteException, ServletException {
119      Long companyId;
120      Long userId;
121      String xml;
122  
123      companyId = (Long)session.getAttribute("companyId");
124      userId = (Long)session.getAttribute("userId");
125      xml = request.getParameter("data");
126      docServices.saveDocument(xml, companyId, userId);
127      initialize(request, response);
128    }
129  
130  
131    private void saveRules(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, RemoteException, ServletException {
132      Long companyId;
133      String xmlRules;
134  
135      companyId = (Long)session.getAttribute("companyId");
136      xmlRules = (String)request.getParameter("data");
137      docServices.saveRules(companyId, xmlRules);
138      initialize(request, response);
139    }
140  
141  
142    private void selection(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, RemoteException, ServletException {
143      Long companyId;
144      String docId;
145      String fields;
146      String objectType;
147      String rules;
148  
149      companyId = (Long)session.getAttribute("companyId");
150      docId = (String)request.getParameter("docId");
151      rules = docServices.getRules(companyId, docId);
152      request.setAttribute("Rules", rules);
153      request.setAttribute("docId", docId);
154      request.setAttribute("objectType", "A");
155      ServletContext sc = getServletConfig().getServletContext();
156      RequestDispatcher rd = sc.getRequestDispatcher("/documents_web/SelectionRulesView.jsp");
157      rd.forward(request, response);
158    }
159  
160  }
161  
162