Skip to content

[Port to dtq-dev] fix: Keep the requested scope and configuration in the /discover/search self link - #1421

Merged
milanmajchrak merged 2 commits into
dtq-devfrom
934-be/discover-search-self-link
Aug 27, 2026
Merged

[Port to dtq-dev] fix: Keep the requested scope and configuration in the /discover/search self link#1421
milanmajchrak merged 2 commits into
dtq-devfrom
934-be/discover-search-self-link

Conversation

@milanmajchrak

@milanmajchrak milanmajchrak commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

References

Description

/api/discover/search left the scope and configuration it was called with out of its own self link, so the link described a different request than the one it answered. In the UI that shows up as an ensureSelfLink console warning on every scoped search.

Instructions for Reviewers

Changes:

  • DiscoverConfigurationConverter now takes the requested configuration name and scope and sets them on the SearchConfigurationRest. It was the only converter in this family implementing DSpaceConverter, which passes just a model object and a projection, so there was nowhere for the request parameters to travel and the link factory built the self link out of two nulls. DiscoverFacetConfigurationConverter already does it this way.
  • DiscoveryRestRepository.getSearchConfiguration passes both values through.
  • The upstream test is added to ClarinDiscoveryRestControllerIT as well, because DiscoveryRestControllerIT carries a class-level @Ignore on dtq-dev and would never run it.

Adapted, not cherry-picked: upstream's first hunk rewrites the class header, where dtq-dev keeps an @Autowired ConfigurationService for the local sort.options.filtered handling. That field and both sort blocks are preserved.

Both fields are @JsonIgnore, so only _links.self changes and the response body stays as it was.

How to test:

curl -s "http://localhost:8080/server/api/discover/search?scope=<community-uuid>&configuration=personOrOrgunit" | jq ._links.self.href

Before, that returns .../api/discover/search. After, it returns the URL that was requested. A request without parameters still gets a bare self link.

Checklist

  • My PR is created against dtq-dev (port of an upstream fix onto our 7.6.5 line).
  • My PR is small in size (5 files, +94/-21).
  • My PR follows all coding best practices based on the Code Conventions Guide.
  • My PR passes Checkstyle validation (0 violations).
  • My PR includes Javadoc for all new (or modified) public methods and classes.
  • My PR passes all tests and includes new/updated Unit or Integration TestsDiscoverConfigurationConverterTest 12/12 with a new case; the two ITs were not run here (no IT environment), left to CI.
  • My PR includes details on how to test it.
  • If my PR includes new libraries/dependencies, licenses align (none added).
  • If my PR modifies REST API endpoints, a REST Contract PR is opened (N/A, the response body and the documented links are unchanged).
  • If my PR includes new configurations, technical documentation is provided (none added).
  • If my PR fixes an issue ticket, I've linked them together.

Written with some help from Claude Code.

milanmajchrak and others added 2 commits August 26, 2026 13:31
…scover/search self link

/api/discover/search built its self link from a SearchConfigurationRest that
never received the scope and configuration the request carried, so the link
described a different request than the one it answered. The frontend then
logged a self-link mismatch warning for every scoped or configured search.

- DiscoverConfigurationConverter: convert() now takes the requested
  configuration name and scope and sets them on SearchConfigurationRest, the
  way DiscoverFacetConfigurationConverter already does for /discover/facets.
  Both fields are @JsonIgnore, so only _links.self changes -- the JSON body is
  untouched. The class no longer implements DSpaceConverter and getModelClass()
  is gone, because the 4-arg signature does not fit that interface; nothing on
  dtq-dev resolves this converter through ConverterService (no toRest() or
  getConverter() call asks for DiscoveryConfiguration), so dropping the
  registry entry orphans nothing.
- DiscoveryRestRepository.getSearchConfiguration(): pass both values through.
- DiscoverConfigurationConverterTest: adapt the existing call sites and add
  testRequestedConfigurationAndScopeAreKept.

Port of DSpace/DSpace PR 12984 (still open upstream), commit 6477dfe.
Upstream tracking issue: DSpace/DSpace issue 8576. Adapted, not cherry-picked:
upstream is on 11.0-SNAPSHOT and its first hunk rewrites the class header, where
dtq-dev keeps an @Autowired ConfigurationService for the local
sort.options.filtered handling. That field, the filtering block and the
commons-lang v2 imports are left as they are. SearchConfigurationRest and
SearchConfigurationResourceHalLinkFactory need no change -- 7.6 already has the
@JsonIgnore scope/configuration fields and the link factory already reads them.

Fixes dataquest-dev/dspace-customers#934

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…actually runs

The upstream patch adds discoverSearchSelfLinkKeepsScopeAndConfigurationTest to
DiscoveryRestControllerIT, but that class is @ignore'd at class level on dtq-dev
(since eb40d60, unrelated facet-configuration failures), so the test would
never execute here.

- DiscoveryRestControllerIT: add the upstream test verbatim, at the same spot,
  so the file stays in step with upstream and future rebases stay clean. The
  class-level @ignore is left alone; lifting it is a separate job.
- ClarinDiscoveryRestControllerIT: mirror the same test, in this file's
  continuation-indent style. This is the fork's live copy of the discovery ITs
  and it runs in CI, so this is where the fix is actually verified. The test
  asserts only on $._links.self.href, so it is independent of the fork's
  discovery.xml facet/sort customisations.

Fixes dataquest-dev/dspace-customers#934

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@milanmajchrak milanmajchrak changed the title 934 be/discover search self link [Port to dtq-dev] fix: Keep the requested scope and configuration in the /discover/search self link Aug 27, 2026
@milanmajchrak
milanmajchrak requested a lite review from Copilot August 27, 2026 11:23
@milanmajchrak
milanmajchrak merged commit f27d932 into dtq-dev Aug 27, 2026
12 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports an upstream DSpace fix to ensure /api/discover/search returns a _links.self that accurately reflects the request’s scope and configuration query parameters, preventing the UI’s ensureSelfLink warning for scoped searches.

Changes:

  • Propagates requested scope and configuration through DiscoveryRestRepository into SearchConfigurationRest so HAL link generation can build an accurate self link.
  • Refactors DiscoverConfigurationConverter to accept request context (configurationName, scope) and persist it on the REST model (both fields remain @JsonIgnore).
  • Adds integration + unit test coverage verifying the self link includes provided parameters and does not invent absent ones.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/DiscoverConfigurationConverter.java Updates conversion to carry scope/configuration into SearchConfigurationRest for correct self link building.
dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/DiscoveryRestRepository.java Passes request parameters into the converter so the REST model can reflect the actual request.
dspace-server-webapp/src/test/java/org/dspace/app/rest/converter/DiscoverConfigurationConverterTest.java Updates converter unit tests for new signature and adds an assertion that scope/config are preserved.
dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinDiscoveryRestControllerIT.java Adds IT validating _links.self keeps the requested scope and configuration (dtq-dev runnable).
dspace-server-webapp/src/test/java/org/dspace/app/rest/DiscoveryRestControllerIT.java Adds the same IT (but this class is currently @Ignore on dtq-dev).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1268 to +1270
@Test
public void discoverSearchSelfLinkKeepsScopeAndConfigurationTest() throws Exception {
context.turnOffAuthorisationSystem();
milanmajchrak added a commit that referenced this pull request Sep 9, 2026
…guration in the /discover/search self link (#1426)

Source: f27d932 (dtq-dev PR #1421)

/api/discover/search built its self link from a SearchConfigurationRest that
never received the scope and configuration the request carried, so the link
described a different request than the one it answered. The frontend then
logged a self-link mismatch warning for every scoped or configured search.

- DiscoverConfigurationConverter: convert() now takes the requested
  configuration name and scope and sets them on SearchConfigurationRest, the
  way DiscoverFacetConfigurationConverter already does for /discover/facets.
  Both fields are @JsonIgnore, so only _links.self changes -- the JSON body is
  untouched. The class no longer implements DSpaceConverter and getModelClass()
  is gone, because the 4-arg signature does not fit that interface; nothing on
  dtq-dev-9-base resolves this converter through ConverterService (no toRest()
  or getConverter() call asks for DiscoveryConfiguration), so dropping the
  registry entry orphans nothing.
- DiscoveryRestRepository.getSearchConfiguration(): pass both values through.
- DiscoverConfigurationConverterTest: adapt the existing call sites and add
  testRequestedConfigurationAndScopeAreKept (12 tests).
- DiscoveryRestControllerIT: add discoverSearchSelfLinkKeepsScopeAndConfiguration
  Test. Unlike dtq-dev, this class is not @ignore'd on dtq-dev-9-base, so the
  test really runs in CI here.

Both production files are byte-identical with vanilla 9.3 on this branch, so the
two production hunks and the converter test applied verbatim.

Deviation from the source commit: its hunk for
dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinDiscoveryRestControllerIT.java
is dropped -- that class does not exist on dtq-dev-9-base (card X-01 tracks it).
The same test is covered by DiscoveryRestControllerIT above, where it executes.

Upstream: DSpace/DSpace PR 12984 (open), commit 6477dfe, issue 8576.
Frontend half: cards FE-06 (d0897c2af7) and FE-01 (51796ec39a) -- the UI warning
disappears only once those land.

Card: BE-02.
Fixes dataquest-dev/dspace-customers#934


(cherry picked from commit f27d932)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants