use of org.cerberus.crud.entity.User 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.entity.User 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.entity.User 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());
}
}
use of org.cerberus.crud.entity.User in project cerberus-source by cerberustesting.
the class UserDAO method readByCriteria.
@Override
public AnswerList readByCriteria(int start, int amount, String column, String dir, String searchTerm, String individualSearch) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<User> applicationList = new ArrayList<User>();
StringBuilder searchSQL = new StringBuilder();
StringBuilder query = new StringBuilder();
// SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
// were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS * FROM user usr ");
searchSQL.append(" where 1=1 ");
if (!StringUtil.isNullOrEmpty(searchTerm)) {
searchSQL.append(" and (usr.`login` like ?");
searchSQL.append(" or usr.`name` like ?");
searchSQL.append(" or usr.`team` like ?");
searchSQL.append(" or usr.`language` like ?");
searchSQL.append(" or usr.`ReportingFavorite` like ?");
searchSQL.append(" or usr.`robotHost` like ?");
searchSQL.append(" or usr.`robotPort` like ?");
searchSQL.append(" or usr.`robotPlatform` like ?");
searchSQL.append(" or usr.`robotBrowser` like ?");
searchSQL.append(" or usr.`robotVersion` like ?");
searchSQL.append(" or usr.`robot` like ?");
searchSQL.append(" or usr.`DefaultSystem` like ?");
searchSQL.append(" or usr.`Email` like ?)");
}
if (!StringUtil.isNullOrEmpty(individualSearch)) {
searchSQL.append(" and (`").append(individualSearch).append("`)");
}
query.append(searchSQL);
if (!StringUtil.isNullOrEmpty(column)) {
query.append(" order by `").append(column).append("` ").append(dir);
}
if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
} else {
query.append(" limit ").append(start).append(" , ").append(amount);
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
int i = 1;
if (!StringUtil.isNullOrEmpty(searchTerm)) {
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
}
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
while (resultSet.next()) {
applicationList.add(this.loadFromResultSet(resultSet));
}
// get the total number of rows
resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
int nrTotalRows = 0;
if (resultSet != null && resultSet.next()) {
nrTotalRows = resultSet.getInt(1);
}
if (applicationList.size() >= MAX_ROW_SELECTED) {
// Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
response = new AnswerList(applicationList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
response = new AnswerList(applicationList, nrTotalRows);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
response.setResultMessage(msg);
response.setDataList(applicationList);
return response;
}
use of org.cerberus.crud.entity.User in project cerberus-source by cerberustesting.
the class UserDAO method readByKey.
@Override
public AnswerItem readByKey(String login) {
AnswerItem ans = new AnswerItem();
User result;
final String query = "SELECT * FROM `user` usr WHERE usr.`login` = ?";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, login);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
ans.setItem(result);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
// sets the message
ans.setResultMessage(msg);
return ans;
}
Aggregations