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);
}
Aggregations