@Override public List<Group> findGroupsByUser(String userId) { String sql = "select r.id id,name,code from tbl_role r" + " left join tbl_user_role ur on r.id=ur.roleid" + " where ur.userid=:userid"; Map<String, Object> param = new HashMap<>(); param.put("userid", userId); List<Map<String, Object>> maps = super.findMapBySql(sql, param); List<Group> groups = new ArrayList<>(); for (Map<String, Object> map : maps) { Group group = new GroupEntity(); group.setId(map.get("id").toString()); group.setName(map.get("name").toString()); group.setType(map.get("code").toString()); groups.add(group); } return groups; }
@ApiOperation(value = "Create a group", tags = {"Groups"}) @ApiResponses(value = { @ApiResponse(code = 201, message = "Indicates the group was created."), @ApiResponse(code = 400, message = "Indicates the id of the group was missing.") }) @RequestMapping(value = "/identity/groups", method = RequestMethod.POST, produces = "application/json") public GroupResponse createGroup(@RequestBody GroupRequest groupRequest, HttpServletRequest httpRequest, HttpServletResponse response) { if (groupRequest.getId() == null) { throw new ActivitiIllegalArgumentException("Id cannot be null."); } // Check if a user with the given ID already exists so we return a // CONFLICT if (identityService.createGroupQuery().groupId(groupRequest.getId()).count() > 0) { throw new ActivitiConflictException("A group with id '" + groupRequest.getId() + "' already exists."); } Group created = identityService.newGroup(groupRequest.getId()); created.setId(groupRequest.getId()); created.setName(groupRequest.getName()); created.setType(groupRequest.getType()); identityService.saveGroup(created); response.setStatus(HttpStatus.CREATED.value()); return restResponseFactory.createGroupResponse(created); }