Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BXC-4779 - Fix viewable files filter #1828

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@
public class MultipleDirectlyOwnedDatastreamsFilter implements QueryFilter {
private Set<DatastreamType> datastreamTypes;
private SearchFieldKey fieldKey;
private boolean onlyDirectlyOwned;

protected MultipleDirectlyOwnedDatastreamsFilter(SearchFieldKey fieldKey, Set<DatastreamType> datastreamTypes) {
protected MultipleDirectlyOwnedDatastreamsFilter(SearchFieldKey fieldKey, Set<DatastreamType> datastreamTypes,
boolean onlyDirectlyOwned) {
this.datastreamTypes = datastreamTypes;
this.fieldKey = fieldKey;
this.onlyDirectlyOwned = onlyDirectlyOwned;
}

@Override
public String toFilterString() {
var dsField = fieldKey.getSolrField();
final var ownershipSuffix = onlyDirectlyOwned ? "||" : "";
return getDatastreamTypes().stream()
// Filtering datastreams to exclude those owned by other objects
.map(ds -> dsField + ":" + ds.getId() + "|*||")
.map(ds -> dsField + ":" + ds.getId() + "|*" + ownershipSuffix)
.collect(Collectors.joining(" OR ", "(", ")"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ public static QueryFilter createFilter(SearchFieldKey fieldKey, DatastreamType d
* @return new QueryFilter instance with the provided datastream types
*/
public static QueryFilter createFilter(SearchFieldKey fieldKey, Set<DatastreamType> datastreamTypes) {
return new MultipleDirectlyOwnedDatastreamsFilter(fieldKey, datastreamTypes);
return new MultipleDirectlyOwnedDatastreamsFilter(fieldKey, datastreamTypes, false);
}

/**
* Create a filter which restricts results to entries which contain at least one of the listed datastreams,
* where the datastreams are owned by the object itself rather than one of its children
* @param fieldKey key of field to filter
* @param datastreamTypes datastreams to filter for
* @return new QueryFilter instance with the provided datastream types
*/
public static QueryFilter createDirectlyOwnedFilter(SearchFieldKey fieldKey, Set<DatastreamType> datastreamTypes) {
return new MultipleDirectlyOwnedDatastreamsFilter(fieldKey, datastreamTypes, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,47 @@
import java.util.HashSet;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;

/**
* @author lfarrell
*/
public class QueryFilterFactoryTest {
@Test
public void NamedDatastreamFilterTest() {
public void namedDatastreamFilterTest() {
var filter = QueryFilterFactory.createFilter(SearchFieldKey.DATASTREAM, DatastreamType.JP2_ACCESS_COPY);
assertInstanceOf(NamedDatastreamFilter.class, filter);
}

@Test
public void MultipleDirectlyOwnedDatastreamsFilterTest() {
public void multipleDirectlyOwnedDatastreamsFilterTest() {
var datastreamTypes = new HashSet<DatastreamType>();
datastreamTypes.add(DatastreamType.JP2_ACCESS_COPY);
datastreamTypes.add(DatastreamType.FULLTEXT_EXTRACTION);
var filter = QueryFilterFactory.createDirectlyOwnedFilter(SearchFieldKey.DATASTREAM, datastreamTypes);
assertInstanceOf(MultipleDirectlyOwnedDatastreamsFilter.class, filter);
assertEquals("(datastream:jp2|*|| OR datastream:fulltext|*||)", filter.toFilterString());
}

@Test
public void datastreamsFilterTest() {
var datastreamTypes = new HashSet<DatastreamType>();
datastreamTypes.add(DatastreamType.JP2_ACCESS_COPY);
datastreamTypes.add(DatastreamType.FULLTEXT_EXTRACTION);
var filter = QueryFilterFactory.createFilter(SearchFieldKey.DATASTREAM, datastreamTypes);
assertInstanceOf(MultipleDirectlyOwnedDatastreamsFilter.class, filter);
assertEquals("(datastream:jp2|* OR datastream:fulltext|*)", filter.toFilterString());
}

@Test
public void HasPopulatedFieldFilterTest() {
public void hasPopulatedFieldFilterTest() {
var filter = QueryFilterFactory.createFilter(SearchFieldKey.STREAMING_TYPE);
assertInstanceOf(HasPopulatedFieldFilter.class, filter);
}

@Test
public void HasValuesFilterTest() {
public void hasValuesFilterTest() {
var filter = QueryFilterFactory.createHasValuesFilter(SearchFieldKey.FILE_FORMAT_TYPE, List.of("application/pdf"));
assertInstanceOf(HasValuesFilter.class, filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ private void adjustRequestPids(ExportXMLRequest request) throws ServiceException
searchRequest.setApplyCutoffs(false);
if (request.getOnlyIncludeValidDatastreams()) {
searchState.addFilter(
QueryFilterFactory.createFilter(SearchFieldKey.DATASTREAM, request.getDatastreams()));
QueryFilterFactory.createDirectlyOwnedFilter(
SearchFieldKey.DATASTREAM, request.getDatastreams()));
}

SearchResultResponse resultResponse = searchService.getSearchResults(searchRequest);
Expand Down
Loading