use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.
the class UserGroupDAO method readByUser.
@Override
public AnswerList<UserGroup> readByUser(String login) {
AnswerList ans = new AnswerList();
MessageEvent msg = null;
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(Query.READ_BY_USER)) {
// Prepare and execute query
preStat.setString(1, login);
try (ResultSet resultSet = preStat.executeQuery()) {
List<UserGroup> result = new ArrayList<>();
while (resultSet.next()) {
result.add(loadUserGroupFromResultSet(resultSet));
}
ans.setDataList(result);
// Set the final message
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "CREATE");
} 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()));
}
} catch (Exception e) {
LOG.warn("Unable to read UserGroup: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
ans.setResultMessage(msg);
}
return ans;
}
use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.
the class FactoryUserGroup method create.
@Override
public UserGroup create(String login, String group) {
UserGroup newGroup = new UserGroup();
newGroup.setGroup(group);
newGroup.setLogin(login);
return newGroup;
}
use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.
the class GetUsers method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String echo = request.getParameter("sEcho");
// data that will be shown in the table
JSONArray data = new JSONArray();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IUserService userService = appContext.getBean(UserService.class);
IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
try {
JSONObject jsonResponse = new JSONObject();
try {
for (User myUser : userService.findallUser()) {
JSONObject u = new JSONObject();
u.put("login", myUser.getLogin());
u.put("name", myUser.getName());
u.put("team", myUser.getTeam());
u.put("defaultSystem", myUser.getDefaultSystem());
u.put("request", myUser.getRequest());
u.put("email", myUser.getEmail());
JSONArray groups = new JSONArray();
for (UserGroup group : userGroupService.findGroupByKey(myUser.getLogin())) {
groups.put(group.getGroup());
}
u.put("group", groups);
JSONArray systems = new JSONArray();
for (UserSystem sys : userSystemService.findUserSystemByUser(myUser.getLogin())) {
systems.put(sys.getSystem());
}
u.put("system", systems);
data.put(u);
}
} catch (CerberusException ex) {
response.setContentType("text/html");
response.getWriter().print(ex.getMessageError().getDescription());
}
jsonResponse.put("aaData", data);
jsonResponse.put("sEcho", echo);
jsonResponse.put("iTotalRecords", data.length());
jsonResponse.put("iTotalDisplayRecords", data.length());
response.setContentType("application/json");
response.getWriter().print(jsonResponse.toString());
} catch (JSONException e) {
LOG.warn(e);
response.setContentType("text/html");
response.getWriter().print(e.getMessage());
}
}
use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.
the class ReadMyUser 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);
IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
response.setContentType("application/json");
response.setCharacterEncoding("utf8");
JSONObject data = new JSONObject();
try {
String user = request.getUserPrincipal().getName();
User myUser = userService.findUserByKey(user);
data.put("login", myUser.getLogin());
data.put("name", myUser.getName());
data.put("team", myUser.getTeam());
data.put("defaultSystem", myUser.getDefaultSystem());
data.put("request", myUser.getRequest());
data.put("email", myUser.getEmail());
data.put("language", myUser.getLanguage());
data.put("robotHost", myUser.getRobotHost());
data.put("robotPort", myUser.getRobotPort());
data.put("robotPlatform", myUser.getRobotPort());
data.put("robotBrowser", myUser.getRobotPort());
data.put("robotVersion", myUser.getRobotPort());
data.put("robot", myUser.getRobot());
data.put("reportingFavorite", myUser.getReportingFavorite());
data.put("userPreferences", myUser.getUserPreferences());
JSONArray groups = new JSONArray();
for (UserGroup group : userGroupService.findGroupByKey(myUser.getLogin())) {
groups.put(group.getGroup());
}
data.put("group", groups);
JSONArray systems = new JSONArray();
for (UserSystem sys : userSystemService.findUserSystemByUser(myUser.getLogin())) {
systems.put(sys.getSystem());
}
data.put("system", systems);
HttpSession session = request.getSession();
session.setAttribute("MySystem", myUser.getDefaultSystem());
session.setAttribute("MyLang", myUser.getLanguage());
} catch (CerberusException ex) {
response.getWriter().print(ex.getMessageError().getDescription());
} catch (JSONException ex) {
LOG.warn(ex);
} catch (NullPointerException ex) {
response.sendRedirect("./Login.jsp");
}
response.getWriter().print(data.toString());
}
use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.
the class ReadUser method readByKey.
private AnswerItem readByKey(ApplicationContext appContext, HttpServletRequest request) throws JSONException {
String login = ParameterParserUtil.parseStringParam(request.getParameter("login"), "");
boolean userHasPermissions = request.isUserInRole("IntegratorRO");
AnswerItem item = new AnswerItem();
JSONObject jsonResponse = new JSONObject();
userService = appContext.getBean(UserService.class);
AnswerItem resp = userService.readByKey(login);
if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null) {
User user = (User) resp.getItem();
JSONObject response = convertUserToJSONObject(user);
if (request.getParameter("systems") != null) {
IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
AnswerList a = userSystemService.readByUser(login);
if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && a.getDataList() != null) {
JSONArray JSONsystems = new JSONArray();
List<UserSystem> systems = a.getDataList();
for (UserSystem u : systems) {
JSONsystems.put(convertUserSystemToJSONObject(u));
}
response.put("systems", JSONsystems);
}
}
if (request.getParameter("groups") != null) {
IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
AnswerList a = userGroupService.readByUser(login);
if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && a.getDataList() != null) {
JSONArray JSONgroups = new JSONArray();
List<UserGroup> groups = a.getDataList();
for (UserGroup u : groups) {
JSONgroups.put(convertUserGroupToJSONObject(u));
}
response.put("groups", JSONgroups);
}
}
jsonResponse.put("contentTable", response);
}
jsonResponse.put("hasPermissions", userHasPermissions);
item.setItem(jsonResponse);
item.setResultMessage(resp.getResultMessage());
return item;
}
Aggregations