How to use findDistinctValuesOfColumn method of org.cerberus.servlet.crud.testdata.ReadTestDataLib class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testdata.ReadTestDataLib.findDistinctValuesOfColumn

Source:ReadTestDataLib.java Github

copy

Full Screen

...133 } else if (request.getParameter("groups") != null) {134 //gets the list of distinct groups135 answer = findDistinctGroups(appContext);136 } else if (!Strings.isNullOrEmpty(columnName)) {137 answer = findDistinctValuesOfColumn(appContext, request, columnName);138 jsonResponse = (JSONObject) answer.getItem();139 } else {140 //no parameters, then retrieves the full list141 answer = findTestDataLibList(appContext, request);142 }143 jsonResponse = (JSONObject) answer.getItem();144 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());145 jsonResponse.put("message", answer.getResultMessage().getDescription());146 response.getWriter().print(jsonResponse.toString());147 } catch (JSONException e) {148 LOG.warn(e);149 //returns a default error message with the json format that is able to be parsed by the client-side150 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());151 }152 }153 /**154 * Auxiliary method that retrieves a list of test data library entries with155 * basis on the GUI information (datatable)156 *157 * @param appContext - context object used to get the required beans158 * @param request - object that contains the search and sort filters used to159 * retrieve the information to be displayed in the GUI.160 * @return object containing the info to be displayed in the GUI161 * @throws IOException162 * @throws BeansException163 * @throws NumberFormatException164 * @throws JSONException165 */166 private AnswerItem<JSONObject> findTestDataLibList(ApplicationContext appContext, HttpServletRequest request) throws IOException, BeansException, NumberFormatException, JSONException {167 AnswerItem<JSONObject> item = new AnswerItem<>();168 JSONObject jsonResponse = new JSONObject();169 testDataLibService = appContext.getBean(ITestDataLibService.class);170 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));171 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));172 /*int sEcho = Integer.valueOf(request.getParameter("sEcho"));*/173 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");174 int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "0"));175 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"),176 "tdl.TestDataLibID,tdl.Name,tdl.System,tdl.Environment,tdl.Country,tdl.Group,tdl.Type,tdl.Database,tdl.Script,tdl.ServicePath,tdl.Method,tdl.Envelope,tdl.databaseCsv,tdl.Description");177 String columnToSort[] = sColumns.split(",");178 String columnName = columnToSort[columnToSortParameter];179 String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");180 List<String> systems = ParameterParserUtil.parseListParamAndDecodeAndDeleteEmptyValue(request.getParameterValues("system"), Arrays.asList("DEFAULT"), "UTF-8");181 Map<String, List<String>> individualSearch = new HashMap<String, List<String>>();182 List<String> individualLike = new ArrayList<>(Arrays.asList(request.getParameter("sLike").split(",")));183 for (int a = 0; a < columnToSort.length; a++) {184 if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {185 List<String> search = new ArrayList<>(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));186 if (individualLike.contains(columnToSort[a])) {187 individualSearch.put(columnToSort[a] + ":like", search);188 } else {189 individualSearch.put(columnToSort[a], search);190 }191 }192 }193 AnswerList<TestDataLib> resp = testDataLibService.readByVariousByCriteria(null, systems, null, null, null, startPosition, length, columnName, sort, searchParameter, individualSearch);194 JSONArray jsonArray = new JSONArray();195 boolean userHasPermissions = request.isUserInRole("TestDataManager");196 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values197 for (TestDataLib testDataLib : (List<TestDataLib>) resp.getDataList()) {198 jsonArray.put(convertTestDataLibToJSONObject(testDataLib, false));199 }200 }201 //recordsFiltered do lado do servidor 202 jsonResponse.put("hasPermissions", userHasPermissions);203 jsonResponse.put("contentTable", jsonArray);204 jsonResponse.put("iTotalRecords", resp.getTotalRows());205 jsonResponse.put("iTotalDisplayRecords", resp.getTotalRows());206 //recordsFiltered207 item.setItem(jsonResponse);208 item.setResultMessage(resp.getResultMessage());209 return item;210 }211 /**212 * Auxiliary method that finds a test data library entry with basis on an213 * identifier214 *215 * @param appContext - context object used to get the required beans216 * @param testDatalib - identifier used to perform the search217 * @return an object containing the information about the test data library218 * that matches the identifier219 * @throws JSONException220 */221 private AnswerItem<JSONObject> findTestDataLibByID(int testDatalib, ApplicationContext appContext, boolean userHasPermissions, String userName) throws JSONException {222 AnswerItem<JSONObject> item = new AnswerItem<>();223 JSONObject object = new JSONObject();224 testDataLibService = appContext.getBean(ITestDataLibService.class);225 //finds the testdatalib 226 AnswerItem answer = testDataLibService.readByKey(testDatalib);227 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {228 //if the service returns an OK message then we can get the item and convert it to JSONformat229 TestDataLib lib = (TestDataLib) answer.getItem();230 JSONObject response = convertTestDataLibToJSONObject(lib, true);231 userHasPermissions = userHasPermissions && testDataLibService.userHasPermission(lib, userName);232 object.put("testDataLib", response);233 }234 object.put("hasPermissions", userHasPermissions);235 item.setItem(object);236 item.setResultMessage(answer.getResultMessage());237 return item;238 }239 /**240 * Handles the auto-complete requests and retrieves a limited list of241 * strings that match (totally or partially) the name entered by the user.242 *243 * @param appContext - context object used to get the required beans244 * @param nameToSearch - value used to perform the auto complete245 * @param limit - limit number of the records that should be retrieved246 * @return object containing values that match the name247 * @throws JSONException248 */249 private AnswerItem<JSONObject> findTestDataLibNameList(String nameToSearch, int limit, boolean like, ApplicationContext appContext) throws JSONException {250 AnswerItem<JSONObject> ansItem = new AnswerItem<>();251 JSONObject object = new JSONObject();252 testDataLibService = appContext.getBean(ITestDataLibService.class);253 AnswerList<TestDataLib> ansList = testDataLibService.readNameListByName(nameToSearch, limit, like);254 JSONArray jsonArray = new JSONArray();255 if (ansList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values256 for (TestDataLib testDataLib : (List<TestDataLib>) ansList.getDataList()) {257 jsonArray.put(convertTestDataLibToJSONObject(testDataLib, false));258 }259 }260 //recordsFiltered do lado do servidor 261 object.put("contentTable", jsonArray);262 object.put("iTotalRecords", ansList.getTotalRows());263 object.put("iTotalDisplayRecords", ansList.getTotalRows());264 //recordsFiltered265 ansItem.setResultMessage(ansList.getResultMessage());266 ansItem.setItem(object);267 return ansItem;268 }269 /**270 * Auxiliary method that extracts the list of test cases that are currently271 * using one test lib.272 *273 * @param appContext - context object used to get the required beans274 * @param testDataLibId - identifier of the library entry275 * @param name - name of the library entry276 * @param country - country of the library entry277 * @return an answer item containing the information about the test cases278 * that use the entry279 * @throws JSONException280 */281 private AnswerItem<JSONObject> getTestCasesUsingTestDataLib(int testDataLibId, String name, String country, ApplicationContext appContext, boolean userHasPermissions) throws JSONException {282 JSONObject object = new JSONObject();283 JSONArray objectArray = new JSONArray();284 AnswerItem<JSONObject> ansItem = new AnswerItem<>();285 tcService = appContext.getBean(ITestCaseService.class);286 AnswerList<TestListDTO> ansList = tcService.findTestCasesThatUseTestDataLib(testDataLibId, name, country);287 //if the response is success then we can iterate and search for the data288 if (ansList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {289 List<TestListDTO> listDTO = ansList.getDataList();290 for (TestListDTO l : listDTO) {291 JSONArray jsonArray = new JSONArray();292 JSONArray arrTestCase = new JSONArray();293 for (TestCaseListDTO testCase : l.getTestCaseList()) {294 JSONObject jsonTestCase = new JSONObject();295 jsonTestCase.put("TestCaseNumber", testCase.getTestCaseNumber());296 jsonTestCase.put("TestCaseDescription", testCase.getTestCaseDescription());297 jsonTestCase.put("Creator", testCase.getCreator());298 jsonTestCase.put("Active", testCase.isIsActive());299 jsonTestCase.put("Status", testCase.getStatus());300 jsonTestCase.put("Group", testCase.getGroup());301 jsonTestCase.put("Application", testCase.getApplication());302 jsonTestCase.put("NrProperties", testCase.getPropertiesList().size());303 arrTestCase.put(jsonTestCase);304 }305 //test details306 jsonArray.put(l.getTest());307 jsonArray.put(l.getDescription());308 jsonArray.put(l.getTestCaseList().size());309 jsonArray.put(arrTestCase);310 //test case details311 objectArray.put(jsonArray);312 }313 }314 object.put("TestCasesList", objectArray);315 object.put("hasPermissions", userHasPermissions);316 ansItem.setItem(object);317 ansItem.setResultMessage(ansList.getResultMessage());318 return ansItem;319 }320 /**321 * Auxiliary method that retrieves the list of groups that are currently322 * defined for a type of testdatalib entries.323 *324 * @param appContext - context object used to get the required beans325 * @param type - type that filters the list of groups that should be326 * retrieved327 * @return an object containing all the groups that belong to that type328 * @throws JSONException329 */330 private AnswerItem<JSONObject> findDistinctGroups(ApplicationContext appContext) throws JSONException {331 AnswerItem<JSONObject> answerItem = new AnswerItem<>();332 ITestDataLibService testDataService = appContext.getBean(ITestDataLibService.class);333 JSONObject jsonObject = new JSONObject();334 AnswerList<String> ansList = testDataService.readDistinctGroups();335 if (ansList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {336 //if the response is success then we can sent the data337 jsonObject.put("contentTable", ((List<String>) ansList.getDataList()).toArray());338 }339 answerItem.setResultMessage(ansList.getResultMessage());340 answerItem.setItem(jsonObject);341 return answerItem;342 }343 /**344 * Auxiliary method that converts a test data library object to a JSON345 * object.346 *347 * @param testDataLib test data library348 * @param unescapeXML indicates whether the XML retrieved in the Envelope349 * should be un-escaped or not.350 * @return JSON object351 * @throws JSONException352 */353 private JSONObject convertTestDataLibToJSONObject(TestDataLib testDataLib, boolean unescapeContent) throws JSONException {354 if (unescapeContent) {355 //general 356 testDataLib.setDescription(StringEscapeUtils.unescapeHtml4(testDataLib.getDescription()));357 //SQL358 testDataLib.setScript(StringEscapeUtils.unescapeHtml4(testDataLib.getScript()));359 //SOAP360 testDataLib.setServicePath(StringEscapeUtils.unescapeHtml4(testDataLib.getServicePath()));361 testDataLib.setMethod(StringEscapeUtils.unescapeHtml4(testDataLib.getMethod()));362 testDataLib.setEnvelope(StringEscapeUtils.unescapeXml(testDataLib.getEnvelope()));363 //CSV364 testDataLib.setCsvUrl(StringEscapeUtils.unescapeHtml4(testDataLib.getCsvUrl()));365 testDataLib.setSeparator(StringEscapeUtils.unescapeHtml4(testDataLib.getSeparator()));366 }367 Gson gson = new Gson();368 JSONObject result = new JSONObject(gson.toJson(testDataLib));369 return result;370 }371 private AnswerItem<JSONObject> findDistinctValuesOfColumn(ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {372 AnswerItem<JSONObject> answer = new AnswerItem<>();373 JSONObject object = new JSONObject();374 testDataLibService = appContext.getBean(ITestDataLibService.class);375 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");376 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "test,testcase,application,project,ticket,description,behaviororvalueexpected,readonly,bugtrackernewurl,deploytype,mavengroupid");377 String columnToSort[] = sColumns.split(",");378 List<String> individualLike = new ArrayList<>(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));379 Map<String, List<String>> individualSearch = new HashMap<>();380 for (int a = 0; a < columnToSort.length; a++) {381 if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {382 List<String> search = new ArrayList<>(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));383 if (individualLike.contains(columnToSort[a])) {384 individualSearch.put(columnToSort[a] + ":like", search);385 } else {...

Full Screen

Full Screen

findDistinctValuesOfColumn

Using AI Code Generation

copy

Full Screen

1public class ReadTestDataLib {2 public static List<String> findDistinctValuesOfColumn(String dataLibName, String columnName, String system, String environment, String country) {3 List<String> result = new ArrayList<String>();4 String data = "";5 data = ReadTestDataLibData(dataLibName, system, environment, country);6 try {7 JSONObject jsonResponse = new JSONObject(data);8 JSONArray columnArray = jsonResponse.getJSONArray("contentTable");9 for (int i = 0; i < columnArray.length(); i++) {10 JSONObject row = columnArray.getJSONObject(i);11 result.add(row.getString(columnName));12 }13 } catch (JSONException ex) {14 Logger.getLogger(ReadTestDataLib.class.getName()).log(Level.SEVERE, null, ex);15 }16 return result;17 }18}19public class ReadTestDataLib {20 public static List<String> findDistinctValuesOfColumn(String dataLibName, String columnName, String system, String environment, String country) {21 List<String> result = new ArrayList<String>();22 String data = "";23 data = ReadTestDataLibData(dataLibName, system, environment, country);24 try {25 JSONObject jsonResponse = new JSONObject(data);26 JSONArray columnArray = jsonResponse.getJSONArray("contentTable");27 for (int i = 0; i < columnArray.length(); i++) {28 JSONObject row = columnArray.getJSONObject(i);29 result.add(row.getString(columnName));30 }31 } catch (JSONException ex) {32 Logger.getLogger(ReadTestDataLib.class.getName()).log(Level.SEVERE, null, ex);33 }34 return result;35 }36}37public class ReadTestDataLib {38 public static List<String> findDistinctValuesOfColumn(String dataLibName, String columnName, String system, String environment, String country) {39 List<String> result = new ArrayList<String>();40 String data = "";41 data = ReadTestDataLibData(dataLibName, system, environment, country);42 try {43 JSONObject jsonResponse = new JSONObject(data);44 JSONArray columnArray = jsonResponse.getJSONArray("contentTable");45 for (int i = 0; i < columnArray.length(); i++) {46 JSONObject row = columnArray.getJSONObject(i);47 result.add(row.getString(columnName));

Full Screen

Full Screen

findDistinctValuesOfColumn

Using AI Code Generation

copy

Full Screen

1var distinctValues = Packages.org.cerberus.servlet.crud.testdata.ReadTestDataLib.findDistinctValuesOfColumn("testDataLibID", "country");2var distinctValuesArray = distinctValues.toArray();3var distinctValuesArrayLength = distinctValuesArray.length;4for (var i = 0; i < distinctValuesArrayLength; i++) {5 print(distinctValuesArray[i]);6}7var distinctValues = Packages.org.cerberus.servlet.crud.testdata.ReadTestDataLib.findDistinctValuesOfColumn("testDataLibID", "country");8var distinctValuesArray = distinctValues.toArray();9var distinctValuesArrayLength = distinctValuesArray.length;10for (var i = 0; i < distinctValuesArrayLength; i++) {11 print(distinctValuesArray[i]);12}13var distinctValues = Packages.org.cerberus.servlet.crud.testdata.ReadTestDataLib.findDistinctValuesOfColumn("testDataLibID", "country");14var distinctValuesArray = distinctValues.toArray();15var distinctValuesArrayLength = distinctValuesArray.length;16for (var i = 0; i < distinctValuesArrayLength; i++) {17 print(distinctValuesArray[i]);18}19var distinctValues = Packages.org.cerberus.servlet.crud.testdata.ReadTestDataLib.findDistinctValuesOfColumn("testDataLibID", "country");

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