Skip to content

Federation search endpoint#15

Open
Imene-Amirat wants to merge 2 commits intodevelopmentfrom
federation-search-endpoint
Open

Federation search endpoint#15
Imene-Amirat wants to merge 2 commits intodevelopmentfrom
federation-search-endpoint

Conversation

@Imene-Amirat
Copy link
Collaborator

@Imene-Amirat Imene-Amirat commented Mar 23, 2026

New endpoint: /api/federation/search

  • Add a new /api/federation/search endpoint that queries the external base4nfdi API Gateway

  • Maps the external API response fields to EarthPortal's format :
    - label → prefLabel
    - synonyms → synonym
    - descriptions → definition

  • Reuses the existing Class.read_only + submission + page_object mechanism so the serializer generates the same JSON structure (@links, @context, pagination) the frontend expects

image

Limitations :

  • totalCount: Always returns 100 because the API Gateway returns a maximum of 100
  • matchType: API Gateway doesn't tell us which field matched the query
  • links.ui: The serializer generates this URL
    http://#{LinkedData.settings.ui_host}/ontologies/#{acronym}?p=classes&conceptid=#{id}
    using a global config ui_host (default: bioportal.bioontology.org, in prod it will be earthportal.eu )
    but for federation all results will point to earthportal.eu even if they come from AgroPortal or EcoPortal, because ui_host is the same for every result
    instead :
    the API Gateway provides source_url field
  • ontologyType: Not returned by the API Gateway

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new federation search API endpoint that proxies queries to the base4nfdi API Gateway and adapts results into EarthPortal’s existing class search/page serialization format.

Changes:

  • Introduces GET /api/federation/search querying the external base4nfdi API Gateway.
  • Maps gateway fields into EarthPortal’s expected class fields (label→prefLabel, synonyms→synonym, descriptions→definition).
  • Wraps results using Class.read_only + submission + page_object to reuse existing JSON structure (links/context/pagination).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

response = GATEWAY_CONNECTION.get("search", gateway_params)

unless response.success?
error response.status, "API Gateway error: #{response.body}"
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Avoid returning the raw upstream response body to clients on gateway errors; it can be large and may leak upstream details. Prefer a generic client-facing message and log the gateway body/status for debugging.

Suggested change
error response.status, "API Gateway error: #{response.body}"
Rails.logger.error("API Gateway error: status=#{response.status}, body=#{response.body}") if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
error response.status, "API Gateway error: upstream service returned an error"

Copilot uses AI. Check for mistakes.

total_found = results.size

reply 200, page_object(docs, total_found)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This endpoint ignores page/pagesize request params and always returns all gateway results. Because page_object assumes the collection is already paginated, this can produce responses where itemsPerPage doesn’t match the number of returned members and pagination links become misleading. Please apply local slicing (using page_params + offset_and_limit) before building the page object.

Suggested change
reply 200, page_object(docs, total_found)
page, page_size = page_params
offset, limit = offset_and_limit(total_found, page, page_size)
paginated_docs = docs.slice(offset, limit) || []
reply 200, page_object(paginated_docs, total_found)

Copilot uses AI. Check for mistakes.
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