Best Cerberus-source code snippet using org.cerberus.servlet.crud.scheduleentry.DeleteScheduleEntry.processRequest
Source:DeleteScheduleEntry.java
...61 * @param response servlet response62 * @throws ServletException if a servlet-specific error occurs63 * @throws IOException if an I/O error occurs64 */65 protected void processRequest(HttpServletRequest request, HttpServletResponse response)66 throws ServletException, IOException, JSONException {67 JSONObject jsonResponse = new JSONObject();68 Answer ans = new AnswerItem<>();69 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);70 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));71 ans.setResultMessage(msg);72 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);73 response.setContentType("application/json");74 // Calling Servlet Transversal Util.75 ServletUtil.servletStart(request);76 /**77 * Parsing and securing all required parameters.78 */79 Integer id = ParameterParserUtil.parseIntegerParam(request.getParameter("id"), 0);80 /**81 * Checking all constrains before calling the services.82 */83 if (id == null || id == 0) {84 msg = new MessageEvent(MessageEventEnum.SCHEDULER_ERROR_EXPECTED);85 msg.setDescription(msg.getDescription().replace("%ITEM%", "campaign")86 .replace("%OPERATION%", "Delete")87 .replace("%REASON%", "Some mendatory fields are missing!"));88 ans.setResultMessage(msg);89 } else {90 /**91 * All data seems cleans so we can call the services.92 */93 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());94 IScheduleEntryService scheduleEntryService = appContext.getBean(IScheduleEntryService.class);95 ScheduleEntry scheduleEntry = scheduleEntryService.readbykey(id).getItem();96 ans = scheduleEntryService.delete(scheduleEntry);97 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {98 /**99 * Object created. Updating scheduler version.100 */101 IMyVersionService myVersionService = appContext.getBean(IMyVersionService.class);102 myVersionService.updateMyVersionString("scheduler_version", String.valueOf(new Date()));103 /**104 * Object created. Adding Log entry.105 */106 ILogEventService logEventService = appContext.getBean(LogEventService.class);107 IFactoryLogEvent factoryLogEvent = appContext.getBean(FactoryLogEvent.class);108 logEventService.createForPrivateCalls("/DeleteScheduleEntry", "DELETE", "Delete schedule entry : ['" + scheduleEntry.getName() + "']", request);109 }110 }111 /**112 * Formating and returning the json result.113 */114 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());115 jsonResponse.put("message", ans.getResultMessage().getDescription());116 response.getWriter().print(jsonResponse);117 response.getWriter().flush();118 }119 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">120 /**121 * Handles the HTTP <code>GET</code> method.122 *123 * @param request servlet request124 * @param response servlet response125 * @throws ServletException if a servlet-specific error occurs126 * @throws IOException if an I/O error occurs127 */128 @Override129 protected void doGet(HttpServletRequest request, HttpServletResponse response)130 throws ServletException, IOException {131 try {132 processRequest(request, response);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 (JSONException ex) {151 LOG.warn(ex);152 }153 }154 /**155 * Returns a short description of the servlet.156 *157 * @return a String containing servlet description158 */159 @Override160 public String getServletInfo() {161 return "Short description";162 }// </editor-fold>163}...
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!!