Commit 2001609b authored by Viacheslav Pavlov's avatar Viacheslav Pavlov
Browse files

Fix: Bug Apply Filters: Dataset traits

parent 68d02346
......@@ -123,7 +123,7 @@ public interface DescriptorService {
* @param page parameters
* @return Page with descriptor list
*/
Page<Descriptor> listDescriptorsForCurrentUser(DescriptorFilter filter, Pageable page);
Page<Descriptor> listDescriptorsForCurrentUser(DescriptorFilter filter, Pageable page) throws IOException;
/**
......@@ -133,7 +133,7 @@ public interface DescriptorService {
* @param page the page
* @return the page
*/
Page<Descriptor> listAccessibleDescriptors(DescriptorFilter filter, Pageable page);
Page<Descriptor> listAccessibleDescriptors(DescriptorFilter filter, Pageable page) throws IOException;
/**
* List published descriptors.
......@@ -223,7 +223,7 @@ public interface DescriptorService {
/**
* Get descriptor for UUID. No lazy-loading.
*
*
* @param uuid
* @return
*/
......
......@@ -343,31 +343,47 @@ public class DescriptorServiceImpl implements DescriptorService {
*/
@Override
@PreAuthorize("isAuthenticated()")
public Page<Descriptor> listDescriptorsForCurrentUser(final DescriptorFilter filter, final Pageable page) {
public Page<Descriptor> listDescriptorsForCurrentUser(final DescriptorFilter filter, final Pageable page) throws IOException {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res;
if (securityUtils.hasRole(UserRole.ADMINISTRATOR)) {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res = descriptorRepository.findAll(filter.buildPredicate(), markdownSortPageRequest);
if (filter.isFulltextQuery()) {
res = elasticsearchService.findAll(Descriptor.class, filter, markdownSortPageRequest);
} else {
res = descriptorRepository.findAll(filter.buildPredicate(), markdownSortPageRequest);
}
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
} else {
final HashSet<Long> partners = new HashSet<>(securityUtils.listObjectIdentityIdsForCurrentUser(Partner.class, BasePermission.WRITE));
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res = descriptorRepository.findAll(descriptor.owner.id.in(partners).and(filter.buildPredicate()), markdownSortPageRequest);
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
if (filter.isFulltextQuery()) {
DescriptorFilter availablePartnersFilter = filter.copy(DescriptorFilter.class);
availablePartnersFilter.owner().id.addAll(partners);
res = elasticsearchService.findAll(Descriptor.class, availablePartnersFilter, markdownSortPageRequest);
} else {
res = descriptorRepository.findAll(descriptor.owner.id.in(partners).and(filter.buildPredicate()), markdownSortPageRequest);
}
}
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
}
@Override
@PreAuthorize("isAuthenticated()")
public Page<Descriptor> listAccessibleDescriptors(DescriptorFilter descriptorFilter, Pageable page) {
public Page<Descriptor> listAccessibleDescriptors(DescriptorFilter descriptorFilter, Pageable page) throws IOException {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res;
if (securityUtils.hasRole(UserRole.ADMINISTRATOR)) {
return listDescriptorsForCurrentUser(descriptorFilter, page);
res = listDescriptorsForCurrentUser(descriptorFilter, markdownSortPageRequest);
} else {
final HashSet<Long> partners = new HashSet<>(securityUtils.listObjectIdentityIdsForCurrentUser(Partner.class, BasePermission.WRITE));
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res = descriptorRepository.findAll(QDescriptor.descriptor.state.in(PublishState.PUBLISHED).or(descriptor.owner.id.in(partners)).and(descriptorFilter
.buildPredicate()), markdownSortPageRequest);
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
DescriptorFilter publishedFilter = descriptorFilter.copy(DescriptorFilter.class);
publishedFilter.state(PublishState.PUBLISHED);
res = listDescriptorsForCurrentUser(publishedFilter, markdownSortPageRequest);
}
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment