Commit 1b9960dc authored by Matija Obreza's avatar Matija Obreza
Browse files

Return multiple matching descriptors

- With permission checks
parent 7ad39c7a
......@@ -49,7 +49,7 @@ public interface DescriptorService {
* @param descriptor the descriptor
* @return matching descriptor
*/
Descriptor searchMatchingDescriptor(Descriptor descriptor);
List<Descriptor> searchMatchingDescriptor(Descriptor descriptor);
/**
* Update descriptor.
......
......@@ -123,10 +123,13 @@ public class DescriptorServiceImpl implements DescriptorService {
* {@inheritDoc}
*/
@Override
public Descriptor searchMatchingDescriptor(final Descriptor input) {
@PostFilter("hasRole('ADMINISTRATOR') or filterObject.published or hasPermission(filterObject, 'READ')")
public List<Descriptor> searchMatchingDescriptor(final Descriptor input) {
final Predicate predicate = descriptor.category.in(input.getCategory()).and(descriptor.dataType.in(input.getDataType())).and(descriptor.crop.eq(input.getCrop()))
.and(descriptor.versionTag.eq(input.getVersionTag())).and(descriptor.title.eq(input.getTitle())).and(descriptor.key.eq(input.isKey()));
return lazyLoad(descriptorRepository.findOne(predicate));
List<Descriptor> matches = new ArrayList<>();
descriptorRepository.findAll(predicate).forEach(match -> matches.add(lazyLoad(match)));
return matches;
}
/**
......
......@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
......@@ -305,14 +306,14 @@ public class DescriptorController extends ApiBaseController {
}
/**
* Search matching descriptor.
* Search matching descriptors.
*
* @param source the source
* @return matching descriptor
* @return matching descriptors
*/
@RequestMapping(value = "/search-matching", method = RequestMethod.POST)
public Descriptor searchMatchingDescriptor(@RequestBody final Descriptor source) {
return descriptorService.searchMatchingDescriptor(source);
public List<Descriptor> searchMatchingDescriptor(@RequestBody final Descriptor source) {
return descriptorService.searchMatchingDescriptor(source).stream().filter(d -> d != null).collect(Collectors.toList());
}
/**
......
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