Skip to content
Snippets Groups Projects
Commit ba29d385 authored by Swen Vermeul's avatar Swen Vermeul
Browse files

search samples with identifier added

parent d04ff276
No related branches found
No related tags found
No related merge requests found
...@@ -121,6 +121,7 @@ def get_attrs_for_entity(entity): ...@@ -121,6 +121,7 @@ def get_attrs_for_entity(entity):
def _type_for_id(ident, entity): def _type_for_id(ident, entity):
ident = ident.strip()
"""Returns the data type for a given identifier/permId for use with the API call, e.g. """Returns the data type for a given identifier/permId for use with the API call, e.g.
{ {
"identifier": "/DEFAULT/SAMPLE_NAME", "identifier": "/DEFAULT/SAMPLE_NAME",
...@@ -161,6 +162,9 @@ def _type_for_id(ident, entity): ...@@ -161,6 +162,9 @@ def _type_for_id(ident, entity):
entity_capitalize = entity.capitalize() entity_capitalize = entity.capitalize()
if is_identifier(ident): if is_identifier(ident):
# people tend to omit the / prefix of an identifier...
if not ident.startswith('/'):
ident = '/'+ident
search_request = { search_request = {
"identifier": ident.upper(), "identifier": ident.upper(),
"@type": "as.dto.{}.id.{}Identifier".format(entity.lower(), entity_capitalize) "@type": "as.dto.{}.id.{}Identifier".format(entity.lower(), entity_capitalize)
...@@ -1310,7 +1314,7 @@ class Openbis: ...@@ -1310,7 +1314,7 @@ class Openbis:
def get_samples( def get_samples(
self, code=None, permId=None, space=None, project=None, experiment=None, type=None, self, identifier=None, code=None, permId=None, space=None, project=None, experiment=None, type=None,
start_with=None, count=None, start_with=None, count=None,
withParents=None, withChildren=None, tags=None, props=None, **properties withParents=None, withChildren=None, tags=None, props=None, **properties
): ):
...@@ -1318,13 +1322,24 @@ class Openbis: ...@@ -1318,13 +1322,24 @@ class Openbis:
""" """
sub_criteria = [] sub_criteria = []
# v3 API does not offer a search for identifiers. We need to do a combined search instead:
# space && code or
# space && project && code
if identifier:
identifier = identifier.lstrip('/')
elements = identifier.split('/')
if len(elements) == 2:
space = elements[0]
code = elements[1]
elif len(elements) == 3:
space = elements[0]
code = elements[2]
else:
raise ValueError("{} is not a valid sample identifier.".format(identifier))
if space: if space:
sub_criteria.append(_gen_search_criteria({ sub_criteria.append(_subcriteria_for_code(space, 'space'))
"space": "Space",
"operator": "AND",
"code": space
})
)
if project: if project:
proj_crit = _subcriteria_for_code(project, 'project') proj_crit = _subcriteria_for_code(project, 'project')
sub_criteria.append(proj_crit) sub_criteria.append(proj_crit)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment