1 package com.instantbank.collections.security.web;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
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 oracle.xml.parser.v2.DOMParser;
14 import oracle.xml.parser.v2.XMLDocument;
15 import oracle.xml.parser.v2.XSLException;
16 import org.xml.sax.SAXException;
17 import com.instantbank.collections.security.ejb.SecurityProfilesServices;
18 import com.instantbank.collections.security.ejb.SecurityProfilesServicesHome;
19 import com.instantbank.collections.security.ejb.SecurityServices;
20 import com.instantbank.collections.security.ejb.SecurityServicesHome;
21 import com.instantbank.collections.util.FilterChain;
22 import com.instantbank.collections.util.InstantbankException;
23 import com.instantbank.collections.util.ServiceLocator;
24
25 public class UserGroupsMaintenanceController extends HttpServlet {
26 private Long companyId;
27 private Integer currentTab;
28 private String debug;
29 private SecurityProfilesServices PrfServices;
30 private SecurityServices SecServices;
31 private HttpSession session;
32 private String typeSel;
33 private Long userId;
34
35
36 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
37 doPost(request, response);
38 }
39
40
41 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
42 String action = "";
43 com.instantbank.collections.util.FilterChain chain;
44
45 debug = "set action";
46 try {
47 session = request.getSession(false);
48 action = request.getParameter("action");
49 session.setAttribute("hasException", "0");
50 typeSel = request.getParameter("type");
51 try {
52 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
53 if(chain.processFilter(request, response)) {
54 return;
55 }
56 if(action.equals("initialize")) {
57 initialize(request, response);
58 }
59 else if(action.equals("selectParent")) {
60 selectParent(request, response, typeSel);
61 }
62 else if(action.equals("selectGroup")) {
63 selectGroup(request, response, typeSel);
64 }
65 else if(action.equals("refreshChildren")) {
66 refreshChildren(request, response);
67 }
68 else if(action.equals("save")) {
69 save(request, response);
70 }
71 else {
72 throw new InstantbankException("132001", "Action " + action + " not supported");
73 }
74 }
75 catch(Exception e) {
76 throw new InstantbankException(e, "132002", "Failed to execute controller action " + action);
77 }
78 }
79 catch(InstantbankException e) {
80 session.setAttribute("hasException", "1");
81 session.setAttribute("Exception", e);
82 if(response.isCommitted()) {
83 return;
84 }
85 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
86 }
87 }
88
89
90 public String getServletInfo() {
91 return "com.instantbank.collections.security.web.UserGroupsMaintenanceController Information";
92 }
93
94
95 public void init(ServletConfig config) throws ServletException {
96 super.init(config);
97 try {
98 SecurityServicesHome SecHome = (SecurityServicesHome)
99 ServiceLocator.instance().createEJB("SecurityServicesHome", SecurityServicesHome.class, false);
100 SecServices = SecHome.create();
101 SecurityProfilesServicesHome PrfHome = (SecurityProfilesServicesHome)
102 ServiceLocator.instance().createEJB("SecurityProfilesServicesHome", SecurityProfilesServicesHome.class, false);
103 PrfServices = PrfHome.create();
104 }
105 catch(Exception e) {
106 throw new ServletException(e);
107 }
108 }
109
110
111 private void initialize(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
112 String xmlGroup;
113 String xmlProfiles;
114 typeSel = "0";
115 Long companyId;
116
117 companyId = (Long)session.getAttribute("companyId");
118 xmlGroup = SecServices.newGroup();
119 xmlProfiles = PrfServices.newProfiles(companyId);
120 currentTab = new Integer(1);
121 showGroup(request, response, xmlGroup, xmlProfiles, typeSel, "");
122 }
123
124
125 private void showGroup(HttpServletRequest request, HttpServletResponse response, String xmlGroup, String xmlProfiles, String Selection, String GroupChild) throws ServletException, IOException, InstantbankException {
126 String xmlList = new String();
127 String xmlQueues = new String();
128
129 companyId = (Long)session.getAttribute("companyId");
130 xmlList = SecServices.getGroups(companyId);
131 xmlQueues = PrfServices.getQueues(companyId);
132 ServletContext sc = getServletConfig().getServletContext();
133 request.setAttribute("currentTab", currentTab.toString());
134 request.setAttribute("data", xmlGroup);
135 request.setAttribute("profiles", xmlProfiles);
136 request.setAttribute("groups", xmlList);
137 request.setAttribute("queues", xmlQueues);
138 request.setAttribute("selection", Selection);
139 request.setAttribute("groupChild", GroupChild);
140 RequestDispatcher rd = sc.getRequestDispatcher("/security_web/UserGroupsView.jsp");
141 rd.forward(request, response);
142 }
143
144
145 private void selectParent(HttpServletRequest request, HttpServletResponse response, String Selection) throws ServletException, InstantbankException, IOException, SAXException, XSLException {
146 String ParentId;
147 Long ProfileId;
148 String xmlGroup;
149 String xmlProfiles;
150 String GroupChild;
151 XMLDocument doc;
152
153 currentTab = new Integer(request.getParameter("currentTab"));
154 xmlGroup = (String)request.getParameter("data");
155 GroupChild = (String)request.getParameter("group");
156 doc = parseInfo(xmlGroup);
157 ParentId = doc.valueOf("/GroupList/Group/id");
158 if(ParentId.equals("_")) {
159 initialize(request, response);
160 }
161 else {
162 ProfileId = new Long(PrfServices.getGroupProfileId(ParentId));
163 xmlProfiles = PrfServices.getProfiles(ProfileId, "C");
164 showGroup(request, response, xmlGroup, xmlProfiles, Selection, GroupChild);
165 }
166 }
167
168
169 private void selectGroup(HttpServletRequest request, HttpServletResponse response, String Selection) throws ServletException, IOException, InstantbankException {
170 Long GroupId;
171 Long ProfileId;
172 String xmlGroup;
173 String xmlProfiles;
174 String GrpTmp;
175 XMLDocument doc;
176
177 currentTab = new Integer(request.getParameter("currentTab"));
178 GrpTmp = (String)request.getParameter("data");
179 if(GrpTmp.equals("")) {
180 initialize(request, response);
181 }
182 else {
183 GroupId = new Long(GrpTmp);
184 xmlGroup = SecServices.getGroup(GroupId);
185 ProfileId = new Long(PrfServices.getGroupProfileId(GroupId.toString()));
186 xmlProfiles = PrfServices.getProfiles(ProfileId, "C");
187 showGroup(request, response, xmlGroup, xmlProfiles, Selection, "");
188 }
189 }
190
191
192 private void refreshChildren(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
193 Long GroupId;
194 Long ProfileId;
195 String xmlGroup;
196 String xmlProfiles;
197 String GrpTmp;
198 XMLDocument doc;
199
200 userId = (Long)session.getAttribute("userId");
201 currentTab = new Integer(request.getParameter("currentTab"));
202 GroupId = new Long((String)request.getParameter("data"));
203 PrfServices.refreshChildren(userId, GroupId, 1);
204 initialize(request, response);
205 }
206
207
208 private void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, InstantbankException {
209 String xmlGroup;
210 String xmlProfiles;
211
212 currentTab = new Integer(request.getParameter("currentTab"));
213 companyId = (Long)session.getAttribute("companyId");
214 userId = (Long)session.getAttribute("userId");
215 xmlGroup = (String)request.getParameter("data");
216 xmlProfiles = (String)request.getParameter("profiles");
217 SecServices.saveGroup(xmlGroup, xmlProfiles, companyId, userId);
218 initialize(request, response);
219 }
220
221
222 public XMLDocument parseInfo(String data) throws ServletException, IOException, InstantbankException, SAXException {
223 DOMParser docParser = new DOMParser();
224 ByteArrayInputStream stream;
225 XMLDocument xmlDoc;
226
227 xmlDoc = null;
228 stream = new ByteArrayInputStream(data.getBytes());
229 docParser.setValidationMode(false);
230 docParser.parse(stream);
231 xmlDoc = docParser.getDocument();
232 return xmlDoc;
233 }
234 }
235