Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derek furst/external process #693

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/schema/provenance_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,15 @@ ENTITIES:
indexed: true
description: "The title of the publication."
required_on_create: true # Only required for create via POST, not update via PUT
creation_action:
type: string
transient: true
generated: true
immutable: true
indexed: true
on_read_trigger: get_creation_action_activity
on_index_trigger: get_creation_action_activity
description: "The activity that was performed."
dataset_type:
before_create_trigger: set_publication_dataset_type
before_property_create_validators:
Expand Down
32 changes: 32 additions & 0 deletions src/schema/schema_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,38 @@ def get_entity(neo4j_driver, uuid):
return result



"""
Get the uuids for each entity in a list that doesn't belong to a certain entity type. Uuids are ordered by type

Parameters
----------
neo4j_driver : neo4j.Driver object
The neo4j database connection pool
direct_ancestor_uuids : list
List of the uuids to be filtered
entity_type : string
The entity to be excluded

Returns
-------
dict
A dictionary of entity uuids that don't pass the filter, grouped by entity_type
"""
def filter_ancestors_by_type(neo4j_driver, direct_ancestor_uuids, entity_type):
query = (f"MATCH (e:Entity) "
f"WHERE e.uuid in {direct_ancestor_uuids} AND toLower(e.entity_type) <> '{entity_type.lower()}' "
f"RETURN e.entity_type AS entity_type, collect(e.uuid) AS uuids")
logger.info("======filter_ancestors_by_type======")
logger.info(query)

with neo4j_driver.session() as session:
records = session.run(query).data()

return records if records else None



"""
Get all children by uuid

Expand Down
10 changes: 8 additions & 2 deletions src/schema/schema_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,19 @@ def validate_publication_date(property_key, normalized_entity_type, request, exi
The json data in request body, already after the regular validations
"""
def validate_creation_action(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict):
accepted_creation_action_values = ["central process", "lab process"]
accepted_creation_action_values = ["central process", "lab process", "external process"]
creation_action = new_data_dict[property_key].lower()
if creation_action and creation_action not in accepted_creation_action_values:
raise ValueError("Invalid {} value. Accepted values are: {}".format(property_key, ", ".join(accepted_creation_action_values)))
if creation_action == '':
raise ValueError(f"The property {property_key} cannot be empty, when specified.")

if creation_action == 'external process':
direct_ancestor_uuids = new_data_dict.get('direct_ancestor_uuids')
entity_types_dict = schema_neo4j_queries.filter_ancestors_by_type(schema_manager.get_neo4j_driver_instance(), direct_ancestor_uuids, "dataset")
if entity_types_dict:
raise ValueError(f"If 'creation_action' field is given, all ancestor uuids must belong to datasets. The following entities belong to non-dataset entities \
{entity_types_dict}")


"""
Validate the provided value of the activity creation action before updating direct ancestors. Certain values prohibited
Expand Down
Loading