Best Cerberus-source code snippet using org.cerberus.util.answer.AnswerList.getDataList
Source:DataLibService.java
...175 }176 resultData = getDataObjectList(lib, columnList, rowLimit, tCExecution, testCaseExecutionData);177 //Manage error message.178 if (resultData.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_DATA.getCode()) {179 if (resultData.getDataList().size() < nbRowsRequested) { // We check if the data provided is enought to provide the answer.180 result = new AnswerList();181 result.setDataList(null);182 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NOTENOUGHTDATA);183 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%NBREQUEST%", Integer.toString(nbRowsRequested)));184 result.setResultMessage(msg);185 return result;186 }187 } else if (resultData.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GENERIC_NODATA.getCode()) {188 result = new AnswerList();189 result.setDataList(null);190 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NODATA);191 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()));192 result.setResultMessage(msg);193 return result;194 } else {195 result = new AnswerList();196 result.setDataList(null);197 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_DATAISSUE);198 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()));199 result.setResultMessage(msg);200 return result;201 }202 /**203 * Filter out the result from requested rows depending on the nature204 */205 result = filterWithNature(testCaseCountryProperty.getNature(), resultData, tCExecution, testCaseCountryProperty, nbRowsRequested);206 //Manage error message.207 if (result.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURE.getCode()) {208 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_GLOBAL);209 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription())210 .replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));211 result.setResultMessage(msg);212 } else if (result.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GENERIC_NATURENOMORERECORD.getCode()) {213 //if the script does not return 214 result.setDataList(null);215 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NODATALEFT);216 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription())217 .replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));218 result.setResultMessage(msg);219 } else {220 //other error had occured221 result.setDataList(null);222 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_GENERIC);223 msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription())224 .replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));225 result.setResultMessage(msg);226 }227 return result;228 }229 /**230 * This method route to the method regarding the nature231 *232 * @param nature : Nature of the property233 * @param dataObjectList : List of dataObject234 * @param tCExecution : TestCaseExecution235 * @param testCaseCountryProperties : TestCaseCountryProperties236 * @return List of items (dataObject) from the dataObjectList filtered out237 * of records depending on the nature.238 */239 private AnswerList<HashMap<String, String>> filterWithNature(String nature, AnswerList dataObjectList, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperties, int outputRequestedDimention) {240 switch (nature) {241 case TestCaseCountryProperties.NATURE_STATIC:242 return filterWithNatureSTATIC(dataObjectList, outputRequestedDimention);243 case TestCaseCountryProperties.NATURE_RANDOM:244 return filterWithNatureRANDOM(dataObjectList, outputRequestedDimention);245 case TestCaseCountryProperties.NATURE_RANDOMNEW:246 return filterWithNatureRANDOMNEW(dataObjectList, tCExecution, testCaseCountryProperties, outputRequestedDimention);247 case TestCaseCountryProperties.NATURE_NOTINUSE:248 return filterWithNatureNOTINUSE(dataObjectList, tCExecution, testCaseCountryProperties, outputRequestedDimention);249 }250 //TODO throw exception when Nature not known251 return null;252 }253 private List<Integer> getRandomListOfInteger(int inputRange, int nbOfResult) {254 List<Integer> listTempRandom;255 listTempRandom = new ArrayList<Integer>();256 for (int i = 0; i < inputRange; i++) {257 listTempRandom.add(i);258 }259 List<Integer> listRandom;260 listRandom = new ArrayList<Integer>();261 for (int i = 0; i < nbOfResult; i++) {262 Random r = new Random();263 int position = r.nextInt(listTempRandom.size());264 listRandom.add(listTempRandom.remove(position));265 }266 return listRandom;267 }268 @Override269 public AnswerList<HashMap<String, String>> filterWithNatureSTATIC(AnswerList<HashMap<String, String>> dataObjectList, int outputRequestedDimention) {270 AnswerList<HashMap<String, String>> result = new AnswerList();271 List<HashMap<String, String>> resultObject;272 resultObject = new ArrayList<HashMap<String, String>>();273 for (int i = 0; i < outputRequestedDimention; i++) {274 resultObject.add(dataObjectList.getDataList().get(i));275 }276 result.setDataList(resultObject);277 String rowMessage = "";278 if (outputRequestedDimention < 2) {279 rowMessage = "row";280 } else {281 rowMessage = Integer.toString(outputRequestedDimention) + " rows";282 }283 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURESTATIC).resolveDescription("ROW", rowMessage));284 return result;285 }286 @Override287 public AnswerList<HashMap<String, String>> filterWithNatureRANDOM(AnswerList<HashMap<String, String>> dataObjectList, int outputRequestedDimention) {288 AnswerList<HashMap<String, String>> result = new AnswerList();289 String selectedList = "";290 List<HashMap<String, String>> resultObject;291 resultObject = new ArrayList<HashMap<String, String>>();292 List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);293 for (int i : listTempRandom) {294 int j = i + 1;295 selectedList += Integer.toString(j) + ",";296 resultObject.add(dataObjectList.getDataList().get(i));297 }298 selectedList = StringUtil.removeLastChar(selectedList, 1);299 result.setDataList(resultObject);300 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURERANDOM)301 .resolveDescription("POS", selectedList).resolveDescription("TOTALPOS", Integer.toString(dataObjectList.getDataList().size())));302 return result;303 }304 @Override305 public AnswerList<HashMap<String, String>> filterWithNatureRANDOMNEW(AnswerList<HashMap<String, String>> dataObjectList, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseProperties, int outputRequestedDimention) {306 AnswerList<HashMap<String, String>> result = new AnswerList();307 List<HashMap<String, String>> list; // Temporary list in order to treat the input list308 List<HashMap<String, String>> resultObject;309 resultObject = new ArrayList<HashMap<String, String>>();310 int initNB = dataObjectList.getDataList().size();311 // We get the list of values that were already used.312 List<String> pastValues = this.testCaseExecutionDataService.getPastValuesOfProperty(tCExecution.getId(),313 testCaseProperties.getProperty(), tCExecution.getTest(), tCExecution.getTestCase(),314 tCExecution.getCountryEnvParam().getBuild(), tCExecution.getEnvironmentData(), tCExecution.getCountry());315 int removedNB = 0;316 // We save all rows that needs to be removed to listToremove.317 List<Map<String, String>> listToremove = new ArrayList<Map<String, String>>();318 list = dataObjectList.getDataList();319 for (String valueToRemove : pastValues) {320 for (Map<String, String> curentRow : list) {321 if (curentRow.get("").equals(valueToRemove)) {322 if (true) {323 listToremove.add(curentRow);324 removedNB++;325 }326 }327 }328 }329 // We remove all listToremove entries from list.330 list.removeAll(listToremove);331 if (list != null && !list.isEmpty()) { // We pick a random value from the left entries of the list.332 if (list.size() < outputRequestedDimention) { // Still some results available but not enougth compared to what we requested.333 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_RANDOMNEW_NOTENOUGTHRECORDS)334 .resolveDescription("REMNB", Integer.toString(listToremove.size()))335 .resolveDescription("TOTNB", Integer.toString(initNB))336 .resolveDescription("NBREQUEST", Integer.toString(outputRequestedDimention)));337 } else {338 // Get a random list.339 List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);340 String selectedList = "";341 // Pick the result from list.342 for (int i : listTempRandom) {343 int j = i + 1;344 selectedList += Integer.toString(j) + ",";345 resultObject.add(dataObjectList.getDataList().get(i));346 }347 selectedList = StringUtil.removeLastChar(selectedList, 1);348 result.setDataList(resultObject);349 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURERANDOMNEW)350 .resolveDescription("TOTNB", Integer.toString(initNB))351 .resolveDescription("REMNB", Integer.toString(removedNB))352 .resolveDescription("POS", selectedList)353 .resolveDescription("TOTALPOS", Integer.toString(list.size())));354 }355 } else { // No more entries available.356 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_RANDOMNEW_NOMORERECORD)357 .resolveDescription("TOTNB", Integer.toString(initNB)));358 }359 return result;360 }361 @Override362 public AnswerList<HashMap<String, String>> filterWithNatureNOTINUSE(AnswerList<HashMap<String, String>> dataObjectList, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, int outputRequestedDimention) {363 AnswerList<HashMap<String, String>> result = new AnswerList();364 List<HashMap<String, String>> list = dataObjectList.getDataList(); // Temporary list in order to treat the input list365 List<HashMap<String, String>> resultObject;366 resultObject = new ArrayList<HashMap<String, String>>();367 int initNB = dataObjectList.getDataList().size();368 // We get the list of values that are beeing used.369 Integer peTimeout;370 try {371 peTimeout = Integer.valueOf(parameterService.findParameterByKey("cerberus_notinuse_timeout", tCExecution.getApplicationObj().getSystem()).getValue());372 List<String> pastValues = this.testCaseExecutionDataService.getInUseValuesOfProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), tCExecution.getEnvironmentData(), tCExecution.getCountry(), peTimeout);373 int removedNB = 0;374 // We save all rows that needs to be removed to listToremove.375 List<Map<String, String>> listToremove = new ArrayList<>();376 for (String valueToRemove : pastValues) {377 for (Map<String, String> curentRow : list) {378 if (curentRow.get("").equals(valueToRemove)) {379 if (true) {380 listToremove.add(curentRow);381 removedNB++;382 }383 }384 }385 }386 // We remove all listToremove entries from list.387 list.removeAll(listToremove);388 if (list != null && !list.isEmpty()) { // We pick a random value from the left entries of the list.389 if (list.size() < outputRequestedDimention) { // Still some results available but not enougth compared to what we requested.390 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTINUSE_NOTENOUGTHRECORDS)391 .resolveDescription("REMNB", Integer.toString(listToremove.size()))392 .resolveDescription("TOTNB", Integer.toString(initNB))393 .resolveDescription("NBREQUEST", Integer.toString(outputRequestedDimention)));394 } else {395 // Get a random list.396 List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);397 String selectedList = "";398 // Pick the result from list.399 for (int i : listTempRandom) {400 int j = i + 1;401 selectedList += Integer.toString(j) + ",";402 resultObject.add(dataObjectList.getDataList().get(i));403 }404 selectedList = StringUtil.removeLastChar(selectedList, 1);405 result.setDataList(resultObject);406 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURENOTINUSE)407 .resolveDescription("TOTNB", Integer.toString(initNB))408 .resolveDescription("REMNB", Integer.toString(removedNB))409 .resolveDescription("POS", selectedList)410 .resolveDescription("TOTALPOS", Integer.toString(list.size())));411 }412 } else { // No more entries available.413 result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTINUSE_NOMORERECORD)414 .resolveDescription("TOTNB", Integer.toString(initNB)));415 }416 } catch (CerberusException ex) {417 LOG.warn(ex);418 }419 return result;420 }421 /**422 * Get the list of subData423 *424 * @param lib425 * @return426 */427 private AnswerItem<HashMap<String, String>> getSubDataFromType(TestDataLib lib) {428 AnswerList answerData = new AnswerList();429 AnswerItem<HashMap<String, String>> result = new AnswerItem();430 MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);431 List<TestDataLibData> objectDataList = new ArrayList<TestDataLibData>();432 HashMap<String, String> row = new HashMap<String, String>();433 switch (lib.getType()) {434 case TestDataLib.TYPE_CSV:435 answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), null, null, "N");436 if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {437 objectDataList = answerData.getDataList();438 boolean missingKey = true;439 for (TestDataLibData tdld : objectDataList) {440 row.put(tdld.getSubData(), tdld.getColumnPosition());441 if (tdld.getSubData().equalsIgnoreCase("")) {442 missingKey = false;443 }444 }445 result.setItem(row);446 if (missingKey) {447 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATACSVNOKEY);448 result.setResultMessage(msg);449 } else {450 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);451 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));452 result.setResultMessage(msg);453 }454 } else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {455 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATACSV);456 result.setResultMessage(msg);457 } else {458 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATACSV);459 result.setResultMessage(msg);460 }461 break;462 case TestDataLib.TYPE_SQL:463 answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), "N", null, null);464 if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {465 objectDataList = answerData.getDataList();466 boolean missingKey = true;467 for (TestDataLibData tdld : objectDataList) {468 row.put(tdld.getSubData(), tdld.getColumn());469 if (tdld.getSubData().equalsIgnoreCase("")) {470 missingKey = false;471 }472 }473 result.setItem(row);474 if (missingKey) {475 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASQLNOKEY);476 result.setResultMessage(msg);477 } else {478 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);479 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));480 result.setResultMessage(msg);481 }482 } else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {483 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATASQL);484 result.setResultMessage(msg);485 } else {486 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASQL);487 result.setResultMessage(msg);488 }489 break;490 case TestDataLib.TYPE_SERVICE:491 answerData = testDataLibDataService.readByVarious(lib.getTestDataLibID(), null, "N", null);492 if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !answerData.getDataList().isEmpty()) {493 objectDataList = answerData.getDataList();494 boolean missingKey = true;495 for (TestDataLibData tdld : objectDataList) {496 row.put(tdld.getSubData(), tdld.getParsingAnswer());497 if (tdld.getSubData().equalsIgnoreCase("")) {498 missingKey = false;499 }500 }501 result.setItem(row);502 if (missingKey) {503 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASOAPNOKEY);504 result.setResultMessage(msg);505 } else {506 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);507 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(answerData.getDataList().size())));508 result.setResultMessage(msg);509 }510 } else if ((answerData.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getDataList().isEmpty()) {511 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOSUBDATASOAP);512 result.setResultMessage(msg);513 } else {514 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATASOAP);515 result.setResultMessage(msg);516 }517 break;518 case TestDataLib.TYPE_INTERNAL:519 // For static Type, there is no need to fetch the subdata as subdata are loaded at the same time of the data.520 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA);521 result.setResultMessage(msg);522 result.setItem(null);523 break;524 }525 return result;526 }527 /**528 * Get the dataObject List depending on the type529 *530 * @param lib531 * @param columnList532 * @return533 */534 private AnswerList<HashMap<String, String>> getDataObjectList(TestDataLib lib, HashMap<String, String> columnList, int rowLimit,535 TestCaseExecution tCExecution, TestCaseExecutionData testCaseExecutionData) {536 AnswerList result = new AnswerList();537 MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);538 CountryEnvironmentDatabase countryEnvironmentDatabase;539 AnswerList responseList;540 String system = tCExecution.getApplicationObj().getSystem();541 String country = tCExecution.getCountry();542 String environment = tCExecution.getEnvironment();543 Pattern pattern;544 Matcher matcher;545 Parameter p;546 List<HashMap<String, String>> list;547 switch (lib.getType()) {548 case TestDataLib.TYPE_CSV:549 /**550 * Before making the call we check if the Service Path is551 * already a proper URL. If it is not, we prefix with the CsvUrl552 * defined from corresponding database. This is used to get the553 * data from the correct environment.554 */555 String servicePathCsv = lib.getCsvUrl();556 LOG.debug("Service Path (Csv) : " + lib.getCsvUrl());557 // Trying making an URL with database context path.558 if (!StringUtil.isURL(servicePathCsv)) {559 // Url is not valid, we try to get the corresponding DatabaseURL CsvURL to prefix.560 if (!(StringUtil.isNullOrEmpty(lib.getDatabaseCsv()))) {561 try {562 countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system,563 country, environment, lib.getDatabaseCsv()));564 if (countryEnvironmentDatabase == null) {565 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLNOTEXIST);566 msg.setDescription(msg.getDescription()567 .replace("%SERVICEURL%", lib.getCsvUrl())568 .replace("%SYSTEM%", system)569 .replace("%COUNTRY%", country)570 .replace("%ENV%", environment)571 .replace("%DATABASE%", lib.getDatabaseCsv()));572 result.setResultMessage(msg);573 return result;574 } else {575 String csvURL = countryEnvironmentDatabase.getCsvUrl();576 if (StringUtil.isNullOrEmpty(csvURL)) {577 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLEMPTY);578 msg.setDescription(msg.getDescription()579 .replace("%SERVICEURL%", lib.getCsvUrl())580 .replace("%SYSTEM%", system)581 .replace("%COUNTRY%", country)582 .replace("%ENV%", environment)583 .replace("%DATABASE%", lib.getDatabaseCsv()));584 result.setResultMessage(msg);585 return result;586 }587 // soapURL from database is not empty so we prefix the Service URL with it.588 servicePathCsv = csvURL + lib.getCsvUrl();589 if (!StringUtil.isURL(servicePathCsv)) {590 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKO);591 msg.setDescription(msg.getDescription()592 .replace("%SERVICEURL%", servicePathCsv)593 .replace("%SOAPURL%", csvURL)594 .replace("%SERVICEPATH%", lib.getCsvUrl())595 .replace("%ENTRY%", lib.getName())596 .replace("%ENTRYID%", lib.getTestDataLibID().toString()));597 result.setResultMessage(msg);598 return result;599 }600 }601 } catch (CerberusException ex) {602 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSV_URLKOANDDATABASECSVURLNOTEXIST);603 msg.setDescription(msg.getDescription()604 .replace("%SERVICEURL%", lib.getCsvUrl())605 .replace("%SYSTEM%", system)606 .replace("%COUNTRY%", country)607 .replace("%ENV%", environment)608 .replace("%DATABASE%", lib.getDatabaseCsv()));609 result.setResultMessage(msg);610 return result;611 }612 }613 }614 // Trying make a valid path with csv parameter path.615 if (!StringUtil.isURL(servicePathCsv)) {616 // Url is still not valid. We try to add the path from csv parameter.617 String csv_path = parameterService.getParameterStringByKey("cerberus_testdatalibcsv_path", "", "");618 csv_path = StringUtil.addSuffixIfNotAlready(csv_path, File.separator);619 servicePathCsv = csv_path + servicePathCsv;620 }621 // CSV Call is made here.622 responseList = fileService.parseCSVFile(servicePathCsv, lib.getSeparator(), columnList);623 list = responseList.getDataList();624 //if the query returns sucess then we can get the data625 if (responseList.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_CSV.getCode()) {626 if (list != null && !list.isEmpty()) {627 result.setDataList(list);628 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_CSV);629 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())).replace("%CSVURL%", servicePathCsv));630 } else {631 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_CSVDATABASENODATA);632 msg.setDescription(msg.getDescription().replace("%CSVURL%", servicePathCsv));633 }634 } else {635 msg = responseList.getResultMessage();636 }637 result.setResultMessage(msg);638 break;639 case TestDataLib.TYPE_SQL:640 String connectionName;641 String db = lib.getDatabase();642 try {643 if (StringUtil.isNullOrEmpty(db)) {644 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASEEMPTY);645 } else {646 countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(countryEnvironmentDatabaseService.readByKey(system,647 country, environment, db));648 if (countryEnvironmentDatabase == null) {649 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENOTCONFIGURED);650 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system)651 .replace("%COUNTRY%", country).replace("%ENV%", environment)652 .replace("%DATABASE%", db));653 } else {654 connectionName = countryEnvironmentDatabase.getConnectionPoolName();655 if (!(StringUtil.isNullOrEmpty(connectionName))) {656 Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_propertyexternalsql_timeout", system, 60);657 //performs a query that returns several rows containing n columns658 responseList = sqlService.queryDatabaseNColumns(connectionName, lib.getScript(), rowLimit, sqlTimeout, system, columnList);659 //if the query returns sucess then we can get the data660 if (responseList.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_SQL.getCode()) {661 list = responseList.getDataList();662 if (list != null && !list.isEmpty()) {663 result.setDataList(list);664 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SQL);665 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())));666 } else {667 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENODATA);668 }669 } else {670 msg = responseList.getResultMessage();671 }672 msg.setDescription(msg.getDescription().replace("%DATABASE%", db));673 msg.setDescription(msg.getDescription().replace("%SQL%", lib.getScript()));674 msg.setDescription(msg.getDescription().replace("%JDBCPOOLNAME%", connectionName));675 } else {676 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASEJDBCRESSOURCEMPTY);677 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", db));678 }679 }680 }681 } catch (CerberusException ex) {682 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SQLDATABASENOTCONFIGURED);683 msg.setDescription(msg.getDescription().replace("%SYSTEM%", system).replace("%COUNTRY%", country).replace("%ENV%", environment).replace("%DATABASE%", db));684 }685 result.setResultMessage(msg);686 break;687 case TestDataLib.TYPE_SERVICE:688 AppService appService = new AppService();689 HashMap<String, String> resultHash = new HashMap<>();690 List<HashMap<String, String>> listResult = new ArrayList<HashMap<String, String>>();691 // Temporary list of string.692 List<String> listTemp1 = null;693 // String containing the XML694 String responseString = "";695 /**696 * Before making the call we check if the Service Path is697 * already a propper URL. If it is not, we prefix with the698 * SoapUrl defined from corresponding database. This is used to699 * get the data from the correct environment.700 */701 String servicePath = lib.getServicePath();702 LOG.debug("Service Path : " + lib.getServicePath());703 // Service Call is made here.704 AnswerItem ai = serviceService.callService(lib.getService(), lib.getDatabaseUrl(), lib.getEnvelope(), lib.getServicePath(), lib.getMethod(), tCExecution);705 msg = ai.getResultMessage();706 //if the call returns success then we can process the soap ressponse707 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {708 appService = (AppService) ai.getItem();709 //Record result in filessytem.710// testCaseExecutionData.addFileList(recorderService.recordServiceCall(tCExecution, null, 0, testCaseExecutionData.getProperty(), appService));711 recorderService.recordServiceCall(tCExecution, null, 0, testCaseExecutionData.getProperty(), appService);712 // Call successful so we can start to parse the result and build RawData per columns from subdata entries.713 /**714 * This Step will calculate hashTemp1 : Hash of List from715 * the Service response.716 */717 // Will contain the nb of row of the target list of Hash.718 int finalnbRow = 0;719 // Will contain the result of the XML parsing.720 HashMap<String, List<String>> hashTemp1 = new HashMap<>();721 if (columnList.isEmpty()) { // No subdata could be found on the testdatalib.722 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_NOSUBDATA);723 msg.setDescription(msg.getDescription()724 .replace("%ENTRY%", lib.getName())725 .replace("%ENTRYID%", lib.getTestDataLibID().toString()));726 } else {727 switch (appService.getResponseHTTPBodyContentType()) {728 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:729 Document xmlDocument = xmlUnitService.getXmlDocument(appService.getResponseHTTPBody());730 // We get the content of the XML in order to report it log messages.731 responseString = appService.getResponseHTTPBody();732 for (Map.Entry<String, String> entry : columnList.entrySet()) {733 String subDataColumnToTreat = entry.getKey(); // SubData734 String subDataParsingAnswer = entry.getValue(); // Parsing Answer735 listTemp1 = new ArrayList<>();736 try {737 // We try to parse the XML with the subdata Parsing Answer.738 NodeList candidates = XmlUtil.evaluate(xmlDocument, subDataParsingAnswer);739 if (candidates.getLength() > 0) {740 for (int i = 0; i < candidates.getLength(); i++) { // Loop on all Values that match in XML.741 //We get the value from XML742 String value = candidates.item(i).getNodeValue();743 if (value == null) { // No value found.744 if (candidates.item(i) != null) {745 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_CHECK_XPATH);746 msg.setDescription(msg.getDescription()747 .replace("%XPATH%", subDataParsingAnswer)748 .replace("%SUBDATA%", subDataColumnToTreat)749 .replace("%ENTRY%", lib.getName())750 .replace("%ENTRYID%", lib.getTestDataLibID().toString()));751 } else {752 //no elements were returned by the XPATH expression753 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XML_NOTFOUND);754 msg.setDescription(msg.getDescription()755 .replace("%XPATH%", subDataParsingAnswer)756 .replace("%SUBDATA%", subDataColumnToTreat)757 .replace("%ENTRY%", lib.getName())758 .replace("%XMLCONTENT%", responseString)759 .replace("%ENTRYID%", lib.getTestDataLibID().toString())760 );761 }762 } else { // Value were found we add it to the current list.763 listTemp1.add(value);764 }765 }766 // Add the Subdata with associated list in the HashMap.767 hashTemp1.put(subDataColumnToTreat, listTemp1);768 // Getting the nb of row of the final result. (Max of all the Subdata retrieved from the XML)769 if (listTemp1.size() > finalnbRow) {770 finalnbRow = listTemp1.size();771 }772 } else {773 //no elements were returned by the XPATH expression774 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XML_NOTFOUND);775 msg.setDescription(msg.getDescription()776 .replace("%XPATH%", subDataParsingAnswer)777 .replace("%SUBDATA%", subDataColumnToTreat)778 .replace("%ENTRY%", lib.getName())779 .replace("%XMLCONTENT%", responseString)780 .replace("%ENTRYID%", lib.getTestDataLibID().toString())781 );782 }783 } catch (XmlUtilException ex) {784 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XMLEXCEPTION);785 msg.setDescription(msg.getDescription()786 .replace("%XPATH%", subDataParsingAnswer)787 .replace("%SUBDATA%", subDataColumnToTreat)788 .replace("%ENTRY%", lib.getName())789 .replace("%ENTRYID%", lib.getTestDataLibID().toString())790 .replace("%REASON%", ex.toString() + " Detail answer " + responseString));791 } catch (Exception ex) {792 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_XMLEXCEPTION);793 msg.setDescription(msg.getDescription()794 .replace("%XPATH%", lib.getSubDataParsingAnswer())795 .replace("%SUBDATA%", "")796 .replace("%REASON%", ex.toString()));797 }798 }799 /**800 * This Step will convert hashTemp1 (Hash of801 * List) to target listResult (list of Hash).802 */803 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {804 for (int i = 0; i < finalnbRow; i++) { // Loop on all Values that match in XML.805 resultHash = new HashMap<String, String>();806 for (Map.Entry<String, String> entry : columnList.entrySet()) { // Loop on all SubData of the TestDataLib.807 listTemp1 = hashTemp1.get(entry.getKey());808 if (listTemp1 != null) {809 if (i < listTemp1.size()) {810 resultHash.put(entry.getKey(), listTemp1.get(i));811 } else {812 resultHash.put(entry.getKey(), "");813 }814 }815 }816 listResult.add(resultHash);817 }818 }819 /**820 * This Step will pick the correct listResult821 * (list of Hash) from the type of Property.822 */823 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {824 result.setDataList(listResult);825 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SOAP);826 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size()))827 .replace("%URL%", servicePath).replace("%OPER%", lib.getMethod()));828 }829 break;830 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:831 // We get the content of the XML in order to report it log messages.832 responseString = appService.getResponseHTTPBody();833 for (Map.Entry<String, String> entry : columnList.entrySet()) {834 String subDataColumnToTreat = entry.getKey(); // SubData835 String subDataParsingAnswer = entry.getValue(); // Parsing Answer836 listTemp1 = new ArrayList<>();837 try {838 // We try to parse the XML with the subdata Parsing Answer.839 listTemp1 = jsonService.getFromJson(responseString, subDataParsingAnswer);840 if (listTemp1.size() > 0) {841 // Add the Subdata with associated list in the HashMap.842 hashTemp1.put(subDataColumnToTreat, listTemp1);843 // Getting the nb of row of the final result. (Max of all the Subdata retrieved from the XML)844 if (listTemp1.size() > finalnbRow) {845 finalnbRow = listTemp1.size();846 }847 } else {848 //no elements were returned by the XPATH expression849 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_JSON_NOTFOUND);850 msg.setDescription(msg.getDescription()851 .replace("%XPATH%", subDataParsingAnswer)852 .replace("%SUBDATA%", subDataColumnToTreat)853 .replace("%ENTRY%", lib.getName())854 .replace("%XMLCONTENT%", responseString)855 .replace("%ENTRYID%", lib.getTestDataLibID().toString())856 );857 }858 } catch (Exception ex) {859 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_JSONEXCEPTION);860 msg.setDescription(msg.getDescription()861 .replace("%XPATH%", lib.getSubDataParsingAnswer())862 .replace("%SUBDATA%", "")863 .replace("%REASON%", ex.toString()));864 }865 }866 /**867 * This Step will convert hashTemp1 (Hash of868 * List) to target listResult (list of Hash).869 */870 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {871 for (int i = 0; i < finalnbRow; i++) { // Loop on all Values that match in XML.872 resultHash = new HashMap<String, String>();873 for (Map.Entry<String, String> entry : columnList.entrySet()) { // Loop on all SubData of the TestDataLib.874 listTemp1 = hashTemp1.get(entry.getKey());875 if (listTemp1 != null) {876 if (i < listTemp1.size()) {877 resultHash.put(entry.getKey(), listTemp1.get(i));878 } else {879 resultHash.put(entry.getKey(), "");880 }881 }882 }883 listResult.add(resultHash);884 }885 }886 /**887 * This Step will pick the correct listResult888 * (list of Hash) from the type of Property.889 */890 if (msg.getCode() == MessageEventEnum.ACTION_SUCCESS_CALLSERVICE.getCode()) {891 result.setDataList(listResult);892 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SOAP);893 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size()))894 .replace("%URL%", servicePath).replace("%OPER%", lib.getMethod()));895 }896 break;897 default:898 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOTSUPPORTEDSERVICERESULT);899 msg.setDescription(msg.getDescription().replace("%FORMAT%", appService.getResponseHTTPBodyContentType()));900 }901 }902 } else {903 String soapError = msg.getDescription();904 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_SOAPCALLFAILED);905 msg.setDescription(msg.getDescription()906 .replace("%SOAPERROR%", soapError));907 }908 msg.setDescription(msg.getDescription()909 .replace("%SERVICE%", servicePath)910 .replace("%OPERATION%", lib.getMethod()));911 result.setResultMessage(msg);912 break;913 case TestDataLib.TYPE_INTERNAL:914 result = testDataLibService.readINTERNALWithSubdataByCriteria(lib.getName(), lib.getSystem(), lib.getCountry(), lib.getEnvironment(), rowLimit, system);915 //if the sql service returns a success message then we can process it916 if ((result.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && !result.getDataList().isEmpty()) {917 msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_INTERNAL);918 msg.setDescription(msg.getDescription().replace("%NBROW%", String.valueOf(result.getDataList().size())));919 result.setResultMessage(msg);920 } else if ((result.getResultMessage().getCode() == MessageEventEnum.DATA_OPERATION_OK.getCode()) && result.getDataList().isEmpty()) {921 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_INTERNALNODATA);922 msg.setDescription(msg.getDescription().replace("%SYSTEM%", lib.getSystem())923 .replace("%ENV%", lib.getEnvironment()).replace("%COUNTRY%", lib.getCountry()));924 result.setResultMessage(msg);925 } else {926 msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_INTERNAL);927 msg.setDescription(msg.getDescription().replace("%SYSTEM%", lib.getSystem())928 .replace("%ENV%", lib.getEnvironment()).replace("%COUNTRY%", lib.getCountry()));929 result.setResultMessage(msg);930 }931 break;932 }933 return result;934 }...
Source:InvariantService.java
...58 @Override59 public HashMap<String, Integer> readToHashMapGp1IntegerByIdname(String idName, Integer defaultValue) {60 HashMap<String, Integer> result = new HashMap<String, Integer>();61 AnswerList answer = readByIdname(idName); //TODO: handle if the response does not turn ok62 for (Invariant inv : (List<Invariant>) answer.getDataList()) {63 int gp1ToInt = ParameterParserUtil.parseIntegerParam(inv.getGp1(), defaultValue);64 result.put(inv.getValue(), gp1ToInt);65 }66 return result;67 }68 @Override69 public HashMap<String, String> readToHashMapGp1StringByIdname(String idName, String defaultValue) {70 HashMap<String, String> result = new HashMap<String, String>();71 AnswerList answer = readByIdname(idName); //TODO: handle if the response does not turn ok72 for (Invariant inv : (List<Invariant>) answer.getDataList()) {73 String gp1 = ParameterParserUtil.parseStringParam(inv.getGp1(), defaultValue);74 result.put(inv.getValue(), gp1);75 }76 return result;77 }78 @Override79 public AnswerList readByIdnameGp1(String idName, String gp) {80 return invariantDao.readByIdnameByGp1(idName, gp);81 }82 @Override83 public AnswerList readCountryListEnvironmentLastChanges(String system, Integer nbDays) {84 return invariantDao.readCountryListEnvironmentLastChanges(system, nbDays);85 }86 @Override87 public AnswerList readByPublicByCriteria(int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {88 // We first get the list of all Public invariant from the invariant table.89 String searchSQL = this.getPublicPrivateFilter("INVARIANTPUBLIC");90 // Then, we build the list of invariant entry based on the filter.91 //TODO this method should return a AnswerList, after complete refactoring this method should be changed92 AnswerList answer = invariantDao.readByCriteria(start, amount, column, dir, searchTerm, individualSearch, searchSQL);93 return answer;94 }95 @Override96 public AnswerList readByPublicByCriteria(int start, int amount, String column, String dir, String searchTerm, String individualSearch) {97 // We first get the list of all Public invariant from the invariant table.98 String searchSQL = this.getPublicPrivateFilter("INVARIANTPUBLIC");99 // Then, we build the list of invariant entry based on the filter.100 //TODO this method should return a AnswerList, after complete refactoring this method should be changed101 AnswerList answer = invariantDao.readByCriteria(start, amount, column, dir, searchTerm, individualSearch, searchSQL);102 return answer;103 }104 @Override105 public AnswerList readDistinctValuesByPublicByCriteria(String column, String dir, String searchTerm, Map<String, List<String>> individualSearch, String columnName) {106 // We first get the list of all Public invariant from the invariant table.107 String searchSQL = this.getPublicPrivateFilter("INVARIANTPUBLIC");108 // Then, we build the list of invariant entry based on the filter.109 //TODO this method should return a AnswerList, after complete refactoring this method should be changed110 AnswerList answer = invariantDao.readDistinctValuesByCriteria(column, dir, searchTerm, individualSearch, searchSQL, columnName);111 return answer;112 }113 @Override114 public AnswerList readByPrivateByCriteria(int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {115 // We first get the list of all Private invariant from the invariant table.116 String searchSQL = this.getPublicPrivateFilter("INVARIANTPRIVATE");117 // Then, we build the list of invariant entry based on the filter.118 //TODO this method should return a AnswerList, after complete refactoring this method should be changed119 AnswerList answer = invariantDao.readByCriteria(start, amount, column, dir, searchTerm, individualSearch, searchSQL);120 return answer;121 }122 @Override123 public AnswerList readByPrivateByCriteria(int start, int amount, String column, String dir, String searchTerm, String individualSearch) {124 // We first get the list of all Private invariant from the invariant table.125 String searchSQL = this.getPublicPrivateFilter("INVARIANTPRIVATE");126 // Then, we build the list of invariant entry based on the filter.127 //TODO this method should return a AnswerList, after complete refactoring this method should be changed128 AnswerList answer = invariantDao.readByCriteria(start, amount, column, dir, searchTerm, individualSearch, searchSQL);129 return answer;130 }131 @Override132 public AnswerList readDistinctValuesByPrivateByCriteria(String column, String dir, String searchTerm, Map<String, List<String>> individualSearch, String columnName) {133 // We first get the list of all Public invariant from the invariant table.134 String searchSQL = this.getPublicPrivateFilter("INVARIANTPRIVATE");135 // Then, we build the list of invariant entry based on the filter.136 //TODO this method should return a AnswerList, after complete refactoring this method should be changed137 AnswerList answer = invariantDao.readDistinctValuesByCriteria(column, dir, searchTerm, individualSearch, searchSQL, columnName);138 return answer;139 }140 @Override141 public AnswerList readByCriteria(int start, int amount, String column, String dir, String searchTerm, String individualSearch) {142 //gets all invariants143 return invariantDao.readByCriteria(start, amount, column, dir, searchTerm, individualSearch, "");//no filter public or private is sent 144 }145 @Override146 public boolean isInvariantExist(String idName, String value) {147 AnswerItem objectAnswer = readByKey(idName, value);148 return (objectAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) && (objectAnswer.getItem() != null); // Call was successfull and object was found.149 }150 @Override151 public boolean isInvariantPublic(Invariant object) {152 AnswerItem objectAnswer = readByKey("INVARIANTPUBLIC", object.getIdName());153 return (objectAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) && (objectAnswer.getItem() != null); // Call was successfull and object was found.154 }155 @Override156 public Answer create(Invariant invariant) {157 return invariantDao.create(invariant);158 }159 @Override160 public Answer delete(Invariant invariant) {161 return invariantDao.delete(invariant);162 }163 @Override164 public Answer update(String idname, String value, Invariant invariant) {165 return invariantDao.update(idname, value, invariant);166 }167 @Override168 public String getPublicPrivateFilter(String filter) {169 String searchSQL = " 1=0 ";170 AnswerList answer = this.readByIdname(filter);171 List<Invariant> invPrivate = answer.getDataList();172 List<String> idnameList = null;173 idnameList = new ArrayList<String>();174 for (Invariant toto : invPrivate) {175 idnameList.add(toto.getValue());176 }177 searchSQL = SqlUtil.createWhereInClause("idname", idnameList, true);178 return searchSQL;179 }180 @Override181 public boolean hasPermissionsRead(Invariant invariant, HttpServletRequest request) {182 // Access right calculation.183 return true;184 }185 @Override186 public boolean hasPermissionsUpdate(Invariant invariant, HttpServletRequest request) {187 // Access right calculation.188 return (request.isUserInRole("Administrator") && isInvariantPublic(invariant));189 }190 @Override191 public boolean hasPermissionsCreate(Invariant invariant, HttpServletRequest request) {192 // Access right calculation.193 return (request.isUserInRole("Administrator") && isInvariantPublic(invariant));194 }195 @Override196 public boolean hasPermissionsDelete(Invariant invariant, HttpServletRequest request) {197 // Access right calculation.198 return (request.isUserInRole("Administrator") && isInvariantPublic(invariant));199 }200 @Override201 public Invariant convert(AnswerItem answerItem) throws CerberusException {202 if (answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {203 //if the service returns an OK message then we can get the item204 return (Invariant) answerItem.getItem();205 }206 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));207 }208 @Override209 public List<Invariant> convert(AnswerList answerList) throws CerberusException {210 if (answerList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {211 //if the service returns an OK message then we can get the item212 return (List<Invariant>) answerList.getDataList();213 }214 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));215 }216 @Override217 public void convert(Answer answer) throws CerberusException {218 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {219 //if the service returns an OK message then we can get the item220 return;221 }222 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));223 }224}...
Source:TestCaseStepExecutionService.java
...69 public AnswerList readByVarious1WithDependency(long executionId, String test, String testcase) {70 AnswerList steps = this.readByVarious1(executionId, test, testcase);71 AnswerList response = null;72 List<TestCaseStepExecution> tcseList = new ArrayList();73 for (Object step : steps.getDataList()) {74 TestCaseStepExecution tces = (TestCaseStepExecution) step;75 AnswerList actions = testCaseStepActionExecutionService.readByVarious1WithDependency(executionId, tces.getTest(), tces.getTestCase(), tces.getStep(), tces.getIndex());76 tces.setTestCaseStepActionExecutionList((List<TestCaseStepActionExecution>) actions.getDataList());77 AnswerList files = testCaseExecutionFileService.readByVarious(executionId, tces.getTest() + "-" + tces.getTestCase() + "-" + tces.getStep() + "-" + tces.getIndex());78 tces.setFileList((List<TestCaseExecutionFile>) files.getDataList());79 tcseList.add(tces);80 }81 response = new AnswerList(tcseList, steps.getTotalRows());82 return response;83 }84}...
getDataList
Using AI Code Generation
1package org.cerberus.util;2import org.cerberus.util.answer.AnswerList;3import org.cerberus.util.answer.AnswerItem;4import org.cerberus.util.answer.Answer;5import java.util.List;6public class Main {7 public static void main(String[] args) {8 AnswerList answerList = new AnswerList();9 List dataList = answerList.getDataList();10 System.out.println(dataList);11 }12}13package org.cerberus.util;14import org.cerberus.util.answer.AnswerList;15import org.cerberus.util.answer.AnswerItem;16import org.cerberus.util.answer.Answer;17import java.util.List;18public class Main {19 public static void main(String[] args) {20 AnswerList answerList = new AnswerList();21 List dataList = answerList.getDataList();22 System.out.println(dataList);23 }24}25package org.cerberus.util;26import org.cerberus.util.answer.AnswerList;27import org.cerberus.util.answer.AnswerItem;28import org.cerberus.util.answer.Answer;29import java.util.List;30public class Main {31 public static void main(String[] args) {32 AnswerList answerList = new AnswerList();33 List dataList = answerList.getDataList();34 System.out.println(dataList);35 }36}37package org.cerberus.util;38import org.cerberus.util.answer.AnswerList;39import org.cerberus.util.answer.AnswerItem;40import org.cerberus.util.answer.Answer;41import java.util.List;42public class Main {43 public static void main(String[] args) {44 AnswerList answerList = new AnswerList();45 List dataList = answerList.getDataList();46 System.out.println(dataList);47 }48}49package org.cerberus.util;50import org.cerberus.util.answer.AnswerList;51import org.cerberus
getDataList
Using AI Code Generation
1import org.cerberus.util.answer.AnswerList;2import org.cerberus.util.answer.AnswerItem;3import java.util.List;4public class 3 {5 public static void main(String[] args) {6 AnswerList answerList = new AnswerList();7 List<AnswerItem> list = answerList.getDataList();8 for (AnswerItem answerItem : list) {9 System.out.println(answerItem.getItem());10 }11 }12}13package org.cerberus.util.answer;14public class AnswerItem {15 private String item;16 public String getItem() {17 return item;18 }19 public void setItem(String item) {20 this.item = item;21 }22}23package org.cerberus.util.answer;24import java.util.ArrayList;25import java.util.List;26public class AnswerList {27 private List<AnswerItem> dataList = new ArrayList<AnswerItem>();28 public List<AnswerItem> getDataList() {29 return dataList;30 }31 public void setDataList(List<AnswerItem> dataList) {32 this.dataList = dataList;33 }34 public AnswerList() {35 AnswerItem answerItem1 = new AnswerItem();36 answerItem1.setItem("item1");37 dataList.add(answerItem1);38 AnswerItem answerItem2 = new AnswerItem();39 answerItem2.setItem("item2");40 dataList.add(answerItem2);41 AnswerItem answerItem3 = new AnswerItem();42 answerItem3.setItem("item3");43 dataList.add(answerItem3);44 AnswerItem answerItem4 = new AnswerItem();45 answerItem4.setItem("item4");46 dataList.add(answerItem4);47 AnswerItem answerItem5 = new AnswerItem();48 answerItem5.setItem("item5");49 dataList.add(answerItem5);50 }51}
getDataList
Using AI Code Generation
1package com.cerberus.test;2import java.util.List;3import org.cerberus.crud.entity.TestCase;4import org.cerberus.util.answer.AnswerList;5public class getDataList {6 public static void main(String args[]) {7 AnswerList answer = new AnswerList();8 List<TestCase> testCaseList = answer.getDataList();9 for (TestCase testCase : testCaseList) {10 System.out.println(testCase.getTest() + " " + testCase.getTestCase());11 }12 }13}
getDataList
Using AI Code Generation
1package org.cerberus.util.answer;2import java.sql.Connection;3import java.sql.ResultSet;4import java.sql.SQLException;5import java.sql.Statement;6import java.util.ArrayList;7import java.util.List;8import org.apache.log4j.Logger;9import org.cerberus.util.answer.AnswerItem;10import org.cerberus.util.answer.AnswerList;11import org.cerberus.util.answer.AnswerUtil;12import org.cerberus.util.answer.IFactoryAnswer;13import org.cerberus.util.answer.Item;14import org.cerberus.util.answer.ItemList;15import org.cerberus.util.answer.ItemUtil;16import org.cerberus.util.answer.MessageEvent;17import org.cerberus.util.answer.MessageGeneral;18import org.cerberus.util.answer.MessageGeneralEnum;19import org.cerberus.util.answer.MessageEventEnum;20import org.cerberus.database.DatabaseSpring;21import org.cerberus.database.DatabaseSpringException;22import org.cerberus.database.IConnectionService;23import org.cerberus.database.IFactoryDatabaseSpring;24import org.cerberus.exception.CerberusException;25import org.cerberus.exception.CerberusFactoryException;26import org.cerberus.factory.IFactoryUser;27import org.cerberus.factory.impl.FactoryUser;28import org.cerberus.util.answer.IAnswerItem;29import org.cerberus.util.answer.IAnswerList;30import org.cerberus.util.answer.IAnswerUtil;31public class AnswerUtil implements IAnswerUtil {32 private static final Logger LOG = Logger.getLogger(AnswerUtil.class);33 public IAnswerItem readByKey(String key, String value, String table, String column, String column2) {34 throw new UnsupportedOperationException("Not supported yet.");35 }36 public IAnswerItem readByKey(String key, String value, String table, String column) {37 throw new UnsupportedOperationException("Not supported yet.");38 }39 public IAnswerItem readByKey(String key, String value, String table) {40 throw new UnsupportedOperationException("Not supported yet.");41 }42 public IAnswerItem readByKey(String key, String value, String table, String column, String column2, String column3) {43 throw new UnsupportedOperationException("Not supported yet.");44 }45 public IAnswerItem readByKey(String key, String value
getDataList
Using AI Code Generation
1package org.cerberus.util.answer;2import java.util.List;3import org.cerberus.util.answer.AnswerItem;4public class AnswerList<T> extends AnswerItem<List<T>> {5 public AnswerList() {6 super();7 }8 public AnswerList(List<T> item) {9 super(item);10 }11 public AnswerList(List<T> item, MessageEvent message) {12 super(item, message);13 }14 public AnswerList(MessageEvent message) {15 super(message);16 }17}18package org.cerberus.util.answer;19import java.util.List;20import org.cerberus.util.answer.AnswerItem;21public class AnswerList<T> extends AnswerItem<List<T>> {22 public AnswerList() {23 super();24 }25 public AnswerList(List<T> item) {26 super(item);27 }28 public AnswerList(List<T> item, MessageEvent message) {29 super(item, message);30 }31 public AnswerList(MessageEvent message) {32 super(message);33 }34}35package org.cerberus.util.answer;36import java.util.List;37import org.cerberus.util.answer.AnswerItem;38public class AnswerList<T> extends AnswerItem<List<T>> {39 public AnswerList() {40 super();41 }42 public AnswerList(List<T> item) {43 super(item);44 }45 public AnswerList(List<T> item, MessageEvent message) {46 super(item, message);47 }48 public AnswerList(MessageEvent message) {49 super(message);50 }51}52package org.cerberus.util.answer;53import java.util.List;54import org.cerberus.util.answer.AnswerItem;55public class AnswerList<T> extends AnswerItem<List<T>> {56 public AnswerList() {57 super();58 }59 public AnswerList(List<T> item) {60 super(item
getDataList
Using AI Code Generation
1package org.cerberus.util.answer;2import java.io.*;3import java.util.*;4import javax.servlet.*;5import javax.servlet.http.*;6import org.cerberus.util.answer.AnswerList;
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!!