Best Cerberus-source code snippet using org.cerberus.servlet.crud.testcampaign.UpdateCampaign.getScheduleEntryListFromParameter
Source:UpdateCampaign.java
...118 String manualExecution = ParameterParserUtil.parseStringParam(request.getParameter("ManualExecution"), "");119 // Getting list of application from JSON Call120 JSONArray objSchedEntryArray = new JSONArray(request.getParameter("SchedulerList"));121 List<ScheduleEntry> schList = new ArrayList<>();122 schList = getScheduleEntryListFromParameter(request, appContext, c, objSchedEntryArray);123 if (StringUtil.isNullOrEmpty(c)) {124 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);125 msg.setDescription(msg.getDescription().replace("%ITEM%", "Campaign")126 .replace("%OPERATION%", "Update")127 .replace("%REASON%", "Campaign name is missing!"));128 finalAnswer.setResultMessage(msg);129 } else {130 // Parameter that we cannot secure as we need the html --> We DECODE them131 //String battery = ParameterParserUtil.parseStringParam(request.getParameter("Batteries"), null);132 String parameter = ParameterParserUtil.parseStringParam(request.getParameter("Parameters"), null);133 String label = ParameterParserUtil.parseStringParam(request.getParameter("Labels"), null);134 ICampaignService campaignService = appContext.getBean(ICampaignService.class);135 AnswerItem resp = campaignService.readByKey(c);136 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {137 /**138 * Object could not be found. We stop here and report the error.139 */140 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);141 } else {142 Campaign camp = (Campaign) resp.getItem();143 camp.setDistribList(distriblist);144 camp.setNotifyStartTagExecution(notifystart);145 camp.setNotifyEndTagExecution(notifyend);146 camp.setDescription(desc);147 camp.setLongDescription(longDesc);148 camp.setGroup1(group1);149 camp.setGroup2(group2);150 camp.setGroup3(group3);151 camp.setSlackChannel(slackChannel);152 camp.setSlackNotifyEndTagExecution(slackNotifyEndTagExecution);153 camp.setSlackNotifyStartTagExecution(slackNotifyStartTagExecution);154 camp.setSlackWebhook(slackWebhook);155 camp.setCIScoreThreshold(cIScoreThreshold);156 camp.setTag(tag);157 camp.setVerbose(verbose);158 camp.setScreenshot(screenshot);159 camp.setPageSource(pageSource);160 camp.setRobotLog(robotLog);161 camp.setTimeout(timeout);162 camp.setRetries(retries);163 camp.setPriority(priority);164 camp.setManualExecution(manualExecution);165 camp.setUsrModif(request.getRemoteUser());166 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);167 msg.setDescription(msg.getDescription().replace("%ITEM%", "Scheduler").replace("%OPERATION%", "No Insert"));168 schedAns.setResultMessage(msg);169 IScheduleEntryService scheduleentryservice = appContext.getBean(IScheduleEntryService.class);170 schedAns = scheduleentryservice.compareSchedListAndUpdateInsertDeleteElements(c, schList);171 if (schedAns.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {172 IMyVersionService myVersionService = appContext.getBean(IMyVersionService.class);173 myVersionService.updateMyVersionString("scheduler_version", String.valueOf(new Date()));174 }175 if (schedAns.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {176 finalAnswer = campaignService.update(camp);177 if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {178 /**179 * Adding Log entry.180 */181 ILogEventService logEventService = appContext.getBean(LogEventService.class);182 logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign : " + c, request);183 }184 if (parameter != null) {185 JSONArray parameters = new JSONArray(parameter);186 ICampaignParameterService campaignParameterService = appContext.getBean(ICampaignParameterService.class);187 IFactoryCampaignParameter factoryCampaignParameter = appContext.getBean(IFactoryCampaignParameter.class);188 ArrayList<CampaignParameter> arr = new ArrayList<>();189 for (int i = 0; i < parameters.length(); i++) {190 JSONArray bat = parameters.getJSONArray(i);191 CampaignParameter co = factoryCampaignParameter.create(0, bat.getString(0), bat.getString(2), bat.getString(3));192 arr.add(co);193 }194 finalAnswer = campaignParameterService.compareListAndUpdateInsertDeleteElements(c, arr);195 if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {196 /**197 * Adding Log entry.198 */199 ILogEventService logEventService = appContext.getBean(LogEventService.class);200 logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign Parameter : " + camp.getCampaign(), request);201 }202 }203 if (label != null) {204 JSONArray labels = new JSONArray(label);205 ICampaignLabelService campaignLabelService = appContext.getBean(ICampaignLabelService.class);206 IFactoryCampaignLabel factoryCampaignLabel = appContext.getBean(IFactoryCampaignLabel.class);207 ArrayList<CampaignLabel> arr = new ArrayList<>();208 for (int i = 0; i < labels.length(); i++) {209 JSONArray bat = labels.getJSONArray(i);210 CampaignLabel co = factoryCampaignLabel.create(0, bat.getString(0), Integer.valueOf(bat.getString(2)), request.getRemoteUser(), null, request.getRemoteUser(), null);211 arr.add(co);212 }213 finalAnswer = campaignLabelService.compareListAndUpdateInsertDeleteElements(c, arr);214 if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {215 /**216 * Adding Log entry.217 */218 ILogEventService logEventService = appContext.getBean(LogEventService.class);219 logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign Label : " + camp.getCampaign(), request);220 }221 }222 } else {223 finalAnswer = schedAns;224 }225 }226 }227 /**228 * Formating and returning the json result.229 */230 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());231 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());232 response.getWriter().print(jsonResponse);233 response.getWriter().flush();234 }235 private List<ScheduleEntry> getScheduleEntryListFromParameter(HttpServletRequest request, ApplicationContext appContext, String campaign, JSONArray json) throws JSONException {236 List<ScheduleEntry> scheList = new ArrayList<>();237 IScheduleEntryService scheService = appContext.getBean(IScheduleEntryService.class);238 IFactoryScheduleEntry scheFactory = appContext.getBean(IFactoryScheduleEntry.class);239 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);240 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();241 for (int i = 0; i < json.length(); i++) {242 JSONObject tcsaJson = json.getJSONObject(i);243 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them244 boolean delete = tcsaJson.getBoolean("toDelete");245 String cronExpression = policy.sanitize(tcsaJson.getString("cronDefinition"));246 String active = policy.sanitize(tcsaJson.getString("active"));247 String strId = tcsaJson.getString("ID");248 String desc = tcsaJson.getString("description");249 String type = "CAMPAIGN";...
getScheduleEntryListFromParameter
Using AI Code Generation
1package org.cerberus.servlet.crud.testcampaign;2import java.io.IOException;3import java.util.ArrayList;4import java.util.List;5import javax.servlet.ServletException;6import javax.servlet.http.HttpServlet;7import javax.servlet.http.HttpServletRequest;8import javax.servlet.http.HttpServletResponse;9import org.apache.logging.log4j.LogManager;10import org.apache.logging.log4j.Logger;11import org.cerberus.crud.entity.ScheduleEntry;12import org.cerberus.crud.factory.IFactoryScheduleEntry;13import org.cerberus.engine.entity.MessageEvent;14import org.cerberus.engine.entity.MessageGeneral;15import org.cerberus.engine.entity.MessageGeneralEnum;16import org.cerberus.enums.MessageEventEnum;17import org.cerberus.exception.CerberusException;18import org.cerberus.exception.FactoryCreationException;19import org.cerberus.factory.IFactoryMessageGeneral;20import org.cerberus.service.ILogEventService;21import org.cerberus.service.IScheduleEntryService;22import org.cerberus.service.ITestCaseExecutionService;23import org.cerberus.service.ITestCaseService;24import org.cerberus.service.ITestCampaignService;25import org.cerberus.service.ITestCaseCountryPropertiesService;26import org.cerberus.service.ITestCaseStepActionControlService;27import org.cerberus.service.ITestCaseStepActionService;28import org.cerberus.service.ITestCaseStepService;29import org.cerberus.service.impl.LogEventService;30import org.cerberus.servlet.crud.testcase.UpdateTestCase;31import org.cerberus.util.answer.Answer;32import org.cerberus.util.answer.AnswerItem;33import org.springframework.context.ApplicationContext;34import org.springframework.web.context.support.WebApplicationContextUtils;35public class UpdateCampaign extends HttpServlet {36 private static final Logger LOG = LogManager.getLogger(UpdateCampaign.class);37 private ITestCampaignService testCampaignService;38 private ITestCaseService testCaseService;39 private ITestCaseExecutionService testCaseExecutionService;40 private ITestCaseStepService testCaseStepService;41 private ITestCaseStepActionService testCaseStepActionService;42 private ITestCaseStepActionControlService testCaseStepActionControlService;43 private ITestCaseCountryPropertiesService testCaseCountryPropertiesService;
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!!