use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class UpdateTest 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
* @throws org.json.JSONException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException {
JSONObject jsonResponse = new JSONObject();
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
String originalTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");
String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");
String description = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Description"), "");
String active = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Active"), "");
String automated = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Automated"), "");
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(test)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Test").replace("%OPERATION%", "Update").replace("%REASON%", "Test name (test) is missing"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestService testService = appContext.getBean(ITestService.class);
AnswerItem resp = testService.readByKey(originalTest);
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
/**
* Object could not be found. We stop here and report the error.
*/
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Application").replace("%OPERATION%", "Update").replace("%REASON%", "Test does not exist."));
ans.setResultMessage(msg);
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
Test testData = (Test) resp.getItem();
testData.setTest(test);
testData.setDescription(description);
testData.setActive(active);
testData.setAutomated(automated);
ans = testService.update(originalTest, testData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateTest", "UPDATE", "Updated Test : ['" + originalTest + "']", request);
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class UpdateTestCaseMass 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();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ILogEventService logEventService = appContext.getBean(LogEventService.class);
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();
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
/**
* Parsing and securing all required parameters.
*/
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
// Parameter that needs to be secured --> We SECURE+DECODE them
String function = request.getParameter("massFunction");
String status = request.getParameter("massStatus");
String application = request.getParameter("massApplication");
// Parameter that we cannot secure as we need the html --> We DECODE them
String[] myTest = request.getParameterValues("test");
String[] myTestCase = request.getParameterValues("testcase");
StringBuilder output_message = new StringBuilder();
int massErrorCounter = 0;
int tcCounter = 0;
for (String myTest1 : myTest) {
String cur_test = myTest1;
String cur_testcase = myTestCase[tcCounter];
/**
* All data seems cleans so we can call the services.
*/
AnswerItem resp = testCaseService.readByKey(cur_test, cur_testcase);
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
/**
* Object could not be found. We stop here and report the error.
*/
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "TestCase does not exist."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(msg.getDescription());
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
TestCase tcData = (TestCase) resp.getItem();
/**
* Before updating, we check that the old entry can be modified.
* If old entry point to a build/revision that already been
* deployed, we cannot update it.
*/
if (!testCaseService.hasPermissionsUpdate(tcData, request)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Not enought privilege to update the testcase. You must belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(msg.getDescription());
} else // We test that at least a data to update has been defined.
if ((function != null) || (status != null) || (application != null)) {
tcData.setUsrModif(request.getRemoteUser());
tcData.setFunction(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(function, tcData.getFunction(), charset));
tcData.setStatus(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(status, tcData.getStatus(), charset));
tcData.setApplication(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(application, tcData.getApplication(), charset));
ans = testCaseService.update(tcData.getTest(), tcData.getTestCase(), tcData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
logEventService.createForPrivateCalls("/UpdateTestCaseMass", "UPDATE", "Updated TestCase : ['" + tcData.getTest() + "'|'" + tcData.getTestCase() + "']", request);
} else {
massErrorCounter++;
output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(ans.getResultMessage().getDescription());
}
}
}
tcCounter++;
}
if (myTest.length > 1) {
if (massErrorCounter == myTest.length) {
// All updates are in ERROR.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " objects(s) out of " + myTest.length + " failed to update due to an issue.<br>") + output_message.toString());
ans.setResultMessage(msg);
} else if (massErrorCounter > 0) {
// At least 1 update in error
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " objects(s) out of " + myTest.length + " failed to update due to an issue.<br>") + output_message.toString());
ans.setResultMessage(msg);
} else {
// No error detected.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update") + "\n\nAll " + myTest.length + " object(s) updated successfuly.");
ans.setResultMessage(msg);
}
logEventService.createForPrivateCalls("/UpdateTestCaseMass", "MASSUPDATE", msg.getDescription(), request);
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class UpdateProject 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
* @throws org.cerberus.exception.CerberusException
* @throws org.json.JSONException
*/
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(LINKS);
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
String idProject = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("idProject"), "");
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(idProject)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Project").replace("%OPERATION%", "Update").replace("%REASON%", "Project ID (id Project) is missing"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IProjectService projectService = appContext.getBean(IProjectService.class);
AnswerItem resp = projectService.readByKey(idProject);
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
/**
* Object could not be found. We stop here and report the error.
*/
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Project").replace("%OPERATION%", "Update").replace("%REASON%", "Project does not exist."));
ans.setResultMessage(msg);
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
Project projectData = (Project) resp.getItem();
projectData.setCode(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("VCCode"), projectData.getCode()));
projectData.setDescription(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Description"), projectData.getDescription()));
projectData.setActive(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Active"), projectData.getActive()));
ans = projectService.update(projectData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateProject", "UPDATE", "Updated Project : ['" + idProject + "']", request);
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class CreateLabel 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
* @throws org.cerberus.exception.CerberusException
* @throws org.json.JSONException
*/
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();
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
String id = policy.sanitize(request.getParameter("id"));
String system = policy.sanitize(request.getParameter("system"));
String type = policy.sanitize(request.getParameter("type"));
String longDesc = policy.sanitize(request.getParameter("longdesc"));
String reqtype = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqtype"), "", charset);
String reqstatus = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqstatus"), "", charset);
String reqcriticity = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqcriticity"), "", charset);
// Parameter that needs to be secured --> We SECURE+DECODE them
String label = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("label"), "", charset);
String color = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("color"), "", charset);
String parentLabel = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("parentLabel"), "", charset);
String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);
String usr = request.getUserPrincipal().getName();
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(label)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Label").replace("%OPERATION%", "Create").replace("%REASON%", "Label is missing!"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ILabelService labelService = appContext.getBean(ILabelService.class);
IFactoryLabel factoryLabel = appContext.getBean(IFactoryLabel.class);
Timestamp creationDate = new Timestamp(new Date().getTime());
Label labelData = factoryLabel.create(0, system, label, type, color, parentLabel, reqtype, reqstatus, reqcriticity, description, longDesc, usr, creationDate, usr, creationDate);
ans = labelService.create(labelData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Object created. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/CreateLabel", "CREATE", "Create Label : ['" + label + "'] for System : [" + system + "]", request);
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class AddToExecutionQueue method processRequest.
/**
* Process request for both GET and POST method.
*
* <p>
* Request processing is divided in two parts:
* <ol>
* <li>Getting all test cases which have been sent to this servlet;</li>
* <li>Try to insert all these test cases to the execution queue.</li>
* </ol>
* </p>
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
// Loading Services.
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPublicCalls("/AddToExecutionQueue", "CALL", "AddToExecutionQueue called : " + request.getRequestURL(), request);
// Parsing all parameters.
String tag = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_TAG), "");
// TO BE IMPLEMENTED...
// Defining help message.
String helpMessage = "\nThis servlet is used to add to Cerberus execution queue a list of execution specified by various parameters:\n" + "- " + PARAMETER_TAG + " [mandatory] : Tag that will be used for every execution triggered. [" + tag + "]\n";
// TO BE IMPLEMENTED...
// Checking the parameter validity.
boolean error = false;
if (tag == null || tag.isEmpty()) {
out.println("Error - Parameter " + PARAMETER_TAG + " is mandatory.");
error = true;
} else if (tag.length() > 255) {
out.println("Error - Parameter " + PARAMETER_TAG + " is too big. Maximum size is 255. Current size is : " + tag.length());
error = true;
}
// Starting the request only if previous parameters exist.
if (!error) {
// Create Tag when exist.
if (!StringUtil.isNullOrEmpty(tag)) {
// We create or update it.
ITagService tagService = appContext.getBean(ITagService.class);
tagService.createAuto(tag, "", "");
}
// Part 1: Getting all test cases which have been sent to this servlet.
List<TestCaseExecutionQueue> toInserts = null;
try {
toInserts = getTestCasesToInsert(request);
} catch (ParameterException pe) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, pe.getMessage());
return;
} catch (CerberusException ex) {
LOG.warn(ex);
}
// Part 2: Try to insert all these test cases to the execution queue.
List<String> errorMessages = new ArrayList<String>();
for (TestCaseExecutionQueue toInsert : toInserts) {
try {
inQueueService.convert(inQueueService.create(toInsert));
} catch (CerberusException e) {
String errorMessage = "Unable to insert " + toInsert.toString() + " due to " + e.getMessage();
LOG.warn(errorMessage);
errorMessages.add(errorMessage);
continue;
}
}
// Part 3 : Put these tests in the queue in memory
try {
executionThreadService.executeNextInQueueAsynchroneously(false);
} catch (CerberusException ex) {
String errorMessage = "Unable to feed the execution queue due to " + ex.getMessage();
LOG.warn(errorMessage);
errorMessages.add(errorMessage);
}
if (!errorMessages.isEmpty()) {
StringBuilder errorMessage = new StringBuilder();
for (String item : errorMessages) {
errorMessage.append(item);
errorMessage.append(LINE_SEPARATOR);
}
response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMessage.toString());
}
response.sendRedirect("ReportingExecutionByTag.jsp?enc=1&Tag=" + StringUtil.encodeAsJavaScriptURIComponent(request.getParameter(PARAMETER_TAG)));
} else {
// In case of errors, we displayu the help message.
out.println(helpMessage);
}
}
Aggregations