From 66a3ff5e42fc065afc624c5b130e48420f4075ac Mon Sep 17 00:00:00 2001 From: maxsibilla Date: Fri, 20 Dec 2024 14:29:16 -0500 Subject: [PATCH 1/3] Updating prov-info neo4j query function to sort derived datasets by last modified timestamp and placing published dataset at front of the list --- src/app_neo4j_queries.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/app_neo4j_queries.py b/src/app_neo4j_queries.py index baa3be2..a9baedc 100644 --- a/src/app_neo4j_queries.py +++ b/src/app_neo4j_queries.py @@ -1864,6 +1864,15 @@ def get_individual_prov_info(neo4j_driver, dataset_uuid): for entry in record_contents[16]: node_dict = _node_to_dict(entry) content_sixteen.append(node_dict) + + # Sort the derived datasets by status and last_modified_timestamp + content_sixteen = sorted(content_sixteen, key=lambda d: d['last_modified_timestamp'], reverse=True) + + published_processed_dataset_location = next((i for i, item in enumerate(content_sixteen) if item["status"] == "Published"), None) + if published_processed_dataset_location and published_processed_dataset_location != 0: + published_processed_dataset = content_sixteen.pop(published_processed_dataset_location) + content_sixteen.insert(0, published_processed_dataset) + record_dict['processed_dataset'] = content_sixteen return record_dict From 334fd9db5c5b11cd6b57a1791d7a3876387a4cd4 Mon Sep 17 00:00:00 2001 From: maxsibilla Date: Fri, 20 Dec 2024 14:47:52 -0500 Subject: [PATCH 2/3] Updating /descendants endpoint to sort results when the requested entity is a Dataset --- src/app.py | 6 ++++-- src/app_neo4j_queries.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/app.py b/src/app.py index c10c5cd..0cdc381 100644 --- a/src/app.py +++ b/src/app.py @@ -1773,7 +1773,8 @@ def get_descendants(id): abort_bad_req(f"Only the following property keys are supported in the query string: {COMMA_SEPARATOR.join(result_filtering_accepted_property_keys)}") # Only return a list of the filtered property value of each entity - property_list = app_neo4j_queries.get_descendants(neo4j_driver_instance, uuid, data_access_level, property_key) + property_list = app_neo4j_queries.get_descendants(neo4j_driver_instance, uuid, data_access_level, + property_key, entity_type=entity_dict['entity_type']) # Final result final_result = property_list @@ -1781,7 +1782,8 @@ def get_descendants(id): abort_bad_req("The specified query string is not supported. Use '?property=' to filter the result") # Return all the details if no property filtering else: - descendants_list = app_neo4j_queries.get_descendants(neo4j_driver_instance, uuid, data_access_level) + descendants_list = app_neo4j_queries.get_descendants(neo4j_driver_instance, uuid, data_access_level, + entity_type=entity_dict['entity_type']) # Generate trigger data and merge into a big dict # and skip some of the properties that are time-consuming to generate via triggers diff --git a/src/app_neo4j_queries.py b/src/app_neo4j_queries.py index a9baedc..f2b839c 100644 --- a/src/app_neo4j_queries.py +++ b/src/app_neo4j_queries.py @@ -1,6 +1,7 @@ import logging from atlas_consortia_commons.object import enum_val +from atlas_consortia_commons.string import equals from neo4j.exceptions import TransactionError from lib.ontology import Ontology @@ -657,7 +658,7 @@ def get_ancestors(neo4j_driver, uuid, data_access_level=None, property_key=None) return results -def get_descendants(neo4j_driver, uuid, data_access_level=None, property_key=None): +def get_descendants(neo4j_driver, uuid, data_access_level=None, property_key=None, entity_type=None): """ Get all descendants by uuid Parameters @@ -711,6 +712,16 @@ def get_descendants(neo4j_driver, uuid, data_access_level=None, property_key=Non # Convert the list of nodes to a list of dicts results = _nodes_to_dicts(record[record_field_name]) + # If asked for the descendants of a Dataset then sort by last_modified_timestamp and place the published dataset at the top + if equals(entity_type, Ontology.ops().entities().DATASET): + sorted(results, key=lambda d: d['last_modified_timestamp'], reverse=True) + + published_processed_dataset_location = next( + (i for i, item in enumerate(results) if item["status"] == "Published"), None) + if published_processed_dataset_location and published_processed_dataset_location != 0: + published_processed_dataset = results.pop(published_processed_dataset_location) + results.insert(0, published_processed_dataset) + for result in results: protocol_url = get_activity_protocol(neo4j_driver, result['uuid']) if protocol_url != {}: From c58a82fe3941859a006f01f9b45e0e0c520e57b8 Mon Sep 17 00:00:00 2001 From: maxsibilla Date: Fri, 20 Dec 2024 14:56:36 -0500 Subject: [PATCH 3/3] Properly setting sorted list --- src/app_neo4j_queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app_neo4j_queries.py b/src/app_neo4j_queries.py index f2b839c..9770f0f 100644 --- a/src/app_neo4j_queries.py +++ b/src/app_neo4j_queries.py @@ -714,7 +714,7 @@ def get_descendants(neo4j_driver, uuid, data_access_level=None, property_key=Non # If asked for the descendants of a Dataset then sort by last_modified_timestamp and place the published dataset at the top if equals(entity_type, Ontology.ops().entities().DATASET): - sorted(results, key=lambda d: d['last_modified_timestamp'], reverse=True) + results = sorted(results, key=lambda d: d['last_modified_timestamp'], reverse=True) published_processed_dataset_location = next( (i for i, item in enumerate(results) if item["status"] == "Published"), None)