Commit c6ee8e19 authored by Maxym Borodenko's avatar Maxym Borodenko

Merge branch '474-allow-keyword-search-in-listaccessibledescriptors' into 'master'

Resolve "Allow keyword search in listAccessibleDescriptors"

Closes #474

See merge request genesys-pgr/genesys-server!472
parents 278884c7 eab79248
......@@ -35,6 +35,7 @@ import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.filters.DescriptorFilter;
import org.genesys.catalog.model.filters.FilterHelpers;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.model.traits.QDescriptor;
......@@ -77,6 +78,7 @@ import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.BooleanExpression;
/**
* The Class DescriptorServiceImpl.
......@@ -382,12 +384,13 @@ public class DescriptorServiceImpl implements DescriptorService {
if (securityUtils.hasRole(UserRole.ADMINISTRATOR)) {
res = listDescriptorsForCurrentUser(descriptorFilter, markdownSortPageRequest);
} else {
final HashSet<Long> partners = new HashSet<>(securityUtils.listObjectIdentityIdsForCurrentUser(Partner.class, BasePermission.WRITE));
BooleanExpression and = QDescriptor.descriptor.state.in(PublishState.PUBLISHED).or(descriptor.owner.id.in(partners)).and(descriptorFilter.buildPredicate());
if (descriptorFilter.isFulltextQuery()) {
throw new InvalidApiUsageException("Full-text query is not supported.");
and = and.andAnyOf(FilterHelpers.containsAll(descriptorFilter.get_text(), QDescriptor.descriptor.title, QDescriptor.descriptor.columnName, QDescriptor.descriptor.description, QDescriptor.descriptor.crop));
}
final HashSet<Long> partners = new HashSet<>(securityUtils.listObjectIdentityIdsForCurrentUser(Partner.class, BasePermission.WRITE));
res = descriptorRepository.findAll(QDescriptor.descriptor.state.in(PublishState.PUBLISHED).or(descriptor.owner.id.in(partners)).and(descriptorFilter
.buildPredicate()), markdownSortPageRequest);
res = descriptorRepository.findAll(and, 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