Search in sources :

Example 1 with MessageGeneral

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

the class CampaignParameterDAO method findCampaignParameterByCriteria.

@Override
public List<CampaignParameter> findCampaignParameterByCriteria(Integer campaignparameterID, String campaign, String parameter, String value) throws CerberusException {
    boolean throwEx = false;
    final StringBuilder query = new StringBuilder("SELECT * FROM campaignparameter c WHERE 1=1 ");
    if (campaignparameterID != null) {
        query.append(" AND c.campaignparameterID = ?");
    }
    if (campaign != null && !"".equals(campaign.trim())) {
        query.append(" AND c.campaign LIKE ?");
    }
    if (parameter != null && !"".equals(parameter.trim())) {
        query.append(" AND c.parameter LIKE ?");
    }
    if (value != null && !"".equals(value.trim())) {
        query.append(" AND c.value LIKE ?");
    }
    // " c.campaignID = ? AND c.campaign LIKE ? AND c.description LIKE ?";
    List<CampaignParameter> campaignParametersList = new ArrayList<CampaignParameter>();
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        int index = 1;
        if (campaignparameterID != null) {
            preStat.setInt(index, campaignparameterID);
            index++;
        }
        if (campaign != null && !"".equals(campaign.trim())) {
            preStat.setString(index, "%" + campaign.trim() + "%");
            index++;
        }
        if (parameter != null && !"".equals(parameter.trim())) {
            preStat.setString(index, "%" + parameter.trim() + "%");
            index++;
        }
        if (value != null && !"".equals(value.trim())) {
            preStat.setString(index, "%" + value.trim() + "%");
            index++;
        }
        try (ResultSet resultSet = preStat.executeQuery()) {
            while (resultSet.next()) {
                campaignParametersList.add(this.loadFromResultSet(resultSet));
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            campaignParametersList = null;
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        campaignParametersList = null;
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return campaignParametersList;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Example 2 with MessageGeneral

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

the class CountryEnvironmentParametersDAO method findCountryEnvironmentParametersByCriteria.

@Override
public List<CountryEnvironmentParameters> findCountryEnvironmentParametersByCriteria(CountryEnvironmentParameters countryEnvironmentParameter) throws CerberusException {
    List<CountryEnvironmentParameters> result = new ArrayList<CountryEnvironmentParameters>();
    boolean throwex = false;
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM countryenvironmentparameters cea ");
    query.append(" WHERE cea.`system` LIKE ? AND cea.country LIKE ? AND cea.environment LIKE ? AND cea.Application LIKE ? ");
    query.append("AND cea.IP LIKE ? AND cea.URL LIKE ? AND cea.URLLOGIN LIKE ? AND cea.domain like ? ");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.system : " + ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getSystem()));
        LOG.debug("SQL.param.country : " + ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getCountry()));
        LOG.debug("SQL.param.environment : " + ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getEnvironment()));
        LOG.debug("SQL.param.application : " + ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getApplication()));
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getSystem()));
            preStat.setString(2, ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getCountry()));
            preStat.setString(3, ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getEnvironment()));
            preStat.setString(4, ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getApplication()));
            preStat.setString(5, ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getIp()));
            preStat.setString(6, ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getUrl()));
            preStat.setString(7, ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getUrlLogin()));
            preStat.setString(8, ParameterParserUtil.wildcardIfEmpty(countryEnvironmentParameter.getDomain()));
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    result.add(loadFromResultSet(resultSet));
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwex) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return result;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IFactoryCountryEnvironmentParameters(org.cerberus.crud.factory.IFactoryCountryEnvironmentParameters) CountryEnvironmentParameters(org.cerberus.crud.entity.CountryEnvironmentParameters) PreparedStatement(java.sql.PreparedStatement)

Example 3 with MessageGeneral

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

the class TestCaseCountryPropertiesDAO method updateTestCaseCountryProperties.

@Override
public void updateTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("UPDATE testcasecountryproperties SET ");
    query.append(" `Description` = ?, `Type` = ? ,`Database` = ? ,Value1 = ?,Value2 = ?,`Length` = ?,  RowLimit = ?,  `Nature` = ? ,  `RetryNb` = ? ,  `RetryPeriod` = ? ");
    query.append(" WHERE Test = ? AND TestCase = ? AND Country = ? AND hex(`Property`) like hex(?)");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setBytes(1, testCaseCountryProperties.getDescription().getBytes("UTF-8"));
            preStat.setString(2, testCaseCountryProperties.getType());
            preStat.setString(3, testCaseCountryProperties.getDatabase());
            preStat.setBytes(4, testCaseCountryProperties.getValue1().getBytes("UTF-8"));
            preStat.setBytes(5, testCaseCountryProperties.getValue2().getBytes("UTF-8"));
            preStat.setString(6, testCaseCountryProperties.getLength());
            preStat.setInt(7, testCaseCountryProperties.getRowLimit());
            preStat.setString(8, testCaseCountryProperties.getNature());
            preStat.setInt(9, testCaseCountryProperties.getRetryNb());
            preStat.setInt(10, testCaseCountryProperties.getRetryPeriod());
            preStat.setString(11, testCaseCountryProperties.getTest());
            preStat.setString(12, testCaseCountryProperties.getTestCase());
            preStat.setString(13, testCaseCountryProperties.getCountry());
            preStat.setBytes(14, testCaseCountryProperties.getProperty().getBytes("UTF-8"));
            preStat.executeUpdate();
            throwExcep = false;
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } catch (UnsupportedEncodingException ex) {
            LOG.error(ex.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PreparedStatement(java.sql.PreparedStatement)

Example 4 with MessageGeneral

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

the class TestCaseDAO method findTestCaseByKey.

@Override
public TestCase findTestCaseByKey(String test, String testCase) throws CerberusException {
    boolean throwExcep = false;
    TestCase result = null;
    final String query = "SELECT * FROM testcase tec  LEFT OUTER JOIN application app on app.application = tec.application WHERE test = ? AND testcase = ?";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testCase);
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.next()) {
                    result = this.loadFromResultSet(resultSet);
                } else {
                    result = null;
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return result;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 5 with MessageGeneral

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

the class TestCaseExecutionQueueDAO method findTestCaseExecutionInQueuebyTag.

@Override
public List<TestCaseExecutionQueue> findTestCaseExecutionInQueuebyTag(String tag) throws CerberusException {
    boolean throwEx = false;
    final StringBuilder query = new StringBuilder("select exq.*, tec.*, app.* from ( select exq.* ").append("from testcaseexecutionqueue exq ").append("where exq.tag = ? ").append(" order by exq.test, exq.testcase, exq.ID desc) as exq ").append("LEFT JOIN testcase tec on exq.Test = tec.Test and exq.TestCase = tec.TestCase ").append("LEFT JOIN application app ON tec.application = app.application ").append("GROUP BY exq.test, exq.testcase, exq.Environment, exq.Browser, exq.Country ");
    List<TestCaseExecutionQueue> testCaseExecutionInQueueList = new ArrayList<TestCaseExecutionQueue>();
    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()) {
                    testCaseExecutionInQueueList.add(this.loadWithDependenciesFromResultSet(resultSet));
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
                testCaseExecutionInQueueList = null;
            } catch (FactoryCreationException ex) {
                LOG.error("Unable to execute query : " + ex.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            testCaseExecutionInQueueList = null;
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        testCaseExecutionInQueueList = null;
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return testCaseExecutionInQueueList;
}
Also used : FactoryCreationException(org.cerberus.exception.FactoryCreationException) CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) PreparedStatement(java.sql.PreparedStatement)

Aggregations

MessageGeneral (org.cerberus.engine.entity.MessageGeneral)71 CerberusException (org.cerberus.exception.CerberusException)61 Connection (java.sql.Connection)46 PreparedStatement (java.sql.PreparedStatement)46 SQLException (java.sql.SQLException)46 ResultSet (java.sql.ResultSet)18 ArrayList (java.util.ArrayList)12 Date (java.util.Date)10 TestCase (org.cerberus.crud.entity.TestCase)10 MessageEvent (org.cerberus.engine.entity.MessageEvent)8 AnswerItem (org.cerberus.util.answer.AnswerItem)7 Timestamp (java.sql.Timestamp)5 CerberusEventException (org.cerberus.exception.CerberusEventException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)4 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)4 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)4 IOException (java.io.IOException)3 CampaignParameter (org.cerberus.crud.entity.CampaignParameter)3 IFactoryCampaignParameter (org.cerberus.crud.factory.IFactoryCampaignParameter)3