Java Code Examples for org.activiti.engine.identity.User#setEmail()

The following examples show how to use org.activiti.engine.identity.User#setEmail() . 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 File: UserInfoResourceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Test getting the info for a user who doesn't have that info set
 */
public void testGetInfoForUserWithoutInfo() throws Exception {
  User savedUser = null;
  try {
    User newUser = identityService.newUser("testuser");
    newUser.setFirstName("Fred");
    newUser.setLastName("McDonald");
    newUser.setEmail("[email protected]");
    identityService.saveUser(newUser);
    savedUser = newUser;

    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "testuser", "key1")), HttpStatus.SC_NOT_FOUND));

  } finally {

    // Delete user after test passes or fails
    if (savedUser != null) {
      identityService.deleteUser(savedUser.getId());
    }
  }
}
 
Example 2
Source File: UserInfoResourceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Test deleting the info for a user who doesn't have that info set
 */
public void testUpdateUnexistingInfo() throws Exception {
  User savedUser = null;
  try {
    User newUser = identityService.newUser("testuser");
    newUser.setFirstName("Fred");
    newUser.setLastName("McDonald");
    newUser.setEmail("[email protected]");
    identityService.saveUser(newUser);
    savedUser = newUser;

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("value", "Updated value");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "testuser", "key1"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));

  } finally {

    // Delete user after test passes or fails
    if (savedUser != null) {
      identityService.deleteUser(savedUser.getId());
    }
  }
}
 
Example 3
Source File: IdentityController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存User
 *
 * @param redirectAttributes
 * @return
 */
@RequestMapping(value = "user/save", method = RequestMethod.POST)
public String saveUser(@RequestParam("userId") String userId,
                       @RequestParam("firstName") String firstName,
                       @RequestParam("lastName") String lastName,
                       @RequestParam(value = "password", required = false) String password,
                       @RequestParam(value = "email", required = false) String email,
                       RedirectAttributes redirectAttributes) {
    User user = identityService.createUserQuery().userId(userId).singleResult();
    if (user == null) {
        user = identityService.newUser(userId);
    }
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    if (StringUtils.isNotBlank(password)) {
        user.setPassword(password);
    }
    identityService.saveUser(user);
    redirectAttributes.addFlashAttribute("message", "成功添加用户[" + firstName + " " + lastName + "]");
    return "redirect:/chapter14/identity/user/list";
}
 
Example 4
Source File: IdmUsersResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/rest/admin/users", method = RequestMethod.POST)
public User createNewUser(@RequestBody CreateUserRepresentation userRepresentation) {
  validateAdminRole();
  
  if(StringUtils.isBlank(userRepresentation.getId()) ||
      StringUtils.isBlank(userRepresentation.getPassword()) || 
      StringUtils.isBlank(userRepresentation.getFirstName())) {
      throw new BadRequestException("Id, password and first name are required");
  }
  
  if (userRepresentation.getEmail() != null && identityService.createUserQuery().userEmail(userRepresentation.getEmail()).count() > 0) {
    throw new ConflictingRequestException("User already registered", "ACCOUNT.SIGNUP.ERROR.ALREADY-REGISTERED");
  } 
  
  User user = identityService.newUser(userRepresentation.getId() != null ? userRepresentation.getId() : userRepresentation.getEmail());
  user.setFirstName(userRepresentation.getFirstName());
  user.setLastName(userRepresentation.getLastName());
  user.setEmail(userRepresentation.getEmail());
  user.setPassword(userRepresentation.getPassword());
  identityService.saveUser(user);
  
  return user;
}
 
Example 5
Source File: IdmProfileResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/profile", method = RequestMethod.POST, produces = "application/json")
public UserRepresentation updateProfile(@RequestBody UserRepresentation userRepresentation) {
  User currentUser = SecurityUtils.getCurrentUserObject();

  // If user is not externally managed, we need the email address for login, so an empty email is not allowed
  if (StringUtils.isEmpty(userRepresentation.getEmail())) {
    throw new BadRequestException("Empty email is not allowed");
  }
  
  User user = identityService.createUserQuery().userId(currentUser.getId()).singleResult();
  user.setFirstName(userRepresentation.getFirstName());
  user.setLastName(userRepresentation.getLastName());
  user.setEmail(userRepresentation.getEmail());
  identityService.saveUser(user);
  return new UserRepresentation(user);
}
 
Example 6
Source File: IdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testUpdateUser() {
  // First, create a new user
  User user = identityService.newUser("johndoe");
  user.setFirstName("John");
  user.setLastName("Doe");
  user.setEmail("[email protected]");
  identityService.saveUser(user);

  // Fetch and update the user
  user = identityService.createUserQuery().userId("johndoe").singleResult();
  user.setEmail("[email protected]");
  user.setFirstName("Jane");
  user.setLastName("Donnel");
  identityService.saveUser(user);

  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertEquals("Jane", user.getFirstName());
  assertEquals("Donnel", user.getLastName());
  assertEquals("[email protected]", user.getEmail());

  identityService.deleteUser(user.getId());
}
 
Example 7
Source File: IdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testUpdateUser() {
  // First, create a new user
  User user = identityService.newUser("johndoe");
  user.setFirstName("John");
  user.setLastName("Doe");
  user.setEmail("[email protected]");
  identityService.saveUser(user);

  // Fetch and update the user
  user = identityService.createUserQuery().userId("johndoe").singleResult();
  user.setEmail("[email protected]");
  user.setFirstName("Jane");
  user.setLastName("Donnel");
  identityService.saveUser(user);

  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertEquals("Jane", user.getFirstName());
  assertEquals("Donnel", user.getLastName());
  assertEquals("[email protected]", user.getEmail());

  identityService.deleteUser(user.getId());
}
 
Example 8
Source File: IdentityServiceTest.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 用户管理API演示
 */
@Test
public void testUser() throws Exception {
    // 创建一个用户
    User user = identityService.newUser("henryyan");
    user.setFirstName("Henry");
    user.setLastName("Yan");
    user.setEmail("[email protected]");

    // 保存用户到数据库
    identityService.saveUser(user);

    // 验证用户是否保存成功
    User userInDb = identityService.createUserQuery().userId("henryyan").singleResult();
    assertNotNull(userInDb);

    // 删除用户
    identityService.deleteUser("henryyan");

    // 验证是否删除成功
    userInDb = identityService.createUserQuery().userId("henryyan").singleResult();
    assertNull(userInDb);
}
 
Example 9
Source File: UserPictureResourceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Test getting the picture for a user who doesn't have a îcture set
 */
public void testGetPictureForUserWithoutPicture() throws Exception {
  User savedUser = null;
  try {
    User newUser = identityService.newUser("testuser");
    newUser.setFirstName("Fred");
    newUser.setLastName("McDonald");
    newUser.setEmail("[email protected]");
    identityService.saveUser(newUser);
    savedUser = newUser;

    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId())), HttpStatus.SC_NOT_FOUND);

    // response content type application/json;charset=UTF-8
    assertEquals("application/json", response.getEntity().getContentType().getValue().split(";")[0]);
    closeResponse(response);

  } finally {

    // Delete user after test passes or fails
    if (savedUser != null) {
      identityService.deleteUser(savedUser.getId());
    }
  }
}
 
Example 10
Source File: IdentityTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testUser() {
  User user = identityService.newUser("johndoe");
  user.setFirstName("John");
  user.setLastName("Doe");
  user.setEmail("[email protected]");
  identityService.saveUser(user);

  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertEquals("johndoe", user.getId());
  assertEquals("John", user.getFirstName());
  assertEquals("Doe", user.getLastName());
  assertEquals("[email protected]", user.getEmail());

  identityService.deleteUser("johndoe");
}
 
Example 11
Source File: UserResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test getting a single user.
 */
public void testGetUser() throws Exception {
  User savedUser = null;
  try {
    User newUser = identityService.newUser("testuser");
    newUser.setFirstName("Fred");
    newUser.setLastName("McDonald");
    newUser.setEmail("[email protected]");
    identityService.saveUser(newUser);
    savedUser = newUser;

    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())), HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("testuser", responseNode.get("id").textValue());
    assertEquals("Fred", responseNode.get("firstName").textValue());
    assertEquals("McDonald", responseNode.get("lastName").textValue());
    assertEquals("[email protected]", responseNode.get("email").textValue());
    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())));

  } finally {

    // Delete user after test passes or fails
    if (savedUser != null) {
      identityService.deleteUser(savedUser.getId());
    }
  }
}
 
Example 12
Source File: DemoDataGenerator.java    From maven-framework-project with MIT License 5 votes vote down vote up
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) {

        // Following data can already be set by demo setup script

        User user = identityService.newUser(userId);
        user.setFirstName(firstName);
        user.setLastName(lastName);
        user.setPassword(password);
        user.setEmail(email);
        identityService.saveUser(user);

        if (groups != null) {
            for (String group : groups) {
                identityService.createMembership(userId, group);
            }
        }
    }

    // Following data is not set by demo setup script

    // image
    if (imageResource != null) {
        byte[] pictureBytes = IoUtil.readInputStream(this.getClass().getClassLoader().getResourceAsStream(imageResource), null);
        Picture picture = new Picture(pictureBytes, "image/jpeg");
        identityService.setUserPicture(userId, picture);
    }

    // user info
    if (userInfo != null) {
        for (int i = 0; i < userInfo.size(); i += 2) {
            identityService.setUserInfo(userId, userInfo.get(i), userInfo.get(i + 1));
        }
    }

}
 
Example 13
Source File: UserCollectionResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 14
Source File: UserResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Update a user", tags = {"Users"},
    notes="All request values are optional. "
        + "For example, you can only include the firstName attribute in the request body JSON-object, only updating the firstName of the user, leaving all other fields unaffected. "
        + "When an attribute is explicitly included and is set to null, the user-value will be updated to null. "
        + "Example: {\"firstName\" : null} will clear the firstName of the user).")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the user was updated."),
    @ApiResponse(code = 404, message = "Indicates the requested user was not found."),
    @ApiResponse(code = 409, message = "Indicates the requested user was updated simultaneously.")
})
@RequestMapping(value = "/identity/users/{userId}", method = RequestMethod.PUT, produces = "application/json")
public UserResponse updateUser(@ApiParam(name = "userId") @PathVariable String userId, @RequestBody UserRequest userRequest, HttpServletRequest request) {
  User user = getUserFromRequest(userId);
  if (userRequest.isEmailChanged()) {
    user.setEmail(userRequest.getEmail());
  }
  if (userRequest.isFirstNameChanged()) {
    user.setFirstName(userRequest.getFirstName());
  }
  if (userRequest.isLastNameChanged()) {
    user.setLastName(userRequest.getLastName());
  }
  if (userRequest.isPasswordChanged()) {
    user.setPassword(userRequest.getPassword());
  }

  identityService.saveUser(user);

  return restResponseFactory.createUserResponse(user, false);
}
 
Example 15
Source File: UserQueryEscapeClauseTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private User createUser(String id, String firstName, String lastName, String email) {
  User user = identityService.newUser(id);
  user.setFirstName(firstName);
  user.setLastName(lastName);
  user.setEmail(email);
  identityService.saveUser(user);
  return user;
}
 
Example 16
Source File: UserAndGroupInUserTaskTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"chapter5/userAndGroupInUserTask.bpmn"})
public void testUserTaskWithGroupContainsTwoUser() throws Exception {

    // 在setUp()的基础上再添加一个用户然后加入到组deptLeader中
    User user = identityService.newUser("jackchen");
    user.setFirstName("Jack");
    user.setLastName("Chen");
    user.setEmail("[email protected]");
    identityService.saveUser(user);

    // 把用户henryyan加入到组deptLeader中
    identityService.createMembership("jackchen", "deptLeader");

    // 启动流程
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("userAndGroupInUserTask");
    assertNotNull(processInstance);

    // jackchen作为候选人的任务
    Task jackchenTask = taskService.createTaskQuery().taskCandidateUser("jackchen").singleResult();
    assertNotNull(jackchenTask);

    // henryyan作为候选人的任务
    Task henryyanTask = taskService.createTaskQuery().taskCandidateUser("henryyan").singleResult();
    assertNotNull(henryyanTask);

    // jackchen签收任务
    taskService.claim(jackchenTask.getId(), "jackchen");

    // 再次查询用户henryyan是否拥有刚刚的候选任务
    henryyanTask = taskService.createTaskQuery().taskCandidateUser("henryyan").singleResult();
    assertNull(henryyanTask);
}
 
Example 17
Source File: IdmUsersResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/rest/admin/users/{userId}", method = RequestMethod.PUT)
public void updateUserDetails(@PathVariable String userId, @RequestBody UpdateUsersRepresentation updateUsersRepresentation) {
  User user = identityService.createUserQuery().userId(userId).singleResult();
  if (user != null) {
    user.setId(updateUsersRepresentation.getId());
    user.setFirstName(updateUsersRepresentation.getFirstName());
    user.setLastName(updateUsersRepresentation.getLastName());
    user.setEmail(updateUsersRepresentation.getEmail());
    identityService.saveUser(user);
  }
}
 
Example 18
Source File: UserInfoResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test getting info for a user.
 */
public void testGetUserInfo() throws Exception {
  User savedUser = null;
  try {
    User newUser = identityService.newUser("testuser");
    newUser.setFirstName("Fred");
    newUser.setLastName("McDonald");
    newUser.setEmail("[email protected]");
    identityService.saveUser(newUser);
    savedUser = newUser;

    identityService.setUserInfo(newUser.getId(), "key1", "Value 1");

    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1")), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals("key1", responseNode.get("key").textValue());
    assertEquals("Value 1", responseNode.get("value").textValue());

    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1")));

  } finally {

    // Delete user after test passes or fails
    if (savedUser != null) {
      identityService.deleteUser(savedUser.getId());
    }
  }
}
 
Example 19
Source File: UserInfoResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Test getting the collection of info for a user.
 */
public void testGetUserInfoCollection() throws Exception {
  User savedUser = null;
  try {
    User newUser = identityService.newUser("testuser");
    newUser.setFirstName("Fred");
    newUser.setLastName("McDonald");
    newUser.setEmail("[email protected]");
    identityService.saveUser(newUser);
    savedUser = newUser;

    identityService.setUserInfo(newUser.getId(), "key1", "Value 1");
    identityService.setUserInfo(newUser.getId(), "key2", "Value 2");

    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO_COLLECTION, newUser.getId())), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertTrue(responseNode.isArray());
    assertEquals(2, responseNode.size());

    boolean foundFirst = false;
    boolean foundSecond = false;

    for (int i = 0; i < responseNode.size(); i++) {
      ObjectNode info = (ObjectNode) responseNode.get(i);
      assertNotNull(info.get("key").textValue());
      assertNotNull(info.get("url").textValue());

      if (info.get("key").textValue().equals("key1")) {
        foundFirst = true;
        assertTrue(info.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1")));
      } else if (info.get("key").textValue().equals("key2")) {
        assertTrue(info.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key2")));
        foundSecond = true;
      }
    }
    assertTrue(foundFirst);
    assertTrue(foundSecond);

  } finally {

    // Delete user after test passes or fails
    if (savedUser != null) {
      identityService.deleteUser(savedUser.getId());
    }
  }
}
 
Example 20
Source File: UserResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Test updating a single user.
 */
public void testUpdateUser() throws Exception {
  User savedUser = null;
  try {
    User newUser = identityService.newUser("testuser");
    newUser.setFirstName("Fred");
    newUser.setLastName("McDonald");
    newUser.setEmail("[email protected]");
    identityService.saveUser(newUser);
    savedUser = newUser;

    ObjectNode taskUpdateRequest = objectMapper.createObjectNode();
    taskUpdateRequest.put("firstName", "Tijs");
    taskUpdateRequest.put("lastName", "Barrez");
    taskUpdateRequest.put("email", "[email protected]");
    taskUpdateRequest.put("password", "updatedpassword");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()));
    httpPut.setEntity(new StringEntity(taskUpdateRequest.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("testuser", responseNode.get("id").textValue());
    assertEquals("Tijs", responseNode.get("firstName").textValue());
    assertEquals("Barrez", responseNode.get("lastName").textValue());
    assertEquals("[email protected]", responseNode.get("email").textValue());
    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())));

    // Check user is updated in activiti
    newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult();
    assertEquals("Barrez", newUser.getLastName());
    assertEquals("Tijs", newUser.getFirstName());
    assertEquals("[email protected]", newUser.getEmail());
    assertEquals("updatedpassword", newUser.getPassword());

  } finally {

    // Delete user after test fails
    if (savedUser != null) {
      identityService.deleteUser(savedUser.getId());
    }
  }
}