diff --git a/sql/README.md b/sql/README.md index 61c8455..90e7c1f 100644 --- a/sql/README.md +++ b/sql/README.md @@ -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 @@ -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. diff --git a/sql/uuid-api.mwb b/sql/uuid-api.mwb index 467ba40..ff732b3 100644 Binary files a/sql/uuid-api.mwb and b/sql/uuid-api.mwb differ diff --git a/sql/uuid-api.pdf b/sql/uuid-api.pdf index 82a0a87..5a17fb8 100644 Binary files a/sql/uuid-api.pdf and b/sql/uuid-api.pdf differ diff --git a/sql/uuid-api.sql b/sql/uuid-api.sql index dfdb014..b128064 100644 --- a/sql/uuid-api.sql +++ b/sql/uuid-api.sql @@ -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, diff --git a/src/instance/app.cfg.example b/src/instance/app.cfg.example index e725111..736148a 100644 --- a/src/instance/app.cfg.example +++ b/src/instance/app.cfg.example @@ -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 diff --git a/src/instance/sennet.app.cfg.example b/src/instance/sennet.app.cfg.example index d5f6826..39d719b 100644 --- a/src/instance/sennet.app.cfg.example +++ b/src/instance/sennet.app.cfg.example @@ -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 diff --git a/src/uuid_worker.py b/src/uuid_worker.py index 9ab054d..0efc075 100644 --- a/src/uuid_worker.py +++ b/src/uuid_worker.py @@ -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 = \ @@ -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 @@ -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'] @@ -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.") @@ -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': @@ -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): @@ -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 = [] @@ -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. @@ -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']