Skip to content

Commit 2359947

Browse files
authored
Merge pull request #693 from hubmapconsortium/Derek-Furst/external-process
Derek furst/external process
2 parents 11472ed + 1690b6f commit 2359947

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/schema/provenance_schema.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,15 @@ ENTITIES:
654654
indexed: true
655655
description: "The title of the publication."
656656
required_on_create: true # Only required for create via POST, not update via PUT
657+
creation_action:
658+
type: string
659+
transient: true
660+
generated: true
661+
immutable: true
662+
indexed: true
663+
on_read_trigger: get_creation_action_activity
664+
on_index_trigger: get_creation_action_activity
665+
description: "The activity that was performed."
657666
dataset_type:
658667
before_create_trigger: set_publication_dataset_type
659668
before_property_create_validators:

src/schema/schema_neo4j_queries.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,38 @@ def get_entity(neo4j_driver, uuid):
112112
return result
113113

114114

115+
116+
"""
117+
Get the uuids for each entity in a list that doesn't belong to a certain entity type. Uuids are ordered by type
118+
119+
Parameters
120+
----------
121+
neo4j_driver : neo4j.Driver object
122+
The neo4j database connection pool
123+
direct_ancestor_uuids : list
124+
List of the uuids to be filtered
125+
entity_type : string
126+
The entity to be excluded
127+
128+
Returns
129+
-------
130+
dict
131+
A dictionary of entity uuids that don't pass the filter, grouped by entity_type
132+
"""
133+
def filter_ancestors_by_type(neo4j_driver, direct_ancestor_uuids, entity_type):
134+
query = (f"MATCH (e:Entity) "
135+
f"WHERE e.uuid in {direct_ancestor_uuids} AND toLower(e.entity_type) <> '{entity_type.lower()}' "
136+
f"RETURN e.entity_type AS entity_type, collect(e.uuid) AS uuids")
137+
logger.info("======filter_ancestors_by_type======")
138+
logger.info(query)
139+
140+
with neo4j_driver.session() as session:
141+
records = session.run(query).data()
142+
143+
return records if records else None
144+
145+
146+
115147
"""
116148
Get all children by uuid
117149

src/schema/schema_validators.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,19 @@ def validate_publication_date(property_key, normalized_entity_type, request, exi
579579
The json data in request body, already after the regular validations
580580
"""
581581
def validate_creation_action(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict):
582-
accepted_creation_action_values = ["central process", "lab process"]
582+
accepted_creation_action_values = ["central process", "lab process", "external process"]
583583
creation_action = new_data_dict[property_key].lower()
584584
if creation_action and creation_action not in accepted_creation_action_values:
585585
raise ValueError("Invalid {} value. Accepted values are: {}".format(property_key, ", ".join(accepted_creation_action_values)))
586586
if creation_action == '':
587587
raise ValueError(f"The property {property_key} cannot be empty, when specified.")
588-
588+
if creation_action == 'external process':
589+
direct_ancestor_uuids = new_data_dict.get('direct_ancestor_uuids')
590+
entity_types_dict = schema_neo4j_queries.filter_ancestors_by_type(schema_manager.get_neo4j_driver_instance(), direct_ancestor_uuids, "dataset")
591+
if entity_types_dict:
592+
raise ValueError(f"If 'creation_action' field is given, all ancestor uuids must belong to datasets. The following entities belong to non-dataset entities \
593+
{entity_types_dict}")
594+
589595

590596
"""
591597
Validate the provided value of the activity creation action before updating direct ancestors. Certain values prohibited

0 commit comments

Comments
 (0)