Search in sources :

Example 41 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseDAO method readByTestByCriteria.

@Override
public AnswerList readByTestByCriteria(String system, String test, int start, int amount, String sortInformation, String searchTerm, Map<String, List<String>> individualSearch) {
    AnswerList answer = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    List<TestCase> testCaseList = new ArrayList<TestCase>();
    StringBuilder searchSQL = new StringBuilder();
    List<String> individalColumnSearchValues = new ArrayList<String>();
    StringBuilder query = new StringBuilder();
    // SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
    // were applied -- used for pagination p
    query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcase tec ");
    query.append(" LEFT OUTER JOIN testcaselabel tel on tec.test = tel.test AND tec.testcase = tel.testcase ");
    query.append(" LEFT OUTER JOIN label lab on tel.labelId = lab.id ");
    query.append(" LEFT OUTER JOIN application app on app.application = tec.application ");
    searchSQL.append("WHERE 1=1");
    if (!StringUtil.isNullOrEmpty(system)) {
        searchSQL.append(" AND app.`system` = ? ");
    }
    if (!StringUtil.isNullOrEmpty(test)) {
        searchSQL.append(" AND tec.`test` = ?");
    }
    if (!StringUtil.isNullOrEmpty(searchTerm)) {
        searchSQL.append(" and (tec.`testcase` like ?");
        searchSQL.append(" or tec.`test` like ?");
        searchSQL.append(" or tec.`application` like ?");
        searchSQL.append(" or tec.`project` like ?");
        searchSQL.append(" or tec.`usrCreated` like ?");
        searchSQL.append(" or tec.`usrModif` like ?");
        searchSQL.append(" or tec.`tcactive` like ?");
        searchSQL.append(" or tec.`status` like ?");
        searchSQL.append(" or tec.`group` like ?");
        searchSQL.append(" or tec.`priority` like ?");
        searchSQL.append(" or tec.`dateCreated` like ?");
        searchSQL.append(" or tec.`description` like ?");
        searchSQL.append(" or lab.`label` like ?)");
    }
    if (individualSearch != null && !individualSearch.isEmpty()) {
        searchSQL.append(" and ( 1=1 ");
        for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
            searchSQL.append(" and ");
            searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
            individalColumnSearchValues.addAll(entry.getValue());
        }
        searchSQL.append(" )");
    }
    query.append(searchSQL);
    query.append(" group by tec.test, tec.testcase ");
    if (!StringUtil.isNullOrEmpty(sortInformation)) {
        query.append(" order by ").append(sortInformation);
    }
    if (amount != 0) {
        query.append(" limit ").append(start).append(" , ").append(amount);
    } else {
        query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
    }
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            int i = 1;
            if (!StringUtil.isNullOrEmpty(system)) {
                preStat.setString(i++, system);
            }
            if (!StringUtil.isNullOrEmpty(test)) {
                preStat.setString(i++, test);
            }
            if (!Strings.isNullOrEmpty(searchTerm)) {
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
            }
            for (String individualColumnSearchValue : individalColumnSearchValues) {
                preStat.setString(i++, individualColumnSearchValue);
            }
            ResultSet resultSet = preStat.executeQuery();
            try {
                // gets the data
                while (resultSet.next()) {
                    testCaseList.add(this.loadFromResultSet(resultSet));
                }
                // get the total number of rows
                resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
                int nrTotalRows = 0;
                if (resultSet != null && resultSet.next()) {
                    nrTotalRows = resultSet.getInt(1);
                }
                if (testCaseList.size() >= MAX_ROW_SELECTED) {
                    // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
                    LOG.error("Partial Result in the query.");
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
                    answer = new AnswerList(testCaseList, nrTotalRows);
                } else if (testCaseList.size() <= 0) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                    answer = new AnswerList(testCaseList, nrTotalRows);
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                    msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                    answer = new AnswerList(testCaseList, nrTotalRows);
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (!this.databaseSpring.isOnTransaction()) {
                if (connection != null) {
                    connection.close();
                }
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    answer.setResultMessage(msg);
    answer.setDataList(testCaseList);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) ResultSet(java.sql.ResultSet) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 42 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseDAO method create.

@Override
public Answer create(TestCase testCase) {
    MessageEvent msg = null;
    final StringBuffer sql = new StringBuffer("INSERT INTO `testcase` ").append(" ( `Test`, `TestCase`, `Application`, `Project`, `Ticket`, ").append("`Description`, `BehaviorOrValueExpected`, ").append("`Priority`, `Status`, `TcActive`, ").append("`Group`, `Origine`, `RefOrigine`, `HowTo`, `Comment`, ").append("`FromBuild`, `FromRev`, `ToBuild`, `ToRev`, ").append("`BugID`, `TargetBuild`, `TargetRev`, `UsrCreated`, ").append("`Implementer`, `function`, `activeQA`, `activeUAT`, `activePROD`, `useragent`, `screenSize`, `conditionOper`, `conditionVal1`, `conditionVal2`, `testCaseVersion`) ").append("VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ").append("?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ); ");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + sql.toString());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(sql.toString());
        try {
            int i = 1;
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTest(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTestCase(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getApplication(), ""));
            preStat.setString(i++, testCase.getProject());
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTicket(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getDescription(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBehaviorOrValueExpected(), ""));
            preStat.setString(i++, Integer.toString(testCase.getPriority()));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getStatus(), ""));
            preStat.setString(i++, testCase.getTcActive() != null && !testCase.getTcActive().equals("Y") ? "N" : "Y");
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getGroup(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getOrigine(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getRefOrigine(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getHowTo(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getComment(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromBuild(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromRev(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToBuild(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToRev(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBugID(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetBuild(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetRev(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUsrCreated(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getImplementer(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFunction(), ""));
            preStat.setString(i++, testCase.getActiveQA() != null && !testCase.getActiveQA().equals("Y") ? "N" : "Y");
            preStat.setString(i++, testCase.getActiveUAT() != null && !testCase.getActiveUAT().equals("Y") ? "N" : "Y");
            preStat.setString(i++, testCase.getActivePROD() != null && !testCase.getActivePROD().equals("N") ? "Y" : "N");
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUserAgent(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getScreenSize(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionOper(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal1(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal2(), ""));
            preStat.setInt(i++, ParameterParserUtil.parseIntegerParam(testCase.getTestCaseVersion(), 0));
            preStat.executeUpdate();
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString(), exception);
            if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
                // 23000 is the sql state for duplicate entries
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
            }
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    return new Answer(msg);
}
Also used : Answer(org.cerberus.util.answer.Answer) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 43 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseExecutionDAO method readDistinctColumnByTag.

@Override
public AnswerList readDistinctColumnByTag(String tag, boolean env, boolean country, boolean browser, boolean app) {
    AnswerList answer = new AnswerList();
    StringBuilder query = new StringBuilder();
    StringBuilder distinct = new StringBuilder();
    int prev = 0;
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    if (!(!env && !country && !app && !browser)) {
        if (env) {
            distinct.append("Environment");
            prev++;
        }
        if (country) {
            if (prev != 0) {
                prev = 0;
                distinct.append(",");
            }
            distinct.append("Country");
            prev++;
        }
        if (browser) {
            if (prev != 0) {
                prev = 0;
                distinct.append(",");
            }
            distinct.append("Browser");
            prev++;
        }
        if (app) {
            if (prev != 0) {
                prev = 0;
                distinct.append(",");
            }
            distinct.append("Application");
        }
        query.append("SELECT ");
        query.append(distinct.toString());
        query.append(" FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY ");
        query.append(distinct.toString());
    } else {
        // If there is no distinct, select nothing
        query.append("SELECT * FROM testcaseexecution exe WHERE 1 = 0 AND exe.tag = ?");
    }
    Connection connection = this.databaseSpring.connect();
    List<TestCaseExecution> column = new ArrayList<TestCaseExecution>();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, tag);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    TestCaseExecution tmp = new TestCaseExecution();
                    if (env) {
                        tmp.setEnvironment(resultSet.getString("Environment"));
                    } else {
                        tmp.setEnvironment("");
                    }
                    if (country) {
                        tmp.setCountry(resultSet.getString("Country"));
                    } else {
                        tmp.setCountry("");
                    }
                    if (browser) {
                        tmp.setBrowser(resultSet.getString("Browser"));
                    } else {
                        tmp.setBrowser("");
                    }
                    if (app) {
                        tmp.setApplication(resultSet.getString("Application"));
                    } else {
                        tmp.setApplication("");
                    }
                    column.add(tmp);
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
                answer = new AnswerList(column, column.size());
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
                column = null;
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
            column = null;
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException ex) {
        LOG.warn(ex.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
        }
    }
    answer.setResultMessage(msg);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 44 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseExecutionDAO method readByTag.

@Override
public AnswerList readByTag(String tag) throws CerberusException {
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    AnswerList answer = new AnswerList();
    final StringBuffer query = new StringBuffer();
    query.append("SELECT * FROM testcaseexecution exe ");
    query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");
    query.append("left join application as app on tec.application = app.application ");
    query.append("where 1=1 and exe.tag = ? ");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
        LOG.debug("SQL.param.tag : " + tag);
    }
    List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, tag);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testCaseExecutionList.add(this.loadWithDependenciesFromResultSet(resultSet));
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
                answer.setTotalRows(testCaseExecutionList.size());
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
                testCaseExecutionList = null;
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
            testCaseExecutionList = null;
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
        testCaseExecutionList = null;
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
        }
    }
    answer.setResultMessage(msg);
    answer.setDataList(testCaseExecutionList);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 45 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseExecutionDAO method readBySystemByVarious.

@Override
public AnswerList readBySystemByVarious(String system, List<String> testList, List<String> applicationList, List<String> projectList, List<String> tcstatusList, List<String> groupList, List<String> tcactiveList, List<String> priorityList, List<String> targetsprintList, List<String> targetrevisionList, List<String> creatorList, List<String> implementerList, List<String> buildList, List<String> revisionList, List<String> environmentList, List<String> countryList, List<String> browserList, List<String> tcestatusList, String ip, String port, String tag, String browserversion, String comment, String bugid, String ticket) {
    AnswerList answer = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    List<TestCaseExecution> tceList = new ArrayList<TestCaseExecution>();
    List<String> whereClauses = new LinkedList<String>();
    StringBuilder query = new StringBuilder();
    int paramNumber = 0;
    query.append(" select t.ID as statusExecutionID, t.* from ( ");
    query.append(" select exe.*, tec.*, app.* ");
    query.append(" from testcaseexecution exe ");
    query.append(" inner join testcase tec on exe.test = tec.test and exe.testcase = tec.testcase ");
    query.append(" inner join application app on exe.application = app.application ");
    String testClause = SqlUtil.generateInClause("exe.test", testList);
    if (!StringUtil.isNullOrEmpty(testClause)) {
        whereClauses.add(testClause);
    }
    String applicationClause = SqlUtil.generateInClause("exe.application", applicationList);
    if (!StringUtil.isNullOrEmpty(applicationClause)) {
        whereClauses.add(applicationClause);
    }
    String projectClause = SqlUtil.generateInClause("tec.project", projectList);
    if (!StringUtil.isNullOrEmpty(projectClause)) {
        whereClauses.add(projectClause);
    }
    // test case status: working, fully_implemented, ...
    String tcsClause = SqlUtil.generateInClause("exe.status", tcstatusList);
    if (!StringUtil.isNullOrEmpty(tcsClause)) {
        whereClauses.add(tcsClause);
    }
    // group
    String groupClause = SqlUtil.generateInClause("tec.group", groupList);
    if (!StringUtil.isNullOrEmpty(groupClause)) {
        whereClauses.add(groupClause);
    }
    // test case active
    String tcactiveClause = SqlUtil.generateInClause("tec.tcactive", tcactiveList);
    if (!StringUtil.isNullOrEmpty(tcactiveClause)) {
        whereClauses.add(tcactiveClause);
    }
    // test case active
    String priorityClause = SqlUtil.generateInClause("tec.Priority", priorityList);
    if (!StringUtil.isNullOrEmpty(priorityClause)) {
        whereClauses.add(priorityClause);
    }
    // target sprint
    String targetsprintClause = SqlUtil.generateInClause("tec.TargetBuild", targetsprintList);
    if (!StringUtil.isNullOrEmpty(targetsprintClause)) {
        whereClauses.add(targetsprintClause);
    }
    // target revision
    String targetrevisionClause = SqlUtil.generateInClause("tec.TargetRev", targetrevisionList);
    if (!StringUtil.isNullOrEmpty(targetrevisionClause)) {
        whereClauses.add(targetrevisionClause);
    }
    // creator
    String creatorClause = SqlUtil.generateInClause("tec.UsrCreated", creatorList);
    if (!StringUtil.isNullOrEmpty(creatorClause)) {
        whereClauses.add(creatorClause);
    }
    // implementer
    String implementerClause = SqlUtil.generateInClause("tec.Implementer", implementerList);
    if (!StringUtil.isNullOrEmpty(implementerClause)) {
        whereClauses.add(implementerClause);
    }
    // build
    String buildClause = SqlUtil.generateInClause("exe.Build", buildList);
    if (!StringUtil.isNullOrEmpty(buildClause)) {
        whereClauses.add(buildClause);
    }
    // revision
    String revisionClause = SqlUtil.generateInClause("exe.Revision", revisionList);
    if (!StringUtil.isNullOrEmpty(revisionClause)) {
        whereClauses.add(revisionClause);
    }
    // environment
    String environmentClause = SqlUtil.generateInClause("exe.Environment", environmentList);
    if (!StringUtil.isNullOrEmpty(environmentClause)) {
        whereClauses.add(environmentClause);
    }
    // country
    String countryClause = SqlUtil.generateInClause("exe.Country", countryList);
    if (!StringUtil.isNullOrEmpty(countryClause)) {
        whereClauses.add(countryClause);
    }
    // browser
    String browserClause = SqlUtil.generateInClause("exe.Browser", browserList);
    if (!StringUtil.isNullOrEmpty(browserClause)) {
        whereClauses.add(browserClause);
    }
    // test case execution
    String tcestatusClause = SqlUtil.generateInClause("exe.ControlStatus", tcestatusList);
    if (!StringUtil.isNullOrEmpty(tcestatusClause)) {
        whereClauses.add(tcestatusClause);
    }
    if (!StringUtil.isNullOrEmpty(system)) {
        whereClauses.add(" app.system like ? ");
    }
    if (!StringUtil.isNullOrEmpty(ip)) {
        whereClauses.add(" exe.IP like ? ");
    }
    if (!StringUtil.isNullOrEmpty(port)) {
        whereClauses.add(" exe.port like ? ");
    }
    if (!StringUtil.isNullOrEmpty(tag)) {
        whereClauses.add(" exe.tag like ? ");
    }
    if (!StringUtil.isNullOrEmpty(browserversion)) {
        whereClauses.add(" exe.browserfullversion like ? ");
    }
    if (!StringUtil.isNullOrEmpty(comment)) {
        whereClauses.add(" exe.comment like ? ");
    }
    if (!StringUtil.isNullOrEmpty(bugid)) {
        whereClauses.add(" tec.BugID like ? ");
    }
    if (!StringUtil.isNullOrEmpty(ticket)) {
        whereClauses.add(" tec.Ticket like ? ");
    }
    if (whereClauses.size() > 0) {
        query.append("where ");
        String joined = StringUtils.join(whereClauses, " and ");
        query.append(joined);
    }
    query.append(" order by exe.ID desc ");
    query.append(" ) as t group by t.test, t.testcase, t.environment, t.browser, t.country");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        if (testList != null) {
            for (String param : testList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (applicationList != null) {
            for (String param : applicationList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (projectList != null) {
            for (String param : projectList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (tcstatusList != null) {
            for (String param : tcstatusList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (groupList != null) {
            for (String param : groupList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (tcactiveList != null) {
            for (String param : tcactiveList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (priorityList != null) {
            for (String param : priorityList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (targetsprintList != null) {
            for (String param : targetsprintList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (targetrevisionList != null) {
            for (String param : targetrevisionList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (creatorList != null) {
            for (String param : creatorList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (implementerList != null) {
            for (String param : implementerList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (buildList != null) {
            for (String param : buildList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (revisionList != null) {
            for (String param : revisionList) {
                preStat.setString(++paramNumber, param);
            }
        }
        // environment
        if (environmentList != null) {
            for (String param : environmentList) {
                preStat.setString(++paramNumber, param);
            }
        }
        // country
        if (countryList != null) {
            for (String param : countryList) {
                preStat.setString(++paramNumber, param);
            }
        }
        // browser
        if (browserList != null) {
            for (String param : browserList) {
                preStat.setString(++paramNumber, param);
            }
        }
        // controlstatus
        if (tcestatusList != null) {
            for (String param : tcestatusList) {
                preStat.setString(++paramNumber, param);
            }
        }
        if (!StringUtil.isNullOrEmpty(system)) {
            preStat.setString(++paramNumber, system);
        }
        if (!StringUtil.isNullOrEmpty(ip)) {
            preStat.setString(++paramNumber, "%" + ip + "%");
        }
        if (!StringUtil.isNullOrEmpty(port)) {
            preStat.setString(++paramNumber, "%" + port + "%");
        }
        if (!StringUtil.isNullOrEmpty(tag)) {
            preStat.setString(++paramNumber, "%" + tag + "%");
        }
        if (!StringUtil.isNullOrEmpty(browserversion)) {
            preStat.setString(++paramNumber, "%" + browserversion + "%");
        }
        if (!StringUtil.isNullOrEmpty(comment)) {
            preStat.setString(++paramNumber, "%" + comment + "%");
        }
        if (!StringUtil.isNullOrEmpty(bugid)) {
            preStat.setString(++paramNumber, "%" + bugid + "%");
        }
        if (!StringUtil.isNullOrEmpty(ticket)) {
            preStat.setString(++paramNumber, "%" + ticket + "%");
        }
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    tceList.add(loadWithDependenciesFromResultSet(resultSet));
                }
                if (tceList.isEmpty()) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                } else {
                    msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
                tceList.clear();
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException ex) {
        LOG.warn(ex.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
        }
    }
    answer.setTotalRows(tceList.size());
    answer.setDataList(tceList);
    answer.setResultMessage(msg);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) LinkedList(java.util.LinkedList) ResultSet(java.sql.ResultSet)

Aggregations

MessageEvent (org.cerberus.engine.entity.MessageEvent)629 SQLException (java.sql.SQLException)306 Connection (java.sql.Connection)304 PreparedStatement (java.sql.PreparedStatement)301 Answer (org.cerberus.util.answer.Answer)227 AnswerItem (org.cerberus.util.answer.AnswerItem)212 ArrayList (java.util.ArrayList)180 ResultSet (java.sql.ResultSet)172 AnswerList (org.cerberus.util.answer.AnswerList)152 JSONObject (org.json.JSONObject)144 ApplicationContext (org.springframework.context.ApplicationContext)122 CerberusException (org.cerberus.exception.CerberusException)95 PolicyFactory (org.owasp.html.PolicyFactory)93 List (java.util.List)83 ILogEventService (org.cerberus.crud.service.ILogEventService)79 JSONException (org.json.JSONException)79 Map (java.util.Map)71 CerberusEventException (org.cerberus.exception.CerberusEventException)51 IOException (java.io.IOException)48 WebDriverException (org.openqa.selenium.WebDriverException)38