How to use findDistinctValuesOfColumn method of org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionQueue class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionQueue.findDistinctValuesOfColumn

Source:ReadTestCaseExecutionQueue.java Github

copy

Full Screen

...109 boolean userHasPermissions = request.isUserInRole("RunTest");110 try {111 JSONObject jsonResponse;112 if (!Strings.isNullOrEmpty(request.getParameter("columnName"))) {113 answer = findDistinctValuesOfColumn(appContext, request, request.getParameter("columnName"));114 jsonResponse = (JSONObject) answer.getItem();115 } else if (queueid != 0) {116 answer = findExecutionQueueByKeyTech(queueid, appContext, userHasPermissions);117 jsonResponse = (JSONObject) answer.getItem();118 } else if (request.getParameter("flag") != null && request.getParameter("flag").equals("queueStatus")) {119 answer = findExecutionInQueueStatus(appContext, request);120 jsonResponse = (JSONObject) answer.getItem();121 } else {122 answer = findExecutionInQueueList(appContext, true, request);123 jsonResponse = (JSONObject) answer.getItem();124 }125 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());126 jsonResponse.put("message", answer.getResultMessage().getDescription());127 jsonResponse.put("sEcho", echo);128 response.getWriter().print(jsonResponse.toString());129 } catch (JSONException e) {130 LOG.warn(e);131 //returns a default error message with the json format that is able to be parsed by the client-side132 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());133 }134 }135 /**136 * Handles the HTTP <code>GET</code> method.137 *138 * @param request servlet request139 * @param response servlet response140 * @throws ServletException if a servlet-specific error occurs141 * @throws IOException if an I/O error occurs142 */143 @Override144 protected void doGet(HttpServletRequest request, HttpServletResponse response)145 throws ServletException, IOException {146 try {147 processRequest(request, response);148 } catch (CerberusException ex) {149 LOG.warn(ex);150 }151 }152 /**153 * Handles the HTTP <code>POST</code> method.154 *155 * @param request servlet request156 * @param response servlet response157 * @throws ServletException if a servlet-specific error occurs158 * @throws IOException if an I/O error occurs159 */160 @Override161 protected void doPost(HttpServletRequest request, HttpServletResponse response)162 throws ServletException, IOException {163 try {164 processRequest(request, response);165 } catch (CerberusException ex) {166 LOG.warn(ex);167 }168 }169 private AnswerItem findExecutionQueueByKeyTech(Long queueid, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {170 AnswerItem item = new AnswerItem();171 JSONObject object = new JSONObject();172 ITestCaseExecutionQueueService queueService = appContext.getBean(ITestCaseExecutionQueueService.class);173 //finds the project 174 AnswerItem answer = queueService.readByKey(queueid);175 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {176 //if the service returns an OK message then we can get the item and convert it to JSONformat177 TestCaseExecutionQueue lib = (TestCaseExecutionQueue) answer.getItem();178 JSONObject response = convertTestCaseExecutionInQueueToJSONObject(lib);179 int nb = 0;180 nb = queueService.getNbEntryToGo(lib.getId(), lib.getPriority());181 response.put("nbEntryInQueueToGo", nb);182 object.put("contentTable", response);183 }184 object.put("hasPermissions", userHasPermissions);185 item.setItem(object);186 item.setResultMessage(answer.getResultMessage());187 return item;188 }189 private AnswerItem findExecutionInQueueList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {190 AnswerItem item = new AnswerItem();191 JSONObject object = new JSONObject();192 executionService = appContext.getBean(ITestCaseExecutionQueueService.class);193 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));194 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));195 /*int sEcho = Integer.valueOf(request.getParameter("sEcho"));*/196 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");197 int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "2"));198 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "id,test,testcase,country,environment,browser,tag");199 String columnToSort[] = sColumns.split(",");200 String columnName = columnToSort[columnToSortParameter];201 String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "desc");202 List<String> individualLike = new ArrayList(Arrays.asList(request.getParameter("sLike").split(",")));203 Map<String, List<String>> individualSearch = new HashMap<>();204 for (int a = 0; a < columnToSort.length; a++) {205 if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {206 List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));207 if(individualLike.contains(columnToSort[a])) {208 individualSearch.put(columnToSort[a]+":like", search);209 }else {210 individualSearch.put(columnToSort[a], search);211 }212 }213 }214 AnswerList resp = executionService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);215 JSONArray jsonArray = new JSONArray();216 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values217 for (TestCaseExecutionQueue exec : (List<TestCaseExecutionQueue>) resp.getDataList()) {218 jsonArray.put(convertTestCaseExecutionInQueueToJSONObject(exec));219 }220 }221 object.put("hasPermissions", userHasPermissions);222 object.put("contentTable", jsonArray);223 object.put("iTotalRecords", resp.getTotalRows());224 object.put("iTotalDisplayRecords", resp.getTotalRows());225 item.setItem(object);226 item.setResultMessage(resp.getResultMessage());227 return item;228 }229 private AnswerItem findExecutionInQueueStatus(ApplicationContext appContext, HttpServletRequest request) throws JSONException {230 AnswerItem item = new AnswerItem();231 JSONObject object = new JSONObject();232 executionThreadPoolService = appContext.getBean(IExecutionThreadPoolService.class);233 parameterService = appContext.getBean(IParameterService.class);234 invariantService = appContext.getBean(IInvariantService.class);235 JSONArray jsonArray = new JSONArray();236 try {237 HashMap<String, Integer> mapRunning = executionThreadPoolService.getCurrentlyRunning();238 HashMap<String, Integer> mapInQueue = executionThreadPoolService.getCurrentlyToTreat();239 HashMap<String, Integer> mapPoolSize = executionThreadPoolService.getCurrentlyPoolSizes();240 for (Map.Entry<String, Integer> entry : mapRunning.entrySet()) {241 String column = entry.getKey();242 Integer name = entry.getValue();243 if (!("".equals(column))) {244 String[] data = column.split("\\/\\/");245 JSONObject jsonObject = new JSONObject();246 switch (data[0]) {247 case TestCaseExecutionQueueToTreat.CONSTRAIN1_GLOBAL:248 jsonObject.put("contrainId", data[0]);249 jsonObject.put("system", "");250 jsonObject.put("environment", "");251 jsonObject.put("country", "");252 jsonObject.put("application", "");253 jsonObject.put("robot", "");254 jsonObject.put("nbInQueue", ParameterParserUtil.parseIntegerParam(mapInQueue.get(column), 0));255 jsonObject.put("nbPoolSize", ParameterParserUtil.parseIntegerParam(mapPoolSize.get(column), 0));256 jsonObject.put("nbRunning", ParameterParserUtil.parseIntegerParam(name, 0));257 jsonObject.put("hasPermissionsUpdate", parameterService.hasPermissionsUpdate("cerberus_queueexecution_global_threadpoolsize", request));258 break;259 case TestCaseExecutionQueueToTreat.CONSTRAIN2_APPLICATION:260 jsonObject.put("contrainId", data[0]);261 jsonObject.put("system", data[1]);262 jsonObject.put("environment", data[2]);263 jsonObject.put("country", data[3]);264 jsonObject.put("application", data[4]);265 jsonObject.put("robot", "");266 jsonObject.put("nbInQueue", ParameterParserUtil.parseIntegerParam(mapInQueue.get(column), 0));267 jsonObject.put("nbPoolSize", ParameterParserUtil.parseIntegerParam(mapPoolSize.get(column), 0));268 jsonObject.put("nbRunning", ParameterParserUtil.parseIntegerParam(name, 0));269 jsonObject.put("hasPermissionsUpdate", parameterService.hasPermissionsUpdate("cerberus_queueexecution_global_threadpoolsize", request));270 break;271 case TestCaseExecutionQueueToTreat.CONSTRAIN3_ROBOT:272 jsonObject.put("contrainId", data[0]);273 jsonObject.put("system", "");274 jsonObject.put("environment", "");275 jsonObject.put("country", "");276 jsonObject.put("application", "");277 if (data.length > 1) {278 jsonObject.put("robot", data[1]);279 if ((data[1] == null) || (data[1].equalsIgnoreCase("null"))) {280 jsonObject.put("invariantExist", false);281 } else {282 jsonObject.put("invariantExist", invariantService.isInvariantExist("ROBOTHOST", data[1]));283 }284 } else {285 jsonObject.put("robot", "");286 jsonObject.put("invariantExist", false);287 }288 jsonObject.put("nbInQueue", ParameterParserUtil.parseIntegerParam(mapInQueue.get(column), 0));289 jsonObject.put("nbPoolSize", ParameterParserUtil.parseIntegerParam(mapPoolSize.get(column), 0));290 jsonObject.put("nbRunning", ParameterParserUtil.parseIntegerParam(name, 0));291 jsonObject.put("hasPermissionsUpdate", parameterService.hasPermissionsUpdate("cerberus_queueexecution_global_threadpoolsize", request));292 break;293 }294 jsonArray.put(jsonObject);295 }296 }297 object.put("contentTable", jsonArray);298 } catch (CerberusException ex) {299 LOG.warn(ex);300 }301 object.put("messageType", "");302 object.put("message", "");303 item.setResultMessage(new MessageEvent(MessageEventEnum.GENERIC_OK));304 item.setItem(object);305 return item;306 }307 private AnswerItem findDistinctValuesOfColumn(ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {308 AnswerItem answer = new AnswerItem();309 JSONObject object = new JSONObject();310 AnswerList values = new AnswerList();311 executionService = appContext.getBean(ITestCaseExecutionQueueService.class);312 String column = ParameterParserUtil.parseStringParam(request.getParameter("columnName"), "");313 String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");314 LOG.debug(columnName);315 switch (columnName) {316 /**317 * Columns from Status318 */319 case "state":320 List<String> dataList = new ArrayList<>();321 dataList.add(TestCaseExecutionQueue.State.QUEUED.name());...

Full Screen

Full Screen

findDistinctValuesOfColumn

Using AI Code Generation

copy

Full Screen

1 public List<String> findDistinctValuesOfColumn(String column) {2 List<String> result = new ArrayList<String>();3 String query = "SELECT DISTINCT " + column + " FROM testcaseexecutionqueue";4 try {5 Statement stmt = this.databaseSpring.connect().createStatement();6 ResultSet resultSet = stmt.executeQuery(query);7 while (resultSet.next()) {8 result.add(resultSet.getString(column));9 }10 resultSet.close();11 stmt.close();12 this.databaseSpring.close();13 } catch (SQLException exception) {14 LOG.error("Unable to execute query : " + query + " Exception : " + exception.toString(), exception);15 }16 return result;17 }18 public List<String> findDistinctValuesOfColumn(String column) {19 List<String> result = new ArrayList<String>();20 String query = "SELECT DISTINCT " + column + " FROM testcaseexecutionqueue";21 try {22 Statement stmt = this.databaseSpring.connect().createStatement();23 ResultSet resultSet = stmt.executeQuery(query);24 while (resultSet.next()) {25 result.add(resultSet.getString(column));26 }27 resultSet.close();28 stmt.close();29 this.databaseSpring.close();30 } catch (SQLException exception) {31 LOG.error("Unable to execute query : " + query + " Exception : " + exception.toString(), exception);32 }33 return result;34 }35 public List<String> findDistinctValuesOfColumn(String column) {36 List<String> result = new ArrayList<String>();37 String query = "SELECT DISTINCT " + column + " FROM testcaseexecutionqueue";38 try {39 Statement stmt = this.databaseSpring.connect().createStatement();40 ResultSet resultSet = stmt.executeQuery(query);41 while (resultSet.next()) {42 result.add(resultSet.getString(column));43 }44 resultSet.close();45 stmt.close();46 this.databaseSpring.close();47 } catch (SQLException exception) {48 LOG.error("Unable to execute query : " + query + " Exception : " + exception.toString(), exception);49 }50 return result;51 }52 public List<String> findDistinctValuesOfColumn(String column) {

Full Screen

Full Screen

findDistinctValuesOfColumn

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionQueue;2List<String> distinctValues = new ArrayList<String>();3distinctValues = ReadTestCaseExecutionQueue.findDistinctValuesOfColumn("country");4for (String value : distinctValues) {5 System.out.println(value);6}7List<WebElement> options = new ArrayList<WebElement>();8for (String value : distinctValues) {9 options.add(new Option(value));10}11SelectBox selectBox = new SelectBox(options, "US", "country", "country", "form-control", "");12String htmlCode = selectBox.getHtmlCode();13System.out.println(htmlCode);14Page page = new Page();15page.addHtmlCode(htmlCode);16page.display();

Full Screen

Full Screen

findDistinctValuesOfColumn

Using AI Code Generation

copy

Full Screen

1applications = findDistinctValuesOfColumn("testcaseexecutionqueue", "application");2nbApplications = 0;3for (i = 0; i < applications.length; i++) {4 nbApplications = nbApplications + 1;5}6logMessage("Number of applications in execution queue: " + nbApplications);

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