Skip to content

Commit aeb9a9a

Browse files
authored
Merge pull request the-library-code#39 from kshepherd/find_by_identifier
New method to "find by identifier"
2 parents 51f9e47 + 6046091 commit aeb9a9a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

dspace_rest_client/client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,10 +1443,38 @@ def get_short_lived_token(self):
14431443
return None
14441444

14451445
def solr_query(self, query, filters=None, fields=None, start=0, rows=999999999):
1446+
"""
1447+
Perform raw Solr query
1448+
@param query: query string
1449+
@param filters: list of filter queries
1450+
@param fields: list of fields to return in results
1451+
@param start: start doc
1452+
@param rows: max docs to return
1453+
@return: solr search results
1454+
"""
14461455
if fields is None:
14471456
fields = []
14481457
if filters is None:
14491458
filters = []
14501459
return self.solr.search(
14511460
query, fq=filters, start=start, rows=rows, **{"fl": ",".join(fields)}
14521461
)
1462+
1463+
def resolve_identifier_to_dso(self, identifier=None):
1464+
"""
1465+
Resolve a DSO identifier (uuid, handle, DOI, etc.) to a DSO URI
1466+
Useful for resolving handles to objects, etc.
1467+
@param identifier: a persistent identifier for an object like handle, doi, uuid
1468+
@return: resolved DSpaceObject or error
1469+
"""
1470+
if identifier is not None:
1471+
url = f'{self.API_ENDPOINT}/pid/find'
1472+
r = self.api_get(url, params={'id': identifier})
1473+
if r.status_code == 200:
1474+
r_json = parse_json(r)
1475+
if r_json is not None and 'uuid' in r_json:
1476+
return DSpaceObject(api_resource=r_json)
1477+
elif r.status_code == 404:
1478+
logging.error(f"Not found: {identifier}")
1479+
else:
1480+
logging.error(f"Error resolving identifier {identifier} to DSO: {r.status_code}")

0 commit comments

Comments
 (0)