Search in sources :

Example 1 with Metadata

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

the class UserRepositoryTest method createUserTest.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
void createUserTest() {
    User reg = new User();
    reg.setEmail("email.com");
    reg.setFullName("test");
    reg.setLogin("created");
    reg.setPassword("new");
    reg.setUserType(UserType.INTERNAL);
    reg.setRole(UserRole.USER);
    Map<String, Object> map = new HashMap<>();
    map.put("last_login", new Date());
    reg.setMetadata(new Metadata(map));
    Project defaultProject = projectRepository.findByName("superadmin_personal").get();
    Set<ProjectUser> projectUsers = defaultProject.getUsers();
    projectUsers.add(new ProjectUser().withProjectRole(ProjectRole.CUSTOMER).withUser(reg).withProject(defaultProject));
    defaultProject.setUsers(projectUsers);
    userRepository.save(reg);
    final Optional<User> created = userRepository.findByLogin("created");
    assertTrue(created.isPresent());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) Metadata(com.epam.ta.reportportal.entity.Metadata) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 2 with Metadata

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

the class UserBinaryDataServiceImpl method saveUserPhoto.

@Override
public void saveUserPhoto(User user, InputStream inputStream, String contentType) {
    try {
        byte[] data = StreamUtils.copyToByteArray(inputStream);
        try (InputStream userPhotoCopy = new ByteArrayInputStream(data);
            InputStream thumbnailCopy = new ByteArrayInputStream(data)) {
            user.setAttachment(dataStoreService.save(Paths.get(ROOT_USER_PHOTO_DIR, user.getLogin()).toString(), userPhotoCopy));
            user.setAttachmentThumbnail(dataStoreService.saveThumbnail(buildThumbnailFileName(ROOT_USER_PHOTO_DIR, user.getLogin()), thumbnailCopy));
        }
        ofNullable(user.getMetadata()).orElseGet(() -> new Metadata(Maps.newHashMap())).getMetadata().put(ATTACHMENT_CONTENT_TYPE, contentType);
    } catch (IOException e) {
        LOGGER.error("Unable to save user photo", e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Metadata(com.epam.ta.reportportal.entity.Metadata) IOException(java.io.IOException)

Example 3 with Metadata

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

the class PersonalProjectService method generatePersonalProject.

/**
 * Generates personal project for provided user
 *
 * @param user User project should be created for
 * @return Built Project object
 */
public Project generatePersonalProject(User user) {
    Project project = new Project();
    project.setName(generatePersonalProjectName(user.getLogin()));
    project.setCreationDate(Date.from(ZonedDateTime.now().toInstant()));
    project.setProjectType(ProjectType.PERSONAL);
    ProjectUser projectUser = new ProjectUser().withUser(user).withProjectRole(ProjectRole.PROJECT_MANAGER).withProject(project);
    project.setUsers(Sets.newHashSet(projectUser));
    project.setMetadata(new Metadata(Collections.singletonMap("additional_info", "Personal project of " + (isNullOrEmpty(user.getFullName()) ? user.getLogin() : user.getFullName()))));
    project.setProjectAttributes(defaultProjectAttributes(project, attributeRepository.getDefaultProjectAttributes()));
    project.setProjectIssueTypes(defaultIssueTypes(project, issueTypeRepository.getDefaultIssueTypes()));
    return project;
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) Metadata(com.epam.ta.reportportal.entity.Metadata)

Example 4 with Metadata

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

the class GitHubUserReplicator method synchronizeUser.

public User synchronizeUser(String accessToken) {
    GitHubClient gitHubClient = GitHubClient.withAccessToken(accessToken);
    UserResource userResource = gitHubClient.getUser();
    Optional<User> userOptional = userRepository.findByLogin(normalizeId(userResource.getLogin()));
    BusinessRule.expect(userOptional, Optional::isPresent).verify(ErrorType.USER_NOT_FOUND, userResource.getLogin());
    User user = userOptional.get();
    BusinessRule.expect(user.getUserType(), userType -> Objects.equals(userType, UserType.GITHUB)).verify(ErrorType.INCORRECT_AUTHENTICATION_TYPE, "User '" + userResource.getLogin() + "' is not GitHUB user");
    if (StringUtils.isNotBlank(userResource.getName())) {
        user.setFullName(userResource.getName());
    }
    String email = userResource.getEmail();
    if (Strings.isNullOrEmpty(email)) {
        email = retrieveEmail(gitHubClient).orElseThrow(() -> new UserSynchronizationException("User 'email' has not been provided"));
    }
    email = normalizeId(email);
    if (!user.getEmail().equals(email)) {
        checkEmail(email);
        user.setEmail(email);
    }
    Metadata metadata = ofNullable(user.getMetadata()).orElse(new Metadata(Maps.newHashMap()));
    metadata.getMetadata().put("synchronizationDate", Date.from(ZonedDateTime.now(ZoneOffset.UTC).toInstant()));
    user.setMetadata(metadata);
    uploadAvatar(gitHubClient, user, userResource.getAvatarUrl());
    userRepository.save(user);
    return 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) Metadata(com.epam.ta.reportportal.entity.Metadata)

Aggregations

Metadata (com.epam.ta.reportportal.entity.Metadata)4 Project (com.epam.ta.reportportal.entity.project.Project)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 ProjectUser (com.epam.ta.reportportal.entity.user.ProjectUser)2 User (com.epam.ta.reportportal.entity.user.User)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 AbstractUserReplicator (com.epam.reportportal.auth.integration.AbstractUserReplicator)1 UserSynchronizationException (com.epam.reportportal.auth.oauth.UserSynchronizationException)1 ContentTypeResolver (com.epam.reportportal.commons.ContentTypeResolver)1 BaseTest (com.epam.ta.reportportal.BaseTest)1 UserBinaryDataService (com.epam.ta.reportportal.binary.UserBinaryDataService)1 EntityUtils.normalizeId (com.epam.ta.reportportal.commons.EntityUtils.normalizeId)1 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)1 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)1 UserRepository (com.epam.ta.reportportal.dao.UserRepository)1 BinaryData (com.epam.ta.reportportal.entity.attachment.BinaryData)1 UserRole (com.epam.ta.reportportal.entity.user.UserRole)1 UserType (com.epam.ta.reportportal.entity.user.UserType)1 PersonalProjectService (com.epam.ta.reportportal.util.PersonalProjectService)1