use of com.epam.ta.reportportal.commons.Preconditions.contains in project service-api by reportportal.
the class UpdateProjectHandlerImpl method assignUsers.
@Override
public OperationCompletionRS assignUsers(String projectName, AssignUsersRQ assignUsersRQ, ReportPortalUser user) {
if (UserRole.ADMINISTRATOR.equals(user.getUserRole())) {
Project project = projectRepository.findByName(normalizeId(projectName)).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, normalizeId(projectName)));
List<String> assignedUsernames = project.getUsers().stream().map(u -> u.getUser().getLogin()).collect(toList());
assignUsersRQ.getUserNames().forEach((name, role) -> {
ProjectRole projectRole = ProjectRole.forName(role).orElseThrow(() -> new ReportPortalException(ROLE_NOT_FOUND, role));
assignUser(name, projectRole, assignedUsernames, project);
});
} else {
expect(assignUsersRQ.getUserNames().keySet(), not(Preconditions.contains(equalTo(user.getUsername())))).verify(UNABLE_ASSIGN_UNASSIGN_USER_TO_PROJECT, "User should not assign himself to project.");
ReportPortalUser.ProjectDetails projectDetails = projectExtractor.extractProjectDetails(user, projectName);
Project project = projectRepository.findById(projectDetails.getProjectId()).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, normalizeId(projectName)));
List<String> assignedUsernames = project.getUsers().stream().map(u -> u.getUser().getLogin()).collect(toList());
assignUsersRQ.getUserNames().forEach((name, role) -> {
ProjectRole projectRole = ProjectRole.forName(role).orElseThrow(() -> new ReportPortalException(ROLE_NOT_FOUND, role));
ProjectRole modifierRole = projectDetails.getProjectRole();
expect(modifierRole.sameOrHigherThan(projectRole), BooleanUtils::isTrue).verify(ACCESS_DENIED);
assignUser(name, projectRole, assignedUsernames, project);
});
}
return new OperationCompletionRS("User(s) with username='" + assignUsersRQ.getUserNames().keySet() + "' was successfully assigned to project='" + normalizeId(projectName) + "'");
}
Aggregations