use of com.epam.ta.reportportal.database.BinaryData 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.BinaryData in project commons-dao by reportportal.
the class LogRepositoryTest method addLogWithBinaryData.
@Before
public void addLogWithBinaryData() {
Map<String, String> metaInfo = new HashMap<>();
metaInfo.put("project", "EPMRPP");
BinaryData binaryData = new BinaryData(CONTENT_TYPE, 64807L, this.getClass().getClassLoader().getResourceAsStream("meh.jpg"));
filename = dataStorage.saveData(binaryData, "filename", metaInfo);
thumbnail = dataStorage.saveData(binaryData, "thumbnail", metaInfo);
BinaryContent binaryContent = new BinaryContent(filename, thumbnail, CONTENT_TYPE);
Log log = new Log();
log.setBinaryContent(binaryContent);
saved = logRepository.save(log);
}
use of com.epam.ta.reportportal.database.BinaryData 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());
}
use of com.epam.ta.reportportal.database.BinaryData in project commons-dao by reportportal.
the class DeleteProjectListenerTest method log.
private Log log(String itemId) {
final Log log = new Log();
log.setTestItemRef(itemId);
Map<String, String> metaInfo = new HashMap<>();
metaInfo.put("project", "test_project");
BinaryData binaryData = new BinaryData(CONTENT_TYPE, 64807L, this.getClass().getClassLoader().getResourceAsStream("meh.jpg"));
String filename = dataStorage.saveData(binaryData, "filename", metaInfo);
String thumbnail = dataStorage.saveData(binaryData, "thumbnail", metaInfo);
BinaryContent binaryContent = new BinaryContent(filename, thumbnail, CONTENT_TYPE);
log.setBinaryContent(binaryContent);
logRepository.save(log);
return log;
}
use of com.epam.ta.reportportal.database.BinaryData in project service-authorization by reportportal.
the class GitHubUserReplicator method uploadAvatar.
private String uploadAvatar(GitHubClient gitHubClient, String login, Object avatarUrl) {
String photoId = null;
if (null != avatarUrl) {
ResponseEntity<Resource> photoRs = gitHubClient.downloadResource(avatarUrl.toString());
try (InputStream photoStream = photoRs.getBody().getInputStream()) {
BinaryData photo = new BinaryData(photoRs.getHeaders().getContentType().toString(), photoRs.getBody().contentLength(), photoStream);
photoId = uploadPhoto(login, photo);
} catch (IOException e) {
LOGGER.error("Unable to load photo for user {}", login);
}
}
return photoId;
}
Aggregations