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