Search in sources :

Example 96 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class UserSystemDAO method readByUser.

@Override
public AnswerList<UserSystem> readByUser(String login) {
    AnswerList ans = new AnswerList();
    MessageEvent msg = null;
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(Query.READ_BY_USER)) {
        // Prepare and execute query
        preStat.setString(1, login);
        try (ResultSet resultSet = preStat.executeQuery()) {
            // Parse query
            List<UserSystem> result = new ArrayList<>();
            while (resultSet.next()) {
                result.add(loadUserSystemFromResultSet(resultSet));
            }
            ans.setDataList(result);
            // Set the final message
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "GET");
        } 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()));
        }
    } catch (Exception e) {
        LOG.warn("Unable to read userSystem: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        ans.setResultMessage(msg);
    }
    return ans;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) UserSystem(org.cerberus.crud.entity.UserSystem) IFactoryUserSystem(org.cerberus.crud.factory.IFactoryUserSystem) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) CerberusException(org.cerberus.exception.CerberusException) SQLException(java.sql.SQLException)

Example 97 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class InvariantService method readToHashMapGp1IntegerByIdname.

@Override
public HashMap<String, Integer> readToHashMapGp1IntegerByIdname(String idName, Integer defaultValue) {
    HashMap<String, Integer> result = new HashMap<String, Integer>();
    // TODO: handle if the response does not turn ok
    AnswerList answer = readByIdname(idName);
    for (Invariant inv : (List<Invariant>) answer.getDataList()) {
        int gp1ToInt = ParameterParserUtil.parseIntegerParam(inv.getGp1(), defaultValue);
        result.put(inv.getValue(), gp1ToInt);
    }
    return result;
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 98 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class InvariantService method readByPrivateByCriteria.

@Override
public AnswerList readByPrivateByCriteria(int start, int amount, String column, String dir, String searchTerm, String individualSearch) {
    // We first get the list of all Private invariant from the invariant table.
    String searchSQL = this.getPublicPrivateFilter("INVARIANTPRIVATE");
    // Then, we build the list of invariant entry based on the filter.
    // TODO this method should return a AnswerList, after complete refactoring this method should be changed
    AnswerList answer = invariantDao.readByCriteria(start, amount, column, dir, searchTerm, individualSearch, searchSQL);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList)

Example 99 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class InvariantService method readByPublicByCriteria.

@Override
public AnswerList readByPublicByCriteria(int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {
    // We first get the list of all Public invariant from the invariant table.
    String searchSQL = this.getPublicPrivateFilter("INVARIANTPUBLIC");
    // Then, we build the list of invariant entry based on the filter.
    // TODO this method should return a AnswerList, after complete refactoring this method should be changed
    AnswerList answer = invariantDao.readByCriteria(start, amount, column, dir, searchTerm, individualSearch, searchSQL);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList)

Example 100 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class InvariantService method readByPublicByCriteria.

@Override
public AnswerList readByPublicByCriteria(int start, int amount, String column, String dir, String searchTerm, String individualSearch) {
    // We first get the list of all Public invariant from the invariant table.
    String searchSQL = this.getPublicPrivateFilter("INVARIANTPUBLIC");
    // Then, we build the list of invariant entry based on the filter.
    // TODO this method should return a AnswerList, after complete refactoring this method should be changed
    AnswerList answer = invariantDao.readByCriteria(start, amount, column, dir, searchTerm, individualSearch, searchSQL);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList)

Aggregations

AnswerList (org.cerberus.util.answer.AnswerList)258 ArrayList (java.util.ArrayList)197 MessageEvent (org.cerberus.engine.entity.MessageEvent)152 List (java.util.List)146 Connection (java.sql.Connection)120 PreparedStatement (java.sql.PreparedStatement)120 ResultSet (java.sql.ResultSet)120 SQLException (java.sql.SQLException)120 JSONObject (org.json.JSONObject)90 AnswerItem (org.cerberus.util.answer.AnswerItem)89 Map (java.util.Map)69 HashMap (java.util.HashMap)65 JSONArray (org.json.JSONArray)62 Statement (java.sql.Statement)35 CerberusException (org.cerberus.exception.CerberusException)20 Invariant (org.cerberus.crud.entity.Invariant)18 IInvariantService (org.cerberus.crud.service.IInvariantService)15 TestCase (org.cerberus.crud.entity.TestCase)14 LinkedHashMap (java.util.LinkedHashMap)11 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)11