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

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

Source:UpdateApplicationObject.java Github

copy

Full Screen

...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 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);75 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));76 ans.setResultMessage(msg);77 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();78 response.setContentType("application/json");79 // Calling Servlet Transversal Util.80 ServletUtil.servletStart(request);81 Map<String, String> fileData = new HashMap<String, String>();82 FileItem file = null;83 FileItemFactory factory = new DiskFileItemFactory();84 ServletFileUpload upload = new ServletFileUpload(factory);85 try {86 List<FileItem> fields = upload.parseRequest(request);87 Iterator<FileItem> it = fields.iterator();88 if (!it.hasNext()) {89 return;90 }91 while (it.hasNext()) {92 FileItem fileItem = it.next();93 boolean isFormField = fileItem.isFormField();94 if (isFormField) {95 fileData.put(fileItem.getFieldName(), fileItem.getString("UTF-8"));96 } else {97 file = fileItem;98 }99 }100 } catch (FileUploadException e) {101 e.printStackTrace();102 }103 /**104 * Parsing and securing all required parameters.105 */106 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them107 // Parameter that needs to be secured --> We SECURE+DECODE them108 String application = ParameterParserUtil.parseStringParamAndDecode(fileData.get("application"), null, charset);109 String object = ParameterParserUtil.parseStringParamAndDecode(fileData.get("object"), null, charset);110 String value = ParameterParserUtil.parseStringParam(fileData.get("value"), null);111 String usrmodif = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getRemoteUser(), "", charset);112 String datemodif = new Timestamp(new java.util.Date().getTime()).toString();113 // Parameter that we cannot secure as we need the html --> We DECODE them114 // Getting list of application from JSON Call115 // 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%", "ApplicationObject")124 .replace("%OPERATION%", "Update")125 .replace("%REASON%", "Application name (applicationobject) is missing."));126 ans.setResultMessage(msg);127 } else if (StringUtil.isNullOrEmpty(object)) {128 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);129 msg.setDescription(msg.getDescription().replace("%ITEM%", "ApplicationObject")130 .replace("%OPERATION%", "Update")131 .replace("%REASON%", "Object name (applicationobject) is missing."));132 ans.setResultMessage(msg);133 } else {134 /**135 * All data seems cleans so we can call the services.136 */137 IApplicationObjectService applicationObjectService = appContext.getBean(IApplicationObjectService.class);138 AnswerItem resp = applicationObjectService.readByKey(application, object);139 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {140 /**141 * Object could not be found. We stop here and report the error.142 */143 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);144 } else {145 /**146 * The service was able to perform the query and confirm the147 * object exist, then we can update it.148 */149 ApplicationObject applicationData = (ApplicationObject) resp.getItem();150 String fileName = applicationData.getScreenShotFileName();151 if (file != null) {152 ans = applicationObjectService.uploadFile(applicationData.getID(), file);153 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {154 fileName = file.getName();155 }156 }157 applicationData.setValue(value);158 applicationData.setScreenShotFileName(fileName);159 applicationData.setUsrModif(usrmodif);160 applicationData.setDateModif(datemodif);161 ans = applicationObjectService.update(applicationData.getApplication(), applicationData.getObject(), applicationData);162 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);163 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {164 /**165 * Update was successful. Adding Log entry.166 */167 ILogEventService logEventService = appContext.getBean(LogEventService.class);168 logEventService.createForPrivateCalls("/UpdateApplicationObject", "UPDATE", "Updated Application Object : ['" + application + "'|'" + object + "']", request);169 }170 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);171 }172 }173 /**174 * Formating and returning the json result.175 */176 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());177 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());178 response.getWriter().print(jsonResponse);179 response.getWriter().flush();180 }181 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">182 /**183 * Handles the HTTP <code>GET</code> method.184 *185 * @param request servlet request186 * @param response servlet response187 * @throws ServletException if a servlet-specific error occurs188 * @throws IOException if an I/O error occurs189 */190 @Override191 protected void doGet(HttpServletRequest request, HttpServletResponse response)192 throws ServletException, IOException {193 try {194 processRequest(request, response);195 } catch (CerberusException ex) {196 LOG.warn(ex);197 } catch (JSONException ex) {198 LOG.warn(ex);199 }200 }201 /**202 * Handles the HTTP <code>POST</code> method.203 *204 * @param request servlet request205 * @param response servlet response206 * @throws ServletException if a servlet-specific error occurs207 * @throws IOException if an I/O error occurs208 */209 @Override210 protected void doPost(HttpServletRequest request, HttpServletResponse response)211 throws ServletException, IOException {212 try {213 processRequest(request, response);214 } catch (CerberusException ex) {215 LOG.warn(ex);216 } catch (JSONException ex) {217 LOG.warn(ex);218 }219 }220 /**221 * Returns a short description of the servlet.222 *223 * @return a String containing servlet description224 */225 @Override226 public String getServletInfo() {227 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 UpdateApplicationObject

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful