Search in sources :

Example 1 with User

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

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

Example 3 with User

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

Example 4 with User

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

Example 5 with User

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

Aggregations

User (com.epam.ta.reportportal.database.entity.user.User)20 Test (org.junit.Test)5 Query (org.springframework.data.mongodb.core.query.Query)5 UserSynchronizationException (com.epam.reportportal.auth.oauth.UserSynchronizationException)3 BinaryData (com.epam.ta.reportportal.database.BinaryData)3 PageImpl (org.springframework.data.domain.PageImpl)3 AbstractUserReplicator (com.epam.reportportal.auth.integration.AbstractUserReplicator)2 BaseDaoTest (com.epam.ta.reportportal.BaseDaoTest)2 EntityUtils.normalizeId (com.epam.ta.reportportal.commons.EntityUtils.normalizeId)2 DataStorage (com.epam.ta.reportportal.database.DataStorage)2 ProjectRepository (com.epam.ta.reportportal.database.dao.ProjectRepository)2 UserRepository (com.epam.ta.reportportal.database.dao.UserRepository)2 UserRole (com.epam.ta.reportportal.database.entity.user.UserRole)2 UserType (com.epam.ta.reportportal.database.entity.user.UserType)2 PersonalProjectService (com.epam.ta.reportportal.database.personal.PersonalProjectService)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 AuthUtils (com.epam.reportportal.auth.AuthUtils)1 SynchronizationAttributes (com.epam.reportportal.auth.store.entity.ldap.SynchronizationAttributes)1