Skip to content

Commit

Permalink
Get catalog record by DOI case-insensitively
Browse files Browse the repository at this point in the history
  • Loading branch information
marksparkza committed Oct 24, 2023
1 parent ed91838 commit 742961d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions odp/api/routers/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from odp.api.models import CatalogModel, PublishedDataCiteRecordModel, PublishedSAEONRecordModel, RetractedRecordModel, SearchResult
from odp.const import DOI_REGEX, ODPCatalog, ODPScope
from odp.db import Session
from odp.db.models import Catalog, CatalogRecord, CatalogRecordFacet, PublishedRecord
from odp.db.models import Catalog, CatalogRecord, CatalogRecordFacet, PublishedRecord, Record
from odp.lib.datacite import DataciteClient, DataciteError

router = APIRouter()
Expand Down Expand Up @@ -282,9 +282,8 @@ async def get_catalog_record_by_id_or_doi(

except ValueError:
if re.match(DOI_REGEX, record_id_or_doi):
stmt = stmt.where(CatalogRecord.published_record.comparator.contains({
'doi': record_id_or_doi
}))
stmt = stmt.join(Record)
stmt = stmt.where(func.lower(Record.doi) == record_id_or_doi.lower())
else:
raise HTTPException(HTTP_422_UNPROCESSABLE_ENTITY, 'Invalid record identifier: expecting a UUID or DOI')

Expand Down
6 changes: 3 additions & 3 deletions test/api/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def check_metadata_record(schema_id, deep=True):
route = f'/catalog/{catalog_id}/records'
resp_code = 200
if endpoint == 'get':
route += f'/{example_record.doi}' if example_record.doi else f'/{example_record.id}'
route += f'/{example_record.doi.swapcase()}' if example_record.doi else f'/{example_record.id}'
resp_code = 200 if published else 404

r = api(scopes, create_scopes=False).get(route)
Expand Down Expand Up @@ -319,7 +319,7 @@ def test_get_published_metadata_value(
)

route = f'/catalog/{catalog_id}/getvalue/'
route += example_record.doi if example_record.doi else example_record.id
route += example_record.doi.swapcase() if example_record.doi else example_record.id

r = api(scopes, create_scopes=False).get(route, params=dict(
schema_id=schema_id,
Expand Down Expand Up @@ -351,7 +351,7 @@ def test_get_published_metadata_document(
)

route = f'/catalog/{catalog_id}/getvalue/'
route += example_record.doi if example_record.doi else example_record.id
route += example_record.doi.swapcase() if example_record.doi else example_record.id

r = api(scopes, create_scopes=False).get(route, params=dict(
schema_id=schema_id,
Expand Down

0 comments on commit 742961d

Please sign in to comment.