Skip to content

Commit

Permalink
Merge pull request #142 from x-atlas-consortia/karlburke/Publications…
Browse files Browse the repository at this point in the history
…WithoutSubclassing

Remove logic mapping Publication entities into Dataset entities, and …
  • Loading branch information
yuanzhou authored Feb 5, 2024
2 parents e10d020 + 968c494 commit 501c3ab
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 47 deletions.
13 changes: 12 additions & 1 deletion sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ After setting the connection parameters and clicking "Next", check the following
````
Omit schema qualifier in object names
````
````
Include model attached scripts
````
and uncheck the following option on the same screen
````
Generate USE statements
Expand All @@ -44,7 +47,15 @@ and
````
Export MySQL Routine Objects
````
Click "Next". Examine the generated SQL script to assure it is independent of the database it is being executed in. Use the buttons or clipboard to save this file as `uuid-api.sql`.
Click "Next". Examine the generated SQL script to assure it is independent of the database it is being executed in. For example, statements should look like

````CREATE TABLE IF NOT EXISTS `uuids`...````

and **_not_**

````CREATE TABLE IF NOT EXISTS `hm_dev_uuids`.`uuids`...````

Use the buttons or clipboard to save this file as `uuid-api.sql`.

Click "Cancel" to abandon the rest of the "forward engineer" process.

Expand Down
Binary file modified sql/uuid-api.mwb
Binary file not shown.
Binary file modified sql/uuid-api.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion sql/uuid-api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ CREATE TABLE IF NOT EXISTS `uuids_attributes` (
`BASE_ID` VARCHAR(10) NULL DEFAULT NULL,
`SUBMISSION_ID` VARCHAR(170) NULL DEFAULT NULL,
`DESCENDANT_COUNT` INT NULL DEFAULT '0',
`ENTITY_CLASS_METADATA` JSON NULL DEFAULT NULL,
PRIMARY KEY (`UUID`),
UNIQUE INDEX `UNQ_HM_SUBMISSION_ID` (`SUBMISSION_ID` ASC) VISIBLE,
UNIQUE INDEX `UNQ_BASE_ID` (`BASE_ID` ASC) VISIBLE,
Expand Down
11 changes: 4 additions & 7 deletions src/instance/app.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ APP_ID = 'hubmap_id'
APP_BASE_ID = 'base_id'

BASE_DIR_TYPES = ['DATA_UPLOAD', 'INGEST_PORTAL_UPLOAD']
BASE_ID_ENTITY_TYPES = ['ACTIVITY', 'SAMPLE', 'DONOR', 'DATASET', 'COLLECTION', 'UPLOAD', 'REFERENCE', 'AVR']
# Entity types which have a uuids_attributes.BASE_ID associated with them
BASE_ID_ENTITY_TYPES = ['ACTIVITY', 'SAMPLE', 'DONOR', 'DATASET', 'COLLECTION', 'UPLOAD', 'REFERENCE', 'AVR', 'PUBLICATION']
# A full list of values found in uuids.ENTITY_TYPE, currently partitioned into those with a BASE_ID and those without.
KNOWN_ENTITY_TYPES = BASE_ID_ENTITY_TYPES + ['FILE', 'LAB']
MAPPED_ENTITY_TYPES = {
'PUBLICATION': { 'entity_type': 'DATASET'
,'entity_class': 'Publication'
,'entity_class_JSON': '{"class": "Publication"}'}
}
ANCESTOR_REQUIRED_ENTITY_TYPES = ['SAMPLE', 'DONOR', 'DATASET', 'FILE', 'UPLOAD']
ANCESTOR_REQUIRED_ENTITY_TYPES = ['SAMPLE', 'DONOR', 'DATASET', 'FILE', 'UPLOAD', 'PUBLICATION']
MULTIPLE_ALLOWED_ORGANS = ['LV', 'LY', 'SK', 'BD', 'BM']

# Only for HubMap, not SenNet
Expand Down
8 changes: 4 additions & 4 deletions src/instance/sennet.app.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ APP_ID = 'sennet_id'
APP_BASE_ID = 'base_id'

BASE_DIR_TYPES = ['DATA_UPLOAD', 'INGEST_PORTAL_UPLOAD']
BASE_ID_ENTITY_TYPES = ['ACTIVITY', 'SAMPLE', 'SOURCE', 'DATASET', 'COLLECTION', 'UPLOAD', 'REFERENCE', 'AVR']
# Entity types which have a uuids_attributes.BASE_ID associated with them
BASE_ID_ENTITY_TYPES = ['ACTIVITY', 'SAMPLE', 'SOURCE', 'DATASET', 'COLLECTION', 'UPLOAD', 'REFERENCE', 'AVR', 'PUBLICATION']]
# A full list of values found in uuids.ENTITY_TYPE, currently partitioned into those with a BASE_ID and those without.
KNOWN_ENTITY_TYPES = BASE_ID_ENTITY_TYPES + ['FILE', 'LAB']
MAPPED_ENTITY_TYPES = {
}
ANCESTOR_REQUIRED_ENTITY_TYPES = ['SAMPLE', 'SOURCE', 'DATASET', 'FILE', 'UPLOAD']
ANCESTOR_REQUIRED_ENTITY_TYPES = ['SAMPLE', 'SOURCE', 'DATASET', 'FILE', 'UPLOAD', 'PUBLICATION']
MULTIPLE_ALLOWED_ORGANS = ['LY', 'SK', 'BD', 'BM']

# Only for HubMap, not SenNet
Expand Down
43 changes: 9 additions & 34 deletions src/uuid_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class EntityTypeUUIDPrefix(Enum):

SQL_INSERT_UUIDS_ATTRIBUTES_DEFAULT_DESC_COUNT = \
("INSERT INTO uuids_attributes "
" (UUID, BASE_ID, SUBMISSION_ID, ENTITY_CLASS_METADATA)"
" (UUID, BASE_ID, SUBMISSION_ID)"
" VALUES"
" (%s, %s, %s, %s)"
" (%s, %s, %s)"
)

SQL_INSERT_ANCESTORS = \
Expand Down Expand Up @@ -284,7 +284,6 @@ def __init__(self, app_config=None):
global BASE_DIR_TYPES
global BASE_ID_ENTITY_TYPES
global KNOWN_ENTITY_TYPES
global MAPPED_ENTITY_TYPES
global ANCESTOR_REQUIRED_ENTITY_TYPES
global MULTIPLE_ALLOWED_ORGANS
global SUBMISSION_ID_ENTITY_TYPES
Expand All @@ -310,7 +309,6 @@ def __init__(self, app_config=None):
BASE_DIR_TYPES = app_config['BASE_DIR_TYPES']
BASE_ID_ENTITY_TYPES = app_config['BASE_ID_ENTITY_TYPES']
KNOWN_ENTITY_TYPES = app_config['KNOWN_ENTITY_TYPES']
MAPPED_ENTITY_TYPES = app_config['MAPPED_ENTITY_TYPES']
ANCESTOR_REQUIRED_ENTITY_TYPES = app_config['ANCESTOR_REQUIRED_ENTITY_TYPES']
MULTIPLE_ALLOWED_ORGANS = app_config['MULTIPLE_ALLOWED_ORGANS']
SUBMISSION_ID_ENTITY_TYPES = app_config['SUBMISSION_ID_ENTITY_TYPES']
Expand Down Expand Up @@ -345,15 +343,6 @@ def __init__(self, app_config=None):
raise Exception("Configuration parameter APP_CLIENT_ID not valid.")
if not clientSecret:
raise Exception("Configuration parameter APP_CLIENT_SECRET not valid.")

# Verify the JSON elements of the configuration, which will be stored in
# MySQL rows of type 'json', contain valid JSON.
for entity_type in MAPPED_ENTITY_TYPES.keys():
try:
json.loads(MAPPED_ENTITY_TYPES[entity_type]['entity_class_JSON'])
except (ValueError, TypeError):
raise Exception(f"MAPPED_ENTITY_TYPES[{entity_type}] configured with invalid JSON:"
f" {MAPPED_ENTITY_TYPES[entity_type]['entity_class_JSON']}.")
except KeyError as ke:
self.logger.error("Expected configuration failed to load %s from app_config=%s.",ke,app_config)
raise Exception("Expected configuration failed to load. See the logs.")
Expand Down Expand Up @@ -445,19 +434,9 @@ def uuidPost(self, req, nIds):

# Verify we know how to handle the entity type provided
entityType = content['entity_type'].upper().strip()
if entityType not in KNOWN_ENTITY_TYPES and entityType not in MAPPED_ENTITY_TYPES.keys():
if entityType not in KNOWN_ENTITY_TYPES:
return Response(f"Unrecognized entity type {content['entity_type']}.", 400)

# If this is an entity type which requires transformation, it is done here so
# all the business logic associated with the actual entity type and with the
# entity class are executed before persisted to the database.
# E.G. "publication" entities become "dataset" entities of class "publication"
entity_class = MAPPED_ENTITY_TYPES[entityType]['entity_class'] if entityType in MAPPED_ENTITY_TYPES.keys() else None
entity_class_JSON = MAPPED_ENTITY_TYPES[entityType]['entity_class_JSON'] if entityType in MAPPED_ENTITY_TYPES.keys() else None
# now that entity_class and entity_class_JSON have been set based on entityType, remap entityType to
# database value, if needed.
entityType = MAPPED_ENTITY_TYPES[entityType]['entity_type'] if entityType in MAPPED_ENTITY_TYPES.keys() else entityType

organ_code = None
if 'organ_code' in content and not isBlank(content['organ_code']):
if not entityType == 'SAMPLE':
Expand Down Expand Up @@ -523,8 +502,7 @@ def uuidPost(self, req, nIds):
return (Response("Parent id " + parentId + " does not exist", 400))

return self.newUUIDs(ancestor_ids, entityType, userId, userEmail, nIds, organ_code=organ_code,
lab_code=lab_code, file_info_array=file_info, base_dir_type=base_dir,
entity_class=entity_class, entity_class_JSON=entity_class_JSON)
lab_code=lab_code, file_info_array=file_info, base_dir_type=base_dir)

'''
def uuidPut(self, req):
Expand Down Expand Up @@ -659,7 +637,7 @@ def __create_submission_ids(self, num_to_gen, parent_id, entity_type, organ_code
# generate multiple ids, one for each display id in the displayIds array

def newUUIDs(self, parentIDs, entityType, userId, userEmail, nIds, organ_code=None, lab_code=None,
file_info_array=None, base_dir_type=None, entity_class=None, entity_class_JSON=None):
file_info_array=None, base_dir_type=None):

gen_base_ids = entityType in BASE_ID_ENTITY_TYPES
returnIds = []
Expand All @@ -682,8 +660,7 @@ def newUUIDs(self, parentIDs, entityType, userId, userEmail, nIds, organ_code=No
# the UUID row that will be created.
# N.B. descendant_count is tied to gen_submission_ids i.e. will not need a
# row to support descendant_count unless submission_id is populated.
insert_attributes_for_uuid = gen_base_ids or gen_submission_ids or \
entity_class == 'Publication'
insert_attributes_for_uuid = gen_base_ids or gen_submission_ids

# Loop to generate the number of entityType requested in the nIds argument, in batches of
# size MAX_GEN_IDS.
Expand Down Expand Up @@ -748,11 +725,9 @@ def newUUIDs(self, parentIDs, entityType, userId, userEmail, nIds, organ_code=No
insertVals.append((insUuid, entityType, awareUTCTimeNow, userId, userEmail))

if insert_attributes_for_uuid:
insertAttribVals.append((insUuid
, ins_app_base_id
, submission_ids[n] if gen_submission_ids else None
, entity_class_JSON if entity_class_JSON else None))

insertAttribVals.append( (insUuid
,ins_app_base_id
,submission_ids[n] if gen_submission_ids else None))
if store_file_info:
info_idx = i + n
file_path = file_info_array[info_idx]['path']
Expand Down

0 comments on commit 501c3ab

Please sign in to comment.