Search in sources :

Example 6 with IUserGroupService

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;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) User(org.cerberus.crud.entity.User) UserSystem(org.cerberus.crud.entity.UserSystem) IUserService(org.cerberus.crud.service.IUserService) UserService(org.cerberus.crud.service.impl.UserService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) IUserGroupService(org.cerberus.crud.service.IUserGroupService) UserGroup(org.cerberus.crud.entity.UserGroup) JSONObject(org.json.JSONObject) IUserSystemService(org.cerberus.crud.service.IUserSystemService)

Aggregations

User (org.cerberus.crud.entity.User)6 UserGroup (org.cerberus.crud.entity.UserGroup)6 IUserGroupService (org.cerberus.crud.service.IUserGroupService)6 IUserService (org.cerberus.crud.service.IUserService)6 UserSystem (org.cerberus.crud.entity.UserSystem)5 IUserSystemService (org.cerberus.crud.service.IUserSystemService)5 JSONArray (org.json.JSONArray)5 JSONObject (org.json.JSONObject)5 ApplicationContext (org.springframework.context.ApplicationContext)4 AnswerList (org.cerberus.util.answer.AnswerList)3 ArrayList (java.util.ArrayList)2 ILogEventService (org.cerberus.crud.service.ILogEventService)2 UserService (org.cerberus.crud.service.impl.UserService)2 CerberusException (org.cerberus.exception.CerberusException)2 JSONException (org.json.JSONException)2 List (java.util.List)1 HttpSession (javax.servlet.http.HttpSession)1 Test (org.cerberus.crud.entity.Test)1 TestCase (org.cerberus.crud.entity.TestCase)1 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)1