use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class NewBuildRevisionV000 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();
String charset = request.getCharacterEncoding();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPublicCalls("/NewBuildRevisionV000", "CALL", "NewBuildRevisionV000 called : " + request.getRequestURL(), request);
ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);
IInvariantService invariantService = appContext.getBean(IInvariantService.class);
IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);
IEmailService emailService = appContext.getBean(IEmailService.class);
IEmailGenerationService emailGenerationService = appContext.getBean(IEmailGenerationService.class);
ICountryEnvParam_logService countryEnvParam_logService = appContext.getBean(ICountryEnvParam_logService.class);
IParameterService parameterService = appContext.getBean(IParameterService.class);
// Parsing all parameters.
String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);
String country = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("country"), "", charset);
String environment = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("environment"), "", charset);
String build = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("build"), "", charset);
String revision = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("revision"), "", charset);
String helpMessage = "\nThis servlet is used to inform Cerberus that a new Build and Revision has been deployed on a system.\n\nParameter list :\n" + "- system [mandatory] : the system where the Build Revision has been deployed. [" + system + "]\n" + "- country [mandatory] : the country where the Build Revision has been deployed. You can use ALL if you want to perform the action for all countries that exist for the given system and environement. [" + country + "]\n" + "- environment [mandatory] : the environment where the Build Revision has been deployed. [" + environment + "]\n" + "- build [mandatory] : the build that has been deployed. [" + build + "]\n" + "- revision [mandatory] : the revision that has been deployed. [" + revision + "]\n";
boolean error = false;
// Checking the parameter validity. If application has been entered, does it exist ?
if (system.equalsIgnoreCase("")) {
out.println("Error - Parameter system is mandatory.");
error = true;
}
if (!system.equalsIgnoreCase("") && !invariantService.isInvariantExist("SYSTEM", system)) {
out.println("Error - System does not exist : " + system);
error = true;
}
if (environment.equalsIgnoreCase("")) {
out.println("Error - Parameter environment is mandatory.");
error = true;
}
if (!environment.equalsIgnoreCase("") && !invariantService.isInvariantExist("ENVIRONMENT", environment)) {
out.println("Error - Environment does not exist : " + environment);
error = true;
}
if (country.equalsIgnoreCase("")) {
out.println("Error - Parameter country is mandatory.");
error = true;
} else if (!country.equalsIgnoreCase(PARAMETERALL)) {
if (!invariantService.isInvariantExist("COUNTRY", country)) {
out.println("Error - Country does not exist : " + country);
error = true;
}
if (!error) {
if (!countryEnvParamService.exist(system, country, environment)) {
out.println("Error - System/Country/Environment does not exist : " + system + "/" + country + "/" + environment);
error = true;
}
}
}
if (build.equalsIgnoreCase("")) {
out.println("Error - Parameter build is mandatory.");
error = true;
}
if (!build.equalsIgnoreCase("") && !buildRevisionInvariantService.exist(system, 1, build)) {
out.println("Error - Build does not exist : " + build);
error = true;
}
if (revision.equalsIgnoreCase("")) {
out.println("Error - Parameter revision is mandatory.");
error = true;
}
if (!revision.equalsIgnoreCase("") && !buildRevisionInvariantService.exist(system, 2, revision)) {
out.println("Error - Revision does not exist : " + revision);
error = true;
}
// Starting the database update only when no blocking error has been detected.
if (error == false) {
/**
* Getting the list of objects to treat.
*/
// We update the object.
MessageEvent msg = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg);
AnswerList answerList = new AnswerList();
if (country.equalsIgnoreCase(PARAMETERALL)) {
country = null;
}
answerList = countryEnvParamService.readByVarious(system, country, environment, null, null, null);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) answerList);
for (CountryEnvParam cepData : (List<CountryEnvParam>) answerList.getDataList()) {
// Email Calculation. Email must be calcuated before we update the Build and revision in order to have the old build revision still available in the mail.
String OutputMessage = "";
Email email = null;
try {
email = emailGenerationService.generateRevisionChangeEmail(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), build, revision);
} catch (Exception ex) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", ex);
logEventService.createForPrivateCalls("/NewBuildRevisionV000", "NEWBUILDREV", "Warning on New Build/Revision environment : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "'] " + ex.getMessage(), request);
OutputMessage = ex.getMessage();
}
/**
* For each object, we can update it.
*/
cepData.setBuild(build);
cepData.setRevision(revision);
cepData.setActive(true);
Answer answerUpdate = countryEnvParamService.update(cepData);
if (!(answerUpdate.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()))) {
/**
* Object could not be updated. We stop here and report the
* error.
*/
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerUpdate);
} else {
/**
* Update was successful.
*/
// Adding Log entry.
logEventService.createForPrivateCalls("/NewBuildRevisionV000", "UPDATE", "Updated CountryEnvParam : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "']", request);
// Adding CountryEnvParam Log entry.
countryEnvParam_logService.createLogEntry(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), build, revision, "New Build Revision.", "PublicCall");
/**
* Email notification.
*/
try {
// Sending the email
emailService.sendHtmlMail(email);
} catch (Exception e) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", e);
logEventService.createForPrivateCalls("/NewBuildRevisionV000", "NEWBUILDREV", "Warning on New Build/Revision environment : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "'] " + e.getMessage(), request);
OutputMessage = e.getMessage();
}
if (OutputMessage.equals("")) {
msg = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer answerSMTP = new AnswerList(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);
} else {
msg = new MessageEvent(MessageEventEnum.GENERIC_WARNING);
msg.setDescription(msg.getDescription().replace("%REASON%", OutputMessage + " when sending email for " + cepData.getSystem() + "/" + cepData.getCountry() + "/" + cepData.getEnvironment()));
Answer answerSMTP = new AnswerList(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);
}
}
}
/**
* Formating and returning the result.
*/
out.println(finalAnswer.getResultMessage().getMessage().getCodeString() + " - " + finalAnswer.getResultMessage().getDescription());
} else {
// In case of errors, we display the help message.
out.println(helpMessage);
}
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class NewEnvironmentEventV000 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();
String charset = request.getCharacterEncoding();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPublicCalls("/NewEnvironmentEventV000", "CALL", "NewEnvironmentEventV000 called : " + request.getRequestURL(), request);
ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);
IInvariantService invariantService = appContext.getBean(IInvariantService.class);
IBatchInvariantService batchInvariantService = appContext.getBean(IBatchInvariantService.class);
IBuildRevisionBatchService buildRevisionBatchService = appContext.getBean(IBuildRevisionBatchService.class);
IEmailService emailService = appContext.getBean(IEmailService.class);
// Parsing all parameters.
String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);
String country = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("country"), "", charset);
String environment = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("environment"), "", charset);
String event = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("event"), "", charset);
String helpMessage = "\nThis servlet is used to inform Cerberus about an event that occured on a given environment. For example when a treatment has been executed.\n\nParameter list :\n" + "- system [mandatory] : the system where the Build Revision has been deployed. [" + system + "]\n" + "- country [mandatory] : the country where the Build Revision has been deployed. You can use ALL if you want to perform the action for all countries that exist for the given system and environement. [" + country + "]\n" + "- environment [mandatory] : the environment where the Build Revision has been deployed. [" + environment + "]\n" + "- event [mandatory] : the event that should be recorded.. [" + event + "]\n";
boolean error = false;
// Checking the parameter validity. If application has been entered, does it exist ?
if (system.equalsIgnoreCase("")) {
out.println("Error - Parameter system is mandatory.");
error = true;
}
if (!system.equalsIgnoreCase("") && !invariantService.isInvariantExist("SYSTEM", system)) {
out.println("Error - System does not exist : " + system);
error = true;
}
if (environment.equalsIgnoreCase("")) {
out.println("Error - Parameter environment is mandatory.");
error = true;
}
if (!environment.equalsIgnoreCase("") && !invariantService.isInvariantExist("ENVIRONMENT", environment)) {
out.println("Error - Environment does not exist : " + environment);
error = true;
}
if (country.equalsIgnoreCase("")) {
out.println("Error - Parameter country is mandatory.");
error = true;
} else if (!country.equalsIgnoreCase(PARAMETERALL)) {
if (!invariantService.isInvariantExist("COUNTRY", country)) {
out.println("Error - Country does not exist : " + country);
error = true;
}
if (!error) {
if (!countryEnvParamService.exist(system, country, environment)) {
out.println("Error - System/Country/Environment does not exist : " + system + "/" + country + "/" + environment);
error = true;
}
}
}
if (event.equalsIgnoreCase("")) {
out.println("Error - Parameter event is mandatory.");
error = true;
}
if (!event.equalsIgnoreCase("") && !batchInvariantService.exist(event)) {
out.println("Error - Event does not exist : " + event);
error = true;
}
// Starting the database update only when no blocking error has been detected.
if (error == false) {
/**
* Getting the list of objects to treat.
*/
MessageEvent msg = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg);
AnswerList answerList = new AnswerList();
if (country.equalsIgnoreCase(PARAMETERALL)) {
country = null;
}
answerList = countryEnvParamService.readByVarious(system, country, environment, null, null, "Y");
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) answerList);
for (CountryEnvParam cepData : (List<CountryEnvParam>) answerList.getDataList()) {
/**
* For each object, we can update it.
*/
// Adding CountryEnvParam Log entry.
buildRevisionBatchService.create(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), cepData.getBuild(), cepData.getRevision(), event);
/**
* Email notification.
*/
String OutputMessage = "";
MessageEvent me = emailService.generateAndSendNewChainEmail(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), event);
if (!"OK".equals(me.getMessage().getCodeString())) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched." + me.getMessage().getDescription());
logEventService.createForPrivateCalls("/NewEnvironmentEventV000", "NEW", "Warning on New environment event : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "'] " + me.getMessage().getDescription(), request);
OutputMessage = me.getMessage().getDescription();
}
if (OutputMessage.equals("")) {
msg = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer answerSMTP = new AnswerList(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);
} else {
msg = new MessageEvent(MessageEventEnum.GENERIC_WARNING);
msg.setDescription(msg.getDescription().replace("%REASON%", OutputMessage + " when sending email for " + cepData.getSystem() + "/" + cepData.getCountry() + "/" + cepData.getEnvironment()));
Answer answerSMTP = new AnswerList(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);
}
}
/**
* Formating and returning the result.
*/
out.println(finalAnswer.getResultMessage().getMessage().getCodeString() + " - " + finalAnswer.getResultMessage().getDescription());
} else {
// In case of errors, we display the help message.
out.println(helpMessage);
}
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class ResultCIV001 method processRequest.
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
response.setContentType("application/json");
response.setCharacterEncoding("utf8");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPublicCalls("/ResultCIV001", "CALL", "ResultCIV001 called : " + request.getRequestURL(), request);
try {
JSONObject jsonResponse = new JSONObject();
String tag = policy.sanitize(request.getParameter("tag"));
String helpMessage = "This servlet is used to provide a json object with various execution counters as well as a global OK or KO status based on the number and status of the execution done on a specific tag. " + "The number of executions are ponderated by parameters by priority from cerberus_ci_okcoefprio1 to cerberus_ci_okcoefprio4. " + "Formula used is the following : " + "Nb Exe Prio 1 testcases * cerberus_ci_okcoefprio1 + Nb Exe Prio 2 testcases * cerberus_ci_okcoefprio2 + " + "Nb Exe Prio 3 testcases * cerberus_ci_okcoefprio3 + Nb Exe Prio 4 testcases * cerberus_ci_okcoefprio4." + "If no executions are found, the result is KO." + "With at least 1 execution, if result is < 1 then global servlet result is OK. If not, it is KO." + "All execution needs to have a status equal to KO, FA, NA or PE." + "Parameter list :" + "- tag [mandatory] : Execution Tag to filter the test cases execution. [" + tag + "]";
boolean error = false;
String error_message = "";
// Checking the parameter validity. Tag is a mandatory parameter
if (StringUtils.isBlank(tag)) {
error_message = "Error - Parameter tag is mandatory.";
error = true;
}
if (!error) {
ITestCaseExecutionService MyTestExecutionService = appContext.getBean(TestCaseExecutionService.class);
List<TestCaseExecution> myList;
int nbok = 0;
int nbko = 0;
int nbfa = 0;
int nbpe = 0;
int nbna = 0;
int nbca = 0;
int nbtotal = 0;
int nbkop1 = 0;
int nbkop2 = 0;
int nbkop3 = 0;
int nbkop4 = 0;
String exeStart = "";
long longStart = 0;
String exeEnd = "";
long longEnd = 0;
try {
myList = MyTestExecutionService.convert(MyTestExecutionService.readByTag(tag));
for (TestCaseExecution curExe : myList) {
if (longStart == 0) {
longStart = curExe.getStart();
}
if (curExe.getStart() < longStart) {
longStart = curExe.getStart();
}
if (longEnd == 0) {
longEnd = curExe.getEnd();
}
if (curExe.getEnd() > longEnd) {
longEnd = curExe.getEnd();
}
nbtotal++;
switch(curExe.getControlStatus()) {
case TestCaseExecution.CONTROLSTATUS_KO:
nbko++;
break;
case TestCaseExecution.CONTROLSTATUS_OK:
nbok++;
break;
case TestCaseExecution.CONTROLSTATUS_FA:
nbfa++;
break;
case TestCaseExecution.CONTROLSTATUS_NA:
nbna++;
break;
case TestCaseExecution.CONTROLSTATUS_CA:
nbca++;
break;
case TestCaseExecution.CONTROLSTATUS_PE:
nbpe++;
break;
}
if (!(curExe.getControlStatus().equals("OK"))) {
switch(curExe.getTestCaseObj().getPriority()) {
case 1:
nbkop1++;
break;
case 2:
nbkop2++;
break;
case 3:
nbkop3++;
break;
case 4:
nbkop4++;
break;
}
}
}
} catch (CerberusException ex) {
LOG.warn(ex);
}
IParameterService parameterService = appContext.getBean(IParameterService.class);
float pond1 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio1", "", 0);
float pond2 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio2", "", 0);
float pond3 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio3", "", 0);
float pond4 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio4", "", 0);
String result;
float resultCal = (nbkop1 * pond1) + (nbkop2 * pond2) + (nbkop3 * pond3) + (nbkop4 * pond4);
if ((resultCal < 1) && (nbtotal > 0)) {
result = "OK";
} else {
result = "KO";
}
jsonResponse.put("messageType", "OK");
jsonResponse.put("message", "CI result calculated with success.");
jsonResponse.put("CI_OK_prio1", pond1);
jsonResponse.put("CI_OK_prio2", pond2);
jsonResponse.put("CI_OK_prio3", pond3);
jsonResponse.put("CI_OK_prio4", pond4);
jsonResponse.put("CI_finalResult", resultCal);
jsonResponse.put("NonOK_prio1_nbOfExecution", nbkop1);
jsonResponse.put("NonOK_prio2_nbOfExecution", nbkop2);
jsonResponse.put("NonOK_prio3_nbOfExecution", nbkop3);
jsonResponse.put("NonOK_prio4_nbOfExecution", nbkop4);
jsonResponse.put("status_OK_nbOfExecution", nbok);
jsonResponse.put("status_KO_nbOfExecution", nbko);
jsonResponse.put("status_FA_nbOfExecution", nbfa);
jsonResponse.put("status_PE_nbOfExecution", nbpe);
jsonResponse.put("status_NA_nbOfExecution", nbna);
jsonResponse.put("status_CA_nbOfExecution", nbca);
jsonResponse.put("TOTAL_nbOfExecution", nbtotal);
jsonResponse.put("result", result);
jsonResponse.put("ExecutionStart", String.valueOf(new Timestamp(longStart)));
jsonResponse.put("ExecutionEnd", String.valueOf(new Timestamp(longEnd)));
response.getWriter().print(jsonResponse.toString());
// Log the result with calculation detail.
logEventService.createForPublicCalls("/ResultCIV001", "CALLRESULT", "ResultCIV001 calculated with result [" + result + "] : " + nbkop1 + "*" + pond1 + " + " + nbkop2 + "*" + pond2 + " + " + nbkop3 + "*" + pond3 + " + " + nbkop4 + "*" + pond4 + " = " + resultCal, request);
} else {
jsonResponse.put("messageType", "KO");
jsonResponse.put("message", error_message);
jsonResponse.put("helpMessage", helpMessage);
response.getWriter().print(jsonResponse.toString());
}
} catch (JSONException e) {
LOG.warn(e);
// returns a default error message with the json format that is able to be parsed by the client-side
response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
}
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class ResultCIV002 method processRequest.
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPublicCalls("/ResultCIV002", "CALL", "ResultCIV002 called : " + request.getRequestURL(), request);
try {
JSONObject jsonResponse = new JSONObject();
String tag = policy.sanitize(request.getParameter("tag"));
String outputFormat = policy.sanitize(request.getParameter("outputFormat"));
String helpMessage = "This servlet is used to provide various execution counters as well as a global OK or KO status based on the number and status of the execution done on a specific tag. " + "The number of executions are ponderated by parameters by priority from cerberus_ci_okcoefprio1 to cerberus_ci_okcoefprio4. " + "Formula used is the following : " + "Nb Exe Prio 1 testcases * cerberus_ci_okcoefprio1 + Nb Exe Prio 2 testcases * cerberus_ci_okcoefprio2 + " + "Nb Exe Prio 3 testcases * cerberus_ci_okcoefprio3 + Nb Exe Prio 4 testcases * cerberus_ci_okcoefprio4." + "If no executions are found, the result is KO." + "With at least 1 execution, if result is < 1 then global servlet result is OK. If not, it is KO." + "All execution needs to have a status equal to KO, FA, NA, PE or NE." + "If at least 1 PE or 1 NE if found, global status will be PE" + "Output format is json by default, or SVG if outputFormat=svg is defined" + "Parameter list :" + "- tag [mandatory] : Execution Tag to filter the test cases execution. [" + tag + "]" + "- outputFormat : ['json', 'svg']. Output format of the result. [" + outputFormat + "]";
boolean error = false;
String error_message = "";
// Checking the parameter validity. Tag is a mandatory parameter
if (StringUtils.isBlank(tag)) {
error_message = "Error - Parameter tag is mandatory.";
error = true;
}
// Checking the parameter validity. outputFormat can be empty, or equals to json or svg
if (!StringUtils.isBlank(outputFormat) && !outputFormat.equals("json") && !outputFormat.equals("svg")) {
error_message = "Error - Value of parameter outputFormat is not recognized.";
error = true;
}
if (!error) {
ITestCaseExecutionService testExecutionService = appContext.getBean(TestCaseExecutionService.class);
List<TestCaseExecution> myList;
int nbok = 0;
int nbko = 0;
int nbfa = 0;
int nbpe = 0;
int nbne = 0;
int nbna = 0;
int nbca = 0;
int nbqu = 0;
int nbtotal = 0;
int nbkop1 = 0;
int nbkop2 = 0;
int nbkop3 = 0;
int nbkop4 = 0;
long longStart = 0;
long longEnd = 0;
try {
myList = testExecutionService.readLastExecutionAndExecutionInQueueByTag(tag);
for (TestCaseExecution curExe : myList) {
if (longStart == 0) {
longStart = curExe.getStart();
}
if (curExe.getStart() < longStart) {
longStart = curExe.getStart();
}
if (longEnd == 0) {
longEnd = curExe.getEnd();
}
if (curExe.getEnd() > longEnd) {
longEnd = curExe.getEnd();
}
nbtotal++;
switch(curExe.getControlStatus()) {
case TestCaseExecution.CONTROLSTATUS_KO:
nbko++;
break;
case TestCaseExecution.CONTROLSTATUS_OK:
nbok++;
break;
case TestCaseExecution.CONTROLSTATUS_FA:
nbfa++;
break;
case TestCaseExecution.CONTROLSTATUS_NA:
nbna++;
break;
case TestCaseExecution.CONTROLSTATUS_CA:
nbca++;
break;
case TestCaseExecution.CONTROLSTATUS_PE:
nbpe++;
break;
case TestCaseExecution.CONTROLSTATUS_NE:
nbne++;
break;
case TestCaseExecution.CONTROLSTATUS_QU:
nbqu++;
break;
}
if (!curExe.getControlStatus().equals("OK") && !curExe.getControlStatus().equals("NE") && !curExe.getControlStatus().equals("PE") && !curExe.getControlStatus().equals("QU")) {
switch(curExe.getTestCaseObj().getPriority()) {
case 1:
nbkop1++;
break;
case 2:
nbkop2++;
break;
case 3:
nbkop3++;
break;
case 4:
nbkop4++;
break;
}
}
}
} catch (CerberusException ex) {
LOG.warn(ex);
} catch (ParseException ex) {
LOG.warn(ex);
}
IParameterService parameterService = appContext.getBean(IParameterService.class);
float pond1 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio1", "", 0);
float pond2 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio2", "", 0);
float pond3 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio3", "", 0);
float pond4 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio4", "", 0);
String result;
float resultCal = (nbkop1 * pond1) + (nbkop2 * pond2) + (nbkop3 * pond3) + (nbkop4 * pond4);
if ((nbtotal > 0) && nbqu + nbne + nbpe > 0) {
result = "PE";
} else if ((resultCal < 1) && (nbtotal > 0)) {
result = "OK";
} else {
result = "KO";
}
jsonResponse.put("messageType", "OK");
jsonResponse.put("message", "CI result calculated with success.");
jsonResponse.put("tag", tag);
jsonResponse.put("CI_OK_prio1", pond1);
jsonResponse.put("CI_OK_prio2", pond2);
jsonResponse.put("CI_OK_prio3", pond3);
jsonResponse.put("CI_OK_prio4", pond4);
jsonResponse.put("CI_finalResult", resultCal);
jsonResponse.put("NonOK_prio1_nbOfExecution", nbkop1);
jsonResponse.put("NonOK_prio2_nbOfExecution", nbkop2);
jsonResponse.put("NonOK_prio3_nbOfExecution", nbkop3);
jsonResponse.put("NonOK_prio4_nbOfExecution", nbkop4);
jsonResponse.put("status_OK_nbOfExecution", nbok);
jsonResponse.put("status_KO_nbOfExecution", nbko);
jsonResponse.put("status_FA_nbOfExecution", nbfa);
jsonResponse.put("status_PE_nbOfExecution", nbpe);
jsonResponse.put("status_NA_nbOfExecution", nbna);
jsonResponse.put("status_CA_nbOfExecution", nbca);
jsonResponse.put("status_NE_nbOfExecution", nbne);
jsonResponse.put("status_QU_nbOfExecution", nbqu);
jsonResponse.put("TOTAL_nbOfExecution", nbtotal);
jsonResponse.put("result", result);
jsonResponse.put("ExecutionStart", String.valueOf(new Timestamp(longStart)));
jsonResponse.put("ExecutionEnd", String.valueOf(new Timestamp(longEnd)));
generateResponse(response, outputFormat, jsonResponse, false);
// Log the result with calculation detail.
logEventService.createForPublicCalls("/ResultCIV002", "CALLRESULT", "ResultCIV002 calculated with result [" + result + "] : " + nbkop1 + "*" + pond1 + " + " + nbkop2 + "*" + pond2 + " + " + nbkop3 + "*" + pond3 + " + " + nbkop4 + "*" + pond4 + " = " + resultCal, request);
} else {
jsonResponse.put("messageType", "KO");
jsonResponse.put("message", error_message);
jsonResponse.put("helpMessage", helpMessage);
generateResponse(response, outputFormat, jsonResponse, true);
}
} catch (JSONException e) {
LOG.warn(e);
// returns a default error message with the json format that is able to be parsed by the client-side
response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
}
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class ResultCIV003 method processRequest.
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPublicCalls("/ResultCIV003", "CALL", "ResultCIV003 called : " + request.getRequestURL(), request);
try {
JSONObject jsonResponse = new JSONObject();
String tag = policy.sanitize(request.getParameter("tag"));
String campaign = policy.sanitize(request.getParameter("campaign"));
String outputFormat = policy.sanitize(request.getParameter("outputformat"));
String helpMessage = "This servlet is used to provide various execution counters as well as a global OK or KO status based on the number and status of the execution done on a specific tag. \n" + "The number of executions are ponderated by parameters by priority from cerberus_ci_okcoefprio1 to cerberus_ci_okcoefprio4. \n" + "Formula used is the following : \n" + "Nb Exe Prio 1 testcases * cerberus_ci_okcoefprio1 + Nb Exe Prio 2 testcases * cerberus_ci_okcoefprio2 + " + "Nb Exe Prio 3 testcases * cerberus_ci_okcoefprio3 + Nb Exe Prio 4 testcases * cerberus_ci_okcoefprio4.\n" + "If no executions are found, the result is KO.\n" + "With at least 1 execution, if result is < 1 then global servlet result is OK. If not, it is KO.\n" + "All execution needs to have a status equal to KO, FA, NA, PE or NE.\n" + "If at least 1 PE or 1 NE if found, global status will be PE\n" + "Output format is json by default, or SVG if outputFormat=svg is defined\n" + "Parameter list :\n" + "- tag : Execution Tag to filter the test cases execution. [" + tag + "]\n" + "- campaign : If you feed the campaign, the lastest Tag from that campaign will be selected. [" + campaign + "]\n" + "- outputformat : ['text','json', 'svg']. Output format of the result. [" + outputFormat + "]\n";
jsonResponse.put("helpMessage", helpMessage);
boolean error = false;
String error_message = "";
// Checking the parameter validity. Tag is a mandatory parameter
if (StringUtil.isNullOrEmpty(tag)) {
if (!StringUtil.isNullOrEmpty(campaign)) {
ITagService tagService = appContext.getBean(ITagService.class);
List<Tag> myList;
AnswerList myAnswerList = tagService.readByVariousByCriteria(campaign, 0, 1, "id", "desc", null, null);
if (myAnswerList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (Tag tagCur : (List<Tag>) myAnswerList.getDataList()) {
tag = tagCur.getTag();
}
}
}
}
if (StringUtil.isNullOrEmpty(tag)) {
error_message += "Error - Either specify a tag or specify a campaign to get the latest tag from that campaign.";
error = true;
}
if (!error) {
ICIService ciService = appContext.getBean(ICIService.class);
jsonResponse = ciService.getCIResult(tag);
// Log the result with calculation detail.
logEventService.createForPublicCalls("/ResultCIV003", "CALLRESULT", "ResultCIV003 calculated for tag " + tag + " result [" + jsonResponse.getString("result") + "]", request);
} else {
jsonResponse.put("messageType", "KO");
jsonResponse.put("message", error_message);
}
generateResponse(response, outputFormat, jsonResponse, error);
} catch (JSONException e) {
LOG.warn(e);
// returns a default error message with the json format that is able to be parsed by the client-side
response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
}
}
Aggregations