Skip to content

Commit c584cb5

Browse files
rework external process creation action validation. Publications now override the creation action property making it "generated". Checks for ancestor entity type now occurs within dedicated neo4j query
1 parent b7cb172 commit c584cb5

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,37 @@ 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+
126+
Returns
127+
-------
128+
dict
129+
A dictionary of entity uuids that don't pass the filter, grouped by entity_type
130+
"""
131+
def filter_ancestors_by_type(neo4j_driver, direct_ancestor_uuids, entity_type):
132+
uuids_str = ", ".join([f'"{uuid}"' for uuid in direct_ancestor_uuids])
133+
query = (f"MATCH (e:Entity) "
134+
f"WHERE e.uuid in [{uuids_str}] AND toLower(e.entity_type) <> '{entity_type.lower()}' "
135+
f"RETURN e.entity_type AS entity_type, collect(e.uuid) AS uuids")
136+
logger.info("======filter_ancestors_by_type======")
137+
logger.info(query)
138+
139+
with neo4j_driver.session() as session:
140+
records = session.run(query).data()
141+
142+
return records if records else None
143+
144+
145+
115146
"""
116147
Get all children by uuid
117148

src/schema/schema_validators.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,11 @@ def validate_creation_action(property_key, normalized_entity_type, request, exis
589589
if normalized_entity_type.lower() != "dataset":
590590
raise ValueError(f"Only datasets are allowed to have creation_action of 'external_process'. Provided entity is a {normalized_entity_type}")
591591
direct_ancestor_uuids = new_data_dict.get('direct_ancestor_uuids')
592-
for ancestor_uuid in direct_ancestor_uuids:
593-
ancestor = schema_neo4j_queries.get_entity(schema_manager.get_neo4j_driver_instance(), ancestor_uuid)
594-
ancestor_type = ancestor['entity_type']
595-
if ancestor_type.lower() != "dataset":
596-
raise ValueError(f"If creation_action is 'external process', all direct ancesotrs must be of type 'dataset'. Ancestor with uuid {ancestor_uuid} has entity type of '{ancestor_type}'")
597-
592+
entity_types_dict = schema_neo4j_queries.filter_ancestors_by_type(schema_manager.get_neo4j_driver_instance(), direct_ancestor_uuids, "dataset")
593+
if entity_types_dict:
594+
raise ValueError(f"If 'creation_action' field is given, all ancestor uuids must belong to datasets. The following entities belong to non-dataset entities \
595+
{entity_types_dict}")
596+
598597

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

0 commit comments

Comments
 (0)