How to use processRequest method of org.cerberus.servlet.crud.buildrevisionchange.DeleteBuildRevisionInvariant class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.buildrevisionchange.DeleteBuildRevisionInvariant.processRequest

Source:DeleteBuildRevisionInvariant.java Github

copy

Full Screen

...59 * @param response servlet response60 * @throws ServletException if a servlet-specific error occurs61 * @throws IOException if an I/O error occurs62 */63 protected void processRequest(HttpServletRequest request, HttpServletResponse response)64 throws ServletException, IOException, CerberusException, JSONException {65 JSONObject jsonResponse = new JSONObject();66 Answer ans = new Answer();67 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);68 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));69 ans.setResultMessage(msg);70 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);71 response.setContentType("application/json");72 // Calling Servlet Transversal Util.73 ServletUtil.servletStart(request);74 75 /**76 * Parsing and securing all required parameters.77 */78 String system = policy.sanitize(request.getParameter("system"));79 Integer level = -1;80 boolean level_error = false;81 try {82 if (request.getParameter("level") != null && !request.getParameter("level").isEmpty()) {83 level = Integer.valueOf(policy.sanitize(request.getParameter("level")));84 }85 } catch (Exception ex) {86 level_error = true;87 }88 Integer seq = -1;89 boolean seq_error = false;90 try {91 if (request.getParameter("seq") != null && !request.getParameter("seq").isEmpty()) {92 seq = Integer.valueOf(policy.sanitize(request.getParameter("seq")));93 }94 } catch (Exception ex) {95 seq_error = true;96 }97 /**98 * Checking all constrains before calling the services.99 */100 if (StringUtil.isNullOrEmpty(system)) {101 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);102 msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant")103 .replace("%OPERATION%", "Delete")104 .replace("%REASON%", "System is missing!"));105 ans.setResultMessage(msg);106 } else if (level_error) {107 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);108 msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant")109 .replace("%OPERATION%", "Delete")110 .replace("%REASON%", "Could not manage to convert level to an integer value!"));111 ans.setResultMessage(msg);112 } else if (seq_error) {113 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);114 msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant")115 .replace("%OPERATION%", "Delete")116 .replace("%REASON%", "Could not manage to convert sequence to an integer value!"));117 ans.setResultMessage(msg);118 } else {119 /**120 * All data seems cleans so we can call the services.121 */122 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());123 IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);124 AnswerItem resp = buildRevisionInvariantService.readByKey(system, level, seq);125 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem()!=null)) {126 /**127 * Object could not be found. We stop here and report the error.128 */129 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);130 msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant")131 .replace("%OPERATION%", "Delete")132 .replace("%REASON%", "BuildRevisionInvariant does not exist."));133 ans.setResultMessage(msg);134 } else {135 /**136 * The service was able to perform the query and confirm the137 * object exist, then we can delete it.138 */139 BuildRevisionInvariant buildRevisionInvariantData = (BuildRevisionInvariant) resp.getItem();140 ans = buildRevisionInvariantService.delete(buildRevisionInvariantData);141 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {142 /**143 * Delete was successful. Adding Log entry.144 */145 ILogEventService logEventService = appContext.getBean(LogEventService.class);146 logEventService.createForPrivateCalls("/DeleteBuildRevisionInvariant", "DELETE", "Delete BuildRevisionInvariant : ['" + system + "'|'" + level + "'|'" + seq + "']", request);147 }148 }149 }150 /**151 * Formating and returning the json result.152 */153 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());154 jsonResponse.put("message", ans.getResultMessage().getDescription());155 response.getWriter().print(jsonResponse.toString());156 response.getWriter().flush();157 }158// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">159 /**160 * Handles the HTTP <code>GET</code> method.161 *162 * @param request servlet request163 * @param response servlet response164 * @throws ServletException if a servlet-specific error occurs165 * @throws IOException if an I/O error occurs166 */167 @Override168 protected void doGet(HttpServletRequest request, HttpServletResponse response)169 throws ServletException, IOException {170 try {171 processRequest(request, response);172 } catch (CerberusException ex) {173 LOG.warn(ex);174 } catch (JSONException ex) {175 LOG.warn(ex);176 }177 }178 /**179 * Handles the HTTP <code>POST</code> method.180 *181 * @param request servlet request182 * @param response servlet response183 * @throws ServletException if a servlet-specific error occurs184 * @throws IOException if an I/O error occurs185 */186 @Override187 protected void doPost(HttpServletRequest request, HttpServletResponse response)188 throws ServletException, IOException {189 try {190 processRequest(request, response);191 } catch (CerberusException ex) {192 LOG.warn(ex);193 } catch (JSONException ex) {194 LOG.warn(ex);195 }196 }197 /**198 * Returns a short description of the servlet.199 *200 * @return a String containing servlet description201 */202 @Override203 public String getServletInfo() {204 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 DeleteBuildRevisionInvariant

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful