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