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;
}
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;
}
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;
}
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;
}
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());
}
}
}
Aggregations