ILLDEV-423#653
Conversation
metadata parser and lookup method
To distinguish it from MetadataLookup
There was a problem hiding this comment.
Pull request overview
This PR introduces configurable metadata enrichment for ISO18626 bibliographic data by extending holdings lookup to optionally fetch/parse metadata (not just holdings) and applying it to outgoing requests/transactions based on directory configuration. It also refactors adapter selection (including consortium config resolution) behind a new factory.
Changes:
- Extend Directory API holdings configuration with
metadataUpdateModeandmetadataFormat(MARC21 parser config). - Split holdings adapter responsibilities into
HoldingsLookupvsMetadataLookup, add MARC metadata parsing, and add request metadata update helpers. - Refactor supplier locating and patron-request creation paths to use
LookupAdapterFactoryand apply metadata updates when configured.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| directory/directory_api.yaml | Adds metadata update mode + metadata parser config schemas to holdings config. |
| broker/service/supplierlocator.go | Uses LookupAdapterFactory, derives lookup params centrally, and applies optional metadata enrichment before holdings lookup. |
| broker/service/supplierlocator_test.go | Updates constructor usage and adds tests around metadata-update behavior and persistence. |
| broker/service/lookupadapterfactory.go | New: centralizes adapter selection + consortium config resolution and exposes config entry access. |
| broker/patron_request/api/api-handler.go | Adds optional metadata enrichment during patron request creation using lookup adapters and directory config. |
| broker/patron_request/api/api-handler_test.go | Adds unit tests for metadataUpdate behavior and error paths. |
| broker/holdings/sru_holdings_test.go | Updates SRU adapter construction and switches tests to HoldingsLookup. |
| broker/holdings/metadata.go | New: applies metadata to ISO18626 bibliographic info with replace/merge semantics. |
| broker/holdings/metadata_parser_marc.go | New: MARCXML (and OPAC-wrapped MARCXML) metadata parser. |
| broker/holdings/metadata_parser_marc_test.go | New: tests for MARC metadata parsing defaults, overrides, and error handling. |
| broker/holdings/holdings.go | Expands adapter interface to support HoldingsLookup + MetadataLookup, and adds metadata types/parser interface. |
| broker/holdings/gvi_holdings_test.go | Updates to HoldingsLookup. |
| broker/holdings/creator_test.go | Renames parser helper usage to getHoldingsParser. |
| broker/holdings/creator_impl.go | Wires metadata parser config into adapter creation and adds shared lookup-param derivation helper. |
| broker/holdings/create_holdings.go | Updates SRU adapter construction for new metadata-parser parameter. |
| broker/holdings/adapter_zoom.go | Renames lookup method and adds Z39.50-backed metadata lookup implementation. |
| broker/holdings/adapter_zoom_test.go | Updates to HoldingsLookup and adds coverage for MetadataLookup. |
| broker/holdings/adapter_sru.go | Renames lookup method and adds MetadataLookup stub (currently returns empty metadata). |
| broker/holdings/adapter_mock.go | Updates mock adapter to satisfy the new interface, including metadata return. |
| broker/holdings/adapter_mock_shared.go | Updates shared mock to satisfy the new interface, including trivial metadata return. |
| broker/holdings/adapter_metaproxy.go | Updates wrapper adapter to forward both holdings and metadata lookup calls. |
| broker/handler/iso18626-handler.go | Updates retry flow to derive holdings params via new helper. |
| broker/app/app.go | Wires LookupAdapterFactory into supplier locator and patron request API handler. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| var queryParams string | ||
| var found bool | ||
| for _, cql := range cqlList { | ||
| sruQuery := "query=" + url.QueryEscape(cql) | ||
| holdings, queryParams, err = s.search(sruUrl, params, sruQuery) | ||
| if err != nil { | ||
| return nil, queryParams, err | ||
| } | ||
| if len(holdings) > 0 { | ||
| return holdings, queryParams, nil | ||
| found, queryParams, err = s.search(sruUrl, params, sruQuery, processRecord) |
There was a problem hiding this comment.
@jakub-id this is existing behavior for the sru adapter. Want me to just return the cql , which would be easier to read rather than path with URI encoded chars.
|
@adamdickmeiss Question regarding the global vs per-peer/directory adapter: I see that they use a different search strategy, the global one creates a single OR query for different params and the per-peer one tries multiple queries one by one. Was this an intended difference in behavior? This is not introduced in this PR but this PR changes the previous behavior and stops trying queries when metadata is successfully parsed (previously it required holdings to be parsed only). |
The adapters (sru, zoom) fetches all records to be conservative. If a search returns > 0 records, it will not try further queries. |
| func (s *SruHoldingsLookupAdapter) lookupServer(sruUrl string, params LookupParams, processRecord func([]byte) (bool, error)) (bool, string, error) { | ||
| cqlList, pqfList, err := s.queryBuilder.Build(params) | ||
| if err != nil { | ||
| return nil, "", err | ||
| return false, "", err | ||
| } |
| for _, cql := range cqlList { | ||
| sruQuery := "query=" + url.QueryEscape(cql) | ||
| holdings, queryParams, err = s.search(sruUrl, params, sruQuery) | ||
| if err != nil { | ||
| return nil, queryParams, err | ||
| } | ||
| if len(holdings) > 0 { | ||
| return holdings, queryParams, nil | ||
| found, queryParams, err = s.search(sruUrl, params, sruQuery, processRecord) | ||
| if err != nil || found { | ||
| return found, queryParams, err |
| lookupParams := holdings.LookupParamsFromBibliographicInfo(illRequest.BibliographicInfo, illRequest.ServiceInfo) | ||
|
|
||
| lookupResult, err := lookupAdapter.Lookup(lookupParams) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to perform lookup for patron request: %w", err) | ||
| } | ||
| metadata, err := lookupResult.GetMetadata() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get metadata for patron request: %w", err) | ||
| } | ||
| return holdings.MetadataRequestUpdate(&illRequest.BibliographicInfo, metadata, lookupParams, mode) | ||
| } |
https://index-data.atlassian.net/browse/ILLDEV-423