Search in sources :

Example 66 with AnswerList

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

the class ReadTestCaseExecutionByTag method getCountryList.

private JSONObject getCountryList(HttpServletRequest request, ApplicationContext appContext) {
    JSONObject countryList = new JSONObject();
    try {
        IInvariantService invariantService = appContext.getBean(InvariantService.class);
        // TODO: handle if the response does not turn ok
        AnswerList answer = invariantService.readByIdname("COUNTRY");
        for (Invariant country : (List<Invariant>) answer.getDataList()) {
            countryList.put(country.getValue(), ParameterParserUtil.parseStringParam(request.getParameter(country.getValue()), "off"));
        }
    } catch (JSONException ex) {
        LOG.error("Error on getCountryList : " + ex);
    }
    return countryList;
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) IInvariantService(org.cerberus.crud.service.IInvariantService) JSONException(org.json.JSONException) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 67 with AnswerList

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

the class ReadTestCaseExecutionByTag method generateLabelStats.

private JSONObject generateLabelStats(ApplicationContext appContext, HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {
    JSONObject jsonResult = new JSONObject();
    boolean stickers = request.getParameter("stickers") != null;
    boolean requirement = request.getParameter("requirement") != null;
    if (stickers || requirement) {
        testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
        AnswerList testCaseLabelList = testCaseLabelService.readByTestTestCase(null, null);
        SummaryStatisticsDTO total = new SummaryStatisticsDTO();
        total.setEnvironment("Total");
        /**
         * Iterate on the label retrieved and generate HashMap based on the
         * key Test_TestCase
         */
        LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap();
        for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList.getDataList()) {
            if ((Label.TYPE_STICKER.equals(label.getLabel().getType()) && stickers) || (Label.TYPE_REQUIREMENT.equals(label.getLabel().getType()) && requirement)) {
                String key = label.getTest() + "_" + label.getTestcase();
                JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());
                if (testCaseWithLabel.containsKey(key)) {
                    testCaseWithLabel.get(key).put(jo);
                } else {
                    testCaseWithLabel.put(key, new JSONArray().put(jo));
                }
            }
        }
        /**
         * For All execution, get all label and generate statistics
         */
        LinkedHashMap<String, SummaryStatisticsDTO> labelPerTestcaseExecution = new LinkedHashMap();
        for (TestCaseExecution testCaseExecution : testCaseExecutions) {
            String controlStatus = testCaseExecution.getControlStatus();
            if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
                // Get label for current test_testcase
                JSONArray labelsForTestCase = testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase());
                if (labelsForTestCase != null) {
                    for (int index = 0; index < labelsForTestCase.length(); index++) {
                        JSONObject j = labelsForTestCase.getJSONObject(index);
                        if (labelPerTestcaseExecution.containsKey(j.get("name"))) {
                            labelPerTestcaseExecution.get(j.get("name").toString()).updateStatisticByStatus(controlStatus);
                        } else {
                            SummaryStatisticsDTO stat = new SummaryStatisticsDTO();
                            stat.setLabel(j);
                            stat.updateStatisticByStatus(controlStatus);
                            labelPerTestcaseExecution.put(j.get("name").toString(), stat);
                        }
                        total.updateStatisticByStatus(controlStatus);
                    }
                }
            }
        }
        jsonResult.put("labelStats", extractSummaryData(labelPerTestcaseExecution, total, true));
    }
    return jsonResult;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) JSONArray(org.json.JSONArray) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.JSONObject) SummaryStatisticsDTO(org.cerberus.dto.SummaryStatisticsDTO) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) ITestCaseLabelService(org.cerberus.crud.service.ITestCaseLabelService)

Example 68 with AnswerList

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

the class ReadTestCaseExecutionQueue method findExecutionInQueueList.

private AnswerItem findExecutionInQueueList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    executionService = appContext.getBean(ITestCaseExecutionQueueService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    /*int sEcho  = Integer.valueOf(request.getParameter("sEcho"));*/
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "2"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "id,test,testcase,country,environment,browser,tag");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "desc");
    List<String> individualLike = new ArrayList(Arrays.asList(request.getParameter("sLike").split(",")));
    Map<String, List<String>> individualSearch = new HashMap<>();
    for (int a = 0; a < columnToSort.length; a++) {
        if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
            List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
            if (individualLike.contains(columnToSort[a])) {
                individualSearch.put(columnToSort[a] + ":like", search);
            } else {
                individualSearch.put(columnToSort[a], search);
            }
        }
    }
    AnswerList resp = executionService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);
    JSONArray jsonArray = new JSONArray();
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (TestCaseExecutionQueue exec : (List<TestCaseExecutionQueue>) resp.getDataList()) {
            jsonArray.put(convertTestCaseExecutionInQueueToJSONObject(exec));
        }
    }
    object.put("hasPermissions", userHasPermissions);
    object.put("contentTable", jsonArray);
    object.put("iTotalRecords", resp.getTotalRows());
    object.put("iTotalDisplayRecords", resp.getTotalRows());
    item.setItem(object);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) ITestCaseExecutionQueueService(org.cerberus.crud.service.ITestCaseExecutionQueueService)

Example 69 with AnswerList

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

the class ReadTestDataLib method findDistinctValuesOfColumn.

private AnswerItem findDistinctValuesOfColumn(ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {
    AnswerItem answer = new AnswerItem();
    JSONObject object = new JSONObject();
    testDataLibService = appContext.getBean(ITestDataLibService.class);
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "test,testcase,application,project,ticket,description,behaviororvalueexpected,readonly,bugtrackernewurl,deploytype,mavengroupid");
    String[] columnToSort = sColumns.split(",");
    List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
    Map<String, List<String>> individualSearch = new HashMap<>();
    for (int a = 0; a < columnToSort.length; a++) {
        if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
            List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
            if (individualLike.contains(columnToSort[a])) {
                individualSearch.put(columnToSort[a] + ":like", search);
            } else {
                individualSearch.put(columnToSort[a], search);
            }
        }
    }
    AnswerList testCaseList = testDataLibService.readDistinctValuesByCriteria(searchParameter, individualSearch, columnName);
    object.put("distinctValues", testCaseList.getDataList());
    answer.setItem(object);
    answer.setResultMessage(testCaseList.getResultMessage());
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ITestDataLibService(org.cerberus.crud.service.ITestDataLibService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 70 with AnswerList

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

the class ReadTestDataLib method findTestDataLibNameList.

/**
 * Handles the auto-complete requests and retrieves a limited list of
 * strings that match (totally or partially) the name entered by the user.
 *
 * @param appContext - context object used to get the required beans
 * @param nameToSearch - value used to perform the auto complete
 * @param limit - limit number of the records that should be retrieved
 * @return object containing values that match the name
 * @throws JSONException
 */
private AnswerItem findTestDataLibNameList(String nameToSearch, int limit, boolean like, ApplicationContext appContext) throws JSONException {
    AnswerItem ansItem = new AnswerItem();
    JSONObject object = new JSONObject();
    ITestDataLibService testDataService = appContext.getBean(ITestDataLibService.class);
    AnswerList ansList = testDataService.readNameListByName(nameToSearch, limit, like);
    JSONArray jsonArray = new JSONArray();
    if (ansList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (TestDataLib testDataLib : (List<TestDataLib>) ansList.getDataList()) {
            jsonArray.put(convertTestDataLibToJSONObject(testDataLib, false));
        }
    }
    // recordsFiltered do lado do servidor
    object.put("contentTable", jsonArray);
    object.put("iTotalRecords", ansList.getTotalRows());
    object.put("iTotalDisplayRecords", ansList.getTotalRows());
    // recordsFiltered
    ansItem.setResultMessage(ansList.getResultMessage());
    ansItem.setItem(object);
    return ansItem;
}
Also used : TestDataLib(org.cerberus.crud.entity.TestDataLib) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ITestDataLibService(org.cerberus.crud.service.ITestDataLibService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem)

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