Search in sources :

Example 1 with TestCaseExecutionwwwDet

use of org.cerberus.crud.entity.TestCaseExecutionwwwDet in project cerberus-source by cerberustesting.

the class TestCaseExecutionwwwDetDAO method getListOfDetail.

@Override
public List<TestCaseExecutionwwwDet> getListOfDetail(int execId) {
    List<TestCaseExecutionwwwDet> list = null;
    final String query = "SELECT * FROM testcaseexecutionwwwdet WHERE execID = ?";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, String.valueOf(execId));
            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<TestCaseExecutionwwwDet>();
                while (resultSet.next()) {
                    TestCaseExecutionwwwDet detail = new TestCaseExecutionwwwDet();
                    detail.setId(resultSet.getString("ID") == null ? 0 : resultSet.getInt("ID"));
                    detail.setExecID(resultSet.getString("EXECID") == null ? 0 : resultSet.getInt("EXECID"));
                    detail.setStart(resultSet.getString("START") == null ? "" : resultSet.getString("START"));
                    detail.setUrl(resultSet.getString("URL") == null ? "" : resultSet.getString("URL"));
                    detail.setEnd(resultSet.getString("END") == null ? "" : resultSet.getString("END"));
                    detail.setExt(resultSet.getString("EXT") == null ? "" : resultSet.getString("EXT"));
                    detail.setStatusCode(resultSet.getInt("StatusCode") == 0 ? 0 : resultSet.getInt("StatusCode"));
                    detail.setMethod(resultSet.getString("Method") == null ? "" : resultSet.getString("Method"));
                    detail.setBytes(resultSet.getString("Bytes") == null ? 0 : resultSet.getInt("Bytes"));
                    detail.setTimeInMillis(resultSet.getString("TimeInMillis") == null ? 0 : resultSet.getInt("TimeInMillis"));
                    detail.setReqHeader_Host(resultSet.getString("ReqHeader_Host") == null ? "" : resultSet.getString("ReqHeader_Host"));
                    detail.setResHeader_ContentType(resultSet.getString("ResHeader_ContentType") == null ? "" : resultSet.getString("ResHeader_ContentType"));
                    list.add(detail);
                }
            } catch (SQLException exception) {
                LOG.warn(exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn(exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn(exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) TestCaseExecutionwwwDet(org.cerberus.crud.entity.TestCaseExecutionwwwDet)

Example 2 with TestCaseExecutionwwwDet

use of org.cerberus.crud.entity.TestCaseExecutionwwwDet in project cerberus-source by cerberustesting.

the class TCEwwwDetail method doGet.

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    String echo = httpServletRequest.getParameter("sEcho");
    String sStart = httpServletRequest.getParameter("iDisplayStart");
    String sAmount = httpServletRequest.getParameter("iDisplayLength");
    String sCol = httpServletRequest.getParameter("iSortCol_0");
    String sdir = httpServletRequest.getParameter("sSortDir_0");
    String dir = "asc";
    // String[] cols = {"id","execID","start","url",
    // "end","ext","statusCode","method","bytes","timeInMillis","reqHeader_Host","resHeader_ContentType"};
    int start = 0;
    int amount = 0;
    int col = 0;
    if (sStart != null) {
        start = Integer.parseInt(sStart);
        if (start < 0)
            start = 0;
    }
    if (sAmount != null) {
        amount = Integer.parseInt(sAmount);
        if (amount < 10 || amount > 100)
            amount = 10;
    }
    if (sCol != null) {
        col = Integer.parseInt(sCol);
        if (col < 0 || col > 5)
            col = 0;
    }
    if (sdir != null) {
        if (!sdir.equals("asc"))
            dir = "desc";
    }
    // String colName = cols[col];
    // data that will be shown in the table
    JSONArray data = new JSONArray();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    ITestCaseExecutionwwwDetService tCEwwwDetService = appContext.getBean(ITestCaseExecutionwwwDetService.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    String id = policy.sanitize(httpServletRequest.getParameter("id"));
    List<TestCaseExecutionwwwDet> detailList = tCEwwwDetService.getListOfDetail(Integer.valueOf(id));
    try {
        JSONObject jsonResponse = new JSONObject();
        for (TestCaseExecutionwwwDet detail : detailList) {
            JSONArray row = new JSONArray();
            row.put(detail.getId()).put(detail.getExecID()).put(detail.getStart()).put(detail.getUrl()).put(detail.getEnd()).put(detail.getExt()).put(detail.getStatusCode()).put(detail.getMethod()).put(detail.getBytes()).put(detail.getTimeInMillis()).put(detail.getReqHeader_Host()).put(detail.getResHeader_ContentType());
            data.put(row);
        }
        jsonResponse.put("aaData", data);
        jsonResponse.put("sEcho", echo);
        httpServletResponse.setContentType("application/json");
        httpServletResponse.getWriter().print(jsonResponse.toString());
    } catch (JSONException e) {
        httpServletResponse.setContentType("text/html");
        httpServletResponse.getWriter().print(e.getMessage());
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ITestCaseExecutionwwwDetService(org.cerberus.crud.service.ITestCaseExecutionwwwDetService) PolicyFactory(org.owasp.html.PolicyFactory) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) TestCaseExecutionwwwDet(org.cerberus.crud.entity.TestCaseExecutionwwwDet)

Aggregations

TestCaseExecutionwwwDet (org.cerberus.crud.entity.TestCaseExecutionwwwDet)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ITestCaseExecutionwwwDetService (org.cerberus.crud.service.ITestCaseExecutionwwwDetService)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 PolicyFactory (org.owasp.html.PolicyFactory)1 ApplicationContext (org.springframework.context.ApplicationContext)1