private void getPositions(HttpServletRequest request, Role item) { String[] pos = request.getParameterValues("positions"); item.clearPositions(); for (int i = 0; i < pos.length; i++) { item.addPosition(Long.parseLong(pos[i])); } }
private void getPermissions(HttpServletRequest request, Role item) { String[] per = request.getParameterValues("permissions"); item.clearPermissions(); for (int i = 0; i < per.length; i++) { item.addPermission(Long.parseLong(per[i])); } }
// Process the request private String processRequest(HttpServletRequest request, HttpServletResponse response) { String command = request.getParameter("command"); String id = request.getParameter("id"); String description = request.getParameter("description"); String status = request.getParameter("rstatus"); status = (status != null && status.compareTo(" ") > 0) ? status : null; String outLine = ""; // String nextScript = "home.jsp"; String nextScript = request.getParameter("nextscript"); OutputStream toClient; HttpSession session = request.getSession(); boolean success = false; String userIDs = (String) session.getAttribute("user.id"); long userID = Long.parseLong(userIDs); command = (command != null && command.compareTo(" ") > 0) ? command : "form"; nextScript = (nextScript != null && nextScript.compareTo(" ") > 0) ? nextScript : "roles.jsp"; // inputstring = (inputstring != null && inputstring.compareTo(" ") > 0) ? inputstring : ""; DbConn myConn = null; try { Context initCtx = new InitialContext(); // String csiSchema = (String) initCtx.lookup("java:comp/env/csi-schema-path"); String acronym = (String) initCtx.lookup("java:comp/env/SystemAcronym"); myConn = new DbConn(); String csiSchema = myConn.getSchemaPath(); if (command.equals("add")) { Role item = new Role(); item.setDescription(description); item.setStatus(status); getPermissions(request, item); getPositions(request, item); item.add(myConn, userID); GlobalMembership.refresh(myConn); success = true; outLine = ""; } else if (command.equals("update")) { Role item = new Role(myConn, Long.parseLong(id)); item.setDescription(description); item.setStatus(status); getPermissions(request, item); getPositions(request, item); item.save(myConn, userID); GlobalMembership.refresh(myConn); success = true; outLine = ""; } else if (command.equals("drop")) { Role item = new Role(myConn, Long.parseLong(id)); item.drop(myConn, userID); success = true; outLine = "Role " + item.getDescription() + " Removed"; } else if (command.equals("test")) { outLine = "test"; } } catch (IllegalArgumentException e) { outLine = outLine + "IllegalArgumentException caught: " + e.getMessage(); ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'"); // log(outLine); } catch (NullPointerException e) { outLine = outLine + "NullPointerException caught: " + e.getMessage(); ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'"); // log(outLine); } // catch (IOException e) { // outLine = outLine + "IOException caught: " + e.getMessage(); // ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'"); // //log(outLine); // } catch (Exception e) { outLine = outLine + "Exception caught: " + e.getMessage(); ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'"); // log(outLine); } finally { try { generateResponse(outLine, command, nextScript, success, response); } catch (Exception i) { } myConn.release(); // log("Test log message\n"); } return outLine; }