use of com.epam.ta.reportportal.database.entity.user.User in project commons-dao by reportportal.
the class UserRepositoryCustomImpl method findUserPhoto.
@Override
public BinaryData findUserPhoto(String login) {
BinaryData photo = null;
Query q = query(where(User.LOGIN).is(login));
q.fields().include(User.PHOTO_ID);
User user = mongoOperations.findOne(q, User.class);
if (user != null && user.getPhotoId() != null)
photo = dataStorage.fetchData(user.getPhotoId());
if (null == photo) {
// Get default photo avatar (batman)
photo = dataStorage.findByFilename(photoFilename(Constants.NONAME_USER.toString())).get(0);
}
return photo;
}
use of com.epam.ta.reportportal.database.entity.user.User in project commons-dao by reportportal.
the class UserRepositoryCustomImpl method searchForUser.
@Override
public Page<User> searchForUser(String term, Pageable pageable) {
Query query = buildSearchUserQuery(term, pageable);
List<User> users = mongoOperations.find(query, User.class);
return new PageImpl<>(users, pageable, mongoOperations.count(query, User.class));
}
use of com.epam.ta.reportportal.database.entity.user.User in project commons-dao by reportportal.
the class CascadeDeleteUserTrigger method onBeforeDelete.
@Override
public void onBeforeDelete(BeforeDeleteEvent<User> event) {
// don't use here cacheable methods
final Object loginObject = event.getDBObject().get("login");
if (loginObject == null) {
return;
}
String login = loginObject.toString();
User user = userRepository.findPhotoIdByLogin(login);
removeNonsharedItems(login);
userPreferenceRepository.deleteByUserName(login);
if (!StringUtils.isEmpty(user.getPhotoId())) {
dataStorage.deleteData(user.getPhotoId());
}
removePersonalProject(user.getId());
clearProject(login);
}
use of com.epam.ta.reportportal.database.entity.user.User in project commons-dao by reportportal.
the class DeleteProjectListener method updateDefaultProject.
private void updateDefaultProject(String projectName) {
if (null == projectName) {
return;
}
List<User> usersForUpdate = userRepository.findByDefaultProject(projectName);
if (null == usersForUpdate) {
return;
}
for (User user : usersForUpdate) {
user.setDefaultProject(projectRepository.findPersonalProjectName(user.getId()).orElse(null));
}
userRepository.save(usersForUpdate);
}
use of com.epam.ta.reportportal.database.entity.user.User in project commons-dao by reportportal.
the class UserRepositoryTest method replaceUserTest.
@Test
public void replaceUserTest() throws IOException {
String username = RandomStringUtils.randomAlphabetic(5);
User user = new User();
user.setLogin(username);
user.setEmail(username + "@epam.com");
user.setType(UserType.INTERNAL);
userRepository.save(user);
BinaryData binaryData = new BinaryData(MediaType.IMAGE_JPEG_VALUE, photoResource.getFile().length(), photoResource.getInputStream());
userRepository.replaceUserPhoto(user.getLogin(), binaryData);
/* add one more data with such filename */
dataStorage.saveData(binaryData, photoFilename(username));
Assert.assertEquals("Incorrect count of files", 2, dataStorage.findByFilename(photoFilename(username)).size());
/* replace photo again */
userRepository.replaceUserPhoto(user.getLogin(), binaryData);
/* make sure duplicates are removed */
Assert.assertEquals("Incorrect count of files", 1, dataStorage.findByFilename(photoFilename(username)).size());
}
Aggregations