How to use processRequest method of org.cerberus.servlet.crud.countryenvironment.UpdateApplication class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.countryenvironment.UpdateApplication.processRequest

Source:UpdateApplication.java Github

copy

Full Screen

...66 * @param response servlet response67 * @throws ServletException if a servlet-specific error occurs68 * @throws IOException if an I/O error occurs69 */70 protected void processRequest(HttpServletRequest request, HttpServletResponse response)71 throws ServletException, IOException, CerberusException, JSONException {72 JSONObject jsonResponse = new JSONObject();73 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());74 Answer ans = new Answer();75 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);76 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));77 ans.setResultMessage(msg);78 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);79 String charset = request.getCharacterEncoding();80 ICountryEnvironmentParametersService ceaService = appContext.getBean(ICountryEnvironmentParametersService.class);81 IFactoryCountryEnvironmentParameters cedFactory = appContext.getBean(IFactoryCountryEnvironmentParameters.class);82 response.setContentType("application/json");83 // Calling Servlet Transversal Util.84 ServletUtil.servletStart(request);85 /**86 * Parsing and securing all required parameters.87 */88 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them89 String system = policy.sanitize(request.getParameter("system"));90 String type = policy.sanitize(request.getParameter("type"));91 String deployType = policy.sanitize(request.getParameter("deploytype"));92 // Parameter that needs to be secured --> We SECURE+DECODE them93 String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), null, charset);94 String originalApplication = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("originalApplication"), null, charset);95 String subSystem = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("subsystem"), "", charset);96 String mavenGpID = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavengroupid"), "", charset);97 String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);98 // Parameter that we cannot secure as we need the html --> We DECODE them99 String svnURL = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("svnurl"), "", charset);100 String bugTrackerURL = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("bugtrackerurl"), "", charset);101 String newBugURL = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("bugtrackernewurl"), "", charset);102 Integer sort = 10;103 boolean sort_error = false;104 try {105 if (request.getParameter("sort") != null && !request.getParameter("sort").equals("")) {106 sort = Integer.valueOf(policy.sanitize(request.getParameter("sort")));107 }108 } catch (Exception ex) {109 sort_error = true;110 }111 // Getting list of application from JSON Call112 JSONArray objApplicationArray = new JSONArray(request.getParameter("environmentList"));113 List<CountryEnvironmentParameters> ceaList = new ArrayList();114 ceaList = getCountryEnvironmentApplicationFromParameter(request, appContext, system, application, objApplicationArray);115 // Prepare the final answer.116 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);117 Answer finalAnswer = new Answer(msg1);118 /**119 * Checking all constrains before calling the services.120 */121 if (StringUtil.isNullOrEmpty(application)) {122 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);123 msg.setDescription(msg.getDescription().replace("%ITEM%", "Application")124 .replace("%OPERATION%", "Update")125 .replace("%REASON%", "Application ID (application) is missing."));126 ans.setResultMessage(msg);127 } else if (StringUtil.isNullOrEmpty(system)) {128 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);129 msg.setDescription(msg.getDescription().replace("%ITEM%", "Application")130 .replace("%OPERATION%", "Update")131 .replace("%REASON%", "System is missing!"));132 ans.setResultMessage(msg);133 } else if (sort_error) {134 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);135 msg.setDescription(msg.getDescription().replace("%ITEM%", "Application")136 .replace("%OPERATION%", "Update")137 .replace("%REASON%", "Could not manage to convert sort to an integer value."));138 ans.setResultMessage(msg);139 } else {140 /**141 * All data seems cleans so we can call the services.142 */143 IApplicationService applicationService = appContext.getBean(IApplicationService.class);144 AnswerItem resp = applicationService.readByKey(originalApplication);145 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {146 /**147 * Object could not be found. We stop here and report the error.148 */149 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);150 } else {151 /**152 * The service was able to perform the query and confirm the153 * object exist, then we can update it.154 */155 Application applicationData = (Application) resp.getItem();156 applicationData.setApplication(application);157 applicationData.setSystem(system);158 applicationData.setSubsystem(subSystem);159 applicationData.setType(type);160 applicationData.setMavengroupid(mavenGpID);161 applicationData.setDeploytype(deployType);162 applicationData.setSvnurl(svnURL);163 applicationData.setBugTrackerUrl(bugTrackerURL);164 applicationData.setBugTrackerNewUrl(newBugURL);165 applicationData.setDescription(description);166 applicationData.setSort(sort);167 applicationData.setUsrModif(request.getRemoteUser());168 ans = applicationService.update(originalApplication, applicationData);169 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);170 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {171 /**172 * Update was successful. Adding Log entry.173 */174 ILogEventService logEventService = appContext.getBean(LogEventService.class);175 logEventService.createForPrivateCalls("/UpdateApplication", "UPDATE", "Updated Application : ['" + originalApplication + "']", request);176 // Update the Database with the new list.177 ans = ceaService.compareListAndUpdateInsertDeleteElements(system, application, ceaList);178 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);179 }180 }181 }182 /**183 * Formating and returning the json result.184 */185 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());186 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());187 response.getWriter().print(jsonResponse);188 response.getWriter().flush();189 }190 private List<CountryEnvironmentParameters> getCountryEnvironmentApplicationFromParameter(HttpServletRequest request, ApplicationContext appContext, String system, String application, JSONArray json) throws JSONException {191 List<CountryEnvironmentParameters> cedList = new ArrayList();192 ICountryEnvironmentParametersService ceaService = appContext.getBean(ICountryEnvironmentParametersService.class);193 IFactoryCountryEnvironmentParameters cedFactory = appContext.getBean(IFactoryCountryEnvironmentParameters.class);194 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);195 String charset = request.getCharacterEncoding();196 for (int i = 0; i < json.length(); i++) {197 JSONObject tcsaJson = json.getJSONObject(i);198 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them199 boolean delete = tcsaJson.getBoolean("toDelete");200 String country = policy.sanitize(tcsaJson.getString("country"));201 String environment = policy.sanitize(tcsaJson.getString("environment"));202 // Parameter that needs to be secured --> We SECURE+DECODE them203 // Parameter that we cannot secure as we need the html --> We DECODE them204 String ip = tcsaJson.getString("ip");205 String domain = tcsaJson.getString("domain");206 String url = tcsaJson.getString("url");207 String urlLogin = tcsaJson.getString("urlLogin");208 String var1 = tcsaJson.getString("var1");209 String var2 = tcsaJson.getString("var2");210 String var3 = tcsaJson.getString("var3");211 String var4 = tcsaJson.getString("var4");212 String strPoolSize = tcsaJson.getString("poolSize");213 int poolSize;214 if (strPoolSize.isEmpty()) {215 poolSize = CountryEnvironmentParameters.DEFAULT_POOLSIZE;216 } else {217 try {218 poolSize = Integer.parseInt(strPoolSize);219 } catch (NumberFormatException e) {220 LOG.warn("Unable to parse pool size: " + strPoolSize + ". Applying default value");221 poolSize = CountryEnvironmentParameters.DEFAULT_POOLSIZE;222 }223 }224 if (!delete) {225 CountryEnvironmentParameters ced = cedFactory.create(system, country, environment, application, ip, domain, url, urlLogin, var1, var2, var3, var4, poolSize);226 cedList.add(ced);227 }228 }229 return cedList;230 }231 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">232 /**233 * Handles the HTTP <code>GET</code> method.234 *235 * @param request servlet request236 * @param response servlet response237 * @throws ServletException if a servlet-specific error occurs238 * @throws IOException if an I/O error occurs239 */240 @Override241 protected void doGet(HttpServletRequest request, HttpServletResponse response)242 throws ServletException, IOException {243 try {244 processRequest(request, response);245 } catch (CerberusException ex) {246 LOG.warn(ex);247 } catch (JSONException ex) {248 LOG.warn(ex);249 }250 }251 /**252 * Handles the HTTP <code>POST</code> method.253 *254 * @param request servlet request255 * @param response servlet response256 * @throws ServletException if a servlet-specific error occurs257 * @throws IOException if an I/O error occurs258 */259 @Override260 protected void doPost(HttpServletRequest request, HttpServletResponse response)261 throws ServletException, IOException {262 try {263 processRequest(request, response);264 } catch (CerberusException ex) {265 LOG.warn(ex);266 } catch (JSONException ex) {267 LOG.warn(ex);268 }269 }270 /**271 * Returns a short description of the servlet.272 *273 * @return a String containing servlet description274 */275 @Override276 public String getServletInfo() {277 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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful