use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class ForgotPassword 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 {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IUserService userService = appContext.getBean(UserService.class);
IEmailService emailService = appContext.getBean(IEmailService.class);
IParameterService parameterService = appContext.getBean(ParameterService.class);
String system = "";
JSONObject jsonResponse = new JSONObject();
String login = ParameterParserUtil.parseStringParam(request.getParameter("login"), "");
/**
* Check if notification parameter is set to Y. If not, return an
* error
*/
String sendNotification = parameterService.findParameterByKey("cerberus_notification_accountcreation_activatenotification", system).getValue();
if (!sendNotification.equalsIgnoreCase("Y")) {
jsonResponse.put("messageType", "Error");
jsonResponse.put("message", "This functionality is not activated. Please contact your Cerberus Administrator.");
response.getWriter().print(jsonResponse);
response.getWriter().flush();
return;
}
/**
* If email not found in database, send error message
*/
AnswerItem ai = userService.readByKey(login);
User user = (User) ai.getItem();
if (user == null) {
jsonResponse.put("messageType", "Error");
jsonResponse.put("message", "Login submitted is unknown !");
response.getWriter().print(jsonResponse);
response.getWriter().flush();
return;
}
/**
* Update user setting a new value in requestresetpassword
*/
userService.requestResetPassword(user);
/**
* Send an email with the hash as a parameter
*/
Answer mailSent = new Answer(emailService.generateAndSendForgotPasswordEmail(user));
if (!mailSent.isCodeStringEquals("OK")) {
jsonResponse.put("messageType", "Error");
jsonResponse.put("message", "An error occured sending the notification. Detail : " + mailSent.getMessageDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
return;
}
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPrivateCalls("/ForgotPassword", "CREATE", "User : " + login + " asked for password recovery", request);
/**
* Build Response Message
*/
jsonResponse.put("messageType", "OK");
jsonResponse.put("message", "An e-mail has been sent to the mailbox " + user.getEmail() + ".");
response.getWriter().print(jsonResponse);
response.getWriter().flush();
} catch (CerberusException myexception) {
response.getWriter().print(myexception.getMessageError().getDescription());
} catch (JSONException ex) {
LOG.warn(ex);
response.setContentType("application/json");
response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
}
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class ReadLogEvent method findLogEventByID.
private AnswerItem findLogEventByID(ApplicationContext appContext, long id) throws JSONException, CerberusException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
ILogEventService libService = appContext.getBean(ILogEventService.class);
AnswerItem answer = libService.readByKey(id);
if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// if the service returns an OK message then we can get the item and convert it to JSONformat
LogEvent lib = (LogEvent) answer.getItem();
JSONObject response = convertLogEventToJSONObject(lib);
object.put("contentTable", response);
}
item.setItem(object);
item.setResultMessage(answer.getResultMessage());
return item;
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class UpdateMyUserReporting method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
String reporting = request.getUserPrincipal().getName();
String login = request.getUserPrincipal().getName();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IUserService userService = appContext.getBean(UserService.class);
try {
User user = userService.findUserByKey(login);
user.setReportingFavorite(reporting);
userService.updateUser(user);
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateMyUserReporting", "UPDATE", "Update user reporting preference for user: " + login, request);
} catch (CerberusException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class UpdateMyUserReporting1 method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
JSONObject jsonResponse = new JSONObject();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
String login = request.getUserPrincipal().getName();
String charset = request.getCharacterEncoding();
/**
* Parse parameters - list of values
*/
List<String> tcstatusList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcstatus"), null, charset);
List<String> groupList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("group"), null, charset);
List<String> tcactiveList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcactive"), null, charset);
List<String> priorityList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("priority"), null, charset);
List<String> countryList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("country"), null, charset);
List<String> browserList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("browser"), null, charset);
List<String> tcestatusList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcestatus"), null, charset);
// environment
List<String> environmentList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("environment"), null, charset);
List<String> projectList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("project"), null, charset);
/**
* Parse parameters - free text
*/
String ip = StringEscapeUtils.escapeHtml4(request.getParameter("ip"));
String port = StringEscapeUtils.escapeHtml4(request.getParameter("port"));
String tag = StringEscapeUtils.escapeHtml4(request.getParameter("tag"));
String browserversion = StringEscapeUtils.escapeHtml4(request.getParameter("browserversion"));
String comment = StringEscapeUtils.escapeHtml4(request.getParameter("comment"));
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IUserService userService = appContext.getBean(UserService.class);
try {
User user = userService.findUserByKey(login);
if (user != null) {
JSONObject preferences = new JSONObject();
if (tcstatusList != null) {
preferences.put("s", tcstatusList);
}
if (groupList != null) {
preferences.put("g", groupList);
}
if (tcactiveList != null) {
preferences.put("a", tcactiveList);
}
if (priorityList != null) {
preferences.put("pr", priorityList);
}
if (countryList != null) {
preferences.put("co", countryList);
}
if (browserList != null) {
preferences.put("b", browserList);
}
if (tcestatusList != null) {
preferences.put("es", tcestatusList);
}
if (environmentList != null) {
preferences.put("e", environmentList);
}
if (projectList != null) {
preferences.put("prj", projectList);
}
if (!StringUtil.isNullOrEmpty(ip)) {
preferences.put("ip", ip);
}
if (!StringUtil.isNullOrEmpty(port)) {
preferences.put("p", port);
}
if (!StringUtil.isNullOrEmpty(tag)) {
preferences.put("t", tag);
}
if (!StringUtil.isNullOrEmpty(browserversion)) {
preferences.put("br", browserversion);
}
if (!StringUtil.isNullOrEmpty(comment)) {
preferences.put("cm", comment);
}
user.setReportingFavorite(preferences.toString());
// TODO: when converting to the new standard this should return an answer
userService.updateUser(user);
// re-send the updated preferences
jsonResponse.put("preferences", preferences);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Execution reporting filters ").replace("%OPERATION%", "Update"));
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateMyUserReporting1", "UPDATE", "Update user reporting preference for user: " + login, request);
} else {
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to update User was not found!"));
}
jsonResponse.put("messageType", msg.getMessage().getCodeString());
jsonResponse.put("message", msg.getDescription());
} 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());
} catch (CerberusException 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());
}
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.service.ILogEventService in project cerberus-source by cerberustesting.
the class UpdateMyUserRobotPreference 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 {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IUserService userService = appContext.getBean(UserService.class);
try {
String ss_ip = ParameterParserUtil.parseStringParam(request.getParameter("ss_ip"), "");
String ss_p = ParameterParserUtil.parseStringParam(request.getParameter("ss_p"), "");
String platform = ParameterParserUtil.parseStringParam(request.getParameter("platform"), "");
String browser = ParameterParserUtil.parseStringParam(request.getParameter("browser"), "");
String version = ParameterParserUtil.parseStringParam(request.getParameter("version"), "");
User usr = userService.findUserByKey(request.getUserPrincipal().getName());
usr.setRobotHost(ss_ip);
usr.setRobotPort(ss_p);
usr.setRobotPlatform(platform);
usr.setRobotBrowser(browser);
usr.setRobotVersion(version);
userService.updateUser(usr);
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateMyUserRobotPreference", "UPDATE", "Update user robot preference for user: " + usr.getLogin(), request);
response.getWriter().print(usr.getLogin());
} catch (CerberusException myexception) {
response.getWriter().print(myexception.getMessageError().getDescription());
}
}
Aggregations