Search in sources :

Example 1 with UseCaseAdminAssignsUserToProject

use of com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject in project sechub by mercedes-benz.

the class ProjectAssignUserService method assignUserToProject.

/* @formatter:off */
@UseCaseAdminAssignsUserToProject(@Step(number = 2, name = "Assign user", description = "The service will add the user to the project. If user does not have ROLE_USER it will obtain it"))
public /* @formatter:on */
void assignUserToProject(String userId, String projectId) {
    LOG.info("User {} triggers assignment of user:{} to project:{}", userContextService.getUserId(), logSanitizer.sanitize(userId, 30), logSanitizer.sanitize(projectId, 30));
    assertion.assertIsValidUserId(userId);
    assertion.assertIsValidProjectId(projectId);
    Project project = projectRepository.findOrFailProject(projectId);
    User user = userRepository.findOrFailUser(userId);
    if (!project.getUsers().add(user)) {
        throw new AlreadyExistsException("User already assigned to this project!");
    }
    user.getProjects().add(project);
    project.getUsers().add(user);
    transactionService.saveInOwnTransaction(project, user);
    sendUserAddedToProjectEvent(projectId, user);
    sendRequestUserRoleRecalculation(user);
}
Also used : UseCaseAdminAssignsUserToProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject) User(com.mercedesbenz.sechub.domain.administration.user.User) AlreadyExistsException(com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException) UseCaseAdminAssignsUserToProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject)

Aggregations

User (com.mercedesbenz.sechub.domain.administration.user.User)1 AlreadyExistsException (com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException)1 UseCaseAdminAssignsUserToProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject)1