Java Code Examples for org.flowable.idm.api.User#setTenantId()

The following examples show how to use org.flowable.idm.api.User#setTenantId() . 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: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateUser() {
    // First, create a new user
    User user = identityService.newUser("johndoe");
    user.setFirstName("John");
    user.setLastName("Doe");
    user.setEmail("[email protected]");
    user.setTenantId("originalTenantId");
    identityService.saveUser(user);

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

    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertThat(user.getFirstName()).isEqualTo("Jane");
    assertThat(user.getLastName()).isEqualTo("Donnel");
    assertThat(user.getEmail()).isEqualTo("[email protected]");
    assertThat(user.getTenantId()).isEqualTo("flowable");

    identityService.deleteUser(user.getId());
}
 
Example 2
Source File: UserServiceImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void updateUserDetails(String userId, String firstName, String lastName, String email, String tenantId) {
    User user = identityService.createUserQuery().userId(userId).singleResult();
    if (user != null) {
        user.setFirstName(firstName);
        user.setLastName(lastName);
        user.setEmail(email);
        user.setTenantId(tenantId);
        identityService.saveUser(user);
    }
}
 
Example 3
Source File: UserServiceImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public User createNewUser(String id, String firstName, String lastName, String email, String password, String tenantId) {
    if (StringUtils.isBlank(id) ||
        StringUtils.isBlank(password) ||
        StringUtils.isBlank(firstName)) {
        throw new BadRequestException("Id, password and first name are required");
    }

    if (StringUtils.isNotBlank(email) && identityService.createUserQuery().userEmail(email).count() > 0) {
        throw new ConflictingRequestException("User already registered", "ACCOUNT.SIGNUP.ERROR.ALREADY-REGISTERED");
    }
    
    if (identityService.createUserQuery().userId(id).count() > 0) {
        throw new ConflictingRequestException("User already registered", "ACCOUNT.SIGNUP.ERROR.ALREADY-REGISTERED");
    }

    User user = identityService.newUser(id);
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    user.setTenantId(tenantId);
    identityService.saveUser(user);

    User savedUser = identityService.createUserQuery().userId(id).singleResult();
    savedUser.setPassword(password);
    identityService.updateUserPassword(savedUser);

    return user;
}
 
Example 4
Source File: UserCollectionResource.java    From flowable-engine 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.")

})
@PostMapping(value = "/identity/users", produces = "application/json")
public UserResponse createUser(@RequestBody UserRequest userRequest, HttpServletRequest request, HttpServletResponse response) {
    if (userRequest.getId() == null) {
        throw new FlowableIllegalArgumentException("Id cannot be null.");
    }
    
    if (restApiInterceptor != null) {
        restApiInterceptor.createUser(userRequest);
    }

    // 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 FlowableConflictException("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.setDisplayName(userRequest.getDisplayName());
    created.setPassword(userRequest.getPassword());
    created.setTenantId(userRequest.getTenantId());
    identityService.saveUser(created);

    response.setStatus(HttpStatus.CREATED.value());

    return restResponseFactory.createUserResponse(created, true);
}
 
Example 5
Source File: UserQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private User createUser(String id, String firstName, String lastName, String email, String tenantId) {
    User user = identityService.newUser(id);
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    user.setTenantId(tenantId);
    identityService.saveUser(user);
    return user;
}