Skip to content

Commit

Permalink
Merge pull request #69 from sennetconsortium/generalize-uuid-branch
Browse files Browse the repository at this point in the history
Generalize UUID branch
  • Loading branch information
yuanzhou authored Apr 21, 2022
2 parents 806dd9a + 2149680 commit 751e8db
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/uuid_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
instance_relative_config=True)
app.config.from_pyfile('app.cfg')

# These application specific IDs are used to generalize the uuid-api to allow it to work with specific instances of entity-api
APP_ID_PREFIX = app.config['APP_ID_PREFIX']
APP_ID = app.config['APP_ID']
APP_UUID = app.config['APP_UUID']
Expand Down Expand Up @@ -773,6 +774,51 @@ def testConnection(self):
self.logger.error(e, exc_info=True)
return False

# get the information for all files attached to a specific entity
# input: id (hubmap_id or uuid) of the parent entity
# output: an array of dicts with each dict containing the attributes of a file
# file attributes:
# path: the local file system path, including name of the file
# checksum: the checksum of the file
# size: the size of the file
# file_uuid: the uuid of the file
# base_dir: the base directory type, one of
# INGEST_PORTAL_UPLOAD - the file was uploaded into the space for file uploads from the Ingest UI
# DATA_UPLOAD - the file was upload into the upload space for datasets usually via Globus
#
def get_file_info(self, entity_id):
# The info is a pretty print json string
info = self.getIdInfo(entity_id)

# if getIdInfo returns a Response, it is sending an error back
if isinstance(info, Response):
return info
# convert to dict
info_d = json.loads(info)

if not APP_UUID in info_d:
return Response("Error: not corresponding UUID found for " + entity_id, 400)

entity_uuid = info_d[APP_UUID]

# query that finds all files associated with entity by joining the ancestors table (entity is the ancestor, files are the descendants) with the files table
sql = f"select * from files left join ancestors on ancestors.descendant_uuid = files.uuid where ancestors.ancestor_uuid = '{entity_uuid}';"

# run the query and morph results to an array of dict
with closing(self.hmdb.getDBConnection()) as dbConn:
with closing(dbConn.cursor()) as curs:
curs.execute(sql)
results = [dict((curs.description[i][0].lower(), value) for i, value in enumerate(row)) for row in
curs.fetchall()]

# remove unneeded result columns and change the name of base_id to file_uuid
for item in results:
item['file_uuid'] = item['uuid']
item.pop('uuid')
item.pop('descendant_uuid')
item.pop('ancestor_uuid')
return results


'''
def newUUID(self, parentID, entityType, userId, userEmail, submissionId=None):
Expand Down

0 comments on commit 751e8db

Please sign in to comment.