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