@Override public List<User> getUserList(QueryCondition condition, PageInfo pageInfo) { String name = null; String groupId = null; if (condition != null) { name = condition.getConditionMap().get("name").toString(); if (condition.getConditionMap().containsKey("groupId")) { groupId = condition.getConditionMap().get("groupId").toString(); } } List<User> userList; long count; UserQuery query = identityService.createUserQuery(); if (!StrUtil.isEmpty(name)) { query = query.userFirstNameLike(name); } if (!StrUtil.isEmpty(groupId)) { query = query.memberOfGroup(groupId); } count = query.count(); userList = query.orderByUserId().asc().listPage((pageInfo.getPageNum() - 1) * pageInfo.getPageSize(), pageInfo.getPageSize()); pageInfo.setCount((int) count); return userList; }
public int size() { return (int) identityService.createUserQuery().count(); }
public int size() { return (int) identityService.createUserQuery().memberOfGroup(groupId).count(); }
@ApiOperation(value = "Delete a member from a group", tags = {"Groups"}) @ApiResponses(value = { @ApiResponse(code = 204, message = "Indicates the group was found and the member has been deleted. The response body is left empty intentionally."), @ApiResponse(code = 404, message = "Indicates the requested group was not found or that the user is not a member of the group. The status description contains additional information about the error.") }) @RequestMapping(value = "/identity/groups/{groupId}/members/{userId}", method = RequestMethod.DELETE) public void deleteMembership(@ApiParam(name = "groupId", value="The id of the group to remove a member from.") @PathVariable("groupId") String groupId,@ApiParam(name = "userId", value="The id of the user to remove.") @PathVariable("userId") String userId, HttpServletRequest request, HttpServletResponse response) { Group group = getGroupFromRequest(groupId); // Check if user is not a member of group since API doesn't return typed // exception if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(userId).count() != 1) { throw new ActivitiObjectNotFoundException("User '" + userId + "' is not part of group '" + group.getId() + "'.", null); } identityService.deleteMembership(userId, group.getId()); response.setStatus(HttpStatus.NO_CONTENT.value()); } }
@ApiOperation(value = "Add a member to a group", tags = {"Groups"}) @ApiResponses(value = { @ApiResponse(code = 201, message = "Indicates the group was found and the member has been added."), @ApiResponse(code = 400, message = "Indicates the userId was not included in the request body."), @ApiResponse(code = 404, message = "Indicates the requested group was not found."), @ApiResponse(code = 409, message = "Indicates the requested user is already a member of the group.") }) @RequestMapping(value = "/identity/groups/{groupId}/members", method = RequestMethod.POST, produces = "application/json") public MembershipResponse createMembership(@ApiParam(name = "groupId", value="The id of the group to add a member to.") @PathVariable String groupId, @RequestBody MembershipRequest memberShip, HttpServletRequest request, HttpServletResponse response) { Group group = getGroupFromRequest(groupId); if (memberShip.getUserId() == null) { throw new ActivitiIllegalArgumentException("UserId cannot be null."); } // Check if user is member of group since API doesn't return typed // exception if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(memberShip.getUserId()).count() > 0) { throw new ActivitiConflictException("User '" + memberShip.getUserId() + "' is already part of group '" + group.getId() + "'."); } identityService.createMembership(memberShip.getUserId(), group.getId()); response.setStatus(HttpStatus.CREATED.value()); return restResponseFactory.createMembershipResponse(memberShip.getUserId(), group.getId()); } }
@Override public Object convertFormValueToModelValue(String propertyValue) { // Check if user exists if (propertyValue != null) { // TODO: perhaps better wiring mechanism for service long count = ProcessEngines.getDefaultProcessEngine().getIdentityService().createUserQuery().userId(propertyValue).count(); if (count == 0) { throw new ActivitiObjectNotFoundException("User " + propertyValue + " does not exist", User.class); } return propertyValue; } return null; }
@Override public Object convertFormValueToModelValue(String propertyValue) { // Check if user exists if(propertyValue != null) { // TODO: perhaps better wiring mechanism for service long count = ProcessEngines.getDefaultProcessEngine() .getIdentityService() .createUserQuery() .userId(propertyValue).count(); if(count == 0) { throw new ActivitiObjectNotFoundException("User " + propertyValue + " does not exist", User.class); } return propertyValue; } return null; }
protected void createUser(String userId, String firstName, String lastName, String password, String email, String imageResource, List<String> groups, List<String> userInfo) { if (identityService.createUserQuery().userId(userId).count() == 0) {
protected void createUser(String userId, String firstName, String lastName, String password, String email, String imageResource, List<String> groups, List<String> userInfo) { if (identityService.createUserQuery().userId(userId).count() == 0) {
@ApiOperation(value = "Create a user", tags = {"Users"}) @ApiResponses(value = { @ApiResponse(code = 201, message = "Indicates the user was created."), @ApiResponse(code = 400, message = "Indicates the id of the user was missing.") }) @RequestMapping(value = "/identity/users", method = RequestMethod.POST, produces = "application/json") public UserResponse createUser(@RequestBody UserRequest userRequest, HttpServletRequest request, HttpServletResponse response) { if (userRequest.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.createUserQuery().userId(userRequest.getId()).count() > 0) { throw new ActivitiConflictException("A user with id '" + userRequest.getId() + "' already exists."); } User created = identityService.newUser(userRequest.getId()); created.setEmail(userRequest.getEmail()); created.setFirstName(userRequest.getFirstName()); created.setLastName(userRequest.getLastName()); created.setPassword(userRequest.getPassword()); identityService.saveUser(created); response.setStatus(HttpStatus.CREATED.value()); return restResponseFactory.createUserResponse(created, true); }