use of org.cerberus.crud.service.IInvariantService in project cerberus-source by cerberustesting.
the class GetNumberOfExecutions method processRequest.
/**
* Processes requests for both HTTP
* <code>GET</code> and
* <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
// Loading Services.
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IApplicationService myApplicationService = appContext.getBean(ApplicationService.class);
IInvariantService myInvariantService = appContext.getBean(InvariantService.class);
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPublicCalls("/GetNumberOfExecutions", "CALL", "GetNumberOfExecutions called : " + request.getRequestURL(), request);
// Parsing all parameters.
String environment = ParameterParserUtil.parseStringParam(request.getParameter("environment"), "PROD");
String test = ParameterParserUtil.parseStringParam(request.getParameter("test"), "");
String application = ParameterParserUtil.parseStringParam(request.getParameter("application"), "");
String country = ParameterParserUtil.parseStringParam(request.getParameter("country"), "");
String controlStatus = ParameterParserUtil.parseStringParam(request.getParameter("controlstatus"), "");
int NbMinutes = ParameterParserUtil.parseIntegerParam(request.getParameter("nbminuteshistory"), 0);
// Defining help message.
String helpMessage = "\nThis servlet return the number of execution performed on WORKING test cases that match the following criterias :\n" + "- nbminuteshistory [mandatory] : the number of minutes in the past from the moment the servlet is called. This parameter must be > 0. [" + NbMinutes + "]\n" + "- test : Executions done on the test. [" + test + "]\n" + "- environment : Environment where the execution happened. Default to PROD. [" + environment + "]\n" + "- country : Executions done on the country. [" + country + "]\n" + "- application : Executions done against that application. [" + application + "]\n" + "- controlstatus : execution that return the following status. [" + controlStatus + "]\n";
try {
// Checking the parameter validity. nbminuteshistory is a mandatory parameter.
boolean error = false;
if (NbMinutes == 0) {
out.println("Error - Parameter nbminuteshistory is mandatory. Please feed it in order to specify the elapsed time where the history should be considered.");
error = true;
}
// Checking the parameter validity. If application has been entered, does it exist ?
if (!application.equalsIgnoreCase("") && !myApplicationService.exist(application)) {
out.println("Error - Application does not exist : " + application);
error = true;
}
if (!country.equalsIgnoreCase("") && !myInvariantService.isInvariantExist("COUNTRY", country)) {
out.println("Warning - Country does not exist : " + country);
}
if (!environment.equalsIgnoreCase("") && !myInvariantService.isInvariantExist("ENVIRONMENT", environment)) {
out.println("Warning - Environment does not exist : " + environment);
}
if (!controlStatus.equalsIgnoreCase("") && !myInvariantService.isInvariantExist("TCESTATUS", controlStatus)) {
out.println("Warning - Control Status does not exist : " + controlStatus);
}
// Starting the request only if previous parameters exist.
if (!error) {
// Getting a timestamp to filter the executions based on the nb of minutes
String dateLimitFrom = DateUtil.getMySQLTimestampTodayDeltaMinutes(-NbMinutes);
ITestCaseExecutionService MyTestExecutionService = appContext.getBean(TestCaseExecutionService.class);
List<TestCaseExecution> myList;
// Getting the lists of test cases the follow the criterias.
try {
myList = MyTestExecutionService.findTCExecutionbyCriteria1(dateLimitFrom, test, "", application, country, environment, controlStatus, "WORKING");
out.println(myList.size());
} catch (CerberusException e) {
out.println("0");
}
} else {
// In case of errors, we displayu the help message.
out.println(helpMessage);
}
} catch (Exception e) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", e);
out.print("Error while Getting number of executions : ");
out.println(e.getMessage());
} finally {
out.close();
}
}
use of org.cerberus.crud.service.IInvariantService 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;
}
use of org.cerberus.crud.service.IInvariantService 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());
}
}
}
use of org.cerberus.crud.service.IInvariantService in project cerberus-source by cerberustesting.
the class Homepage method readApplicationList.
private AnswerItem readApplicationList(String system, ApplicationContext appContext) throws JSONException {
AnswerItem item = new AnswerItem();
JSONObject jsonResponse = new JSONObject();
IApplicationService applicationService = appContext.getBean(ApplicationService.class);
AnswerItem resp = applicationService.readTestCaseCountersBySystemByStatus(system);
JSONArray jsonArray = new JSONArray();
HashMap<String, HashMap<String, Integer>> totalMap = (HashMap<String, HashMap<String, Integer>>) resp.getItem();
if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null) {
IInvariantService invariantService = appContext.getBean(InvariantService.class);
AnswerList<Invariant> answerList = invariantService.readByIdnameGp1("TCSTATUS", "Y");
List<Invariant> myInvariants = answerList.getDataList();
for (String application : totalMap.keySet()) {
JSONObject row = extractRow(application, totalMap, myInvariants);
jsonArray.put(row);
}
}
jsonResponse.put("aaData", jsonArray);
jsonResponse.put("iTotalRecords", totalMap.size());
jsonResponse.put("iTotalDisplayRecords", totalMap.size());
item.setItem(jsonResponse);
item.setResultMessage(resp.getResultMessage());
return item;
}
use of org.cerberus.crud.service.IInvariantService in project cerberus-source by cerberustesting.
the class UpdateInvariant method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
JSONObject jsonResponse = new JSONObject();
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
String charset = request.getCharacterEncoding();
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
String id = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("idName"), "", charset);
String value = request.getParameter("value");
String oriId = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("originalIdName"), "", charset);
String oriValue = request.getParameter("originalValue");
String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);
String veryShortDescField = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("veryShortDesc"), "", charset);
String gp1 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp1"), "", charset);
String gp2 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp2"), "", charset);
String gp3 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp3"), "", charset);
String gp4 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp4"), "", charset);
String gp5 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp5"), "", charset);
String gp6 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp6"), "", charset);
String gp7 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp7"), "", charset);
String gp8 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp8"), "", charset);
String gp9 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("gp9"), "", charset);
Integer sort = 10;
boolean sort_error = false;
try {
if (request.getParameter("sort") != null && !request.getParameter("sort").equals("")) {
sort = Integer.valueOf(policy.sanitize(request.getParameter("sort")));
}
} catch (Exception ex) {
sort_error = true;
}
boolean userHasPermissions = request.isUserInRole("Administrator");
// Prepare the final answer.
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(id)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Invariant").replace("%OPERATION%", "Update").replace("%REASON%", "Invariant name is missing!"));
finalAnswer.setResultMessage(msg);
} else if (sort_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Invariant").replace("%OPERATION%", "Update").replace("%REASON%", "Could not manage to convert sort to an integer value!"));
finalAnswer.setResultMessage(msg);
} else if (!userHasPermissions) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Invariant").replace("%OPERATION%", "Update").replace("%REASON%", "You don't have the right to do that"));
finalAnswer.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IInvariantService invariantService = appContext.getBean(IInvariantService.class);
AnswerItem resp = invariantService.readByKey(oriId, oriValue);
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
/**
* Object could not be found. We stop here and report the error.
*/
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);
} else {
Invariant invariantData = (Invariant) resp.getItem();
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
/**
* Object could not be found. We stop here and report the
* error.
*/
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);
} else {
if (invariantService.hasPermissionsUpdate(invariantData, request)) {
invariantData.setIdName(id);
invariantData.setValue(value);
invariantData.setSort(sort);
invariantData.setDescription(description);
invariantData.setVeryShortDesc(veryShortDescField);
invariantData.setGp1(gp1);
invariantData.setGp2(gp2);
invariantData.setGp3(gp3);
invariantData.setGp4(gp4);
invariantData.setGp5(gp5);
invariantData.setGp6(gp6);
invariantData.setGp7(gp7);
invariantData.setGp8(gp8);
invariantData.setGp9(gp9);
ans = invariantService.update(oriId, oriValue, invariantData);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Object updated. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateInvariant2", "UPDATE", "Update Invariant : ['" + id + "']", request);
}
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Invariant").replace("%OPERATION%", "Update").replace("%REASON%", "The Invariant is not Public!"));
ans.setResultMessage(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
Aggregations