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

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

Source:DeleteBuildRevisionParameters.java Github

copy

Full Screen

...58 * @param response servlet response59 * @throws ServletException if a servlet-specific error occurs60 * @throws IOException if an I/O error occurs61 */62 protected void processRequest(HttpServletRequest request, HttpServletResponse response)63 throws ServletException, IOException, CerberusException, JSONException {64 JSONObject jsonResponse = new JSONObject();65 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());66 ILogEventService logEventService = appContext.getBean(LogEventService.class);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 Integer brpid = 0;76 String[] myId = request.getParameterValues("id");77 StringBuilder output_message = new StringBuilder();78 MessageEvent final_msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);79 int massErrorCounter = 0;80 for (String myId1 : myId) {81 /**82 * Parsing and securing all required parameters.83 */84 brpid = 0;85 boolean brpid_error = true;86 try {87 if (myId1 != null && !myId1.equals("")) {88 brpid = Integer.valueOf(policy.sanitize(myId1));89 brpid_error = false;90 }91 } catch (Exception ex) {92 brpid_error = true;93 }94 /**95 * Checking all constrains before calling the services.96 */97 if (brpid_error) {98 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);99 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)100 .replace("%OPERATION%", "Delete")101 .replace("%REASON%", "BuildRevisionParameters ID (id) : Could not manage to convert id to an integer value or id is missing."));102 ans.setResultMessage(msg);103 massErrorCounter++;104 output_message.append("<br>id : ").append(myId1).append(" - ").append(msg.getDescription());105 } else {106 /**107 * All data seems cleans so we can call the services.108 */109 IBuildRevisionParametersService brpService = appContext.getBean(IBuildRevisionParametersService.class);110 AnswerItem resp = brpService.readByKeyTech(brpid);111 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {112 /**113 * Object could not be found. We stop here and report the114 * error.115 */116 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);117 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)118 .replace("%OPERATION%", "Delete")119 .replace("%REASON%", "BuildRevisionParameter does not exist."));120 ans.setResultMessage(msg);121 massErrorCounter++;122 output_message.append("<br>id : ").append(myId1).append(" - ").append(msg.getDescription());123 } else {124 /**125 * The service was able to perform the query and confirm the126 * object exist, then we can delete it.127 */128 BuildRevisionParameters brpData = (BuildRevisionParameters) resp.getItem();129 ans = brpService.delete(brpData);130 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {131 /**132 * Delete was successful. Adding Log entry.133 */134 logEventService.createForPrivateCalls("/DeleteBuildRevisionParameters", "DELETE", "Delete BuildRevisionParameters : ['" + brpid + "'|'" + brpData.getRelease() + "']", request);135 } else {136 massErrorCounter++;137 output_message.append("<br>id : ").append(myId1).append(" - ").append(ans.getResultMessage().getDescription());138 }139 }140 }141 }142 if (myId.length > 1) {143 if (massErrorCounter == myId.length) { // All updates are in ERROR.144 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);145 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)146 .replace("%OPERATION%", "Mass Update")147 .replace("%REASON%", massErrorCounter + " objects(s) out of " + myId.length + " failed to update due to an issue.<br>") + output_message.toString());148 ans.setResultMessage(msg);149 } else if (massErrorCounter > 0) { // At least 1 update in error150 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING);151 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)152 .replace("%OPERATION%", "Mass Update")153 .replace("%REASON%", massErrorCounter + " objects(s) out of " + myId.length + " failed to update due to an issue.<br>") + output_message.toString());154 ans.setResultMessage(msg);155 } else { // No error detected.156 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);157 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)158 .replace("%OPERATION%", "Mass Update") + "\n\nAll " + myId.length + " object(s) updated successfuly.");159 ans.setResultMessage(msg);160 }161 logEventService.createForPrivateCalls("/DeleteBuildRevisionParameters", "MASSUPDATE", msg.getDescription(), request);162 }163 /**164 * Formating and returning the json result.165 */166 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());167 jsonResponse.put("message", ans.getResultMessage().getDescription());168 response.getWriter().print(jsonResponse.toString());169 response.getWriter().flush();170 }171// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">172 /**173 * Handles the HTTP <code>GET</code> method.174 *175 * @param request servlet request176 * @param response servlet response177 * @throws ServletException if a servlet-specific error occurs178 * @throws IOException if an I/O error occurs179 */180 @Override181 protected void doGet(HttpServletRequest request, HttpServletResponse response)182 throws ServletException, IOException {183 try {184 processRequest(request, response);185 } catch (CerberusException ex) {186 LOG.warn(ex);187 } catch (JSONException ex) {188 LOG.warn(ex);189 }190 }191 /**192 * Handles the HTTP <code>POST</code> method.193 *194 * @param request servlet request195 * @param response servlet response196 * @throws ServletException if a servlet-specific error occurs197 * @throws IOException if an I/O error occurs198 */199 @Override200 protected void doPost(HttpServletRequest request, HttpServletResponse response)201 throws ServletException, IOException {202 try {203 processRequest(request, response);204 } catch (CerberusException ex) {205 LOG.warn(ex);206 } catch (JSONException ex) {207 LOG.warn(ex);208 }209 }210 /**211 * Returns a short description of the servlet.212 *213 * @return a String containing servlet description214 */215 @Override216 public String getServletInfo() {217 return "Short description";...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.crud.buildrevisionchange;2import java.io.IOException;3import java.util.logging.Level;4import java.util.logging.Logger;5import javax.servlet.ServletException;6import javax.servlet.annotation.WebServlet;7import javax.servlet.http.HttpServlet;8import javax.servlet.http.HttpServletRequest;9import javax.servlet.http.HttpServletResponse;10import org.cerberus.crud.entity.BuildRevisionParameters;11import org.cerberus.crud.factory.IFactoryBuildRevisionParameters;12import org.cerberus.crud.service.IBuildRevisionParametersService;13import org.cerberus.engine.entity.MessageEvent;14import org.cerberus.engine.entity.MessageGeneral;15import org.cerberus.exception.CerberusException;16import org.cerberus.log.MyLogger;17import org.cerberus.service.json.IJsonService;18import org.cerberus.servlet.api.IApiService;19import org.cerberus.servlet.api.IApiService.ApiServiceEnum;20import org.json.JSONArray;21import org.json.JSONException;22import org.json.JSONObject;23import org.springframework.beans.factory.annotation.Autowired;24import org.springframework.context.ApplicationContext;25import org.springframework.web.context.support.WebApplicationContextUtils;26@WebServlet(name = "DeleteBuildRevisionParameters", urlPatterns = {"/DeleteBuildRevisionParameters"})27public class DeleteBuildRevisionParameters extends HttpServlet {28 private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(DeleteBuildRevisionParameters.class);29 private IApiService apiService;30 private IFactoryBuildRevisionParameters factoryBuildRevisionParameters;31 private IBuildRevisionParametersService buildRevisionParametersService;32 private IJsonService jsonService;33 public void init() throws ServletException {34 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());35 apiService = appContext.getBean(IApiService.class);36 factoryBuildRevisionParameters = appContext.getBean(IFactoryBuildRevisionParameters.class);37 buildRevisionParametersService = appContext.getBean(IBuildRevisionParametersService.class);38 jsonService = appContext.getBean(IJsonService.class);39 }40 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {41 String charset = request.getCharacterEncoding();42 String data = apiService.readRequestData(request);

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 DeleteBuildRevisionParameters

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful