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

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

Source:UpdateBatchInvariant.java Github

copy

Full Screen

...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, CerberusException, JSONException {67 JSONObject jsonResponse = new JSONObject();68 Answer ans = new Answer();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 String charset = request.getCharacterEncoding();74 response.setContentType("application/json");75 // Calling Servlet Transversal Util.76 ServletUtil.servletStart(request);77 78 /**79 * Parsing and securing all required parameters.80 */81 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them82 // Parameter that needs to be secured --> We SECURE+DECODE them83 String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);84 String batch = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("batch"), null, charset);85 String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);86 // Parameter that we cannot secure as we need the html --> We DECODE them87 /**88 * Checking all constrains before calling the services.89 */90 if (StringUtil.isNullOrEmpty(batch)) {91 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);92 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)93 .replace("%OPERATION%", "Update")94 .replace("%REASON%", "Batch is missing!"));95 ans.setResultMessage(msg);96 } else if (StringUtil.isNullOrEmpty(system)) {97 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);98 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)99 .replace("%OPERATION%", "Update")100 .replace("%REASON%", "System name is missing!"));101 ans.setResultMessage(msg);102 } else {103 /**104 * All data seems cleans so we can call the services.105 */106 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());107 IBatchInvariantService batchInvariantService = appContext.getBean(IBatchInvariantService.class);108 AnswerItem resp = batchInvariantService.readByKey(batch);109 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem()!=null)) {110 /**111 * Object could not be found. We stop here and report the error.112 */113 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);114 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)115 .replace("%OPERATION%", "Update")116 .replace("%REASON%", "BatchInvariant does not exist."));117 ans.setResultMessage(msg);118 } else {119 /**120 * The service was able to perform the query and confirm the121 * object exist, then we can update it.122 */123 BatchInvariant batchInvariantData = (BatchInvariant) resp.getItem();124 batchInvariantData.setSystem(system);125 batchInvariantData.setDescription(description);126 ans = batchInvariantService.update(batchInvariantData.getBatch(), batchInvariantData);127 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {128 /**129 * Update was successful. Adding Log entry.130 */131 ILogEventService logEventService = appContext.getBean(LogEventService.class);132 logEventService.createForPrivateCalls("/UpdateBatchInvariant", "UPDATE", "Updated BatchInvariant : ['" + batch + "']", request);133 }134 }135 }136 /**137 * Formating and returning the json result.138 */139 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());140 jsonResponse.put("message", ans.getResultMessage().getDescription());141 response.getWriter().print(jsonResponse);142 response.getWriter().flush();143 }144 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">145 /**146 * Handles the HTTP <code>GET</code> method.147 *148 * @param request servlet request149 * @param response servlet response150 * @throws ServletException if a servlet-specific error occurs151 * @throws IOException if an I/O error occurs152 */153 @Override154 protected void doGet(HttpServletRequest request, HttpServletResponse response)155 throws ServletException, IOException {156 try {157 processRequest(request, response);158 } catch (CerberusException ex) {159 LOG.warn(ex);160 } catch (JSONException ex) {161 LOG.warn(ex);162 }163 }164 /**165 * Handles the HTTP <code>POST</code> method.166 *167 * @param request servlet request168 * @param response servlet response169 * @throws ServletException if a servlet-specific error occurs170 * @throws IOException if an I/O error occurs171 */172 @Override173 protected void doPost(HttpServletRequest request, HttpServletResponse response)174 throws ServletException, IOException {175 try {176 processRequest(request, response);177 } catch (CerberusException ex) {178 LOG.warn(ex);179 } catch (JSONException ex) {180 LOG.warn(ex);181 }182 }183 /**184 * Returns a short description of the servlet.185 *186 * @return a String containing servlet description187 */188 @Override189 public String getServletInfo() {190 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 UpdateBatchInvariant

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful