use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class UpdateCountryEnvParam 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());
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();
ICountryEnvironmentDatabaseService cebService = appContext.getBean(ICountryEnvironmentDatabaseService.class);
ICountryEnvironmentParametersService ceaService = appContext.getBean(ICountryEnvironmentParametersService.class);
ICountryEnvDeployTypeService cedService = appContext.getBean(ICountryEnvDeployTypeService.class);
ICountryEnvLinkService celService = appContext.getBean(ICountryEnvLinkService.class);
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 system = policy.sanitize(request.getParameter("system"));
String country = policy.sanitize(request.getParameter("country"));
String environment = policy.sanitize(request.getParameter("environment"));
String type = policy.sanitize(request.getParameter("type"));
String chain = policy.sanitize(request.getParameter("chain"));
boolean maintenanceAct = ParameterParserUtil.parseBooleanParam(request.getParameter("maintenanceAct"), true);
// Parameter that needs to be secured --> We SECURE+DECODE them
String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);
String maintenanceStr = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("maintenanceStr"), "01:00:00", charset);
String maintenanceEnd = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("maintenanceEnd"), "01:00:00", charset);
// Parameter that we cannot secure as we need the html --> We DECODE them
String distribList = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("distribList"), "", charset);
String eMailBodyRevision = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("eMailBodyRevision"), "", charset);
String eMailBodyChain = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("eMailBodyChain"), "", charset);
String eMailBodyDisableEnvironment = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("eMailBodyDisableEnvironment"), "", charset);
// Getting list of database from JSON Call
JSONArray objDatabaseArray = new JSONArray(request.getParameter("database"));
List<CountryEnvironmentDatabase> cebList;
cebList = getCountryEnvironmentDatabaseFromParameter(request, appContext, system, country, environment, objDatabaseArray);
// Getting list of application from JSON Call
JSONArray objApplicationArray = new JSONArray(request.getParameter("application"));
List<CountryEnvironmentParameters> ceaList;
ceaList = getCountryEnvironmentApplicationFromParameter(request, appContext, system, country, environment, objApplicationArray);
// Getting list of database from JSON Call
JSONArray objDeployTypeArray = new JSONArray(request.getParameter("deployType"));
List<CountryEnvDeployType> cedList;
cedList = getCountryEnvironmentDeployTypeFromParameter(request, appContext, system, country, environment, objDeployTypeArray);
// Getting list of database from JSON Call
JSONArray objDepArray = new JSONArray(request.getParameter("dependencies"));
List<CountryEnvLink> celList;
celList = getCountryEnvironmentLinkFromParameter(request, appContext, system, country, environment, objDepArray);
// 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(system)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "System is missing"));
ans.setResultMessage(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
} else if (StringUtil.isNullOrEmpty(country)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Country is missing"));
ans.setResultMessage(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
} else if (StringUtil.isNullOrEmpty(environment)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Environment is missing"));
ans.setResultMessage(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
} else {
/**
* All data seems cleans so we can call the services.
*/
ICountryEnvParamService cepService = appContext.getBean(ICountryEnvParamService.class);
AnswerItem resp = cepService.readByKey(system, country, environment);
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 {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
CountryEnvParam cepData = (CountryEnvParam) resp.getItem();
cepData.setDescription(description);
cepData.setDistribList(distribList);
cepData.seteMailBodyRevision(eMailBodyRevision);
cepData.setType(type);
cepData.seteMailBodyChain(eMailBodyChain);
cepData.seteMailBodyDisableEnvironment(eMailBodyDisableEnvironment);
if (request.getParameter("maintenanceAct") != null) {
cepData.setMaintenanceAct(maintenanceAct);
}
cepData.setMaintenanceStr(maintenanceStr);
cepData.setMaintenanceEnd(maintenanceEnd);
cepData.setChain(chain);
ans = cepService.update(cepData);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateCountryEnvParam", "UPDATE", "Updated CountryEnvParam : ['" + system + "','" + country + "','" + environment + "']", request);
}
// Update the Database with the new list.
ans = cebService.compareListAndUpdateInsertDeleteElements(system, country, environment, cebList);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
// Update the Database with the new list.
ans = ceaService.compareListAndUpdateInsertDeleteElements(system, country, environment, ceaList);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
// Update the Database with the new list.
ans = cedService.compareListAndUpdateInsertDeleteElements(system, country, environment, cedList);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
// Update the Database with the new list.
ans = celService.compareListAndUpdateInsertDeleteElements(system, country, environment, celList);
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();
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class UpdateSqlLibrary 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());
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String charset = request.getCharacterEncoding();
// 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 name = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("name"), null, charset);
String type = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("type"), null, charset);
String database = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("database"), null, charset);
String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), null, charset);
// Parameter that we cannot secure as we need the html --> We DECODE them
String script = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("script"), null, charset);
// 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(name)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "SqlLibrary").replace("%OPERATION%", "Update").replace("%REASON%", "SqlLibrary ID (name) is missing."));
finalAnswer.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ISqlLibraryService sqlLibraryService = appContext.getBean(ISqlLibraryService.class);
AnswerItem resp = sqlLibraryService.readByKey(name);
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 {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
SqlLibrary sqlLib = (SqlLibrary) resp.getItem();
sqlLib.setType(type);
sqlLib.setDescription(description);
sqlLib.setDatabase(database);
sqlLib.setScript(script);
ans = sqlLibraryService.update(sqlLib);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateSqlLibrary", "UPDATE", "Updated SqlLibrary : ['" + name + "']", request);
}
}
}
/**
* 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();
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class ImportPropertyOfATestCaseToAnOtherTestCase 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 {
JSONObject jsonResponse = new JSONObject();
MessageEvent rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(TestCaseCountryPropertiesService.class);
ITestCaseCountryService testCaseCountryService = appContext.getBean(TestCaseCountryService.class);
try {
String fromTest = request.getParameter("fromtest");
String fromTestCase = request.getParameter("fromtestcase");
String propertyName = request.getParameter("property");
String toTest = request.getParameter("totest");
String toTestCase = request.getParameter("totestcase");
// We retrieve all country of the destination TestCase
List<String> toCountriesAll = testCaseCountryService.findListOfCountryByTestTestCase(toTest, toTestCase);
if (toCountriesAll != null && toCountriesAll.size() > 0) {
// Variable for the countries of a property of the source TestCase
List<String> fromCountriesProp;
// Variable for the countries of a property of the destination TestCase
List<String> toCountriesProp;
// Variable for the countryProperty will be retrieve
TestCaseCountryProperties countryProperties;
// List of all country of the destination test for the current property
List<String> toCountries = new ArrayList<String>();
toCountries.addAll(toCountriesAll);
// Retrieve the country of the destination TestCase for the property,
// if not empty remove it (property aleady exists for these countries)
toCountriesProp = testCaseCountryPropertiesService.findCountryByPropertyNameAndTestCase(toTest, toTestCase, propertyName);
if (toCountriesProp != null && toCountriesProp.size() > 0) {
toCountries.removeAll(toCountriesProp);
}
// Retrieve the country of the source TestCase for the property, if empty do nothing
fromCountriesProp = testCaseCountryPropertiesService.findCountryByPropertyNameAndTestCase(fromTest, fromTestCase, propertyName);
if (fromCountriesProp != null && fromCountriesProp.size() > 0) {
// Only retain country in the two TestCase for the property
toCountries.retainAll(fromCountriesProp);
// If countries list is empty do nothing
if (toCountries.size() > 0) {
List<TestCaseCountryProperties> listOfPropertiesToInsert = new ArrayList<TestCaseCountryProperties>();
for (String country : toCountries) {
try {
// retrieve the source property for the current country
countryProperties = testCaseCountryPropertiesService.findTestCaseCountryPropertiesByKey(fromTest, fromTestCase, country, propertyName);
if (countryProperties != null) {
// change the TestCase information to the destination TestCase
countryProperties.setTest(toTest);
countryProperties.setTestCase(toTestCase);
listOfPropertiesToInsert.add(countryProperties);
// Insert the new property
// testCaseCountryPropertiesService.insertTestCaseCountryProperties(countryProperties);
}
} catch (CerberusException ex) {
LOG.debug(ex.toString());
}
}
// insert the new property for all countries specified
Answer answer = testCaseCountryPropertiesService.createListTestCaseCountryPropertiesBatch(listOfPropertiesToInsert);
rs = answer.getResultMessage();
// then a new entry should be added by the log service
if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// Adding Log entry.
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/ImportPropertyOfATestCaseToAnOtherTestCase", "CREATE", "Override from imported test step: " + propertyName, request);
}
}
} else {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
rs.setDescription(rs.getDescription().replace("%ITEM%", "Property ").replace("%OPERATION%", "CREATE").replace("%REASON%", "Property was not imported. Please check if is" + " correctly defined on the imported step."));
}
} else {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
rs.setDescription(rs.getDescription().replace("%ITEM%", "Property ").replace("%OPERATION%", "CREATE").replace("%REASON%", "No countries were defined for the test case."));
}
// sets the message returned by the operations
jsonResponse.put("messageType", rs.getMessage().getCodeString());
jsonResponse.put("message", rs.getDescription());
response.setContentType("application/json");
response.getWriter().print(jsonResponse);
response.getWriter().flush();
} catch (JSONException ex) {
LOG.warn(ex);
// 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 DeleteTestCaseLabel 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_OK);
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
// Parameter that needs to be secured --> We SECURE+DECODE them
// Parameter that we cannot secure as we need the html --> We DECODE them
Integer myIdInt = 0;
String[] myLabelIdList = request.getParameterValues("labelid");
String[] myTestList = request.getParameterValues("test");
String[] myTestCaseList = request.getParameterValues("testcase");
if ((myTestList.length == 0) || (myTestCaseList.length == 0) || (myLabelIdList.length == 0)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Create").replace("%REASON%", "Missing Parameter (either test, testcase or labelid)."));
ans.setResultMessage(msg);
} else if (myTestList.length != myTestCaseList.length) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Create").replace("%REASON%", "Number of Test does not match number of testcase."));
ans.setResultMessage(msg);
}
StringBuilder output_message = new StringBuilder();
int massErrorCounter = 0;
for (int i = 0; i < myLabelIdList.length; i++) {
String myLabelId = myLabelIdList[i];
myIdInt = 0;
boolean label_error = true;
try {
if (myLabelId != null && !myLabelId.equals("")) {
myIdInt = Integer.valueOf(policy.sanitize(myLabelId));
label_error = false;
}
} catch (Exception ex) {
label_error = true;
}
/**
* Checking all constrains before calling the services.
*/
if (label_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Could not manage to convert labelid to an integer value or labelid is missing."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(myLabelId).append(" - ").append(msg.getDescription());
} else {
/**
* All data seems cleans so we can call the services.
*/
ILabelService labelService = appContext.getBean(ILabelService.class);
IFactoryTestCaseLabel factoryTestCaseLabel = appContext.getBean(IFactoryTestCaseLabel.class);
ITestCaseLabelService testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
AnswerItem resp = labelService.readByKey(myIdInt);
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%", "Delete").replace("%REASON%", "Label does not exist."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>labelid : ").append(myLabelId).append(" - ").append(msg.getDescription());
} else {
for (int j = 0; j < myTestList.length; j++) {
/**
* The service was able to perform the query and confirm
* the object exist, then we can create it.
*/
resp = testCaseLabelService.readByKey(myTestList[j], myTestCaseList[j], myIdInt);
if ((resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
TestCaseLabel tcLabel = (TestCaseLabel) resp.getItem();
ans = testCaseLabelService.delete(tcLabel);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
logEventService.createForPrivateCalls("/DeleteTestCaseLabel", "DELETE", "Deleted TestCaseLabel : ['" + myIdInt + "'|'" + myTestList[j] + "'|'" + myTestCaseList[j] + "']", request);
} else {
massErrorCounter++;
output_message.append("<br>Label : ").append(myLabelId).append(" Test : '").append(myTestList[j]).append("' TestCase : '").append(myTestCaseList[j]).append("' - ").append(ans.getResultMessage().getDescription());
}
}
}
}
}
}
if (myTestList.length > 1) {
if (massErrorCounter == myTestList.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 + " label links(s) out of " + (myTestList.length * myLabelIdList.length) + " failed to be deleted 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 + " label links(s) out of " + (myTestList.length * myLabelIdList.length) + " failed to be deleted 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 " + (myTestList.length * myLabelIdList.length) + " label links(s) deleted successfuly.");
ans.setResultMessage(msg);
}
logEventService.createForPrivateCalls("/DeleteTestCaseLabel", "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 DuplicateTestCase method processRequest.
// </editor-fold>
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException, CerberusException {
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);
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");
String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), "");
String originalTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");
String originalTestCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTestCase"), null);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(test) || StringUtil.isNullOrEmpty(testCase) || StringUtil.isNullOrEmpty(originalTest) || originalTestCase != null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case").replace("%OPERATION%", "Duplicate").replace("%REASON%", "mandatory fields are missing."));
ans.setResultMessage(msg);
} else {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
ITestCaseCountryService testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);
ITestCaseStepActionService testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
ITestCaseStepActionControlService testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);
ITestCaseLabelService testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
AnswerItem originalTestAI = testCaseService.readByKey(originalTest, originalTestCase);
AnswerItem targetTestAI = testCaseService.readByKey(test, testCase);
TestCase originalTC = (TestCase) originalTestAI.getItem();
TestCase targetTC = (TestCase) targetTestAI.getItem();
if (!(originalTestAI.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && originalTestAI.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%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "TestCase 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.
*/
if (!request.isUserInRole("Test")) {
// We cannot update the testcase if the user is not at least in Test role.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "Not enought privilege to duplicate the testcase. You must belong to Test Privilege."));
ans.setResultMessage(msg);
} else if (targetTC != null) {
// If target Test Case already exists.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "The test case you try to create already exists. Please define a test/testcase that is not already existing."));
ans.setResultMessage(msg);
} else {
getInfo(request, originalTC);
// Update object with new testcase id and insert it in db
originalTC.setTest(test);
originalTC.setTestCase(testCase);
ans = testCaseService.create(originalTC);
List<TestCaseCountry> countryList = new ArrayList();
countryList = testCaseCountryService.findTestCaseCountryByTestTestCase(originalTest, originalTestCase);
boolean success = true;
if (!countryList.isEmpty()) {
ans = testCaseCountryService.duplicateList(countryList, test, testCase);
}
// List<TestCaseCountry> countryList = getCountryList(test, testCase, request);
// boolean success = false;
// if (countryList.isEmpty()) {
// success = true;
// } else {
// success = testCaseCountryService.insertListTestCaseCountry(countryList);
// }
List<TestCaseCountryProperties> tccpList = new ArrayList();
if (!countryList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tccpList = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCase(originalTest, originalTestCase);
if (!tccpList.isEmpty()) {
ans = testCaseCountryPropertiesService.duplicateList(tccpList, test, testCase);
}
}
List<TestCaseStep> tcsList = new ArrayList();
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tcsList = testCaseStepService.getListOfSteps(originalTest, originalTestCase);
if (!tcsList.isEmpty()) {
ans = testCaseStepService.duplicateList(tcsList, test, testCase);
}
}
List<TestCaseStepAction> tcsaList = new ArrayList();
if (!tcsList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tcsaList = testCaseStepActionService.findTestCaseStepActionbyTestTestCase(originalTest, originalTestCase);
if (!tcsaList.isEmpty()) {
ans = testCaseStepActionService.duplicateList(tcsaList, test, testCase);
}
}
if (!tcsList.isEmpty() && !tcsaList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
List<TestCaseStepActionControl> tcsacList = testCaseStepActionControlService.findControlByTestTestCase(originalTest, originalTestCase);
if (!tcsacList.isEmpty()) {
ans = testCaseStepActionControlService.duplicateList(tcsacList, test, testCase);
}
}
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
List<TestCaseLabel> tclList = testCaseLabelService.readByTestTestCase(originalTest, originalTestCase).getDataList();
if (!tclList.isEmpty()) {
ans = testCaseLabelService.duplicateList(tclList, test, testCase);
}
}
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate"));
ans.setResultMessage(msg);
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/DuplicateTestCase", "CREATE", "Create testcase : ['" + test + "'|'" + testCase + "']", 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();
}
Aggregations