use of org.cerberus.util.answer.AnswerItem 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.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class ReadCerberusDetailInformation 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();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ExecutionUUID euuid = appContext.getBean(ExecutionUUID.class);
SessionCounter sc = appContext.getBean(SessionCounter.class);
Infos infos = new Infos();
try {
jsonResponse.put("simultaneous_execution", euuid.size());
JSONArray executionArray = new JSONArray();
for (Object ex : euuid.getExecutionUUIDList().values()) {
TestCaseExecution execution = (TestCaseExecution) ex;
JSONObject object = new JSONObject();
object.put("id", execution.getId());
object.put("test", execution.getTest());
object.put("testcase", execution.getTestCase());
object.put("system", execution.getApplicationObj().getSystem());
object.put("application", execution.getApplication());
object.put("environment", execution.getEnvironmentData());
object.put("country", execution.getCountry());
object.put("robotIP", execution.getSeleniumIP());
object.put("tag", execution.getTag());
object.put("start", new Timestamp(execution.getStart()));
executionArray.put(object);
}
jsonResponse.put("simultaneous_execution_list", executionArray);
jsonResponse.put("simultaneous_session", sc.getTotalActiveSession());
jsonResponse.put("active_users", sc.getActiveUsers());
cerberusDatabaseInformation = appContext.getBean(ICerberusInformationDAO.class);
AnswerItem ans = cerberusDatabaseInformation.getDatabaseInformation();
HashMap<String, String> cerberusInformation = (HashMap<String, String>) ans.getItem();
// Database Informations.
jsonResponse.put("DatabaseProductName", cerberusInformation.get("DatabaseProductName"));
jsonResponse.put("DatabaseProductVersion", cerberusInformation.get("DatabaseProductVersion"));
jsonResponse.put("DatabaseMajorVersion", cerberusInformation.get("DatabaseMajorVersion"));
jsonResponse.put("DatabaseMinorVersion", cerberusInformation.get("DatabaseMinorVersion"));
jsonResponse.put("DriverName", cerberusInformation.get("DriverName"));
jsonResponse.put("DriverVersion", cerberusInformation.get("DriverVersion"));
jsonResponse.put("DriverMajorVersion", cerberusInformation.get("DriverMajorVersion"));
jsonResponse.put("DriverMinorVersion", cerberusInformation.get("DriverMinorVersion"));
jsonResponse.put("JDBCMajorVersion", cerberusInformation.get("JDBCMajorVersion"));
jsonResponse.put("JDBCMinorVersion", cerberusInformation.get("JDBCMinorVersion"));
// Cerberus Informations.
jsonResponse.put("projectName", infos.getProjectName());
jsonResponse.put("projectVersion", infos.getProjectVersion());
jsonResponse.put("environment", System.getProperty("org.cerberus.environment"));
databaseVersionService = appContext.getBean(IDatabaseVersioningService.class);
jsonResponse.put("databaseCerberusTargetVersion", databaseVersionService.getSQLScript().size());
myVersionService = appContext.getBean(IMyVersionService.class);
if (myVersionService.findMyVersionByKey("database") != null) {
jsonResponse.put("databaseCerberusCurrentVersion", myVersionService.findMyVersionByKey("database").getValue());
} else {
jsonResponse.put("databaseCerberusCurrentVersion", "0");
}
// JAVA Informations.
jsonResponse.put("javaVersion", System.getProperty("java.version"));
Runtime instance = Runtime.getRuntime();
int mb = 1024 * 1024;
jsonResponse.put("javaFreeMemory", instance.freeMemory() / mb);
jsonResponse.put("javaTotalMemory", instance.totalMemory() / mb);
jsonResponse.put("javaUsedMemory", (instance.totalMemory() - instance.freeMemory()) / mb);
jsonResponse.put("javaMaxMemory", instance.maxMemory() / mb);
String str1 = getServletContext().getServerInfo();
jsonResponse.put("applicationServerInfo", str1);
} catch (JSONException ex) {
LOG.warn(ex);
}
response.setContentType("application/json");
response.getWriter().print(jsonResponse.toString());
}
use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class DisableEnvironment 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, JSONException {
JSONObject jsonResponse = new JSONObject();
AnswerItem answerItem = new AnswerItem();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
answerItem.setResultMessage(msg);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
response.setContentType("application/json");
/**
* Parsing and securing all required parameters.
*/
String system = policy.sanitize(request.getParameter("system"));
String country = policy.sanitize(request.getParameter("country"));
String env = policy.sanitize(request.getParameter("environment"));
// Init Answer with potencial error from Parsing parameter.
// AnswerItem answer = new AnswerItem(msg);
String eMailContent = "";
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IEmailService emailService = appContext.getBean(IEmailService.class);
ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);
ICountryEnvParam_logService countryEnvParam_logService = appContext.getBean(ICountryEnvParam_logService.class);
ILogEventService logEventService = appContext.getBean(LogEventService.class);
if (request.getParameter("system") == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM).replace("%OPERATION%", OPERATION).replace("%REASON%", "System name is missing!"));
answerItem.setResultMessage(msg);
} else if (request.getParameter("country") == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM).replace("%OPERATION%", OPERATION).replace("%REASON%", "Country is missing!"));
answerItem.setResultMessage(msg);
} else if (request.getParameter("environment") == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM).replace("%OPERATION%", OPERATION).replace("%REASON%", "Environment is missing!"));
answerItem.setResultMessage(msg);
} else {
// All parameters are OK we can start performing the operation.
// Getting the contryEnvParam based on the parameters.
answerItem = countryEnvParamService.readByKey(system, country, env);
if (!(answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerItem.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%", OPERATION).replace("%REASON%", OBJECT_NAME + " ['" + system + "','" + country + "','" + env + "'] does not exist. Cannot disable it!"));
answerItem.setResultMessage(msg);
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
CountryEnvParam cepData = (CountryEnvParam) answerItem.getItem();
cepData.setActive(false);
Answer answer = countryEnvParamService.update(cepData);
if (!(answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()))) {
/**
* Object could not be updated. We stop here and report the
* error.
*/
answerItem.setResultMessage(answer.getResultMessage());
} else {
/**
* Update was successful.
*/
// Adding Log entry.
logEventService.createForPrivateCalls("/DisableEnvironment", "UPDATE", "Updated CountryEnvParam : ['" + system + "','" + country + "','" + env + "']", request);
// Adding CountryEnvParam Log entry.
countryEnvParam_logService.createLogEntry(system, country, env, "", "", "Disabled.", request.getUserPrincipal().getName());
/**
* Email notification.
*/
String OutputMessage = "";
MessageEvent me = emailService.generateAndSendDisableEnvEmail(system, country, env);
if (!"OK".equals(me.getMessage().getCodeString())) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched." + me.getMessage().getDescription());
logEventService.createForPrivateCalls("/DisableEnvironment", "DISABLE", "Warning on Disable environment : ['" + system + "','" + country + "','" + env + "'] " + me.getMessage().getDescription(), request);
OutputMessage = me.getMessage().getDescription();
}
if (OutputMessage.equals("")) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Environment").replace("%OPERATION%", OPERATION));
answerItem.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Environment").replace("%OPERATION%", OPERATION).concat(" Just one warning : ").concat(OutputMessage));
answerItem.setResultMessage(msg);
}
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", answerItem.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", answerItem.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class NewBuildRev 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, JSONException {
JSONObject jsonResponse = new JSONObject();
AnswerItem answerItem = new AnswerItem();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
answerItem.setResultMessage(msg);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
response.setContentType("application/json");
/**
* Parsing and securing all required parameters.
*/
String system = policy.sanitize(request.getParameter("system"));
String country = policy.sanitize(request.getParameter("country"));
String env = policy.sanitize(request.getParameter("environment"));
String build = policy.sanitize(request.getParameter("build"));
String revision = policy.sanitize(request.getParameter("revision"));
// Init Answer with potencial error from Parsing parameter.
// AnswerItem answer = new AnswerItem(msg);
String eMailContent;
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IEmailService emailService = appContext.getBean(IEmailService.class);
IEmailGenerationService emailGenerationService = appContext.getBean(IEmailGenerationService.class);
IParameterService parameterService = appContext.getBean(IParameterService.class);
ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);
ICountryEnvParam_logService countryEnvParam_logService = appContext.getBean(ICountryEnvParam_logService.class);
ILogEventService logEventService = appContext.getBean(LogEventService.class);
if (request.getParameter("system") == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM).replace("%OPERATION%", OPERATION).replace("%REASON%", "System name is missing!"));
answerItem.setResultMessage(msg);
} else if (request.getParameter("country") == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM).replace("%OPERATION%", OPERATION).replace("%REASON%", "Country is missing!"));
answerItem.setResultMessage(msg);
} else if (request.getParameter("environment") == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM).replace("%OPERATION%", OPERATION).replace("%REASON%", "Environment is missing!"));
answerItem.setResultMessage(msg);
} else if (request.getParameter("build") == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM).replace("%OPERATION%", OPERATION).replace("%REASON%", "Build is missing!"));
answerItem.setResultMessage(msg);
} else if (request.getParameter("revision") == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM).replace("%OPERATION%", OPERATION).replace("%REASON%", "Revision is missing!"));
answerItem.setResultMessage(msg);
} else {
// All parameters are OK we can start performing the operation.
// Getting the contryEnvParam based on the parameters.
answerItem = countryEnvParamService.readByKey(system, country, env);
if (!(answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerItem.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%", OPERATION).replace("%REASON%", OBJECT_NAME + " ['" + system + "','" + country + "','" + env + "'] does not exist. Cannot activate it!"));
answerItem.setResultMessage(msg);
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
// 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(system, country, env, build, revision);
} catch (Exception ex) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", ex);
logEventService.createForPrivateCalls("/NewBuildRev", "NEWBUILDREV", "Warning on New Build/Revision environment : ['" + system + "','" + country + "','" + env + "'] " + ex.getMessage(), request);
OutputMessage = ex.getMessage();
}
// We update the object.
CountryEnvParam cepData = (CountryEnvParam) answerItem.getItem();
cepData.setBuild(build);
cepData.setRevision(revision);
cepData.setActive(true);
Answer answer = countryEnvParamService.update(cepData);
if (!(answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()))) {
/**
* Object could not be updated. We stop here and report the
* error.
*/
answerItem.setResultMessage(answer.getResultMessage());
} else {
/**
* Update was successful.
*/
// Adding Log entry.
logEventService.createForPrivateCalls("/NewBuildRev", "UPDATE", "Updated CountryEnvParam : ['" + system + "','" + country + "','" + env + "']", request);
// Adding CountryEnvParam Log entry.
countryEnvParam_logService.createLogEntry(system, country, env, build, revision, "New Build Revision.", request.getUserPrincipal().getName());
/**
* Email notification.
*/
try {
emailService.sendHtmlMail(email);
} catch (Exception e) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", e);
logEventService.createForPrivateCalls("/NewBuildRev", "NEWBUILDREV", "Warning on New Build/Revision environment : ['" + system + "','" + country + "','" + env + "'] " + e.getMessage(), request);
OutputMessage = e.getMessage();
}
if (OutputMessage.equals("")) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Environment").replace("%OPERATION%", OPERATION));
answerItem.setResultMessage(msg);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Environment").replace("%OPERATION%", OPERATION).concat(" Just one warning : ").concat(OutputMessage));
answerItem.setResultMessage(msg);
}
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", answerItem.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", answerItem.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class ReadLabel 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
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException {
String echo = request.getParameter("sEcho");
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);
// Default message to unexpected error.
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
/**
* Parsing and securing all required parameters.
*/
// Nothing to do here as no parameter to check.
//
// Global boolean on the servlet that define if the user has permition to edit and delete object.
boolean userHasPermissions = request.isUserInRole("Label");
// Get Parameters
String columnName = ParameterParserUtil.parseStringParam(request.getParameter("columnName"), "");
Boolean likeColumn = ParameterParserUtil.parseBooleanParam(request.getParameter("likeColumn"), false);
// Init Answer with potencial error from Parsing parameter.
AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
try {
JSONObject jsonResponse = new JSONObject();
if ((request.getParameter("id") == null) && (request.getParameter("system") == null) && Strings.isNullOrEmpty(columnName)) {
answer = findLabelList(null, appContext, userHasPermissions, request);
jsonResponse = (JSONObject) answer.getItem();
} else {
if (request.getParameter("id") != null) {
Integer id = Integer.valueOf(policy.sanitize(request.getParameter("id")));
answer = findLabelByKey(id, appContext, userHasPermissions);
jsonResponse = (JSONObject) answer.getItem();
} else if (request.getParameter("system") != null && !Strings.isNullOrEmpty(columnName)) {
answer = findDistinctValuesOfColumn(request.getParameter("system"), appContext, request, columnName);
jsonResponse = (JSONObject) answer.getItem();
} else if (request.getParameter("system") != null) {
String system = policy.sanitize(request.getParameter("system"));
answer = findLabelList(system, appContext, userHasPermissions, request);
jsonResponse = (JSONObject) answer.getItem();
}
}
jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", answer.getResultMessage().getDescription());
jsonResponse.put("sEcho", echo);
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());
}
}
Aggregations