From 7f8bb19e0c33678efbf6ca24b569368be3caa950 Mon Sep 17 00:00:00 2001 From: "Gantner, Florian Klaus" Date: Fri, 8 Mar 2024 14:41:21 +0100 Subject: [PATCH] search filterfacet isOpenByDefault as facetentry property https://github.com/DSpace/DSpace/issues/9404 --- .../DiscoverFacetConfigurationConverter.java | 1 + .../DiscoverFacetResultsConverter.java | 1 + .../converter/DiscoverFacetsConverter.java | 1 + .../app/rest/model/SearchFacetEntryRest.java | 14 ++++++++++++++ .../app/rest/matcher/FacetEntryMatcher.java | 19 +++++++++++++++++++ 5 files changed, 36 insertions(+) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetConfigurationConverter.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetConfigurationConverter.java index 32768d419618..c778b04856e5 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetConfigurationConverter.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetConfigurationConverter.java @@ -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); } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetResultsConverter.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetResultsConverter.java index 8d4610b6bae9..e0af9077306e 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetResultsConverter.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetResultsConverter.java @@ -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()); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetsConverter.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetsConverter.java index cbbdc3e9cbec..d099c6016666 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetsConverter.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverFacetsConverter.java @@ -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)) { diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/SearchFacetEntryRest.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/SearchFacetEntryRest.java index aafa3a110836..7d9eadb2866a 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/SearchFacetEntryRest.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/SearchFacetEntryRest.java @@ -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; /** @@ -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; @@ -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()} */ diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/FacetEntryMatcher.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/FacetEntryMatcher.java index cc15700b924e..433e270912f3 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/FacetEntryMatcher.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/FacetEntryMatcher.java @@ -28,6 +28,7 @@ public static Matcher 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")) ); @@ -40,6 +41,7 @@ public static Matcher 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")) ); @@ -50,6 +52,7 @@ public static Matcher 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")) @@ -61,6 +64,7 @@ public static Matcher 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")) @@ -72,6 +76,7 @@ public static Matcher 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")) @@ -83,6 +88,7 @@ public static Matcher 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")) ); @@ -95,6 +101,7 @@ public static Matcher 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")) ); @@ -105,6 +112,7 @@ public static Matcher 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")) ); @@ -115,6 +123,7 @@ public static Matcher 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)) ); @@ -133,6 +142,7 @@ public static Matcher 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")) ); @@ -151,6 +161,7 @@ public static Matcher 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")) ); @@ -165,6 +176,7 @@ public static Matcher 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")) ); @@ -175,6 +187,7 @@ public static Matcher 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")) ); @@ -185,6 +198,7 @@ public static Matcher 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")) ); @@ -195,6 +209,7 @@ public static Matcher 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")) ); @@ -205,6 +220,7 @@ public static Matcher 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")) ); @@ -215,6 +231,7 @@ public static Matcher 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")) ); @@ -225,6 +242,7 @@ public static Matcher 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")) ); @@ -235,6 +253,7 @@ public static Matcher 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")) );