Search in sources :

Example 71 with AnswerList

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

the class ReadTestDataLibData method readAll.

private AnswerItem readAll(ApplicationContext appContext) throws JSONException {
    JSONObject jsonResponse = new JSONObject();
    ITestDataLibDataService testDataLibDataService = appContext.getBean(ITestDataLibDataService.class);
    AnswerList answer = testDataLibDataService.readAll();
    // retrieves the data for the entry
    JSONArray jsonArray = new JSONArray();
    Gson gson = new Gson();
    for (TestDataLibData subData : (List<TestDataLibData>) answer.getDataList()) {
        jsonArray.put(new JSONObject(gson.toJson(subData)));
    }
    jsonResponse.put("contentTable", jsonArray);
    AnswerItem item = new AnswerItem();
    item.setItem(jsonResponse);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : ITestDataLibDataService(org.cerberus.crud.service.ITestDataLibDataService) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem) TestDataLibData(org.cerberus.crud.entity.TestDataLibData)

Example 72 with AnswerList

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

the class ReadTestDataLibData method readById.

// </editor-fold>
private AnswerItem readById(ApplicationContext appContext, int testDatalib) throws JSONException {
    JSONObject jsonResponse = new JSONObject();
    ITestDataLibDataService testDataLibDataService = appContext.getBean(ITestDataLibDataService.class);
    AnswerList answer = testDataLibDataService.readByVarious(testDatalib, null, null, null);
    // retrieves the data for the entry
    JSONArray jsonArray = new JSONArray();
    for (TestDataLibData subdata : (List<TestDataLibData>) answer.getDataList()) {
        jsonArray.put(convertTestDataLibDataToJSONObject(subdata));
    }
    jsonResponse.put("contentTable", jsonArray);
    AnswerItem item = new AnswerItem();
    item.setItem(jsonResponse);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : ITestDataLibDataService(org.cerberus.crud.service.ITestDataLibDataService) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem) TestDataLibData(org.cerberus.crud.entity.TestDataLibData)

Example 73 with AnswerList

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

the class ReadRobot method findRobotList.

// </editor-fold>
private AnswerItem findRobotList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    robotService = appContext.getBean(RobotService.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"), "1"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "robotID,robot,host,port,platform,browser,version,active,useragent,description");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    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 resp = robotService.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 (Robot robot : (List<Robot>) resp.getDataList()) {
            if (robot != null) {
                // hide the password to the view
                robot.setHostPassword(null);
            }
            jsonArray.put(convertRobotToJSONObject(robot));
        }
    }
    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) RobotService(org.cerberus.crud.service.impl.RobotService) IRobotService(org.cerberus.crud.service.IRobotService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) Robot(org.cerberus.crud.entity.Robot)

Example 74 with AnswerList

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

the class ReadRobot method findDistinctValuesOfColumn.

private AnswerItem findDistinctValuesOfColumn(ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {
    AnswerItem answer = new AnswerItem();
    JSONObject object = new JSONObject();
    robotService = appContext.getBean(RobotService.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 = robotService.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) RobotService(org.cerberus.crud.service.impl.RobotService) IRobotService(org.cerberus.crud.service.IRobotService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 75 with AnswerList

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

the class FindTestImplementationStatusPerApplication method processRequest.

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    String echo = policy.sanitize(request.getParameter("sEcho"));
    String mySystem = policy.sanitize(request.getParameter("MySystem"));
    String application = policy.sanitize(request.getParameter("Application"));
    Connection connection = null;
    JSONObject jsonResponse = new JSONObject();
    try {
        List<String> sArray = new ArrayList<String>();
        if (!mySystem.equals("")) {
            String smySystem = " `system` like '%" + mySystem + "%'";
            sArray.add(smySystem);
        }
        JSONArray data = new JSONArray();
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        IInvariantService invariantService = appContext.getBean(InvariantService.class);
        DatabaseSpring database = appContext.getBean(DatabaseSpring.class);
        connection = database.connect();
        AnswerList answer = invariantService.readByIdnameGp1("TCSTATUS", "Y");
        List<Invariant> myInvariants = answer.getDataList();
        StringBuilder SQL = new StringBuilder();
        StringBuilder SQLa = new StringBuilder();
        StringBuilder SQLb = new StringBuilder();
        SQLa.append("SELECT t.test, count(*) as TOTAL ");
        SQLb.append(" FROM testcase t ");
        for (Invariant i : myInvariants) {
            i.getSort();
            SQLa.append(", Col");
            SQLa.append(String.valueOf(i.getSort()));
            SQLb.append(" LEFT JOIN (SELECT g.test, count(*) as Col");
            SQLb.append(String.valueOf(i.getSort()));
            SQLb.append(" FROM testcase g WHERE Status = '");
            SQLb.append(i.getValue());
            SQLb.append("' and application ='");
            SQLb.append(application);
            SQLb.append("' GROUP BY g.test) Tab");
            SQLb.append(String.valueOf(i.getSort()));
            SQLb.append(" ON Tab");
            SQLb.append(String.valueOf(i.getSort()));
            SQLb.append(".test=t.test ");
        }
        SQLb.append(" where t.application ='");
        SQLb.append(application);
        SQLb.append("'");
        SQLb.append(" group by t.test");
        SQL.append(SQLa);
        SQL.append(SQLb);
        LOG.debug(" SQL1 : " + SQL.toString());
        PreparedStatement stmt_teststatus = connection.prepareStatement(SQL.toString());
        try (ResultSet rs_teststatus = stmt_teststatus.executeQuery()) {
            // Integer tot = 0;
            List<Integer> totLine;
            totLine = new ArrayList<Integer>();
            for (Invariant i : myInvariants) {
                totLine.add(0);
            }
            try {
                while (rs_teststatus.next()) {
                    JSONArray row = new JSONArray();
                    StringBuilder testLink = new StringBuilder();
                    testLink.append("<a href=\"TestCaseList.jsp?test=");
                    testLink.append(rs_teststatus.getString("t.test"));
                    testLink.append("\">");
                    testLink.append(rs_teststatus.getString("t.test"));
                    testLink.append("</a>");
                    row.put(testLink.toString());
                    row.put(rs_teststatus.getString("TOTAL"));
                    for (Invariant i : myInvariants) {
                        i.getSort();
                        row.put(rs_teststatus.getString("Col" + String.valueOf(i.getSort())));
                    }
                    data.put(row);
                }
                // data that will be shown in the table
                jsonResponse.put("aaData", data);
                jsonResponse.put("sEcho", echo);
                jsonResponse.put("iTotalRecords", data.length());
                jsonResponse.put("iTotalDisplayRecords", data.length());
                response.setContentType("application/json");
                response.getWriter().print(jsonResponse.toString());
            } catch (JSONException ex) {
                LOG.warn(ex.toString());
            } finally {
                out.close();
            }
        } catch (SQLException ex) {
            LOG.warn(" Exception trying to query '" + SQL.toString() + "' : " + ex);
        } finally {
            stmt_teststatus.close();
        }
    } catch (Exception ex) {
        LOG.warn(" Exception catched : " + ex);
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) AnswerList(org.cerberus.util.answer.AnswerList) PolicyFactory(org.owasp.html.PolicyFactory) SQLException(java.sql.SQLException) IInvariantService(org.cerberus.crud.service.IInvariantService) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) PreparedStatement(java.sql.PreparedStatement) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) JSONException(org.json.JSONException) IOException(java.io.IOException) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) DatabaseSpring(org.cerberus.database.DatabaseSpring) ResultSet(java.sql.ResultSet) PrintWriter(java.io.PrintWriter)

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