Conversation
There was a problem hiding this comment.
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/searchquerying 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_objectto 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}" |
There was a problem hiding this comment.
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.
| 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" |
|
|
||
| total_found = results.size | ||
|
|
||
| reply 200, page_object(docs, total_found) |
There was a problem hiding this comment.
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.
| 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) |
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
Limitations :
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