Best Cerberus-source code snippet using org.cerberus.servlet.crud.testcampaign.UpdateCampaign.processRequest
Source:UpdateCampaign.java
...65 * @param response servlet response66 * @throws ServletException if a servlet-specific error occurs67 * @throws IOException if an I/O error occurs68 */69 protected void processRequest(HttpServletRequest request, HttpServletResponse response)70 throws ServletException, IOException, CerberusException, JSONException {71 JSONObject jsonResponse = new JSONObject();72 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());73 Answer ans = new Answer();74 Answer finalAnswer = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));75 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);76 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));77 ans.setResultMessage(msg);78 response.setContentType("application/json");79 response.setCharacterEncoding("utf8");80 PrintWriter out = response.getWriter();81 String charset = request.getCharacterEncoding();82 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them83 // Parameter that needs to be secured --> We SECURE+DECODE them84 int cID = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("CampaignID"), 0, charset);85 String c = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("Campaign"), null, charset);86 String notifystart = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("NotifyStart"), null, charset);87 String notifyend = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("NotifyEnd"), null, charset);88 String desc = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("Description"), null, charset);89 // Parameter that we cannot secure as we need the html --> We DECODE them90 String distriblist = ParameterParserUtil.parseStringParam(request.getParameter("DistribList"), "");91 if (StringUtil.isNullOrEmpty(c)) {92 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);93 msg.setDescription(msg.getDescription().replace("%ITEM%", "Campaign")94 .replace("%OPERATION%", "Update")95 .replace("%REASON%", "Campaign name is missing!"));96 finalAnswer.setResultMessage(msg);97 } else {98 // Parameter that we cannot secure as we need the html --> We DECODE them99 //String battery = ParameterParserUtil.parseStringParam(request.getParameter("Batteries"), null);100 String parameter = ParameterParserUtil.parseStringParam(request.getParameter("Parameters"), null);101 String label = ParameterParserUtil.parseStringParam(request.getParameter("Labels"), null);102 ICampaignService campaignService = appContext.getBean(ICampaignService.class);103 AnswerItem resp = campaignService.readByKey(c);104 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {105 /**106 * Object could not be found. We stop here and report the error.107 */108 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);109 } else {110 Campaign camp = (Campaign) resp.getItem();111 camp.setDistribList(distriblist);112 camp.setNotifyStartTagExecution(notifystart);113 camp.setNotifyEndTagExecution(notifyend);114 camp.setDescription(desc);115 finalAnswer = campaignService.update(camp);116 if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {117 /**118 * Adding Log entry.119 */120 ILogEventService logEventService = appContext.getBean(LogEventService.class);121 logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign : " + c, request);122 }123 if (parameter != null) {124 JSONArray parameters = new JSONArray(parameter);125 ICampaignParameterService campaignParameterService = appContext.getBean(ICampaignParameterService.class);126 IFactoryCampaignParameter factoryCampaignParameter = appContext.getBean(IFactoryCampaignParameter.class);127 ArrayList<CampaignParameter> arr = new ArrayList<>();128 for (int i = 0; i < parameters.length(); i++) {129 JSONArray bat = parameters.getJSONArray(i);130 CampaignParameter co = factoryCampaignParameter.create(0, bat.getString(0), bat.getString(2), bat.getString(3));131 arr.add(co);132 }133 finalAnswer = campaignParameterService.compareListAndUpdateInsertDeleteElements(c, arr);134 if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {135 /**136 * Adding Log entry.137 */138 ILogEventService logEventService = appContext.getBean(LogEventService.class);139 logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign Parameter : " + camp.getCampaign(), request);140 }141 }142 if (label != null) {143 JSONArray labels = new JSONArray(label);144 ICampaignLabelService campaignLabelService = appContext.getBean(ICampaignLabelService.class);145 IFactoryCampaignLabel factoryCampaignLabel = appContext.getBean(IFactoryCampaignLabel.class);146 ArrayList<CampaignLabel> arr = new ArrayList<>();147 for (int i = 0; i < labels.length(); i++) {148 JSONArray bat = labels.getJSONArray(i);149 CampaignLabel co = factoryCampaignLabel.create(0, bat.getString(0), Integer.valueOf(bat.getString(2)), request.getRemoteUser(), null, request.getRemoteUser(), null);150 arr.add(co);151 }152 finalAnswer = campaignLabelService.compareListAndUpdateInsertDeleteElements(c, arr);153 if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {154 /**155 * Adding Log entry.156 */157 ILogEventService logEventService = appContext.getBean(LogEventService.class);158 logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign Label : " + camp.getCampaign(), request);159 }160 }161 }162 }163 /**164 * Formating and returning the json result.165 */166 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());167 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());168 response.getWriter().print(jsonResponse);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 String t = request.getParameter("value");204 processRequest(request, response);205 } catch (CerberusException ex) {206 LOG.warn(ex);207 } catch (JSONException ex) {208 LOG.warn(ex);209 }210 }211 /**212 * Returns a short description of the servlet.213 *214 * @return a String containing servlet description215 */216 @Override217 public String getServletInfo() {218 return "Short description";...
processRequest
Using AI Code Generation
1 String campaign = request.getParameter("campaign");2 String description = request.getParameter("description");3 String active = request.getParameter("active");4 String maintenanceAct = request.getParameter("maintenanceAct");5 String maintenanceStr = request.getParameter("maintenanceStr");6 String maintenanceEnd = request.getParameter("maintenanceEnd");7 String maintenanceUsr = request.getParameter("maintenanceUsr");8 String maintenancePwd = request.getParameter("maintenancePwd");9 String maintenanceWin = request.getParameter("maintenanceWin");10 String maintenanceWinUsr = request.getParameter("maintenanceWinUsr");11 String maintenanceWinPwd = request.getParameter("maintenanceWinPwd");12 String maintenanceWinDomain = request.getParameter("maintenanceWinDomain");13 String maintenanceWinHost = request.getParameter("maintenanceWinHost");14 String maintenanceWinKey = request.getParameter("maintenanceWinKey");15 String maintenanceWinKeyPwd = request.getParameter("maintenanceWinKeyPwd");16 String maintenanceWinKeyPath = request.getParameter("maintenanceWinKeyPath");17 String maintenanceWinKeyPathPwd = request.getParameter("maintenanceWinKeyPathPwd");18 String maintenanceWinPort = request.getParameter("maintenanceWinPort");19 String maintenanceWinProtocol = request.getParameter("maintenanceWinProtocol");20 String maintenanceWinTimeout = request.getParameter("maintenanceWinTimeout");21 String maintenanceWinVersion = request.getParameter("maintenanceWinVersion");22 String maintenanceWinVncPort = request.getParameter("maintenanceWinVncPort");23 String maintenanceWinVncPwd = request.getParameter("maintenanceWinVncPwd");24 String maintenanceWinVncTimeout = request.getParameter("maintenanceWinVncTimeout");25 String maintenanceWinVncUrl = request.getParameter("maintenanceWinVncUrl");26 String maintenanceWinVncUrlPwd = request.getParameter("maintenanceWinVncUrlPwd");27 String maintenanceWinVncUrlTimeout = request.getParameter("maintenanceWinVncUrlTimeout");28 String maintenanceWinVncUrlUsr = request.getParameter("maintenanceWinVncUrlUsr");29 String maintenanceWinVncUrlVncPort = request.getParameter("maintenanceWinVncUrlVncPort");30 String maintenanceWinVncUrlVncPwd = request.getParameter("maintenanceWinVncUrlVncPwd");31 String maintenanceWinVncUrlVncTimeout = request.getParameter("maintenanceWinVncUrlVncTimeout");32 String maintenanceWinVncUrlVncUsr = request.getParameter("maintenanceWinVncUrl
processRequest
Using AI Code Generation
1importClass(org.cerberus.servlet.crud.testcampaign.UpdateCampaign);2importClass(org.cerberus.util.ParameterParserUtil);3importClass(org.cerberus.util.answer.AnswerItem);4importClass(org.cerberus.util.answer.AnswerUtil);5importClass(org.cerberus.util.answer.AnswerList);6importClass(org.cerberus.util.answer.Answer);7importClass(org.cerberus.util.answer.AnswerItem);8var updateCampaign = new UpdateCampaign();9var parameterParserUtil = new ParameterParserUtil();10var answerItem = new AnswerItem();11var answerUtil = new AnswerUtil();12var answerList = new AnswerList();13var answer = new Answer();14var answerItem = new AnswerItem();15var jsonObject = new JSONObject();16var jsonArray = new JSONArray();17var jsonParser = new JSONParser();18var jsonStringer = new JSONStringer();19var jsonWriter = new JSONWriter();20var jsonString = new JSONString();21var jsonTokener = new JSONTokener();22var jsonStringer = new JSONStringer();23var jsonWriter = new JSONWriter();24var jsonString = new JSONString();25var jsonTokener = new JSONTokener();26var jsonStringer = new JSONStringer();
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!!