@Test public void getShared() { final Set<T> results = service.getShared(); assertThat(results, hasSize(3)); final Set<T> canEditTrueResults = results.stream() .filter(SavedSearch::isCanEdit) .collect(Collectors.toSet()); assertThat(canEditTrueResults, hasSize(1)); }
@Override public Set<T> getShared() { final Long userId = userEntityAuditorAware.getCurrentAuditor().getUserId(); final Set<SharedToUser> permissions = sharedToUserRepository.findByUserId(userId, type); final Set<Long> uniqueSavedSearchIds = new HashSet<Long>(); final Set<T> userShared = permissions.stream() .map(sharedToUser -> { uniqueSavedSearchIds.add(sharedToUser.getSavedSearch().getId()); return type.cast(sharedToUser.getSavedSearch().toBuilder() .setCanEdit(sharedToUser.getCanEdit()) .build()); }) .collect(toSet()); final LinkedHashSet<T> shared = new LinkedHashSet<>(userShared); for(SharedToEveryone globalShare : sharedToEveryoneRepository.findActiveByType(type)) { final SavedSearch<?, ?> savedSearch = globalShare.getSavedSearch(); if (!userId.equals(savedSearch.getUser().getUserId()) && !uniqueSavedSearchIds.contains(savedSearch.getId())) { shared.add(type.cast(savedSearch)); } } return augmentOutputWithDisplayNames(shared); }
AbstractSavedSearchService implements SavedSearchService<T, B> { @Override public Set<T> getShared() { final Long userId = userEntityAuditorAware.getCurrentAuditor().getUserId(); final Set<SharedToUser> permissions = sharedToUserRepository.findByUserId(userId, type); final Set<Long> uniqueSavedSearchIds = new HashSet<Long>(); final Set<T> userShared = permissions.stream() .map(sharedToUser -> { uniqueSavedSearchIds.add(sharedToUser.getSavedSearch().getId()); return type.cast(sharedToUser.getSavedSearch().toBuilder() .setCanEdit(sharedToUser.getCanEdit()) .build()); }) .collect(toSet()); final LinkedHashSet<T> shared = new LinkedHashSet<>(userShared); for(SharedToEveryone globalShare : sharedToEveryoneRepository.findActiveByType(type)) { final SavedSearch<?, ?> savedSearch = globalShare.getSavedSearch(); if (!userId.equals(savedSearch.getUser().getUserId()) && !uniqueSavedSearchIds.contains(savedSearch.getId())) { shared.add(type.cast(savedSearch)); } } return augmentOutputWithDisplayNames(shared); } }
AbstractSavedSearchService implements SavedSearchService<T, B> { @Override public Set<T> getShared() { final Long userId = userEntityAuditorAware.getCurrentAuditor().getUserId(); final Set<SharedToUser> permissions = sharedToUserRepository.findByUserId(userId, type); final Set<Long> uniqueSavedSearchIds = new HashSet<Long>(); final Set<T> userShared = permissions.stream() .map(sharedToUser -> { uniqueSavedSearchIds.add(sharedToUser.getSavedSearch().getId()); return type.cast(sharedToUser.getSavedSearch().toBuilder() .setCanEdit(sharedToUser.getCanEdit()) .build()); }) .collect(toSet()); final LinkedHashSet<T> shared = new LinkedHashSet<>(userShared); for(SharedToEveryone globalShare : sharedToEveryoneRepository.findActiveByType(type)) { final SavedSearch<?, ?> savedSearch = globalShare.getSavedSearch(); if (!userId.equals(savedSearch.getUser().getUserId()) && !uniqueSavedSearchIds.contains(savedSearch.getId())) { shared.add(type.cast(savedSearch)); } } return augmentOutputWithDisplayNames(shared); } protected  AbstractSavedSearchService(final SavedSearchRepository<T, B> crudRepository,
                                         final SharedToUserRepository sharedToUserRepository,
                                         final SharedToEveryoneRepository sharedToEveryoneRepository,
                                         final AuditorAware<UserEntity> userEntityAuditorAware,
                                         final TagNameFactory tagNameFactory,
                                         final Class<T> type); }
AbstractSavedSearchService implements SavedSearchService<T, B> { @Override public Set<T> getShared() { final Long userId = userEntityAuditorAware.getCurrentAuditor().getUserId(); final Set<SharedToUser> permissions = sharedToUserRepository.findByUserId(userId, type); final Set<Long> uniqueSavedSearchIds = new HashSet<Long>(); final Set<T> userShared = permissions.stream() .map(sharedToUser -> { uniqueSavedSearchIds.add(sharedToUser.getSavedSearch().getId()); return type.cast(sharedToUser.getSavedSearch().toBuilder() .setCanEdit(sharedToUser.getCanEdit()) .build()); }) .collect(toSet()); final LinkedHashSet<T> shared = new LinkedHashSet<>(userShared); for(SharedToEveryone globalShare : sharedToEveryoneRepository.findActiveByType(type)) { final SavedSearch<?, ?> savedSearch = globalShare.getSavedSearch(); if (!userId.equals(savedSearch.getUser().getUserId()) && !uniqueSavedSearchIds.contains(savedSearch.getId())) { shared.add(type.cast(savedSearch)); } } return augmentOutputWithDisplayNames(shared); } protected  AbstractSavedSearchService(final SavedSearchRepository<T, B> crudRepository,
                                         final SharedToUserRepository sharedToUserRepository,
                                         final SharedToEveryoneRepository sharedToEveryoneRepository,
                                         final AuditorAware<UserEntity> userEntityAuditorAware,
                                         final TagNameFactory tagNameFactory,
                                         final Class<T> type); @Override Set<T> getOwned(); @Override Set<T> getShared(); @Override T get(final long id); @Override T create(final T search); @Override T update(final T search); @Override T updateShared(final T search); @Override void deleteById(final long id); @Override T getDashboardSearch(final long id); }
AbstractSavedSearchService implements SavedSearchService<T, B> { @Override public Set<T> getShared() { final Long userId = userEntityAuditorAware.getCurrentAuditor().getUserId(); final Set<SharedToUser> permissions = sharedToUserRepository.findByUserId(userId, type); final Set<Long> uniqueSavedSearchIds = new HashSet<Long>(); final Set<T> userShared = permissions.stream() .map(sharedToUser -> { uniqueSavedSearchIds.add(sharedToUser.getSavedSearch().getId()); return type.cast(sharedToUser.getSavedSearch().toBuilder() .setCanEdit(sharedToUser.getCanEdit()) .build()); }) .collect(toSet()); final LinkedHashSet<T> shared = new LinkedHashSet<>(userShared); for(SharedToEveryone globalShare : sharedToEveryoneRepository.findActiveByType(type)) { final SavedSearch<?, ?> savedSearch = globalShare.getSavedSearch(); if (!userId.equals(savedSearch.getUser().getUserId()) && !uniqueSavedSearchIds.contains(savedSearch.getId())) { shared.add(type.cast(savedSearch)); } } return augmentOutputWithDisplayNames(shared); } protected  AbstractSavedSearchService(final SavedSearchRepository<T, B> crudRepository,
                                         final SharedToUserRepository sharedToUserRepository,
                                         final SharedToEveryoneRepository sharedToEveryoneRepository,
                                         final AuditorAware<UserEntity> userEntityAuditorAware,
                                         final TagNameFactory tagNameFactory,
                                         final Class<T> type); @Override Set<T> getOwned(); @Override Set<T> getShared(); @Override T get(final long id); @Override T create(final T search); @Override T update(final T search); @Override T updateShared(final T search); @Override void deleteById(final long id); @Override T getDashboardSearch(final long id);  }