Best Cerberus-source code snippet using org.cerberus.servlet.zzpublic.NewBuildRevisionV000
Source:NewBuildRevisionV000.java
...47import org.cerberus.service.email.entity.Email;48/**49 * @author vertigo50 */51@WebServlet(name = "NewBuildRevisionV000", urlPatterns = {"/NewBuildRevisionV000"})52public class NewBuildRevisionV000 extends HttpServlet {53 private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger("NewBuildRevisionV000");54 private final String OPERATION = "New Build/Revision";55 private final String PARAMETERALL = "ALL";56 /**57 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>58 * methods.59 *60 * @param request servlet request61 * @param response servlet response62 * @throws ServletException if a servlet-specific error occurs63 * @throws IOException if an I/O error occurs64 */65 protected void processRequest(HttpServletRequest request, HttpServletResponse response)66 throws ServletException, IOException {67 PrintWriter out = response.getWriter();68 String charset = request.getCharacterEncoding();69 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());70 /**71 * Adding Log entry.72 */73 ILogEventService logEventService = appContext.getBean(ILogEventService.class);74 logEventService.createForPublicCalls("/NewBuildRevisionV000", "CALL", "NewBuildRevisionV000 called : " + request.getRequestURL(), request);75 ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);76 IInvariantService invariantService = appContext.getBean(IInvariantService.class);77 IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);78 IEmailService emailService = appContext.getBean(IEmailService.class);79 IEmailGenerationService emailGenerationService = appContext.getBean(IEmailGenerationService.class);80 ICountryEnvParam_logService countryEnvParam_logService = appContext.getBean(ICountryEnvParam_logService.class);81 IParameterService parameterService = appContext.getBean(IParameterService.class);82 // Parsing all parameters.83 String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);84 String country = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("country"), "", charset);85 String environment = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("environment"), "", charset);86 String build = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("build"), "", charset);87 String revision = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("revision"), "", charset);88 String helpMessage = "\nThis servlet is used to inform Cerberus that a new Build and Revision has been deployed on a system.\n\nParameter list :\n"89 + "- system [mandatory] : the system where the Build Revision has been deployed. [" + system + "]\n"90 + "- country [mandatory] : the country where the Build Revision has been deployed. You can use ALL if you want to perform the action for all countries that exist for the given system and environement. [" + country + "]\n"91 + "- environment [mandatory] : the environment where the Build Revision has been deployed. [" + environment + "]\n"92 + "- build [mandatory] : the build that has been deployed. [" + build + "]\n"93 + "- revision [mandatory] : the revision that has been deployed. [" + revision + "]\n";94 boolean error = false;95 // Checking the parameter validity. If application has been entered, does it exist ?96 if (system.equalsIgnoreCase("")) {97 out.println("Error - Parameter system is mandatory.");98 error = true;99 }100 if (!system.equalsIgnoreCase("") && !invariantService.isInvariantExist("SYSTEM", system)) {101 out.println("Error - System does not exist : " + system);102 error = true;103 }104 if (environment.equalsIgnoreCase("")) {105 out.println("Error - Parameter environment is mandatory.");106 error = true;107 }108 if (!environment.equalsIgnoreCase("") && !invariantService.isInvariantExist("ENVIRONMENT", environment)) {109 out.println("Error - Environment does not exist : " + environment);110 error = true;111 }112 if (country.equalsIgnoreCase("")) {113 out.println("Error - Parameter country is mandatory.");114 error = true;115 } else if (!country.equalsIgnoreCase(PARAMETERALL)) {116 if (!invariantService.isInvariantExist("COUNTRY", country)) {117 out.println("Error - Country does not exist : " + country);118 error = true;119 }120 if (!error) {121 if (!countryEnvParamService.exist(system, country, environment)) {122 out.println("Error - System/Country/Environment does not exist : " + system + "/" + country + "/" + environment);123 error = true;124 }125 }126 }127 if (build.equalsIgnoreCase("")) {128 out.println("Error - Parameter build is mandatory.");129 error = true;130 }131 if (!build.equalsIgnoreCase("") && !buildRevisionInvariantService.exist(system, 1, build)) {132 out.println("Error - Build does not exist : " + build);133 error = true;134 }135 if (revision.equalsIgnoreCase("")) {136 out.println("Error - Parameter revision is mandatory.");137 error = true;138 }139 if (!revision.equalsIgnoreCase("") && !buildRevisionInvariantService.exist(system, 2, revision)) {140 out.println("Error - Revision does not exist : " + revision);141 error = true;142 }143 // Starting the database update only when no blocking error has been detected.144 if (error == false) {145 /**146 * Getting the list of objects to treat.147 */148 // We update the object.149 MessageEvent msg = new MessageEvent(MessageEventEnum.GENERIC_OK);150 Answer finalAnswer = new Answer(msg);151 AnswerList answerList = new AnswerList();152 if (country.equalsIgnoreCase(PARAMETERALL)) {153 country = null;154 }155 answerList = countryEnvParamService.readByVarious(system, country, environment, null, null, null);156 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) answerList);157 for (CountryEnvParam cepData : (List<CountryEnvParam>) answerList.getDataList()) {158 // Email Calculation. Email must be calcuated before we update the Build and revision in order to have the old build revision still available in the mail.159 String OutputMessage = "";160 Email email = null;161 try {162 email = emailGenerationService.generateRevisionChangeEmail(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), build, revision);163 } catch (Exception ex) {164 LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", ex);165 logEventService.createForPrivateCalls("/NewBuildRevisionV000", "NEWBUILDREV", "Warning on New Build/Revision environment : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "'] " + ex.getMessage(), request);166 OutputMessage = ex.getMessage();167 }168 /**169 * For each object, we can update it.170 */171 cepData.setBuild(build);172 cepData.setRevision(revision);173 cepData.setActive(true);174 Answer answerUpdate = countryEnvParamService.update(cepData);175 if (!(answerUpdate.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()))) {176 /**177 * Object could not be updated. We stop here and report the178 * error.179 */180 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerUpdate);181 } else {182 /**183 * Update was successful.184 */185 // Adding Log entry.186 logEventService.createForPrivateCalls("/NewBuildRevisionV000", "UPDATE", "Updated CountryEnvParam : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "']", request);187 // Adding CountryEnvParam Log entry.188 countryEnvParam_logService.createLogEntry(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), build, revision, "New Build Revision.", "PublicCall");189 /**190 * Email notification.191 */192 try {193 //Sending the email194 emailService.sendHtmlMail(email);195 } catch (Exception e) {196 LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", e);197 logEventService.createForPrivateCalls("/NewBuildRevisionV000", "NEWBUILDREV", "Warning on New Build/Revision environment : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "'] " + e.getMessage(), request);198 OutputMessage = e.getMessage();199 }200 if (OutputMessage.equals("")) {201 msg = new MessageEvent(MessageEventEnum.GENERIC_OK);202 Answer answerSMTP = new AnswerList(msg);203 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);204 } else {205 msg = new MessageEvent(MessageEventEnum.GENERIC_WARNING);206 msg.setDescription(msg.getDescription().replace("%REASON%", OutputMessage + " when sending email for " + cepData.getSystem() + "/" + cepData.getCountry() + "/" + cepData.getEnvironment()));207 Answer answerSMTP = new AnswerList(msg);208 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);209 }210 }211 }...
NewBuildRevisionV000
Using AI Code Generation
1NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();2buildRevision.doService(request, response);3NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();4buildRevision.doService(request, response);5NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();6buildRevision.doService(request, response);7NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();8buildRevision.doService(request, response);9NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();10buildRevision.doService(request, response);11NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();12buildRevision.doService(request, response);13NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();14buildRevision.doService(request, response);15NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();16buildRevision.doService(request, response);17NewBuildRevisionV000 buildRevision = new NewBuildRevisionV000();18buildRevision.doService(request
NewBuildRevisionV000
Using AI Code Generation
1import org.cerberus.servlet.zzpublic.NewBuildRevisionV000;2if (request.getMethod().equals("POST")) {3 String build = request.getParameter("build");4 String application = request.getParameter("application");5 String environment = request.getParameter("environment");6 String country = request.getParameter("country");7 String description = request.getParameter("description");8 NewBuildRevisionV000 newBuildRevision = new NewBuildRevisionV000();9 String newRevision = newBuildRevision.createNewRevision(build, application, environment, country, description);10 response.setContentType("application/json");11 response.setCharacterEncoding("UTF-8");12 response.getWriter().write("{\"revision\": \""+newRevision+"\"}");13} else {14 response.setContentType("text/plain");15 response.setCharacterEncoding("UTF-8");16 response.getWriter().write("ERROR: must be called from a POST method");17}
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!!