Best Cerberus-source code snippet using org.cerberus.crud.entity.RobotExecutor.getDescription
Source:CreateRobot.java
...79 Answer ans = new Answer();80 Gson gson = new Gson();81 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());82 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);83 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));84 ans.setResultMessage(msg);85 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);86 response.setContentType("application/json");87 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();88 /**89 * Parsing and securing all required parameters.90 */91 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them92 // Parameter that needs to be secured --> We SECURE+DECODE them93 String robot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robot"), null, charset);94 String platform = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("platform"), null, charset);95 String browser = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("browser"), null, charset);96 String version = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("version"), "", charset);97 String active = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("active"), "Y", charset);98 String description = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("description"), "", charset);99 String userAgent = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("useragent"), "", charset);100 String screenSize = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("screensize"), "", charset);101 String robotDecli = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("robotDecli"), "", charset);102 String lbexemethod = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("lbexemethod"), "", charset);103 String type = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("type"), "", charset);104 List<RobotCapability> capabilities;105 if (request.getParameter("capabilities") == null) {106 capabilities = Collections.emptyList();107 } else {108 capabilities = gson.fromJson(request.getParameter("capabilities"), new TypeToken<List<RobotCapability>>() {109 }.getType());110 }111 JSONArray objExecutorArray = new JSONArray(request.getParameter("executors"));112 List<RobotExecutor> executors = new ArrayList<>();113 executors = getExecutorsFromParameter(robot, request, appContext, objExecutorArray);114 // Parameter that we cannot secure as we need the html --> We DECODE them115 // Securing capabilities by setting them the associated robot name116 // Check also if there is no duplicated capability117 Map<String, Object> capabilityMap = new HashMap<>();118 for (RobotCapability capability : capabilities) {119 capabilityMap.put(capability.getCapability(), null);120 capability.setRobot(robot);121 }122 Map<String, Object> executorMap = new HashMap<String, Object>();123 for (RobotExecutor executor : executors) {124 executorMap.put(executor.getExecutor(), null);125 executor.setRobot(robot);126 }127 Integer robotid = 0;128 boolean robotid_error = false;129 try {130 if (request.getParameter("robotid") != null && !request.getParameter("robotid").equals("")) {131 robotid = Integer.valueOf(policy.sanitize(request.getParameter("robotid")));132 }133 } catch (Exception ex) {134 robotid_error = true;135 }136 /**137 * Checking all constrains before calling the services.138 */139 if (StringUtil.isNullOrEmpty(robot)) {140 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);141 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")142 .replace("%OPERATION%", "Create")143 .replace("%REASON%", "Robot name is missing."));144 ans.setResultMessage(msg);145 } else if (StringUtil.isNullOrEmpty(platform)) {146 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);147 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")148 .replace("%OPERATION%", "Create")149 .replace("%REASON%", "Robot platform is missing."));150 ans.setResultMessage(msg);151 } else if (robotid_error) {152 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);153 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")154 .replace("%OPERATION%", "Create")155 .replace("%REASON%", "Could not manage to convert robotid to an integer value or robotid is missing."));156 ans.setResultMessage(msg);157 } else if (capabilityMap.size() != capabilities.size()) {158 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);159 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")160 .replace("%OPERATION%", "Create")161 .replace("%REASON%", "There is at least one duplicated capability. Please edit or remove it to continue."));162 ans.setResultMessage(msg);163 } else if (executorMap.size() != executors.size()) {164 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);165 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")166 .replace("%OPERATION%", "Create")167 .replace("%REASON%", "There is at least one duplicated executor. Please edit or remove it to continue."));168 ans.setResultMessage(msg);169 } else if (executorMap.size() < 1) {170 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);171 msg.setDescription(msg.getDescription().replace("%ITEM%", "Robot")172 .replace("%OPERATION%", "Create")173 .replace("%REASON%", "You need to specify at least 1 executor with non empty host in order to submit execution. Please add it from Executor TAB to continue."));174 ans.setResultMessage(msg);175 } else {176 /**177 * All data seems cleans so we can call the services.178 */179 IRobotService robotService = appContext.getBean(IRobotService.class);180 IFactoryRobot robotFactory = appContext.getBean(IFactoryRobot.class);181 Robot robotData = robotFactory.create(robotid, robot, platform, browser, version, active, lbexemethod, description, userAgent, screenSize, capabilities, executors, robotDecli, type);182 ans = robotService.create(robotData);183 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {184 /**185 * Object created. Adding Log entry.186 */187 ILogEventService logEventService = appContext.getBean(LogEventService.class);188 logEventService.createForPrivateCalls("/CreateRobot", "CREATE", "Create Robot : ['" + robot + "']", request);189 }190 }191 /**192 * Formating and returning the json result.193 */194 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());195 jsonResponse.put("message", ans.getResultMessage().getDescription());196 response.getWriter().print(jsonResponse);197 response.getWriter().flush();198 }199 private List<RobotExecutor> getExecutorsFromParameter(String robot, HttpServletRequest request, ApplicationContext appContext, JSONArray json) throws JSONException, CerberusException {200 List<RobotExecutor> reList = new ArrayList<>();201 IFactoryRobotExecutor reFactory = appContext.getBean(IFactoryRobotExecutor.class);202 IRobotExecutorService reService = appContext.getBean(IRobotExecutorService.class);203 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);204 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();205 List<RobotExecutor> reList1 = reService.convert(reService.readByRobot(robot));206 for (int i = 0; i < json.length(); i++) {207 JSONObject reJson = json.getJSONObject(i);208 boolean delete = reJson.getBoolean("toDelete");209 Integer id = reJson.getInt("ID");...
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!!