Skip to content

Commit

Permalink
search filterfacet isOpenByDefault as facetentry property
Browse files Browse the repository at this point in the history
  • Loading branch information
floriangantner committed Dec 27, 2024
1 parent f6ce766 commit 7f8bb19
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private void addSidebarFacets(FacetConfigurationRest facetConfigurationRest,
SearchFacetEntryRest facetEntry = new SearchFacetEntryRest(discoverySearchFilterFacet.getIndexFieldName());
facetEntry.setFacetType(discoverySearchFilterFacet.getType());
facetEntry.setFacetLimit(discoverySearchFilterFacet.getFacetLimit());
facetEntry.setOpenByDefault(discoverySearchFilterFacet.isOpenByDefault());

facetConfigurationRest.addSidebarFacet(facetEntry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private SearchFacetEntryRest convertFacetEntry(final String facetName, final Dis
}

facetEntryRest.setFacetLimit(field.getFacetLimit());
facetEntryRest.setOpenByDefault(field.isOpenByDefault());

//We requested one extra facet value. Check if that value is present to indicate that there are more results
facetEntryRest.setHasMore(facetResults.size() > page.getPageSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void addFacetValues(Context context, final DiscoverResult searchResult, f
if (field.exposeMinAndMaxValue()) {
handleExposeMinMaxValues(context, field, facetEntry);
}
facetEntry.setOpenByDefault(field.isOpenByDefault());
facetEntry.setExposeMinMax(field.exposeMinAndMaxValue());
facetEntry.setFacetType(field.getType());
for (DiscoverResult.FacetResult value : CollectionUtils.emptyIfNull(facetValues)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.dspace.app.rest.DiscoveryRestController;
import org.dspace.discovery.configuration.DiscoverySearchFilter;
import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;

/**
Expand All @@ -31,6 +32,9 @@ public class SearchFacetEntryRest extends RestAddressableModel {
private Boolean hasMore = null;
private int facetLimit;

@JsonIgnore
private Boolean isOpenByDefault;

@JsonIgnore
private boolean exposeMinMax = false;

Expand Down Expand Up @@ -107,6 +111,16 @@ public void setFacetLimit(final int facetLimit) {
this.facetLimit = facetLimit;
}

public void setOpenByDefault(boolean isOpenByDefault) {
this.isOpenByDefault = Boolean.valueOf(isOpenByDefault);
}
/**
* See documentation at {@link DiscoverySearchFilter#isOpenByDefault()}
*/
public Boolean isOpenByDefault() {
return this.isOpenByDefault;
}

/**
* See documentation at {@link DiscoverySearchFilterFacet#exposeMinAndMaxValue()}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static Matcher<? super Object> authorFacet(boolean hasNext) {
hasJsonPath("$.name", is("author")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/author")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/author"))
);
Expand All @@ -40,6 +41,7 @@ public static Matcher<? super Object> authorFacetWithMinMax(boolean hasNext, Str
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.minValue", is(min)),
hasJsonPath("$.maxValue", is(max)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/author")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/author"))
);
Expand All @@ -50,6 +52,7 @@ public static Matcher<? super Object> subjectFacet(boolean hasNext) {
hasJsonPath("$.name", is("subject")),
hasJsonPath("$.facetType", is("hierarchical")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/subject")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/subject"))

Expand All @@ -61,6 +64,7 @@ public static Matcher<? super Object> submitterFacet(boolean hasNext) {
hasJsonPath("$.name", is("submitter")),
hasJsonPath("$.facetType", is("authority")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/submitter")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/submitter"))

Expand All @@ -72,6 +76,7 @@ public static Matcher<? super Object> supervisedByFacet(boolean hasNext) {
hasJsonPath("$.name", is("supervisedBy")),
hasJsonPath("$.facetType", is("authority")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/supervisedBy")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/supervisedBy"))

Expand All @@ -83,6 +88,7 @@ public static Matcher<? super Object> dateIssuedFacet(boolean hasNext) {
hasJsonPath("$.name", is("dateIssued")),
hasJsonPath("$.facetType", is("date")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/dateIssued")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/dateIssued"))
);
Expand All @@ -95,6 +101,7 @@ public static Matcher<? super Object> dateIssuedFacetWithMinMax(boolean hasNext,
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.minValue", is(min)),
hasJsonPath("$.maxValue", is(max)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/dateIssued")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/dateIssued"))
);
Expand All @@ -105,6 +112,7 @@ public static Matcher<? super Object> hasContentInOriginalBundleFacet(boolean ha
hasJsonPath("$.name", is("has_content_in_original_bundle")),
hasJsonPath("$.facetType", is("standard")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/has_content_in_original_bundle")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/has_content_in_original_bundle"))
);
Expand All @@ -115,6 +123,7 @@ public static Matcher<? super Object> matchFacet(boolean hasNext, String name, S
hasJsonPath("$.name", is(name)),
hasJsonPath("$.facetType", is(facetType)),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/" + name)),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/" + name))
);
Expand All @@ -133,6 +142,7 @@ public static Matcher<? super Object> typeFacet(boolean b) {
hasJsonPath("$.name", is("itemtype")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/itemtype")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/itemtype"))
);
Expand All @@ -151,6 +161,7 @@ public static Matcher<? super Object> resourceTypeFacet(boolean b) {
hasJsonPath("$.name", is("namedresourcetype")),
hasJsonPath("$.facetType", is("authority")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/namedresourcetype")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/namedresourcetype"))
);
Expand All @@ -165,6 +176,7 @@ public static Matcher<? super Object> entityTypeFacet(boolean hasNext) {
return allOf(
hasJsonPath("$.name", is("entityType")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/entityType")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/entityType"))
);
Expand All @@ -175,6 +187,7 @@ public static Matcher<? super Object> relatedItemFacet(boolean b) {
hasJsonPath("$.name", is("relateditem")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/relateditem")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/relateditem"))
);
Expand All @@ -185,6 +198,7 @@ public static Matcher<? super Object> originFacet(boolean b) {
hasJsonPath("$.name", is("origin")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/origin")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/origin"))
);
Expand All @@ -195,6 +209,7 @@ public static Matcher<? super Object> targetFacet(boolean b) {
hasJsonPath("$.name", is("target")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/target")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/target"))
);
Expand All @@ -205,6 +220,7 @@ public static Matcher<? super Object> queueStatusFacet(boolean b) {
hasJsonPath("$.name", is("queue_status")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/queue_status")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/queue_status"))
);
Expand All @@ -215,6 +231,7 @@ public static Matcher<? super Object> activityStreamTypeFacet(boolean b) {
hasJsonPath("$.name", is("activity_stream_type")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/activity_stream_type")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/activity_stream_type"))
);
Expand All @@ -225,6 +242,7 @@ public static Matcher<? super Object> coarNotifyTypeFacet(boolean b) {
hasJsonPath("$.name", is("coar_notify_type")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/coar_notify_type")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/coar_notify_type"))
);
Expand All @@ -235,6 +253,7 @@ public static Matcher<? super Object> notificationTypeFacet(boolean b) {
hasJsonPath("$.name", is("notification_type")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$.openByDefault", any(Boolean.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/notification_type")),
hasJsonPath("$._links", matchNextLink(b, "api/discover/facets/notification_type"))
);
Expand Down

0 comments on commit 7f8bb19

Please sign in to comment.