How to use processRequest method of org.cerberus.servlet.crud.batch.DeleteBatchInvariant class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.batch.DeleteBatchInvariant.processRequest

Source:DeleteBatchInvariant.java Github

copy

Full Screen

...60 * @param response servlet response61 * @throws ServletException if a servlet-specific error occurs62 * @throws IOException if an I/O error occurs63 */64 protected void processRequest(HttpServletRequest request, HttpServletResponse response)65 throws ServletException, IOException, CerberusException, JSONException {66 JSONObject jsonResponse = new JSONObject();67 Answer ans = new Answer();68 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);69 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));70 ans.setResultMessage(msg);71 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);72 response.setContentType("application/json");73 // Calling Servlet Transversal Util.74 ServletUtil.servletStart(request);75 76 /**77 * Parsing and securing all required parameters.78 */79 String batch = policy.sanitize(request.getParameter("batch"));80 /**81 * Checking all constrains before calling the services.82 */83 if (StringUtil.isNullOrEmpty(batch)) {84 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);85 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)86 .replace("%OPERATION%", "Delete")87 .replace("%REASON%", "Batch is 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 IBatchInvariantService batchInvariantService = appContext.getBean(IBatchInvariantService.class);95 AnswerItem resp = batchInvariantService.readByKey(batch);96 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem()!=null)) {97 /**98 * Object could not be found. We stop here and report the error.99 */100 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);101 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)102 .replace("%OPERATION%", "Delete")103 .replace("%REASON%", "Batch does not exist."));104 ans.setResultMessage(msg);105 } else {106 /**107 * The service was able to perform the query and confirm the108 * object exist, then we can delete it.109 */110 BatchInvariant batchInvariantData = (BatchInvariant) resp.getItem();111 ans = batchInvariantService.delete(batchInvariantData);112 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {113 /**114 * Delete was successful. Adding Log entry.115 */116 ILogEventService logEventService = appContext.getBean(LogEventService.class);117 logEventService.createForPrivateCalls("/DeleteBatchInvariant", "DELETE", "Delete BatchInvariant : ['" + batch + "']", request);118 }119 }120 }121 /**122 * Formating and returning the json result.123 */124 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());125 jsonResponse.put("message", ans.getResultMessage().getDescription());126 response.getWriter().print(jsonResponse.toString());127 response.getWriter().flush();128 }129// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">130 /**131 * Handles the HTTP <code>GET</code> method.132 *133 * @param request servlet request134 * @param response servlet response135 * @throws ServletException if a servlet-specific error occurs136 * @throws IOException if an I/O error occurs137 */138 @Override139 protected void doGet(HttpServletRequest request, HttpServletResponse response)140 throws ServletException, IOException {141 try {142 processRequest(request, response);143 } catch (CerberusException ex) {144 LOG.warn(ex);145 } catch (JSONException ex) {146 LOG.warn(ex);147 }148 }149 /**150 * Handles the HTTP <code>POST</code> method.151 *152 * @param request servlet request153 * @param response servlet response154 * @throws ServletException if a servlet-specific error occurs155 * @throws IOException if an I/O error occurs156 */157 @Override158 protected void doPost(HttpServletRequest request, HttpServletResponse response)159 throws ServletException, IOException {160 try {161 processRequest(request, response);162 } catch (CerberusException ex) {163 LOG.warn(ex);164 } catch (JSONException ex) {165 LOG.warn(ex);166 }167 }168 /**169 * Returns a short description of the servlet.170 *171 * @return a String containing servlet description172 */173 @Override174 public String getServletInfo() {175 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 DeleteBatchInvariant

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful