use of org.cerberus.crud.service.IUserGroupService 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