Search in sources :

Example 1 with UserService

use of org.cerberus.crud.service.impl.UserService in project cerberus-source by cerberustesting.

the class ReadUser method findUserList.

// </editor-fold>
private AnswerItem findUserList(ApplicationContext appContext, HttpServletRequest request, HttpServletResponse response) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject jsonResponse = new JSONObject();
    userService = appContext.getBean(UserService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    /*int sEcho  = Integer.valueOf(request.getParameter("sEcho"));*/
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "1"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "userID,login,name");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
    Map<String, List<String>> individualSearch = new HashMap<>();
    for (int a = 0; a < columnToSort.length; a++) {
        if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
            List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
            if (individualLike.contains(columnToSort[a])) {
                individualSearch.put(columnToSort[a] + ":like", search);
            } else {
                individualSearch.put(columnToSort[a], search);
            }
        }
    }
    AnswerList resp = userService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);
    JSONArray jsonArray = new JSONArray();
    boolean userHasPermissions = request.isUserInRole("IntegratorRO");
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (User user : (List<User>) resp.getDataList()) {
            JSONObject res = convertUserToJSONObject(user);
            if (request.getParameter("systems") != null) {
                IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
                AnswerList a = userSystemService.readByUser(user.getLogin());
                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));
                    }
                    res.put("systems", JSONsystems);
                }
            }
            if (request.getParameter("groups") != null) {
                IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
                AnswerList a = userGroupService.readByUser(user.getLogin());
                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));
                    }
                    res.put("groups", JSONgroups);
                }
            }
            jsonArray.put(res);
        }
    }
    jsonResponse.put("hasPermissions", userHasPermissions);
    jsonResponse.put("contentTable", jsonArray);
    jsonResponse.put("iTotalRecords", resp.getTotalRows());
    jsonResponse.put("iTotalDisplayRecords", resp.getTotalRows());
    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) AnswerList(org.cerberus.util.answer.AnswerList) IUserSystemService(org.cerberus.crud.service.IUserSystemService)

Example 2 with UserService

use of org.cerberus.crud.service.impl.UserService 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)

Example 3 with UserService

use of org.cerberus.crud.service.impl.UserService in project cerberus-source by cerberustesting.

the class ReadUserPublic method findUserList.

private AnswerItem findUserList(ApplicationContext appContext, HttpServletRequest request, HttpServletResponse response) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject jsonResponse = new JSONObject();
    userService = appContext.getBean(UserService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    /*int sEcho  = Integer.valueOf(request.getParameter("sEcho"));*/
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "1"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "userID,login,name");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    AnswerList resp = userService.readByCriteria(startPosition, length, columnName, sort, searchParameter, "");
    JSONArray jsonArray = new JSONArray();
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (User user : (List<User>) resp.getDataList()) {
            jsonArray.put(convertUserToJSONObject(user));
        }
    }
    jsonResponse.put("contentTable", jsonArray);
    jsonResponse.put("iTotalRecords", resp.getTotalRows());
    jsonResponse.put("iTotalDisplayRecords", resp.getTotalRows());
    item.setItem(jsonResponse);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) User(org.cerberus.crud.entity.User) JSONObject(org.json.JSONObject) IUserService(org.cerberus.crud.service.IUserService) UserService(org.cerberus.crud.service.impl.UserService) JSONArray(org.json.JSONArray) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem)

Aggregations

User (org.cerberus.crud.entity.User)3 IUserService (org.cerberus.crud.service.IUserService)3 UserService (org.cerberus.crud.service.impl.UserService)3 AnswerItem (org.cerberus.util.answer.AnswerItem)3 AnswerList (org.cerberus.util.answer.AnswerList)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 UserGroup (org.cerberus.crud.entity.UserGroup)2 UserSystem (org.cerberus.crud.entity.UserSystem)2 IUserGroupService (org.cerberus.crud.service.IUserGroupService)2 IUserSystemService (org.cerberus.crud.service.IUserSystemService)2 List (java.util.List)1