Best Cerberus-source code snippet using org.cerberus.util.StringUtil.isNull
Source:TestCaseExecutionDAO.java
...284 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 285 //were applied -- used for pagination p286 query.append("select * from testcaseexecution exe ");287 searchSQL.append(" where 1=1 ");288 if (!StringUtil.isNullOrEmpty(application)) {289 searchSQL.append(" and (`application` = ? )");290 }291 query.append(searchSQL);292 query.append(" order by id DESC limit 1 ");293 // Debug message on SQL.294 if (LOG.isDebugEnabled()) {295 LOG.debug("SQL : " + query);296 }297 Connection connection = this.databaseSpring.connect();298 try {299 PreparedStatement preStat = connection.prepareStatement(query.toString());300 try {301 int i = 1;302 if (!StringUtil.isNullOrEmpty(application)) {303 preStat.setString(i++, application);304 }305 ResultSet resultSet = preStat.executeQuery();306 try {307 if (resultSet.first()) {308 result = loadFromResultSet(resultSet);309 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);310 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));311 ans.setItem(result);312 } else {313 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);314 }315 } catch (SQLException exception) {316 LOG.error("Unable to execute query : " + exception.toString());317 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);318 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));319 } finally {320 resultSet.close();321 }322 } catch (SQLException exception) {323 LOG.error("Unable to execute query : " + exception.toString());324 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);325 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));326 } finally {327 preStat.close();328 }329 } catch (SQLException exception) {330 LOG.error("Unable to execute query : " + exception.toString());331 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);332 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));333 } finally {334 try {335 if (connection != null) {336 connection.close();337 }338 } catch (SQLException exception) {339 LOG.warn("Unable to close connection : " + exception.toString());340 }341 }342 //sets the message343 ans.setResultMessage(msg);344 return ans;345 }346 @Override347 public TestCaseExecution findLastTCExecutionByCriteria(String test, String testcase, String environment, String country,348 String build, String revision) throws CerberusException {349 TestCaseExecution result = null;350 final String query = new StringBuffer("SELECT exe.* FROM testcaseexecution exe ")351 .append("WHERE exe.test = ? AND exe.testcase = ? AND exe.environment = ? ")352 .append("AND exe.country = ? AND exe.build = ? AND exe.revision = ? ")353 .append("ORDER BY exe.id DESC").toString();354 try (Connection connection = this.databaseSpring.connect();355 PreparedStatement preStat = connection.prepareStatement(query);) {356 preStat.setString(1, test);357 preStat.setString(2, testcase);358 preStat.setString(3, environment);359 preStat.setString(4, country);360 preStat.setString(5, build);361 preStat.setString(6, revision);362 try (ResultSet resultSet = preStat.executeQuery();) {363 if (resultSet.first()) {364 result = this.loadFromResultSet(resultSet);365 } else {366 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));367 }368 } catch (SQLException exception) {369 LOG.error("Unable to execute query : " + exception.toString());370 }371 } catch (SQLException exception) {372 LOG.error("Unable to execute query : " + exception.toString());373 }374 return result;375 }376 @Override377 public TestCaseExecution findLastTCExecutionByCriteria(String test, String testCase, String environment, String country,378 String build, String revision, String browser, String browserVersion,379 String ip, String port, String tag) {380 TestCaseExecution result = null;381 final String query = new StringBuffer("SELECT exe.* FROM testcaseexecution exe ")382 .append("WHERE exe.test = ? AND exe.testcase = ? ")383 .append("AND exe.environment LIKE ? AND exe.country = ? AND exe.build LIKE ? ")384 .append("AND exe.revision LIKE ? AND exe.browser = ? AND exe.browserfullversion LIKE ? ")385 .append("AND exe.ip LIKE ? AND exe.port LIKE ? AND exe.tag LIKE ? ")386 .append("ORDER BY exe.id DESC").toString();387 try (Connection connection = this.databaseSpring.connect();388 PreparedStatement preStat = connection.prepareStatement(query);) {389 preStat.setString(1, test);390 preStat.setString(2, testCase);391 preStat.setString(3, ParameterParserUtil.wildcardIfEmpty(environment));392 preStat.setString(4, country);393 preStat.setString(5, ParameterParserUtil.wildcardIfEmpty(build));394 preStat.setString(6, ParameterParserUtil.wildcardIfEmpty(revision));395 preStat.setString(7, browser);396 preStat.setString(8, ParameterParserUtil.wildcardIfEmpty(browserVersion));397 preStat.setString(9, ParameterParserUtil.wildcardIfEmpty(ip));398 preStat.setString(10, ParameterParserUtil.wildcardIfEmpty(port));399 preStat.setString(11, ParameterParserUtil.wildcardIfEmpty(tag));400 try (ResultSet resultSet = preStat.executeQuery();) {401 if (resultSet.first()) {402 result = this.loadFromResultSet(resultSet);403 }404 } catch (SQLException exception) {405 LOG.error("Unable to execute query : " + exception.toString());406 }407 } catch (SQLException exception) {408 LOG.error("Unable to execute query : " + exception.toString());409 }410 return result;411 }412 @Override413 public List<TestCaseExecution> findExecutionbyCriteria1(String dateLimit, String test, String testCase, String application, String country, String environment, String controlStatus, String status) throws CerberusException {414 List<TestCaseExecution> myTestCaseExecutions = null;415 TestCaseExecution Execution;416 boolean throwException = false;417 final String query = new StringBuffer("SELECT exe.*, tec.*, app.* FROM testcaseexecution exe ")418 .append("LEFT JOIN testcase tec ON exe.test = tec.test AND exe.testcase = tec.testcase ")419 .append("LEFT JOIN application app ON exe.application = app.application ")420 .append("WHERE exe.start > ? AND exe.test LIKE ? AND exe.testcase LIKE ? AND exe.environment LIKE ? ")421 .append("AND exe.country LIKE ? AND exe.application LIKE ? AND exe.controlstatus LIKE ? ")422 .append("AND exe.status LIKE ?").toString();423 try (Connection connection = this.databaseSpring.connect();424 PreparedStatement preStat = connection.prepareStatement(query);) {425 preStat.setString(1, dateLimit);426 preStat.setString(2, test);427 preStat.setString(3, testCase);428 preStat.setString(4, environment);429 preStat.setString(5, country);430 preStat.setString(6, application);431 preStat.setString(7, controlStatus);432 preStat.setString(8, status);433 try (ResultSet resultSet = preStat.executeQuery();) {434 if (!(resultSet.first())) {435 throwException = true;436 } else {437 myTestCaseExecutions = new ArrayList<TestCaseExecution>();438 do {439 Execution = this.loadWithDependenciesFromResultSet(resultSet);440 myTestCaseExecutions.add(Execution);441 } while (resultSet.next());442 }443 } catch (SQLException exception) {444 LOG.error("Unable to execute query : " + exception.toString());445 }446 } catch (Exception exception) {447 LOG.error("Unable to execute query : " + exception.toString());448 }449 if (throwException) {450 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));451 }452 return myTestCaseExecutions;453 }454 @Override455 public TestCaseExecution findTCExecutionByKey(long id) throws CerberusException {456 TestCaseExecution result = null;457 final String query = "SELECT * FROM testcaseexecution exe, application app WHERE exe.application = app.application AND ID = ?";458 // Debug message on SQL.459 if (LOG.isDebugEnabled()) {460 LOG.debug("SQL : " + query);461 }462 try (Connection connection = this.databaseSpring.connect();463 PreparedStatement preStat = connection.prepareStatement(query);) {464 preStat.setLong(1, id);465 try (ResultSet resultSet = preStat.executeQuery();) {466 if (resultSet.first()) {467 result = this.loadTestCaseExecutionAndApplicationFromResultSet(resultSet);468 }469 } catch (SQLException exception) {470 LOG.error("Unable to execute query : " + exception.toString());471 }472 } catch (SQLException exception) {473 LOG.error("Unable to execute query : " + exception.toString());474 }475 return result;476 }477 @Override478 public TestCaseExecution findLastTestCaseExecutionNotPE(String test, String testCase) throws CerberusException {479 TestCaseExecution result = null;480 StringBuilder query = new StringBuilder();481 query.append("SELECT exe.* FROM `testcaseexecution` exe ");482 query.append(" WHERE Test = ? and TestCase= ? and ID = ");483 query.append(" (SELECT MAX(ID) from `testcaseexecution` ");484 query.append("WHERE Test= ? and TestCase= ? and ControlStatus!='PE')");485 try (Connection connection = this.databaseSpring.connect();486 PreparedStatement preStat = connection.prepareStatement(query.toString());) {487 preStat.setString(1, test);488 preStat.setString(2, testCase);489 preStat.setString(3, test);490 preStat.setString(4, testCase);491 try (ResultSet resultSet = preStat.executeQuery();) {492 if (resultSet.first()) {493 result = loadFromResultSet(resultSet);494 }495 } catch (SQLException exception) {496 LOG.error("Unable to execute query : " + exception.toString());497 }498 } catch (SQLException exception) {499 LOG.error("Unable to execute query : " + exception.toString());500 }501 return result;502 }503 @Override504 public TestCaseExecution findLastTCExecutionInGroup(String test, String testCase, String environment, String country,505 String build, String revision, String browser, String browserVersion,506 String ip, String port, String tag) {507 TestCaseExecution result = null;508 StringBuilder query = new StringBuilder();509 query.append("SELECT exe.* FROM testcaseexecution exe ")510 .append("WHERE exe.test = ? AND exe.testcase = ? AND exe.country = ? AND exe.browser = ? ");511 if (!StringUtil.isNull(environment)) {512 query.append("AND exe.environment IN (");513 query.append(environment);514 query.append(") ");515 }516 if (!StringUtil.isNull(build)) {517 query.append("AND exe.build IN (");518 query.append(build);519 query.append(") ");520 }521 if (!StringUtil.isNull(revision)) {522 query.append("AND exe.revision IN (");523 query.append(revision);524 query.append(") ");525 }526 if (!StringUtil.isNull(browserVersion)) {527 query.append("AND exe.browserfullversion LIKE ? ");528 }529 if (!StringUtil.isNull(ip)) {530 query.append("AND exe.ip LIKE ? ");531 }532 if (!StringUtil.isNull(port)) {533 query.append("AND exe.port LIKE ? ");534 }535 if (!StringUtil.isNull(tag)) {536 query.append("AND exe.tag LIKE ? ");537 }538 query.append("ORDER BY exe.id DESC");539 try (Connection connection = this.databaseSpring.connect();540 PreparedStatement preStat = connection.prepareStatement(query.toString());) {541 preStat.setString(1, test);542 preStat.setString(2, testCase);543 preStat.setString(3, country);544 preStat.setString(4, browser);545 int i = 5;546 if (!StringUtil.isNull(browserVersion)) {547 preStat.setString(i, browserVersion);548 i++;549 }550 if (!StringUtil.isNull(ip)) {551 preStat.setString(i, ip);552 i++;553 }554 if (!StringUtil.isNull(port)) {555 preStat.setString(i, port);556 i++;557 }558 if (!StringUtil.isNull(tag)) {559 preStat.setString(i, tag);560 }561 try (ResultSet resultSet = preStat.executeQuery();) {562 if (resultSet.first()) {563 result = this.loadFromResultSet(resultSet);564 }565 } catch (SQLException exception) {566 LOG.error("Unable to execute query : " + exception.toString());567 }568 } catch (SQLException exception) {569 LOG.error("Unable to execute query : " + exception.toString());570 }571 return result;572 }573 @Override574 public List<String> findDistinctTag(boolean withUUIDTag) throws CerberusException {575 List<String> list = null;576 StringBuilder query = new StringBuilder();577 query.append("select distinct tag from testcaseexecution exe ")578 .append("where tag != '' ");579 if (!withUUIDTag) {580 query.append(" and length(tag) != length('c3888898-c65a-11e3-9b3e-0000004047e0')");581 }582 query.append(" UNION select distinct tag from testcaseexecutionqueue where tag !='' ");583 Connection connection = this.databaseSpring.connect();584 try {585 PreparedStatement preStat = connection.prepareStatement(query.toString());586 try {587 ResultSet resultSet = preStat.executeQuery();588 try {589 list = new ArrayList<String>();590 while (resultSet.next()) {591 list.add(resultSet.getString("tag"));592 }593 } catch (SQLException exception) {594 LOG.error("Unable to execute query : " + exception.toString());595 } finally {596 resultSet.close();597 }598 } catch (SQLException exception) {599 LOG.error("Unable to execute query : " + exception.toString());600 } finally {601 preStat.close();602 }603 } catch (SQLException exception) {604 LOG.error("Unable to execute query : " + exception.toString());605 } finally {606 try {607 if (connection != null) {608 connection.close();609 }610 } catch (SQLException e) {611 LOG.warn(e.toString());612 }613 }614 return list;615 }616 @Override617 public AnswerList findTagList(int tagnumber) {618 AnswerList response = new AnswerList();619 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);620 List<String> list = null;621 StringBuilder query = new StringBuilder();622 query.append("SELECT DISTINCT exe.tag FROM testcaseexecution exe WHERE tag != ''");623 if (tagnumber != 0) {624 query.append("ORDER BY id desc LIMIT ");625 query.append(tagnumber);626 }627 query.append(";");628 Connection connection = this.databaseSpring.connect();629 try {630 PreparedStatement preStat = connection.prepareStatement(query.toString());631 try {632 ResultSet resultSet = preStat.executeQuery();633 try {634 list = new ArrayList<String>();635 while (resultSet.next()) {636 list.add(resultSet.getString("exe.tag"));637 }638 msg.setDescription(msg.getDescription().replace("%ITEM%", "TagList").replace("%OPERATION%", "SELECT"));639 } catch (SQLException exception) {640 LOG.error("Unable to execute query : " + exception.toString());641 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);642 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));643 } finally {644 resultSet.close();645 }646 } catch (SQLException exception) {647 LOG.error("Unable to execute query : " + exception.toString());648 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);649 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));650 } finally {651 preStat.close();652 }653 } catch (SQLException exception) {654 LOG.error("Unable to execute query : " + exception.toString());655 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);656 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));657 } finally {658 try {659 if (connection != null) {660 connection.close();661 }662 } catch (SQLException e) {663 LOG.warn(e.toString());664 }665 }666 response.setResultMessage(msg);667 response.setDataList(list);668 return response;669 }670 @Override671 public void setTagToExecution(long id, String tag) throws CerberusException {672 boolean throwEx = false;673 final String query = "UPDATE testcaseexecution exe SET exe.tag = ? WHERE exe.id = ?";674 Connection connection = this.databaseSpring.connect();675 try {676 PreparedStatement preStat = connection.prepareStatement(query);677 try {678 preStat.setString(1, tag);679 preStat.setLong(2, id);680 preStat.executeUpdate();681 } catch (SQLException exception) {682 LOG.error("Unable to execute query : " + exception.toString());683 throwEx = true;684 } finally {685 preStat.close();686 }687 } catch (SQLException exception) {688 LOG.error("Unable to execute query : " + exception.toString());689 } finally {690 try {691 if (connection != null) {692 connection.close();693 }694 } catch (SQLException e) {695 LOG.warn(e.toString());696 }697 }698 if (throwEx) {699 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));700 }701 }702 @Override703 public AnswerList readByTagByCriteria(String tag, int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch) throws CerberusException {704 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);705 AnswerList answer = new AnswerList();706 List<String> individalColumnSearchValues = new ArrayList<String>();707 final StringBuffer query = new StringBuffer();708 query.append("SELECT * FROM testcaseexecution exe ");709 query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");710 query.append("left join application app on tec.application = app.application ");711 query.append("where exe.ID IN ");712 query.append("(select MAX(exe.ID) from testcaseexecution exe ");713 query.append("where 1=1 ");714 if (!StringUtil.isNullOrEmpty(tag)) {715 query.append("and exe.tag = ? ");716 }717 query.append("group by exe.test, exe.testcase, exe.Environment, exe.Browser, exe.Country) ");718 if (!StringUtil.isNullOrEmpty(searchTerm)) {719 query.append("and (exe.`test` like ? ");720 query.append(" or exe.`testCase` like ? ");721 query.append(" or exe.`application` like ? ");722 query.append(" or tec.`bugid` like ? ");723 query.append(" or tec.`priority` like ? ");724 query.append(" or tec.`description` like ? )");725 }726 if (individualSearch != null && !individualSearch.isEmpty()) {727 query.append(" and ( 1=1 ");728 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {729 query.append(" and ");730 query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));731 individalColumnSearchValues.addAll(entry.getValue());732 }733 query.append(" ) ");734 }735 if (!StringUtil.isNullOrEmpty(sort)) {736 query.append(" order by ").append(sort);737 }738 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {739 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);740 } else {741 query.append(" limit ").append(start).append(" , ").append(amount);742 }743 // Debug message on SQL.744 if (LOG.isDebugEnabled()) {745 LOG.debug("SQL : " + query.toString());746 LOG.debug("SQL.param.tag : " + tag);747 }748 List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();749 Connection connection = this.databaseSpring.connect();750 try {751 PreparedStatement preStat = connection.prepareStatement(query.toString());752 int i = 1;753 if (!StringUtil.isNullOrEmpty(tag)) {754 preStat.setString(i++, tag);755 }756 if (!Strings.isNullOrEmpty(searchTerm)) {757 preStat.setString(i++, "%" + searchTerm + "%");758 preStat.setString(i++, "%" + searchTerm + "%");759 preStat.setString(i++, "%" + searchTerm + "%");760 preStat.setString(i++, "%" + searchTerm + "%");761 preStat.setString(i++, "%" + searchTerm + "%");762 preStat.setString(i++, "%" + searchTerm + "%");763 }764 for (String individualColumnSearchValue : individalColumnSearchValues) {765 preStat.setString(i++, individualColumnSearchValue);766 }767 try {768 ResultSet resultSet = preStat.executeQuery();769 try {770 while (resultSet.next()) {771 testCaseExecutionList.add(this.loadWithDependenciesFromResultSet(resultSet));772 }773 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));774// answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size());775 answer.setTotalRows(testCaseExecutionList.size());776 } catch (SQLException exception) {777 LOG.warn("Unable to execute query : " + exception.toString());778 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);779 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));780 testCaseExecutionList = null;781 } finally {782 resultSet.close();783 }784 } catch (SQLException exception) {785 LOG.warn("Unable to execute query : " + exception.toString());786 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);787 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));788 testCaseExecutionList = null;789 } finally {790 preStat.close();791 }792 } catch (SQLException exception) {793 LOG.warn("Unable to execute query : " + exception.toString());794 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);795 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));796 testCaseExecutionList = null;797 } finally {798 try {799 if (connection != null) {800 connection.close();801 }802 } catch (SQLException e) {803 LOG.warn(e.toString());804 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);805 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));806 }807 }808 answer.setResultMessage(msg);809 answer.setDataList(testCaseExecutionList);810 return answer;811 }812 @Override813 public AnswerList readByTag(String tag) throws CerberusException {814 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);815 AnswerList answer = new AnswerList();816 final StringBuffer query = new StringBuffer();817 query.append("SELECT * FROM testcaseexecution exe ");818 query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");819 query.append("left join application as app on tec.application = app.application ");820 query.append("where 1=1 and exe.tag = ? ");821 // Debug message on SQL.822 if (LOG.isDebugEnabled()) {823 LOG.debug("SQL : " + query.toString());824 LOG.debug("SQL.param.tag : " + tag);825 }826 List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();827 Connection connection = this.databaseSpring.connect();828 try {829 PreparedStatement preStat = connection.prepareStatement(query.toString());830 preStat.setString(1, tag);831 try {832 ResultSet resultSet = preStat.executeQuery();833 try {834 while (resultSet.next()) {835 testCaseExecutionList.add(this.loadWithDependenciesFromResultSet(resultSet));836 }837 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));838 answer.setTotalRows(testCaseExecutionList.size());839 } catch (SQLException exception) {840 LOG.warn("Unable to execute query : " + exception.toString());841 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);842 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));843 testCaseExecutionList = null;844 } finally {845 resultSet.close();846 }847 } catch (SQLException exception) {848 LOG.warn("Unable to execute query : " + exception.toString());849 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);850 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));851 testCaseExecutionList = null;852 } finally {853 preStat.close();854 }855 } catch (SQLException exception) {856 LOG.warn("Unable to execute query : " + exception.toString());857 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);858 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));859 testCaseExecutionList = null;860 } finally {861 try {862 if (connection != null) {863 connection.close();864 }865 } catch (SQLException e) {866 LOG.warn(e.toString());867 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);868 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));869 }870 }871 answer.setResultMessage(msg);872 answer.setDataList(testCaseExecutionList);873 return answer;874 }875 @Override876 public AnswerList readByCriteria(int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch, List<String> individualLike) throws CerberusException {877 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);878 AnswerList answer = new AnswerList();879 List<String> individalColumnSearchValues = new ArrayList<String>();880 final StringBuffer query = new StringBuffer();881 query.append("SELECT * FROM testcaseexecution exe ");882 query.append("where exe.`start`> '").append(DateUtil.getMySQLTimestampTodayDeltaMinutes(-360000)).append("' ");883 if (!StringUtil.isNullOrEmpty(searchTerm)) {884 query.append("and (exe.`id` like ? ");885 query.append(" or exe.`test` like ? ");886 query.append(" or exe.`testCase` like ? ");887 query.append(" or exe.`build` like ? ");888 query.append(" or exe.`revision` like ? ");889 query.append(" or exe.`environment` like ? ");890 query.append(" or exe.`country` like ? ");891 query.append(" or exe.`browser` like ? ");892 query.append(" or exe.`version` like ? ");893 query.append(" or exe.`platform` like ? ");894 query.append(" or exe.`browserfullversion` like ? ");895 query.append(" or exe.`start` like ? ");896 query.append(" or exe.`end` like ? ");897 query.append(" or exe.`controlstatus` like ? ");898 query.append(" or exe.`controlmessage` like ? ");899 query.append(" or exe.`application` like ? ");900 query.append(" or exe.`ip` like ? ");901 query.append(" or exe.`url` like ? ");902 query.append(" or exe.`port` like ? ");903 query.append(" or exe.`tag` like ? ");904 query.append(" or exe.`end` like ? ");905 query.append(" or exe.`status` like ? ");906 query.append(" or exe.`crbversion` like ? ");907 query.append(" or exe.`executor` like ? ");908 query.append(" or exe.`screensize` like ? ");909 query.append(" or exe.`userAgent` like ? )");910 }911 if (individualSearch != null && !individualSearch.isEmpty()) {912 query.append(" and ( 1=1 ");913 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {914 query.append(" and ");915 query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));916 individalColumnSearchValues.addAll(entry.getValue());917 }918 query.append(" ) ");919 }920 if (!StringUtil.isNullOrEmpty(sort)) {921 query.append(" order by ").append(sort);922 }923 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {924 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);925 } else {926 query.append(" limit ").append(start).append(" , ").append(amount);927 }928 // Debug message on SQL.929 if (LOG.isDebugEnabled()) {930 LOG.debug("SQL : " + query.toString());931 }932 List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();933 Connection connection = this.databaseSpring.connect();934 try {935 PreparedStatement preStat = connection.prepareStatement(query.toString());936 int i = 1;937 if (!Strings.isNullOrEmpty(searchTerm)) {938 preStat.setString(i++, "%" + searchTerm + "%");939 preStat.setString(i++, "%" + searchTerm + "%");940 preStat.setString(i++, "%" + searchTerm + "%");941 preStat.setString(i++, "%" + searchTerm + "%");942 preStat.setString(i++, "%" + searchTerm + "%");943 preStat.setString(i++, "%" + searchTerm + "%");944 preStat.setString(i++, "%" + searchTerm + "%");945 preStat.setString(i++, "%" + searchTerm + "%");946 preStat.setString(i++, "%" + searchTerm + "%");947 preStat.setString(i++, "%" + searchTerm + "%");948 preStat.setString(i++, "%" + searchTerm + "%");949 preStat.setString(i++, "%" + searchTerm + "%");950 preStat.setString(i++, "%" + searchTerm + "%");951 preStat.setString(i++, "%" + searchTerm + "%");952 preStat.setString(i++, "%" + searchTerm + "%");953 preStat.setString(i++, "%" + searchTerm + "%");954 preStat.setString(i++, "%" + searchTerm + "%");955 preStat.setString(i++, "%" + searchTerm + "%");956 preStat.setString(i++, "%" + searchTerm + "%");957 preStat.setString(i++, "%" + searchTerm + "%");958 preStat.setString(i++, "%" + searchTerm + "%");959 preStat.setString(i++, "%" + searchTerm + "%");960 preStat.setString(i++, "%" + searchTerm + "%");961 preStat.setString(i++, "%" + searchTerm + "%");962 preStat.setString(i++, "%" + searchTerm + "%");963 preStat.setString(i++, "%" + searchTerm + "%");964 }965 for (String individualColumnSearchValue : individalColumnSearchValues) {966 preStat.setString(i++, individualColumnSearchValue);967 }968 try {969 ResultSet resultSet = preStat.executeQuery();970 try {971 while (resultSet.next()) {972 testCaseExecutionList.add(this.loadFromResultSet(resultSet));973 }974 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));975// answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size());976 answer.setTotalRows(testCaseExecutionList.size());977 } catch (SQLException exception) {978 LOG.warn("Unable to execute query : " + exception.toString());979 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);980 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));981 testCaseExecutionList = null;982 } finally {983 resultSet.close();984 }985 } catch (SQLException exception) {986 LOG.warn("Unable to execute query : " + exception.toString());987 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);988 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));989 testCaseExecutionList = null;990 } finally {991 preStat.close();992 }993 } catch (SQLException exception) {994 LOG.warn("Unable to execute query : " + exception.toString());995 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);996 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));997 testCaseExecutionList = null;998 } finally {999 try {1000 if (connection != null) {1001 connection.close();1002 }1003 } catch (SQLException e) {1004 LOG.warn(e.toString());1005 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1006 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1007 }1008 }1009 answer.setResultMessage(msg);1010 answer.setDataList(testCaseExecutionList);1011 return answer;1012 }1013 @Override1014 public AnswerList readDistinctEnvCoutnryBrowserByTag(String tag) {1015 AnswerList answer = new AnswerList();1016 StringBuilder query = new StringBuilder();1017 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1018 query.append("SELECT exe.* FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY exe.Environment, exe.Country, exe.Browser, exe.ControlStatus");1019 Connection connection = this.databaseSpring.connect();1020 List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();1021 try {1022 PreparedStatement preStat = connection.prepareStatement(query.toString());1023 preStat.setString(1, tag);1024 try {1025 ResultSet resultSet = preStat.executeQuery();1026 try {1027 while (resultSet.next()) {1028 testCaseExecutionList.add(this.loadFromResultSet(resultSet));1029 }1030 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));1031 answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size());1032 } catch (SQLException exception) {1033 LOG.warn("Unable to execute query : " + exception.toString());1034 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1035 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1036 testCaseExecutionList = null;1037 } finally {1038 if (resultSet != null) {1039 resultSet.close();1040 }1041 }1042 } catch (SQLException ex) {1043 LOG.warn("Unable to execute query : " + ex.toString());1044 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1045 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1046 testCaseExecutionList = null;1047 } finally {1048 if (preStat != null) {1049 preStat.close();1050 }1051 }1052 } catch (SQLException ex) {1053 LOG.warn(ex.toString());1054 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1055 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1056 } finally {1057 try {1058 if (connection != null) {1059 connection.close();1060 }1061 } catch (SQLException ex) {1062 LOG.warn("Unable to execute query : " + ex.toString());1063 }1064 }1065 answer.setResultMessage(msg);1066 return answer;1067 }1068 @Override1069 public AnswerList readDistinctColumnByTag(String tag, boolean env, boolean country, boolean browser, boolean app) {1070 AnswerList answer = new AnswerList();1071 StringBuilder query = new StringBuilder();1072 StringBuilder distinct = new StringBuilder();1073 int prev = 0;1074 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1075 if (!(!env && !country && !app && !browser)) {1076 if (env) {1077 distinct.append("Environment");1078 prev++;1079 }1080 if (country) {1081 if (prev != 0) {1082 prev = 0;1083 distinct.append(",");1084 }1085 distinct.append("Country");1086 prev++;1087 }1088 if (browser) {1089 if (prev != 0) {1090 prev = 0;1091 distinct.append(",");1092 }1093 distinct.append("Browser");1094 prev++;1095 }1096 if (app) {1097 if (prev != 0) {1098 prev = 0;1099 distinct.append(",");1100 }1101 distinct.append("Application");1102 }1103 query.append("SELECT ");1104 query.append(distinct.toString());1105 query.append(" FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY ");1106 query.append(distinct.toString());1107 } else {1108 //If there is no distinct, select nothing1109 query.append("SELECT * FROM testcaseexecution exe WHERE 1 = 0 AND exe.tag = ?");1110 }1111 Connection connection = this.databaseSpring.connect();1112 List<TestCaseExecution> column = new ArrayList<TestCaseExecution>();1113 try {1114 PreparedStatement preStat = connection.prepareStatement(query.toString());1115 preStat.setString(1, tag);1116 try {1117 ResultSet resultSet = preStat.executeQuery();1118 try {1119 while (resultSet.next()) {1120 TestCaseExecution tmp = new TestCaseExecution();1121 if (env) {1122 tmp.setEnvironment(resultSet.getString("Environment"));1123 } else {1124 tmp.setEnvironment("");1125 }1126 if (country) {1127 tmp.setCountry(resultSet.getString("Country"));1128 } else {1129 tmp.setCountry("");1130 }1131 if (browser) {1132 tmp.setBrowser(resultSet.getString("Browser"));1133 } else {1134 tmp.setBrowser("");1135 }1136 if (app) {1137 tmp.setApplication(resultSet.getString("Application"));1138 } else {1139 tmp.setApplication("");1140 }1141 column.add(tmp);1142 }1143 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));1144 answer = new AnswerList(column, column.size());1145 } catch (SQLException exception) {1146 LOG.warn("Unable to execute query : " + exception.toString());1147 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1148 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1149 column = null;1150 } finally {1151 if (resultSet != null) {1152 resultSet.close();1153 }1154 }1155 } catch (SQLException ex) {1156 LOG.warn("Unable to execute query : " + ex.toString());1157 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1158 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1159 column = null;1160 } finally {1161 if (preStat != null) {1162 preStat.close();1163 }1164 }1165 } catch (SQLException ex) {1166 LOG.warn(ex.toString());1167 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1168 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1169 } finally {1170 try {1171 if (connection != null) {1172 connection.close();1173 }1174 } catch (SQLException ex) {1175 LOG.warn("Unable to execute query : " + ex.toString());1176 }1177 }1178 answer.setResultMessage(msg);1179 return answer;1180 }1181 @Override1182 public AnswerList readBySystemByVarious(String system, List<String> testList, List<String> applicationList, List<String> projectList, List<String> tcstatusList,1183 List<String> groupList, List<String> tcactiveList, List<String> priorityList, List<String> targetsprintList, List<String> targetrevisionList,1184 List<String> creatorList, List<String> implementerList, List<String> buildList, List<String> revisionList, List<String> environmentList,1185 List<String> countryList, List<String> browserList, List<String> tcestatusList, String ip, String port, String tag, String browserversion,1186 String comment, String bugid, String ticket) {1187 AnswerList answer = new AnswerList();1188 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1189 List<TestCaseExecution> tceList = new ArrayList<TestCaseExecution>();1190 List<String> whereClauses = new LinkedList<String>();1191 StringBuilder query = new StringBuilder();1192 int paramNumber = 0;1193 query.append(" select t.ID as statusExecutionID, t.* from ( ");1194 query.append(" select exe.*, tec.*, app.* ");1195 query.append(" from testcaseexecution exe ");1196 query.append(" inner join testcase tec on exe.test = tec.test and exe.testcase = tec.testcase ");1197 query.append(" inner join application app on exe.application = app.application ");1198 String testClause = SqlUtil.generateInClause("exe.test", testList);1199 if (!StringUtil.isNullOrEmpty(testClause)) {1200 whereClauses.add(testClause);1201 }1202 String applicationClause = SqlUtil.generateInClause("exe.application", applicationList);1203 if (!StringUtil.isNullOrEmpty(applicationClause)) {1204 whereClauses.add(applicationClause);1205 }1206 String projectClause = SqlUtil.generateInClause("tec.project", projectList);1207 if (!StringUtil.isNullOrEmpty(projectClause)) {1208 whereClauses.add(projectClause);1209 }1210 //test case status: working, fully_implemented, ...1211 String tcsClause = SqlUtil.generateInClause("exe.status", tcstatusList);1212 if (!StringUtil.isNullOrEmpty(tcsClause)) {1213 whereClauses.add(tcsClause);1214 }1215 //group 1216 String groupClause = SqlUtil.generateInClause("tec.group", groupList);1217 if (!StringUtil.isNullOrEmpty(groupClause)) {1218 whereClauses.add(groupClause);1219 }1220 //test case active1221 String tcactiveClause = SqlUtil.generateInClause("tec.tcactive", tcactiveList);1222 if (!StringUtil.isNullOrEmpty(tcactiveClause)) {1223 whereClauses.add(tcactiveClause);1224 }1225 //test case active1226 String priorityClause = SqlUtil.generateInClause("tec.Priority", priorityList);1227 if (!StringUtil.isNullOrEmpty(priorityClause)) {1228 whereClauses.add(priorityClause);1229 }1230 //target sprint1231 String targetsprintClause = SqlUtil.generateInClause("tec.TargetBuild", targetsprintList);1232 if (!StringUtil.isNullOrEmpty(targetsprintClause)) {1233 whereClauses.add(targetsprintClause);1234 }1235 //target revision1236 String targetrevisionClause = SqlUtil.generateInClause("tec.TargetRev", targetrevisionList);1237 if (!StringUtil.isNullOrEmpty(targetrevisionClause)) {1238 whereClauses.add(targetrevisionClause);1239 }1240 //creator1241 String creatorClause = SqlUtil.generateInClause("tec.UsrCreated", creatorList);1242 if (!StringUtil.isNullOrEmpty(creatorClause)) {1243 whereClauses.add(creatorClause);1244 }1245 //implementer1246 String implementerClause = SqlUtil.generateInClause("tec.Implementer", implementerList);1247 if (!StringUtil.isNullOrEmpty(implementerClause)) {1248 whereClauses.add(implementerClause);1249 }1250 //build1251 String buildClause = SqlUtil.generateInClause("exe.Build", buildList);1252 if (!StringUtil.isNullOrEmpty(buildClause)) {1253 whereClauses.add(buildClause);1254 }1255 //revision1256 String revisionClause = SqlUtil.generateInClause("exe.Revision", revisionList);1257 if (!StringUtil.isNullOrEmpty(revisionClause)) {1258 whereClauses.add(revisionClause);1259 }1260 //environment1261 String environmentClause = SqlUtil.generateInClause("exe.Environment", environmentList);1262 if (!StringUtil.isNullOrEmpty(environmentClause)) {1263 whereClauses.add(environmentClause);1264 }1265 //country1266 String countryClause = SqlUtil.generateInClause("exe.Country", countryList);1267 if (!StringUtil.isNullOrEmpty(countryClause)) {1268 whereClauses.add(countryClause);1269 }1270 //browser1271 String browserClause = SqlUtil.generateInClause("exe.Browser", browserList);1272 if (!StringUtil.isNullOrEmpty(browserClause)) {1273 whereClauses.add(browserClause);1274 }1275 //test case execution1276 String tcestatusClause = SqlUtil.generateInClause("exe.ControlStatus", tcestatusList);1277 if (!StringUtil.isNullOrEmpty(tcestatusClause)) {1278 whereClauses.add(tcestatusClause);1279 }1280 if (!StringUtil.isNullOrEmpty(system)) {1281 whereClauses.add(" app.system like ? ");1282 }1283 if (!StringUtil.isNullOrEmpty(ip)) {1284 whereClauses.add(" exe.IP like ? ");1285 }1286 if (!StringUtil.isNullOrEmpty(port)) {1287 whereClauses.add(" exe.port like ? ");1288 }1289 if (!StringUtil.isNullOrEmpty(tag)) {1290 whereClauses.add(" exe.tag like ? ");1291 }1292 if (!StringUtil.isNullOrEmpty(browserversion)) {1293 whereClauses.add(" exe.browserfullversion like ? ");1294 }1295 if (!StringUtil.isNullOrEmpty(comment)) {1296 whereClauses.add(" exe.comment like ? ");1297 }1298 if (!StringUtil.isNullOrEmpty(bugid)) {1299 whereClauses.add(" tec.BugID like ? ");1300 }1301 if (!StringUtil.isNullOrEmpty(ticket)) {1302 whereClauses.add(" tec.Ticket like ? ");1303 }1304 if (whereClauses.size() > 0) {1305 query.append("where ");1306 String joined = StringUtils.join(whereClauses, " and ");1307 query.append(joined);1308 }1309 query.append(" order by exe.ID desc ");1310 query.append(" ) as t group by t.test, t.testcase, t.environment, t.browser, t.country");1311 Connection connection = this.databaseSpring.connect();1312 try {1313 PreparedStatement preStat = connection.prepareStatement(query.toString());1314 if (testList != null) {1315 for (String param : testList) {1316 preStat.setString(++paramNumber, param);1317 }1318 }1319 if (applicationList != null) {1320 for (String param : applicationList) {1321 preStat.setString(++paramNumber, param);1322 }1323 }1324 if (projectList != null) {1325 for (String param : projectList) {1326 preStat.setString(++paramNumber, param);1327 }1328 }1329 if (tcstatusList != null) {1330 for (String param : tcstatusList) {1331 preStat.setString(++paramNumber, param);1332 }1333 }1334 if (groupList != null) {1335 for (String param : groupList) {1336 preStat.setString(++paramNumber, param);1337 }1338 }1339 if (tcactiveList != null) {1340 for (String param : tcactiveList) {1341 preStat.setString(++paramNumber, param);1342 }1343 }1344 if (priorityList != null) {1345 for (String param : priorityList) {1346 preStat.setString(++paramNumber, param);1347 }1348 }1349 if (targetsprintList != null) {1350 for (String param : targetsprintList) {1351 preStat.setString(++paramNumber, param);1352 }1353 }1354 if (targetrevisionList != null) {1355 for (String param : targetrevisionList) {1356 preStat.setString(++paramNumber, param);1357 }1358 }1359 if (creatorList != null) {1360 for (String param : creatorList) {1361 preStat.setString(++paramNumber, param);1362 }1363 }1364 if (implementerList != null) {1365 for (String param : implementerList) {1366 preStat.setString(++paramNumber, param);1367 }1368 }1369 if (buildList != null) {1370 for (String param : buildList) {1371 preStat.setString(++paramNumber, param);1372 }1373 }1374 if (revisionList != null) {1375 for (String param : revisionList) {1376 preStat.setString(++paramNumber, param);1377 }1378 }1379 //environment1380 if (environmentList != null) {1381 for (String param : environmentList) {1382 preStat.setString(++paramNumber, param);1383 }1384 }1385 //country1386 if (countryList != null) {1387 for (String param : countryList) {1388 preStat.setString(++paramNumber, param);1389 }1390 }1391 //browser 1392 if (browserList != null) {1393 for (String param : browserList) {1394 preStat.setString(++paramNumber, param);1395 }1396 }1397 //controlstatus1398 if (tcestatusList != null) {1399 for (String param : tcestatusList) {1400 preStat.setString(++paramNumber, param);1401 }1402 }1403 if (!StringUtil.isNullOrEmpty(system)) {1404 preStat.setString(++paramNumber, system);1405 }1406 if (!StringUtil.isNullOrEmpty(ip)) {1407 preStat.setString(++paramNumber, "%" + ip + "%");1408 }1409 if (!StringUtil.isNullOrEmpty(port)) {1410 preStat.setString(++paramNumber, "%" + port + "%");1411 }1412 if (!StringUtil.isNullOrEmpty(tag)) {1413 preStat.setString(++paramNumber, "%" + tag + "%");1414 }1415 if (!StringUtil.isNullOrEmpty(browserversion)) {1416 preStat.setString(++paramNumber, "%" + browserversion + "%");1417 }1418 if (!StringUtil.isNullOrEmpty(comment)) {1419 preStat.setString(++paramNumber, "%" + comment + "%");1420 }1421 if (!StringUtil.isNullOrEmpty(bugid)) {1422 preStat.setString(++paramNumber, "%" + bugid + "%");1423 }1424 if (!StringUtil.isNullOrEmpty(ticket)) {1425 preStat.setString(++paramNumber, "%" + ticket + "%");1426 }1427 try {1428 ResultSet resultSet = preStat.executeQuery();1429 try {1430 while (resultSet.next()) {1431 tceList.add(loadWithDependenciesFromResultSet(resultSet));1432 }1433 if (tceList.isEmpty()) {1434 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1435 } else {1436 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));1437 }1438 } catch (SQLException exception) {1439 LOG.warn("Unable to execute query : " + exception.toString());1440 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1441 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1442 tceList.clear();1443 } finally {1444 if (resultSet != null) {1445 resultSet.close();1446 }1447 }1448 } catch (SQLException ex) {1449 LOG.warn("Unable to execute query : " + ex.toString());1450 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1451 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1452 } finally {1453 if (preStat != null) {1454 preStat.close();1455 }1456 }1457 } catch (SQLException ex) {1458 LOG.warn(ex.toString());1459 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1460 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1461 } finally {1462 try {1463 if (connection != null) {1464 connection.close();1465 }1466 } catch (SQLException ex) {1467 LOG.warn("Unable to execute query : " + ex.toString());1468 }1469 }1470 answer.setTotalRows(tceList.size());1471 answer.setDataList(tceList);1472 answer.setResultMessage(msg);1473 return answer;1474 }1475 @Override1476 public AnswerItem readByKey(long executionId) {1477 AnswerItem ans = new AnswerItem();1478 TestCaseExecution result = null;1479 final String query = "SELECT * FROM `testcaseexecution` exe WHERE exe.`id` = ?";1480 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1481 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1482 Connection connection = this.databaseSpring.connect();1483 try {1484 PreparedStatement preStat = connection.prepareStatement(query);1485 try {1486 preStat.setLong(1, executionId);1487 ResultSet resultSet = preStat.executeQuery();1488 try {1489 if (resultSet.first()) {1490 result = loadFromResultSet(resultSet);1491 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1492 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));1493 ans.setItem(result);1494 } else {1495 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1496 }1497 } catch (SQLException exception) {1498 LOG.error("Unable to execute query : " + exception.toString());1499 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1500 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1501 } finally {1502 resultSet.close();1503 }1504 } catch (SQLException exception) {1505 LOG.error("Unable to execute query : " + exception.toString());1506 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1507 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1508 } finally {1509 preStat.close();1510 }1511 } catch (SQLException exception) {1512 LOG.error("Unable to execute query : " + exception.toString());1513 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1514 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1515 } finally {1516 try {1517 if (connection != null) {1518 connection.close();1519 }1520 } catch (SQLException exception) {1521 LOG.warn("Unable to close connection : " + exception.toString());1522 }1523 }1524 //sets the message1525 ans.setResultMessage(msg);1526 return ans;1527 }1528 @Override1529 public TestCaseExecution loadFromResultSet(ResultSet resultSet) throws SQLException {1530 long id = ParameterParserUtil.parseLongParam(resultSet.getString("exe.ID"), 0);1531 String test = ParameterParserUtil.parseStringParam(resultSet.getString("exe.test"), "");1532 String testcase = ParameterParserUtil.parseStringParam(resultSet.getString("exe.testcase"), "");1533 String description = ParameterParserUtil.parseStringParam(resultSet.getString("exe.description"), "");1534 String build = ParameterParserUtil.parseStringParam(resultSet.getString("exe.build"), "");1535 String revision = ParameterParserUtil.parseStringParam(resultSet.getString("exe.revision"), "");1536 String environment = ParameterParserUtil.parseStringParam(resultSet.getString("exe.environment"), "");1537 String environmentData = ParameterParserUtil.parseStringParam(resultSet.getString("exe.environmentData"), "");1538 String country = ParameterParserUtil.parseStringParam(resultSet.getString("exe.country"), "");1539 String browser = ParameterParserUtil.parseStringParam(resultSet.getString("exe.browser"), "");1540 String version = ParameterParserUtil.parseStringParam(resultSet.getString("exe.version"), "");1541 String platform = ParameterParserUtil.parseStringParam(resultSet.getString("exe.platform"), "");1542 String browserFullVersion = ParameterParserUtil.parseStringParam(resultSet.getString("exe.browserFullVersion"), "");1543 long start = ParameterParserUtil.parseLongParam(String.valueOf(resultSet.getTimestamp("exe.start").getTime()), 0);1544 long end = ParameterParserUtil.parseLongParam(String.valueOf(resultSet.getTimestamp("exe.end").getTime()), 0);1545 String controlStatus = ParameterParserUtil.parseStringParam(resultSet.getString("exe.controlStatus"), "");1546 String controlMessage = ParameterParserUtil.parseStringParam(resultSet.getString("exe.controlMessage"), "");1547 String application = ParameterParserUtil.parseStringParam(resultSet.getString("exe.application"), "");1548 String ip = ParameterParserUtil.parseStringParam(resultSet.getString("exe.ip"), ""); // Host the Selenium IP1549 String url = ParameterParserUtil.parseStringParam(resultSet.getString("exe.url"), "");1550 String port = ParameterParserUtil.parseStringParam(resultSet.getString("exe.port"), ""); // host the Selenium Port1551 String tag = ParameterParserUtil.parseStringParam(resultSet.getString("exe.tag"), "");1552 String status = ParameterParserUtil.parseStringParam(resultSet.getString("exe.status"), "");1553 String crbVersion = ParameterParserUtil.parseStringParam(resultSet.getString("exe.crbVersion"), "");1554 String executor = ParameterParserUtil.parseStringParam(resultSet.getString("exe.executor"), "");1555 String screenSize = ParameterParserUtil.parseStringParam(resultSet.getString("exe.screensize"), "");1556 String conditionOper = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionOper"), "");1557 String conditionVal1 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal1"), "");1558 String conditionVal1Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal1Init"), "");1559 String conditionVal2 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal2"), "");1560 String conditionVal2Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal2Init"), "");1561 String manualExecution = ParameterParserUtil.parseStringParam(resultSet.getString("exe.manualExecution"), "N");1562 String userAgent = ParameterParserUtil.parseStringParam(resultSet.getString("exe.userAgent"), "");1563 String system = ParameterParserUtil.parseStringParam(resultSet.getString("exe.system"), "");1564 String robotDecli = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotdecli"), "");1565 long queueId = ParameterParserUtil.parseLongParam(resultSet.getString("exe.queueId"), 0);1566 int testCaseVersion = ParameterParserUtil.parseIntegerParam(resultSet.getInt("exe.testCaseVersion"), 0);1567 TestCaseExecution result = factoryTCExecution.create(id, test, testcase, description, build, revision, environment,1568 country, browser, version, platform, browserFullVersion, start, end, controlStatus, controlMessage, application, null, ip, url,1569 port, tag, 0, 0, 0, 0, true, "", "", status, crbVersion, null, null, null,1570 false, null, null, null, environmentData, null, null, null, null, executor, 0, screenSize, null,1571 conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, manualExecution, userAgent, testCaseVersion, system, robotDecli);1572 result.setQueueID(queueId);1573 return result;1574 }1575 private TestCaseExecution loadWithDependenciesFromResultSet(ResultSet resultSet) throws SQLException {1576 TestCaseExecution testCaseExecution = new TestCaseExecution();1577 testCaseExecution = this.loadFromResultSet(resultSet);1578 testCaseExecution.setTestCaseObj(testCaseDAO.loadFromResultSet(resultSet));1579 testCaseExecution.setApplicationObj(applicationDAO.loadFromResultSet(resultSet));1580 return testCaseExecution;1581 }1582 private TestCaseExecution loadWithTestCaseFromResultSet(ResultSet resultSet) throws SQLException {1583 TestCaseExecution testCaseExecution = new TestCaseExecution();1584 testCaseExecution = this.loadFromResultSet(resultSet);1585 testCaseExecution.setTestCaseObj(testCaseDAO.loadFromResultSet(resultSet));1586 return testCaseExecution;1587 }1588 private TestCaseExecution loadTestCaseExecutionAndApplicationFromResultSet(ResultSet resultSet) throws SQLException {1589 TestCaseExecution testCaseExecution = new TestCaseExecution();1590 testCaseExecution = this.loadFromResultSet(resultSet);1591 testCaseExecution.setApplicationObj(applicationDAO.loadFromResultSet(resultSet));1592 return testCaseExecution;1593 }1594 @Override1595 public AnswerList<List<String>> readDistinctValuesByCriteria(String system, String test, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {1596 AnswerList answer = new AnswerList();1597 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1598 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1599 List<String> distinctValues = new ArrayList<>();1600 List<String> individalColumnSearchValues = new ArrayList<String>();1601 final StringBuffer query = new StringBuffer();1602 query.append("SELECT distinct ");1603 query.append(columnName);1604 query.append(" as distinctValues FROM testcaseexecution exe ");1605 query.append("where exe.`start`> '").append(DateUtil.getMySQLTimestampTodayDeltaMinutes(-360000)).append("' ");1606 if (!StringUtil.isNullOrEmpty(searchParameter)) {1607 query.append("and (exe.`id` like ? ");1608 query.append(" or exe.`test` like ? ");1609 query.append(" or exe.`testCase` like ? ");1610 query.append(" or exe.`build` like ? ");1611 query.append(" or exe.`revision` like ? ");1612 query.append(" or exe.`environment` like ? ");1613 query.append(" or exe.`country` like ? ");1614 query.append(" or exe.`browser` like ? ");1615 query.append(" or exe.`version` like ? ");1616 query.append(" or exe.`platform` like ? ");1617 query.append(" or exe.`browserfullversion` like ? ");1618 query.append(" or exe.`start` like ? ");1619 query.append(" or exe.`end` like ? ");1620 query.append(" or exe.`controlstatus` like ? ");1621 query.append(" or exe.`controlmessage` like ? ");1622 query.append(" or exe.`application` like ? ");1623 query.append(" or exe.`ip` like ? ");1624 query.append(" or exe.`url` like ? ");1625 query.append(" or exe.`port` like ? ");1626 query.append(" or exe.`tag` like ? ");1627 query.append(" or exe.`finished` like ? ");1628 query.append(" or exe.`status` like ? ");1629 query.append(" or exe.`crbversion` like ? ");1630 query.append(" or exe.`executor` like ? ");1631 query.append(" or exe.`screensize` like ? )");1632 }1633 if (individualSearch != null && !individualSearch.isEmpty()) {1634 query.append(" and ( 1=1 ");1635 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {1636 query.append(" and ");1637 query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));1638 individalColumnSearchValues.addAll(entry.getValue());1639 }1640 query.append(" ) ");1641 }1642 query.append(" order by ").append(columnName).append(" asc");1643 // Debug message on SQL.1644 if (LOG.isDebugEnabled()) {1645 LOG.debug("SQL : " + query.toString());1646 }1647 try (Connection connection = databaseSpring.connect();1648 PreparedStatement preStat = connection.prepareStatement(query.toString());1649 Statement stm = connection.createStatement();) {1650 int i = 1;1651 if (!Strings.isNullOrEmpty(searchParameter)) {1652 preStat.setString(i++, "%" + searchParameter + "%");1653 preStat.setString(i++, "%" + searchParameter + "%");1654 preStat.setString(i++, "%" + searchParameter + "%");1655 preStat.setString(i++, "%" + searchParameter + "%");1656 preStat.setString(i++, "%" + searchParameter + "%");1657 preStat.setString(i++, "%" + searchParameter + "%");1658 preStat.setString(i++, "%" + searchParameter + "%");1659 preStat.setString(i++, "%" + searchParameter + "%");1660 preStat.setString(i++, "%" + searchParameter + "%");1661 preStat.setString(i++, "%" + searchParameter + "%");1662 preStat.setString(i++, "%" + searchParameter + "%");1663 preStat.setString(i++, "%" + searchParameter + "%");1664 preStat.setString(i++, "%" + searchParameter + "%");1665 preStat.setString(i++, "%" + searchParameter + "%");...
isNull
Using AI Code Generation
1if (StringUtil.isNull(myString)) {2}3if (StringUtil.isNotNull(myString)) {4}5if (StringUtil.isBlank(myString)) {6}7if (StringUtil.isNotBlank(myString)) {8}9if (StringUtil.isNumeric(myString)) {10}11if (StringUtil.isNotNumeric(myString)) {12}13if (StringUtil.isAlpha(myString)) {14}15if (StringUtil.isNotAlpha(myString)) {16}17if (StringUtil.isAlphaNumeric(myString)) {18}19if (StringUtil.isNotAlphaNumeric(myString)) {20}21if (StringUtil.isAlphaNumericSpace(myString)) {22}23if (StringUtil.isNotAlphaNumericSpace(myString)) {24}25if (StringUtil.isAlphaNumericSpaceUnderscore(myString)) {26}27if (StringUtil.isNotAlphaNumericSpaceUnderscore(myString)) {28}
isNull
Using AI Code Generation
1if (StringUtil.isNull("test")) {2} else {3}4if (StringUtil.isNotNull("test")) {5} else {6}7if (StringUtil.isNull("test")) {8} else {9}10if (StringUtil.isNotNull("test")) {11} else {12}13if (StringUtil.isNull("test")) {14} else {15}16if (StringUtil.isNotNull("test")) {17} else {18}
isNull
Using AI Code Generation
1if (!StringUtil.isNull(myString)) {2}3if (!StringUtil.isNull(myObject)) {4}5if (!StringUtil.isNull(myArray)) {6}7if (!StringUtil.isNull(myList)) {8}9if (!StringUtil.isNull(myMap)) {10}11if (!StringUtil.isNull(mySet)) {12}13if (!StringUtil.isNull(myCollection)) {14}15if (!StringUtil.isNull(myFile)) {16}17if (!StringUtil.isNull(myJsonElement)) {18}19if (!StringUtil.isNull(myJsonArray)) {20}21if (!StringUtil.isNull(myJsonObject)) {22}23if (!StringUtil.isNull(myJsonPrimitive)) {24}25if (!StringUtil.isNull(myJsonString)) {26}27if (!StringUtil.isNull(myJsonNull)) {28}29if (!StringUtil.isNull(myJsonArray)) {30}31if (!StringUtil.isNull(myJsonObject)) {32}33if (!StringUtil.isNull(myJsonPrimitive)) {34}35if (!StringUtil.isNull(myJsonString)) {
isNull
Using AI Code Generation
1if (StringUtil.isNull(parameter)) {2}3if (StringUtil.isNotNull(parameter)) {4}5if (StringUtil.isBlank(parameter)) {6}7if (StringUtil.isNotBlank(parameter)) {8}9if (StringUtil.isNumeric(parameter)) {10}11if (StringUtil.isNotNumeric(parameter)) {12}13if (StringUtil.isAlpha(parameter)) {14}15if (StringUtil.isNotAlpha(parameter)) {16}17if (StringUtil.isAlphaNumeric(parameter)) {18}19if (StringUtil.isNotAlphaNumeric(parameter)) {20}21if (StringUtil.isAlphaNumericWithUnderscore(parameter)) {22}
isNull
Using AI Code Generation
1import org.cerberus.util.StringUtil;2String s = StringUtil.isNull("test", "default");3System.out.println(s);4import org.cerberus.util.StringUtil;5String s = StringUtil.isNull(null, "default");6System.out.println(s);7import org.cerberus.util.StringUtil;8String s = StringUtil.isNull(null, null);9System.out.println(s);10import org.cerberus.util.StringUtil;11String s = StringUtil.isNull("", "default");12System.out.println(s);13import org.cerberus.util.StringUtil;14String s = StringUtil.isNull("", null);15System.out.println(s);16import org.cerberus.util.StringUtil;17String s = StringUtil.isNull("", "");18System.out.println(s);19import org.cerberus.util.StringUtil;20String s = StringUtil.isNull(" ", "default");21System.out.println(s);22import org.cerberus.util.StringUtil;23String s = StringUtil.isNull(" ", null);24System.out.println(s);25import org.cerberus.util.StringUtil;26String s = StringUtil.isNull(" ", "");27System.out.println(s);28import org.cerberus.util.StringUtil;29String s = StringUtil.isNull(" ", " ");30System.out.println(s);
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!!