Search in sources :

Example 1 with UserType

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

the class GitHubUserReplicator method synchronizeUser.

public User synchronizeUser(String accessToken) {
    GitHubClient gitHubClient = GitHubClient.withAccessToken(accessToken);
    UserResource userInfo = gitHubClient.getUser();
    User user = userRepository.findOne(normalizeId(userInfo.login));
    BusinessRule.expect(user, Objects::nonNull).verify(ErrorType.USER_NOT_FOUND, userInfo.login);
    BusinessRule.expect(user.getType(), userType -> Objects.equals(userType, UserType.GITHUB)).verify(ErrorType.INCORRECT_AUTHENTICATION_TYPE, "User '" + userInfo.login + "' is not GitHUB user");
    user.setFullName(userInfo.name);
    user.getMetaInfo().setSynchronizationDate(Date.from(ZonedDateTime.now().toInstant()));
    String newPhotoId = uploadAvatar(gitHubClient, userInfo.login, userInfo.avatarUrl);
    if (!Strings.isNullOrEmpty(newPhotoId)) {
        dataStorage.deleteData(user.getPhotoId());
        user.setPhotoId(newPhotoId);
    }
    userRepository.save(user);
    return user;
}
Also used : AbstractUserReplicator(com.epam.reportportal.auth.integration.AbstractUserReplicator) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) DataStorage(com.epam.ta.reportportal.database.DataStorage) Date(java.util.Date) PersonalProjectService(com.epam.ta.reportportal.database.personal.PersonalProjectService) ZonedDateTime(java.time.ZonedDateTime) ProjectRepository(com.epam.ta.reportportal.database.dao.ProjectRepository) UserRepository(com.epam.ta.reportportal.database.dao.UserRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) BinaryData(com.epam.ta.reportportal.database.BinaryData) UserRole(com.epam.ta.reportportal.database.entity.user.UserRole) Objects(java.util.Objects) Strings(com.google.common.base.Strings) Component(org.springframework.stereotype.Component) EntityUtils.normalizeId(com.epam.ta.reportportal.commons.EntityUtils.normalizeId) User(com.epam.ta.reportportal.database.entity.user.User) ResponseEntity(org.springframework.http.ResponseEntity) UserSynchronizationException(com.epam.reportportal.auth.oauth.UserSynchronizationException) UserType(com.epam.ta.reportportal.database.entity.user.UserType) Resource(org.springframework.core.io.Resource) InputStream(java.io.InputStream) User(com.epam.ta.reportportal.database.entity.user.User)

Aggregations

AbstractUserReplicator (com.epam.reportportal.auth.integration.AbstractUserReplicator)1 UserSynchronizationException (com.epam.reportportal.auth.oauth.UserSynchronizationException)1 EntityUtils.normalizeId (com.epam.ta.reportportal.commons.EntityUtils.normalizeId)1 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)1 BinaryData (com.epam.ta.reportportal.database.BinaryData)1 DataStorage (com.epam.ta.reportportal.database.DataStorage)1 ProjectRepository (com.epam.ta.reportportal.database.dao.ProjectRepository)1 UserRepository (com.epam.ta.reportportal.database.dao.UserRepository)1 User (com.epam.ta.reportportal.database.entity.user.User)1 UserRole (com.epam.ta.reportportal.database.entity.user.UserRole)1 UserType (com.epam.ta.reportportal.database.entity.user.UserType)1 PersonalProjectService (com.epam.ta.reportportal.database.personal.PersonalProjectService)1 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)1 Strings (com.google.common.base.Strings)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ZonedDateTime (java.time.ZonedDateTime)1 Date (java.util.Date)1 Objects (java.util.Objects)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1