Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsibilla committed Jan 9, 2025
2 parents 2e80ce3 + 567f63e commit 773d242
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,15 +1773,17 @@ 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
else:
abort_bad_req("The specified query string is not supported. Use '?property=<key>' 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
Expand Down
22 changes: 21 additions & 1 deletion src/app_neo4j_queries.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
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)
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 != {}:
Expand Down Expand Up @@ -1864,6 +1875,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

Expand Down

0 comments on commit 773d242

Please sign in to comment.