Search in sources :

Example 16 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class ProjectDetailChangeServiceTest method when_change_description_called_changed_project_will_be_stored.

@Test
public void when_change_description_called_changed_project_will_be_stored() {
    /* prepare */
    Project project = new Project();
    project.id = PROJECT_ID;
    project.description = "old";
    project.owner = new User();
    String json = "{\n" + "    \"description\": \"new\"\n" + "}";
    ProjectJsonInput withNewDescription = new ProjectJsonInput();
    withNewDescription = withNewDescription.fromJSON(json);
    when(projectRepository.findOrFailProject(PROJECT_ID)).thenReturn(project);
    when(transactionService.saveInOwnTransaction(project)).thenReturn(project);
    /* execute */
    serviceToTest.changeProjectDescription(PROJECT_ID, withNewDescription);
    /* test */
    verify(transactionService).saveInOwnTransaction(project);
}
Also used : User(com.mercedesbenz.sechub.domain.administration.user.User) Test(org.junit.Test)

Example 17 with User

use of com.mercedesbenz.sechub.domain.administration.user.User 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)

Example 18 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class ProjectChangeOwnerService method changeProjectOwnerAndReturnPreviousOwner.

private User changeProjectOwnerAndReturnPreviousOwner(Project project, User newOwner) {
    User previousOwner = project.owner;
    project.owner = newOwner;
    newOwner.getOwnedProjects().add(project);
    previousOwner.getOwnedProjects().remove(project);
    return previousOwner;
}
Also used : User(com.mercedesbenz.sechub.domain.administration.user.User)

Example 19 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class ProjectChangeOwnerService method changeProjectOwner.

/* @formatter:off */
@UseCaseAdminChangesProjectOwner(@Step(number = 2, name = "Change project owner", description = "The service will set the user as the owner of the project. If user does not have ROLE_OWNER it will obtain it. The old owner will loose project ownership."))
public /* @formatter:on */
void changeProjectOwner(String newOnwerUserId, String projectId) {
    LOG.info("User {} triggers project owner change - user:{} to project:{}", userContextService.getUserId(), logSanitizer.sanitize(newOnwerUserId, 30), logSanitizer.sanitize(projectId, 30));
    assertion.assertIsValidUserId(newOnwerUserId);
    assertion.assertIsValidProjectId(projectId);
    Project project = projectRepository.findOrFailProject(projectId);
    User newOwner = userRepository.findOrFailUser(newOnwerUserId);
    if (project.owner.equals(newOwner)) {
        throw new AlreadyExistsException("User already assigned in the role as owner to this project!");
    }
    User previousOwner = changeProjectOwnerAndReturnPreviousOwner(project, newOwner);
    transactionService.saveInOwnTransaction(project, newOwner, previousOwner);
    sendOwnerChangedForProjectEvent(project, previousOwner, newOwner);
    sendRequestOwnerRoleRecalculation(newOwner);
    sendRequestOwnerRoleRecalculation(previousOwner);
}
Also used : User(com.mercedesbenz.sechub.domain.administration.user.User) AlreadyExistsException(com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException) UseCaseAdminChangesProjectOwner(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminChangesProjectOwner)

Example 20 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class JobCancelService method buildMessage.

private JobMessage buildMessage(UUID jobUUID) {
    JobMessage message = new JobMessage();
    message.setJobUUID(jobUUID);
    JobInformation probe = new JobInformation();
    probe.setJobUUID(jobUUID);
    Example<JobInformation> example = Example.of(probe);
    Optional<JobInformation> optJobInfo = repository.findOne(example);
    if (!optJobInfo.isPresent()) {
        LOG.warn("Did not found job information, so not able to resolve owner email address");
        return message;
    }
    JobInformation jobInfo = optJobInfo.get();
    if (jobInfo.owner == null) {
        LOG.warn("Did not found owner inside job information, so not able to resolve owner email address");
        return message;
    }
    Optional<User> optUser = userRepository.findById(jobInfo.owner);
    if (!optUser.isPresent()) {
        LOG.warn("Did not found owner {} inside user repo, so not able to resolve owner email address", jobInfo.owner);
        return message;
    }
    message.setOwner(jobInfo.owner);
    message.setOwnerEmailAddress(optUser.get().getEmailAdress());
    return message;
}
Also used : User(com.mercedesbenz.sechub.domain.administration.user.User) JobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage)

Aggregations

User (com.mercedesbenz.sechub.domain.administration.user.User)20 Test (org.junit.Test)11 AlreadyExistsException (com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException)4 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Project (com.mercedesbenz.sechub.domain.administration.project.Project)3 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)3 UseCaseAdminCreatesProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject)3 UseCaseAdminDeleteProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject)3 UseCaseAdminAssignsUserToProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject)3 UseCaseAdminUnassignsUserFromProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject)3 URI (java.net.URI)3 LinkedHashSet (java.util.LinkedHashSet)3 ProjectDetailInformation (com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation)2 ProjectMetaDataEntity (com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity)2 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)2 JobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage)2 ProjectMessage (com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage)2 ProjectMetaData (com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData)1 UserDetailInformation (com.mercedesbenz.sechub.domain.administration.user.UserDetailInformation)1