Search in sources :

Example 1 with BinaryData

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;
}
Also used : User(com.epam.ta.reportportal.database.entity.user.User) Query(org.springframework.data.mongodb.core.query.Query) BinaryData(com.epam.ta.reportportal.database.BinaryData)

Example 2 with BinaryData

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);
}
Also used : HashMap(java.util.HashMap) Log(com.epam.ta.reportportal.database.entity.Log) BinaryData(com.epam.ta.reportportal.database.BinaryData) BinaryContent(com.epam.ta.reportportal.database.entity.BinaryContent) Before(org.junit.Before)

Example 3 with BinaryData

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());
}
Also used : User(com.epam.ta.reportportal.database.entity.user.User) BinaryData(com.epam.ta.reportportal.database.BinaryData) BaseDaoTest(com.epam.ta.reportportal.BaseDaoTest) Test(org.junit.Test)

Example 4 with BinaryData

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;
}
Also used : HashMap(java.util.HashMap) BinaryData(com.epam.ta.reportportal.database.BinaryData)

Example 5 with BinaryData

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;
}
Also used : InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) BinaryData(com.epam.ta.reportportal.database.BinaryData) IOException(java.io.IOException)

Aggregations

BinaryData (com.epam.ta.reportportal.database.BinaryData)5 User (com.epam.ta.reportportal.database.entity.user.User)2 HashMap (java.util.HashMap)2 BaseDaoTest (com.epam.ta.reportportal.BaseDaoTest)1 BinaryContent (com.epam.ta.reportportal.database.entity.BinaryContent)1 Log (com.epam.ta.reportportal.database.entity.Log)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Resource (org.springframework.core.io.Resource)1 Query (org.springframework.data.mongodb.core.query.Query)1