Skip to content

Commit

Permalink
Increment version to 0.3.4 and changed get_es_metadata to do a search…
Browse files Browse the repository at this point in the history
…, so it doesn't need schema name
  • Loading branch information
carlvitzthum committed Jul 16, 2018
1 parent 946c635 commit d933338
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dcicutils/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Version information."""

# The following line *must* be the last in the module, exactly as formatted:
__version__ = "0.3.3"
__version__ = "0.3.4"
17 changes: 11 additions & 6 deletions dcicutils/ff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ def delete_field(obj_id, del_field, key=None, ff_env=None):
return get_response_json(response)


def get_es_metadata(uuid, schema_name, es_client=None, key=None, ff_env=None):
def get_es_metadata(uuid, es_client=None, key=None, ff_env=None):
"""
Given string item uuid and schema name (e.g. "file_fastq"), will return a
Given string item uuid, will return a
dictionary response of the full ES ecord for that item (or an empty
dictionary if the item doesn't exist/ is not indexed)
You can pass in an Elasticsearch client (initialized by create_es_client)
Expand All @@ -347,11 +347,16 @@ def get_es_metadata(uuid, schema_name, es_client=None, key=None, ff_env=None):
health_res = authorized_request(auth['server'] + '/health', auth=auth, verb='GET')
es_url = get_response_json(health_res)['elasticsearch']
es_client = es_utils.create_es_client(es_url, use_aws_auth=True)
try:
es_res = es_client.get(index=schema_name, doc_type=schema_name, id=uuid)
except TransportError:
es_res = es_client.search(index='_all', body={'query': {'term': {'_id': uuid}}})
es_hits = es_res['hits']['hits']
if not isinstance(es_hits, list):
raise Exception('ERROR malformed results found when searching for uuid %s' % uuid)
elif len(es_hits) > 1:
raise Exception('ERROR multiple results found when searching for uuid %s' % uuid)
elif len(es_hits) == 0:
return {}
return es_res.get('_source', {})
# es_hits should only be length 1, so this is the result
return es_hits[0]


#####################
Expand Down
4 changes: 2 additions & 2 deletions test/test_ff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_get_es_metadata(integrated_ff):
from dcicutils import es_utils
# use this test biosource
test_item = '331111bc-8535-4448-903e-854af460b254'
res = ff_utils.get_es_metadata(test_item, 'biosource', key=integrated_ff['ff_key'])
res = ff_utils.get_es_metadata(test_item, key=integrated_ff['ff_key'])
assert res['uuid'] == test_item
assert res['item_type'] == 'biosource'
assert isinstance(res['embedded'], dict)
Expand All @@ -348,7 +348,7 @@ def test_get_es_metadata(integrated_ff):
auth=integrated_ff['ff_key'])
es_url = ff_utils.get_response_json(health_res)['elasticsearch']
es_client = es_utils.create_es_client(es_url, use_aws_auth=True)
res2 = ff_utils.get_es_metadata(test_item, 'biosource', es_client=es_client,
res2 = ff_utils.get_es_metadata(test_item, es_client=es_client,
key=integrated_ff['ff_key'])
assert res2['uuid'] == res['uuid']

Expand Down

0 comments on commit d933338

Please sign in to comment.