How to use processRequest method of org.cerberus.servlet.crud.usermanagement.DeleteUser class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.usermanagement.DeleteUser.processRequest

Source:DeleteUser.java Github

copy

Full Screen

...53 * @param response servlet response54 * @throws ServletException if a servlet-specific error occurs55 * @throws IOException if an I/O error occurs56 */57 protected void processRequest(HttpServletRequest request, HttpServletResponse response)58 throws ServletException, IOException, CerberusException, JSONException {59 JSONObject jsonResponse = new JSONObject();60 Answer ans = new Answer();61 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);62 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));63 ans.setResultMessage(msg);64 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);65 String charset = request.getCharacterEncoding();66 String login = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("login"), "", charset);67 boolean userHasPermissions = request.isUserInRole("Administrator");68 /**69 * Checking all constrains before calling the services.70 */71 if (StringUtil.isNullOrEmpty(login)) {72 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);73 msg.setDescription(msg.getDescription().replace("%ITEM%", "User")74 .replace("%OPERATION%", "Delete")75 .replace("%REASON%", "User name is missing!"));76 ans.setResultMessage(msg);77 } else if (!userHasPermissions) {78 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);79 msg.setDescription(msg.getDescription().replace("%ITEM%", "User")80 .replace("%OPERATION%", "Delete")81 .replace("%REASON%", "You don't have the right to do that"));82 ans.setResultMessage(msg);83 } else {84 /**85 * All data seems cleans so we can call the services.86 */87 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());88 IUserService userService = appContext.getBean(IUserService.class);89 AnswerItem resp = userService.readByKey(login);90 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {91 if (resp.getItem() != null) {92 ans = userService.delete((User) resp.getItem());93 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {94 /**95 * Object updated. Adding Log entry.96 */97 ILogEventService logEventService = appContext.getBean(LogEventService.class);98 logEventService.createForPrivateCalls("/DeleteUser", "DELETE", "Delete User : ['" + login + "']", request);99 }100 } else {101 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);102 msg.setDescription(msg.getDescription().replace("%ITEM%", "User")103 .replace("%OPERATION%", "Delete")104 .replace("%REASON%", "User not found"));105 ans.setResultMessage(msg);106 }107 }108 }109 /**110 * Formating and returning the json result.111 */112 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());113 jsonResponse.put("message", ans.getResultMessage().getDescription());114 response.getWriter().print(jsonResponse);115 response.getWriter().flush();116 }117 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">118 /**119 * Handles the HTTP <code>GET</code> method.120 *121 * @param request servlet request122 * @param response servlet response123 * @throws ServletException if a servlet-specific error occurs124 * @throws IOException if an I/O error occurs125 */126 @Override127 protected void doGet(HttpServletRequest request, HttpServletResponse response)128 throws ServletException, IOException {129 try {130 processRequest(request, response);131 } catch (CerberusException ex) {132 LOG.warn(ex);133 } catch (JSONException ex) {134 LOG.warn(ex);135 }136 }137 /**138 * Handles the HTTP <code>POST</code> method.139 *140 * @param request servlet request141 * @param response servlet response142 * @throws ServletException if a servlet-specific error occurs143 * @throws IOException if an I/O error occurs144 */145 @Override146 protected void doPost(HttpServletRequest request, HttpServletResponse response)147 throws ServletException, IOException {148 try {149 processRequest(request, response);150 } catch (CerberusException ex) {151 LOG.warn(ex);152 } catch (JSONException ex) {153 LOG.warn(ex);154 }155 }156 /**157 * Returns a short description of the servlet.158 *159 * @return a String containing servlet description160 */161 @Override162 public String getServletInfo() {163 return "Short description";...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in DeleteUser

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful