Best Cerberus-source code snippet using org.cerberus.servlet.crud.usermanagement.DeleteUser.processRequest
Source: DeleteUser.java
...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";...
Check out the latest blogs from LambdaTest on this topic:
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
Hey LambdaTesters! We’ve got something special for you this week. ????
API (Application Programming Interface) is a set of definitions and protocols for building and integrating applications. It’s occasionally referred to as a contract between an information provider and an information user establishing the content required from the consumer and the content needed by the producer.
In general, software testers have a challenging job. Software testing is frequently the final significant activity undertaken prior to actually delivering a product. Since the terms “software” and “late” are nearly synonymous, it is the testers that frequently catch the ire of the whole business as they try to test the software at the end. It is the testers who are under pressure to finish faster and deem the product “release candidate” before they have had enough opportunity to be comfortable. To make matters worse, if bugs are discovered in the product after it has been released, everyone looks to the testers and says, “Why didn’t you spot those bugs?” The testers did not cause the bugs, but they must bear some of the guilt for the bugs that were disclosed.
In some sense, testing can be more difficult than coding, as validating the efficiency of the test cases (i.e., the ‘goodness’ of your tests) can be much harder than validating code correctness. In practice, the tests are just executed without any validation beyond the pass/fail verdict. On the contrary, the code is (hopefully) always validated by testing. By designing and executing the test cases the result is that some tests have passed, and some others have failed. Testers do not know much about how many bugs remain in the code, nor about their bug-revealing efficiency.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!