Search in sources :

Example 51 with AnswerList

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

the class TestCaseExecutionDAO method readByCriteria.

@Override
public AnswerList readByCriteria(int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch, List<String> individualLike) throws CerberusException {
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    AnswerList answer = new AnswerList();
    List<String> individalColumnSearchValues = new ArrayList<String>();
    final StringBuffer query = new StringBuffer();
    query.append("SELECT * FROM testcaseexecution exe ");
    query.append("where exe.`start`> '").append(DateUtil.getMySQLTimestampTodayDeltaMinutes(-360000)).append("' ");
    if (!StringUtil.isNullOrEmpty(searchTerm)) {
        query.append("and (exe.`id` like ? ");
        query.append(" or exe.`test` like ? ");
        query.append(" or exe.`testCase` like ? ");
        query.append(" or exe.`build` like ? ");
        query.append(" or exe.`revision` like ? ");
        query.append(" or exe.`environment` like ? ");
        query.append(" or exe.`country` like ? ");
        query.append(" or exe.`browser` like ? ");
        query.append(" or exe.`version` like ? ");
        query.append(" or exe.`platform` like ? ");
        query.append(" or exe.`browserfullversion` like ? ");
        query.append(" or exe.`start` like ? ");
        query.append(" or exe.`end` like ? ");
        query.append(" or exe.`controlstatus` like ? ");
        query.append(" or exe.`controlmessage` like ? ");
        query.append(" or exe.`application` like ? ");
        query.append(" or exe.`ip` like ? ");
        query.append(" or exe.`url` like ? ");
        query.append(" or exe.`port` like ? ");
        query.append(" or exe.`tag` like ? ");
        query.append(" or exe.`end` like ? ");
        query.append(" or exe.`status` like ? ");
        query.append(" or exe.`crbversion` like ? ");
        query.append(" or exe.`executor` like ? ");
        query.append(" or exe.`screensize` like ? ");
        query.append(" or exe.`userAgent` like ? )");
    }
    if (individualSearch != null && !individualSearch.isEmpty()) {
        query.append(" and ( 1=1 ");
        for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
            query.append(" and ");
            query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
            individalColumnSearchValues.addAll(entry.getValue());
        }
        query.append(" ) ");
    }
    if (!StringUtil.isNullOrEmpty(sort)) {
        query.append(" order by ").append(sort);
    }
    if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
        query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
    } else {
        query.append(" limit ").append(start).append(" , ").append(amount);
    }
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
    }
    List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        int i = 1;
        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 + "%");
            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);
        }
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testCaseExecutionList.add(this.loadFromResultSet(resultSet));
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
                // answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size());
                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) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Map(java.util.Map)

Example 52 with AnswerList

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

the class TestCaseExecutionDAO method readDistinctEnvCoutnryBrowserByTag.

@Override
public AnswerList readDistinctEnvCoutnryBrowserByTag(String tag) {
    AnswerList answer = new AnswerList();
    StringBuilder query = new StringBuilder();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    query.append("SELECT exe.* FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY exe.Environment, exe.Country, exe.Browser, exe.ControlStatus");
    Connection connection = this.databaseSpring.connect();
    List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, tag);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testCaseExecutionList.add(this.loadFromResultSet(resultSet));
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
                answer = new AnswerList(testCaseExecutionList, 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 {
                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!"));
            testCaseExecutionList = 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 53 with AnswerList

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

the class SQLService method queryDatabaseNColumns.

@Override
public AnswerList queryDatabaseNColumns(String connectionName, String sql, int rowLimit, int defaultTimeOut, String system, HashMap<String, String> columnsToGet) {
    AnswerList listResult = new AnswerList();
    List<HashMap<String, String>> list;
    int maxSecurityFetch = parameterService.getParameterIntegerByKey("cerberus_testdatalib_fetchmax", system, 100);
    int maxFetch;
    if (rowLimit > 0 && rowLimit < maxSecurityFetch) {
        maxFetch = rowLimit;
    } else {
        maxFetch = maxSecurityFetch;
    }
    int nbFetch = 0;
    int nbColMatch = 0;
    String error_desc = "";
    MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);
    msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));
    try (Connection connection = this.databaseSpring.connect(connectionName);
        PreparedStatement preStat = connection.prepareStatement(sql)) {
        preStat.setQueryTimeout(defaultTimeOut);
        try {
            LOG.info("Sending to external Database (queryDatabaseNColumns) : '" + connectionName + "' SQL '" + sql + "'");
            ResultSet resultSet = preStat.executeQuery();
            int nrColumns = resultSet.getMetaData().getColumnCount();
            list = new ArrayList<HashMap<String, String>>();
            try {
                while ((resultSet.next()) && (nbFetch < maxFetch)) {
                    nbColMatch = 0;
                    HashMap<String, String> row = new HashMap<String, String>();
                    for (Map.Entry<String, String> entry : columnsToGet.entrySet()) {
                        String column = entry.getValue();
                        String name = entry.getKey();
                        try {
                            String valueSQL = resultSet.getString(column);
                            if (valueSQL == null) {
                                // If data is null from the database, we convert it to the static string <NULL>.
                                valueSQL = "<NULL>";
                            }
                            // We put the result of the subData.
                            row.put(name, valueSQL);
                            nbColMatch++;
                        } catch (SQLException exception) {
                            if (nbFetch == 0) {
                                if ("".equals(error_desc)) {
                                    error_desc = column;
                                } else {
                                    error_desc = error_desc + ", " + column;
                                }
                            }
                        }
                    }
                    list.add(row);
                    nbFetch++;
                }
                listResult.setDataList(list);
                listResult.setTotalRows(list.size());
                if (list.isEmpty()) {
                    // No data was fetched.
                    msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_NODATA);
                } else if (nbColMatch == 0) {
                    // None of the columns could be match.
                    msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_NOCOLUMNMATCH);
                    msg.setDescription(msg.getDescription().replace("%BADCOLUMNS%", error_desc));
                } else if (!("".equals(error_desc))) {
                    // At least a column could not be parsed
                    msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_COLUMNNOTMATCHING);
                    msg.setDescription(msg.getDescription().replace("%BADCOLUMNS%", error_desc));
                }
            } catch (SQLTimeoutException exception) {
                msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_TIMEOUT);
                msg.setDescription(msg.getDescription().replace("%SQL%", sql));
                msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(defaultTimeOut)));
                msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLTimeoutException exception) {
            LOG.warn("TimeOut " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_TIMEOUT);
            msg.setDescription(msg.getDescription().replace("%SQL%", sql));
            msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(defaultTimeOut)));
            msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
        } catch (SQLException exception) {
            LOG.warn(exception.toString());
            msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_ERROR);
            msg.setDescription(msg.getDescription().replace("%SQL%", sql));
            msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
        }
    } catch (SQLException exception) {
        LOG.warn(exception.toString());
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_ERROR);
        msg.setDescription(msg.getDescription().replace("%SQL%", sql));
        msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
    } catch (NullPointerException exception) {
        // TODO check where exception occur
        LOG.warn(exception.toString());
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_CANNOTACCESSJDBC);
        msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));
        msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
    }
    listResult.setResultMessage(msg);
    return listResult;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) SQLTimeoutException(java.sql.SQLTimeoutException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 54 with AnswerList

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

the class DataLibService method getFromDataLib.

@Override
public AnswerList<HashMap<String, String>> getFromDataLib(TestDataLib lib, TestCaseCountryProperties testCaseCountryProperty, TestCaseExecution tCExecution, TestCaseExecutionData testCaseExecutionData) {
    AnswerItem<HashMap<String, String>> resultColumns;
    AnswerList<HashMap<String, String>> resultData;
    AnswerList<HashMap<String, String>> result;
    MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);
    // Length contains the nb of rows that the result must fetch. If defined at 0 we force at 1.
    Integer nbRowsRequested = 0;
    try {
        nbRowsRequested = Integer.parseInt(testCaseExecutionData.getLength());
        if (nbRowsRequested < 1) {
            nbRowsRequested = 1;
        }
    } catch (NumberFormatException e) {
        LOG.error(e.toString());
    }
    /**
     * Gets the list of columns (subdata) to get from TestDataLibData.
     */
    resultColumns = getSubDataFromType(lib);
    HashMap<String, String> columnList = null;
    // Manage error message.
    if (resultColumns.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA.getCode()) {
        AnswerItem answerDecode = new AnswerItem();
        columnList = resultColumns.getItem();
        // Now that we have the list of column with subdata and value, we can try to decode it.
        if (columnList != null) {
            for (Map.Entry<String, String> entry : columnList.entrySet()) {
                // Loop on all Column in order to decode all values.
                // SubData
                String eKey = entry.getKey();
                // Parsing Answer
                String eValue = entry.getValue();
                try {
                    answerDecode = variableService.decodeStringCompletly(eValue, tCExecution, null, false);
                    columnList.put(eKey, (String) answerDecode.getItem());
                    if (!(answerDecode.isCodeStringEquals("OK"))) {
                        // If anything wrong with the decode --> we stop here with decode message in the action result.
                        result = new AnswerList();
                        result.setDataList(null);
                        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_SUBDATAISSUE);
                        msg.setDescription(msg.getDescription().replace("%SUBDATAMESSAGE%", answerDecode.getMessageDescription().replace("%FIELD%", "Column value '" + eValue + "'")));
                        result.setResultMessage(msg);
                        LOG.debug("Datalib interupted due to decode 'column value' Error.");
                        return result;
                    }
                } catch (CerberusEventException cex) {
                    LOG.warn(cex);
                }
            }
        }
    } else if (resultColumns.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATA.getCode()) {
        result = new AnswerList();
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_SUBDATAISSUE);
        msg.setDescription(msg.getDescription().replace("%SUBDATAMESSAGE%", resultColumns.getMessageDescription()));
        result.setResultMessage(msg);
        return result;
    }
    /**
     * Get List of DataObject in a format List<Map<String>> - 1 item per row
     * with key = column and value = content
     */
    int rowLimit = testCaseCountryProperty.getRowLimit();
    if (testCaseCountryProperty.getNature().equalsIgnoreCase(TestCaseCountryProperties.NATURE_STATIC)) {
        // If Nature of the property is static, we don't need to getch more than reqested record.
        rowLimit = nbRowsRequested;
    }
    resultData = getDataObjectList(lib, columnList, rowLimit, tCExecution, testCaseExecutionData);
    // Manage error message.
    if (resultData.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_DATA.getCode()) {
        if (resultData.getDataList().size() < nbRowsRequested) {
            // We check if the data provided is enought to provide the answer.
            result = new AnswerList();
            result.setDataList(null);
            msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NOTENOUGHTDATA);
            msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%NBREQUEST%", Integer.toString(nbRowsRequested)));
            result.setResultMessage(msg);
            return result;
        }
    } else if (resultData.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GENERIC_NODATA.getCode()) {
        result = new AnswerList();
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NODATA);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()));
        result.setResultMessage(msg);
        return result;
    } else {
        result = new AnswerList();
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_DATAISSUE);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()));
        result.setResultMessage(msg);
        return result;
    }
    /**
     * Filter out the result from requested rows depending on the nature
     */
    result = filterWithNature(testCaseCountryProperty.getNature(), resultData, tCExecution, testCaseCountryProperty, nbRowsRequested);
    // Manage error message.
    if (result.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURE.getCode()) {
        msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_GLOBAL);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));
        result.setResultMessage(msg);
    } else if (result.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GENERIC_NATURENOMORERECORD.getCode()) {
        // if the script does not return
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NODATALEFT);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));
        result.setResultMessage(msg);
    } else {
        // other error had occured
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_GENERIC);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));
        result.setResultMessage(msg);
    }
    return result;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem) CerberusEventException(org.cerberus.exception.CerberusEventException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 55 with AnswerList

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

the class DataLibService method filterWithNatureRANDOM.

@Override
public AnswerList<HashMap<String, String>> filterWithNatureRANDOM(AnswerList<HashMap<String, String>> dataObjectList, int outputRequestedDimention) {
    AnswerList<HashMap<String, String>> result = new AnswerList();
    String selectedList = "";
    List<HashMap<String, String>> resultObject;
    resultObject = new ArrayList<HashMap<String, String>>();
    List<Integer> listTempRandom = getRandomListOfInteger(dataObjectList.getDataList().size(), outputRequestedDimention);
    for (int i : listTempRandom) {
        int j = i + 1;
        selectedList += Integer.toString(j) + ",";
        resultObject.add(dataObjectList.getDataList().get(i));
    }
    selectedList = StringUtil.removeLastChar(selectedList, 1);
    result.setDataList(resultObject);
    result.setResultMessage(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURERANDOM).resolveDescription("POS", selectedList).resolveDescription("TOTALPOS", Integer.toString(dataObjectList.getDataList().size())));
    return result;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent)

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