Search in sources :

Example 6 with User

use of com.epam.ta.reportportal.entity.user.User in project commons-dao by reportportal.

the class ProjectUtilsTest method isAssignedNegativeTest.

@Test
void isAssignedNegativeTest() {
    User user = new User();
    ProjectUser projectUser = new ProjectUser();
    projectUser.setUser(user);
    Project project = new Project();
    project.setId(1L);
    projectUser.setProject(project);
    user.setProjects(Sets.newHashSet(projectUser));
    assertFalse(ProjectUtils.isAssignedToProject(user, 2L));
}
Also used : ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) User(com.epam.ta.reportportal.entity.user.User) Test(org.junit.jupiter.api.Test)

Example 7 with User

use of com.epam.ta.reportportal.entity.user.User in project commons-dao by reportportal.

the class ProjectUtilsTest method getProjectWithRecipients.

private Project getProjectWithRecipients() {
    User firstUser = new User();
    firstUser.setLogin(userLoginsToExclude[0]);
    firstUser.setEmail(userEmailsToExclude[0]);
    User secondUser = new User();
    secondUser.setLogin(userLoginsToExclude[1]);
    secondUser.setEmail(userEmailsToExclude[1]);
    User thirdUser = new User();
    thirdUser.setLogin(userLoginsToExclude[2]);
    thirdUser.setEmail(userEmailsToExclude[2]);
    Set<User> users = Sets.newHashSet(firstUser, secondUser, thirdUser);
    Project project = new Project();
    Set<ProjectUser> projectUsers = users.stream().map(u -> {
        ProjectUser projectUser = new ProjectUser();
        projectUser.setUser(u);
        projectUser.setProject(project);
        return projectUser;
    }).collect(Collectors.toSet());
    project.setUsers(projectUsers);
    return project;
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) SenderCase(com.epam.ta.reportportal.entity.project.email.SenderCase) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) User(com.epam.ta.reportportal.entity.user.User) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) ProjectAttributeEnum(com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ProjectType(com.epam.ta.reportportal.entity.enums.ProjectType) Test(org.junit.jupiter.api.Test) Attribute(com.epam.ta.reportportal.entity.attribute.Attribute) Stream(java.util.stream.Stream) IssueGroup(com.epam.ta.reportportal.entity.item.issue.IssueGroup) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) Assertions(org.junit.jupiter.api.Assertions) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) User(com.epam.ta.reportportal.entity.user.User)

Example 8 with User

use of com.epam.ta.reportportal.entity.user.User in project commons-dao by reportportal.

the class ProjectUtilsTest method getTestUser.

private static User getTestUser() {
    User user = new User();
    user.setLogin("test_user");
    return user;
}
Also used : ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) User(com.epam.ta.reportportal.entity.user.User)

Example 9 with User

use of com.epam.ta.reportportal.entity.user.User in project service-authorization by reportportal.

the class DetailsContextMapper method mapUserFromContext.

@Override
@Transactional
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
    UserDetails userDetails = super.mapUserFromContext(ctx, username, authorities);
    User user = ldapUserReplicator.replicateUser(userDetails.getUsername(), ctx, attributes.get());
    return ReportPortalUser.userBuilder().fromUser(user);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with User

use of com.epam.ta.reportportal.entity.user.User in project service-authorization by reportportal.

the class GitHubUserReplicator method replicateUser.

/**
 * Replicates GitHub user to internal database (if does NOT exist). Updates if exist. Creates personal project for that user
 *
 * @param userResource GitHub user to be replicated
 * @param gitHubClient Configured github client
 * @return Internal User representation
 */
@Transactional
public ReportPortalUser replicateUser(UserResource userResource, GitHubClient gitHubClient) {
    String login = normalizeId(userResource.getLogin());
    User user = userRepository.findByLogin(login).map(u -> {
        if (UserType.GITHUB.equals(u.getUserType())) {
            updateUser(u, userResource, gitHubClient);
        } else {
            // if user with such login exists, but it's not GitHub user than throw an exception
            throw new UserSynchronizationException("User with login '" + u.getLogin() + "' already exists");
        }
        return u;
    }).orElseGet(() -> userRepository.save(createUser(userResource, gitHubClient)));
    return ReportPortalUser.userBuilder().fromUser(user);
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) PersonalProjectService(com.epam.ta.reportportal.util.PersonalProjectService) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) StringUtils(org.apache.commons.lang3.StringUtils) Strings(com.google.common.base.Strings) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) UserRole(com.epam.ta.reportportal.entity.user.UserRole) ZoneOffset(java.time.ZoneOffset) UserType(com.epam.ta.reportportal.entity.user.UserType) UserSynchronizationException(com.epam.reportportal.auth.oauth.UserSynchronizationException) Resource(org.springframework.core.io.Resource) BinaryData(com.epam.ta.reportportal.entity.attachment.BinaryData) AbstractUserReplicator(com.epam.reportportal.auth.integration.AbstractUserReplicator) ContentTypeResolver(com.epam.reportportal.commons.ContentTypeResolver) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Optional.ofNullable(java.util.Optional.ofNullable) User(com.epam.ta.reportportal.entity.user.User) UserRepository(com.epam.ta.reportportal.dao.UserRepository) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Objects(java.util.Objects) Metadata(com.epam.ta.reportportal.entity.Metadata) Component(org.springframework.stereotype.Component) EntityUtils.normalizeId(com.epam.ta.reportportal.commons.EntityUtils.normalizeId) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) UserBinaryDataService(com.epam.ta.reportportal.binary.UserBinaryDataService) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) UserSynchronizationException(com.epam.reportportal.auth.oauth.UserSynchronizationException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.epam.ta.reportportal.entity.user.User)22 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)14 ProjectUser (com.epam.ta.reportportal.entity.user.ProjectUser)13 Test (org.junit.jupiter.api.Test)13 BaseTest (com.epam.ta.reportportal.BaseTest)10 Filter (com.epam.ta.reportportal.commons.querygen.Filter)7 Project (com.epam.ta.reportportal.entity.project.Project)7 CompositeFilterCondition (com.epam.ta.reportportal.commons.querygen.CompositeFilterCondition)6 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)6 Transactional (org.springframework.transaction.annotation.Transactional)6 AbstractUserReplicator (com.epam.reportportal.auth.integration.AbstractUserReplicator)4 ContentTypeResolver (com.epam.reportportal.commons.ContentTypeResolver)4 UserBinaryDataService (com.epam.ta.reportportal.binary.UserBinaryDataService)4 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)4 UserRepository (com.epam.ta.reportportal.dao.UserRepository)4 UserRole (com.epam.ta.reportportal.entity.user.UserRole)4 UserType (com.epam.ta.reportportal.entity.user.UserType)4 PersonalProjectService (com.epam.ta.reportportal.util.PersonalProjectService)4 Optional (java.util.Optional)4 Component (org.springframework.stereotype.Component)4