Java Code Examples for org.activiti.engine.identity.UserQuery

The following examples show how to use org.activiti.engine.identity.UserQuery. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: activiti6-boot2   Source File: IdmGroupsResource.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{groupId}/users", method = RequestMethod.GET)
public ResultListDataRepresentation getGroupUsers(@PathVariable String groupId, @RequestParam(required = false) String filter, @RequestParam(required = false) Integer page,
    @RequestParam(required = false) Integer pageSize) {
  validateAdminRole();
  int pageValue = page != null ? page.intValue() : 0;
  int pageSizeValue = pageSize != null ? pageSize.intValue() : 50;
  
  UserQuery userQuery = identityService.createUserQuery().memberOfGroup(groupId);
  if (StringUtils.isNotEmpty(filter)) {
    userQuery.userFullNameLike("%" + filter + "%");
  }
  List<User> users = userQuery.listPage(pageValue, pageSizeValue);
  
  List<UserRepresentation> userRepresentations = new ArrayList<UserRepresentation>(users.size());
  for (User user : users) {
    userRepresentations.add(new UserRepresentation(user));
  }

  ResultListDataRepresentation resultListDataRepresentation = new ResultListDataRepresentation(userRepresentations);
  resultListDataRepresentation.setStart(pageValue * pageSizeValue);
  resultListDataRepresentation.setSize(userRepresentations.size());
  resultListDataRepresentation.setTotal(userQuery.count());
  return resultListDataRepresentation;
}
 
Example 2
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testQuerySorting() {
  // asc
  assertEquals(3, identityService.createUserQuery().orderByUserId().asc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserEmail().asc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserFirstName().asc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserLastName().asc().count());

  // desc
  assertEquals(3, identityService.createUserQuery().orderByUserId().desc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserEmail().desc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserFirstName().desc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserLastName().desc().count());

  // Combined with criteria
  UserQuery query = identityService.createUserQuery().userLastNameLike("%ea%").orderByUserFirstName().asc();
  List<User> users = query.list();
  assertEquals(2, users.size());
  assertEquals("Fozzie", users.get(0).getFirstName());
  assertEquals("Gonzo", users.get(1).getFirstName());
}
 
Example 3
Source Project: activiti6-boot2   Source File: UserQueryEscapeClauseTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testQueryByFullNameLike() {
  UserQuery query = identityService.createUserQuery().userFullNameLike("%og\\%%");
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  assertEquals("kermit", query.singleResult().getId());
  
  query = identityService.createUserQuery().userFullNameLike("%it\\%%");
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  assertEquals("kermit", query.singleResult().getId());
  
  query = identityService.createUserQuery().userFullNameLike("%ar\\_%");
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  assertEquals("fozzie", query.singleResult().getId());
  
  query = identityService.createUserQuery().userFullNameLike("%ie\\_%");
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  assertEquals("fozzie", query.singleResult().getId());
}
 
Example 4
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testQuerySorting() {
  // asc
  assertEquals(3, identityService.createUserQuery().orderByUserId().asc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserEmail().asc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserFirstName().asc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserLastName().asc().count());
  
  // desc
  assertEquals(3, identityService.createUserQuery().orderByUserId().desc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserEmail().desc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserFirstName().desc().count());
  assertEquals(3, identityService.createUserQuery().orderByUserLastName().desc().count());

  // Combined with criteria
  UserQuery query = identityService.createUserQuery().userLastNameLike("%ea%").orderByUserFirstName().asc();
  List<User> users = query.list();
  assertEquals(2,users.size());
  assertEquals("Fozzie", users.get(0).getFirstName());
  assertEquals("Gonzo", users.get(1).getFirstName());
}
 
Example 5
Source Project: activiti6-boot2   Source File: UserQueryEscapeClauseTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testQueryByFullNameLike() {
  UserQuery query = identityService.createUserQuery().userFullNameLike("%og\\%%");
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  assertEquals("kermit", query.singleResult().getId());
  
  query = identityService.createUserQuery().userFullNameLike("%it\\%%");
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  assertEquals("kermit", query.singleResult().getId());
  
  query = identityService.createUserQuery().userFullNameLike("%ar\\_%");
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  assertEquals("fozzie", query.singleResult().getId());
  
  query = identityService.createUserQuery().userFullNameLike("%ie\\_%");
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  assertEquals("fozzie", query.singleResult().getId());
}
 
Example 6
Source Project: activiti6-boot2   Source File: IdmUsersResource.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/rest/admin/users", method = RequestMethod.GET)
public ResultListDataRepresentation getUsers(@RequestParam(required=false) String filter, 
        @RequestParam(required=false) String sort,
        @RequestParam(required=false) Integer start,
        @RequestParam(required=false) String groupId) {

  validateAdminRole();
  
  ResultListDataRepresentation result = new ResultListDataRepresentation();
  
  UserQuery userQuery = identityService.createUserQuery();
  if (StringUtils.isNotEmpty(filter)) {
    userQuery.userFullNameLike("%" + filter + "%");
  }
  
  if (StringUtils.isNotEmpty(sort)) {
    if ("idDesc".equals(sort)) {
      userQuery.orderByUserId().desc();
    } else if ("idAsc".equals(sort)) {
      userQuery.orderByUserId().asc();
    } else if ("emailAsc".equals(sort)) {
      userQuery.orderByUserEmail().asc();
    } else if ("emailDesc".equals(sort)) {
      userQuery.orderByUserEmail().desc();
    }
    
  }
  
  Integer startValue = start != null ? start.intValue() : 0;
  Integer size = MAX_USER_SIZE; // TODO: pass actual size
  List<User> users = userQuery.listPage(startValue, (size != null && size > 0) ? size : MAX_USER_SIZE);
  Long totalCount = userQuery.count();
  result.setTotal(Long.valueOf(totalCount.intValue()));
  result.setStart(startValue);
  result.setSize(users.size());
  result.setData(convertToUserRepresentations(users));
  
  return result;
}
 
Example 7
public ResultListDataRepresentation getUsers(String filter, String email, String excludeTaskId, String excludeProcessId, Long groupId) {

    // Actual query
    int page = 0;
    int pageSize = MAX_PEOPLE_SIZE;

    UserQuery userQuery = identityService.createUserQuery();
    if (StringUtils.isNotEmpty(filter)) {
      userQuery.userFullNameLike("%" + filter + "%");
    }
    List<User> matchingUsers = userQuery.listPage(page, pageSize);

    // Filter out users already part of the task/process of which the ID has been passed
    if (excludeTaskId != null) {
      filterUsersInvolvedInTask(excludeTaskId, matchingUsers);
    } else if (excludeProcessId != null) {
      filterUsersInvolvedInProcess(excludeProcessId, matchingUsers);
    }

    List<UserRepresentation> userRepresentations = new ArrayList<UserRepresentation>(matchingUsers.size());
    for (User user : matchingUsers) {
      userRepresentations.add(new UserRepresentation(user));
    }
    ResultListDataRepresentation result = new ResultListDataRepresentation(userRepresentations);

    if (page != 0 || (page == 0 && matchingUsers.size() == pageSize)) {
      // Total differs from actual result size, need to fetch it
      result.setTotal(userQuery.count());
    }
    return result;
  }
 
Example 8
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery userId(String id) {
  if (id == null) {
    throw new ActivitiIllegalArgumentException("Provided id is null");
  }
  this.id = id;
  return this;
}
 
Example 9
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery userFirstName(String firstName) {
  if (firstName == null) {
    throw new ActivitiIllegalArgumentException("Provided firstName is null");
  }
  this.firstName = firstName;
  return this;
}
 
Example 10
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery userFirstNameLike(String firstNameLike) {
  if (firstNameLike == null) {
    throw new ActivitiIllegalArgumentException("Provided firstNameLike is null");
  }
  this.firstNameLike = firstNameLike;
  return this;
}
 
Example 11
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery userLastName(String lastName) {
  if (lastName == null) {
    throw new ActivitiIllegalArgumentException("Provided lastName is null");
  }
  this.lastName = lastName;
  return this;
}
 
Example 12
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery userLastNameLike(String lastNameLike) {
  if (lastNameLike == null) {
    throw new ActivitiIllegalArgumentException("Provided lastNameLike is null");
  }
  this.lastNameLike = lastNameLike;
  return this;
}
 
Example 13
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery userFullNameLike(String fullNameLike) {
  if (fullNameLike == null) {
    throw new ActivitiIllegalArgumentException("Provided full name is null");
  }
  this.fullNameLike = fullNameLike;
  return this;
}
 
Example 14
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery userEmail(String email) {
  if (email == null) {
    throw new ActivitiIllegalArgumentException("Provided email is null");
  }
  this.email = email;
  return this;
}
 
Example 15
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery userEmailLike(String emailLike) {
  if (emailLike == null) {
    throw new ActivitiIllegalArgumentException("Provided emailLike is null");
  }
  this.emailLike = emailLike;
  return this;
}
 
Example 16
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery memberOfGroup(String groupId) {
  if (groupId == null) {
    throw new ActivitiIllegalArgumentException("Provided groupIds is null or empty");
  }
  this.groupId = groupId;
  return this;
}
 
Example 17
Source Project: activiti6-boot2   Source File: UserQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
public UserQuery potentialStarter(String procDefId) {
  if (procDefId == null) {
    throw new ActivitiIllegalArgumentException("Provided processDefinitionId is null or empty");
  }
  this.procDefId = procDefId;
  return this;

}
 
Example 18
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByInvalidId() {
  UserQuery query = identityService.createUserQuery().userId("invalid");
  verifyQueryResults(query, 0);

  try {
    identityService.createUserQuery().userId(null).singleResult();
    fail();
  } catch (ActivitiIllegalArgumentException e) {
  }
}
 
Example 19
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByFirstName() {
  UserQuery query = identityService.createUserQuery().userFirstName("Gonzo");
  verifyQueryResults(query, 1);

  User result = query.singleResult();
  assertEquals("gonzo", result.getId());
}
 
Example 20
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByInvalidFirstName() {
  UserQuery query = identityService.createUserQuery().userFirstName("invalid");
  verifyQueryResults(query, 0);

  try {
    identityService.createUserQuery().userFirstName(null).singleResult();
    fail();
  } catch (ActivitiIllegalArgumentException e) {
  }
}
 
Example 21
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByFirstNameLike() {
  UserQuery query = identityService.createUserQuery().userFirstNameLike("%o%");
  verifyQueryResults(query, 2);

  query = identityService.createUserQuery().userFirstNameLike("Ker%");
  verifyQueryResults(query, 1);
}
 
Example 22
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByInvalidFirstNameLike() {
  UserQuery query = identityService.createUserQuery().userFirstNameLike("%mispiggy%");
  verifyQueryResults(query, 0);

  try {
    identityService.createUserQuery().userFirstNameLike(null).singleResult();
    fail();
  } catch (ActivitiIllegalArgumentException e) {
  }
}
 
Example 23
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByLastName() {
  UserQuery query = identityService.createUserQuery().userLastName("Bear");
  verifyQueryResults(query, 1);

  User result = query.singleResult();
  assertEquals("fozzie", result.getId());
}
 
Example 24
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByInvalidLastName() {
  UserQuery query = identityService.createUserQuery().userLastName("invalid");
  verifyQueryResults(query, 0);

  try {
    identityService.createUserQuery().userLastName(null).singleResult();
    fail();
  } catch (ActivitiIllegalArgumentException e) {
  }
}
 
Example 25
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByLastNameLike() {
  UserQuery query = identityService.createUserQuery().userLastNameLike("%rog%");
  verifyQueryResults(query, 1);

  query = identityService.createUserQuery().userLastNameLike("%ea%");
  verifyQueryResults(query, 2);
}
 
Example 26
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByFullNameLike() {
  UserQuery query = identityService.createUserQuery().userFullNameLike("%erm%");
  verifyQueryResults(query, 1);

  query = identityService.createUserQuery().userFullNameLike("%ea%");
  verifyQueryResults(query, 2);

  query = identityService.createUserQuery().userFullNameLike("%e%");
  verifyQueryResults(query, 3);
}
 
Example 27
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByInvalidLastNameLike() {
  UserQuery query = identityService.createUserQuery().userLastNameLike("%invalid%");
  verifyQueryResults(query, 0);

  try {
    identityService.createUserQuery().userLastNameLike(null).singleResult();
    fail();
  } catch (ActivitiIllegalArgumentException e) {
  }
}
 
Example 28
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByInvalidEmail() {
  UserQuery query = identityService.createUserQuery().userEmail("invalid");
  verifyQueryResults(query, 0);

  try {
    identityService.createUserQuery().userEmail(null).singleResult();
    fail();
  } catch (ActivitiIllegalArgumentException e) {
  }
}
 
Example 29
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByEmailLike() {
  UserQuery query = identityService.createUserQuery().userEmailLike("%muppetshow.com");
  verifyQueryResults(query, 3);

  query = identityService.createUserQuery().userEmailLike("%kermit%");
  verifyQueryResults(query, 1);
}
 
Example 30
Source Project: activiti6-boot2   Source File: UserQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByInvalidEmailLike() {
  UserQuery query = identityService.createUserQuery().userEmailLike("%invalid%");
  verifyQueryResults(query, 0);

  try {
    identityService.createUserQuery().userEmailLike(null).singleResult();
    fail();
  } catch (ActivitiIllegalArgumentException e) {
  }
}