@@ -1046,7 +1046,6 @@ def get_entities_by_type(entity_type):
10461046 # Response with the final result
10471047 return jsonify (final_result )
10481048
1049-
10501049"""
10511050Create an entity of the target type in neo4j
10521051
@@ -1116,6 +1115,14 @@ def create_entity(entity_type):
11161115 except schema_errors .UnimplementedValidatorException as uve :
11171116 internal_server_error (uve )
11181117
1118+ # Check URL parameters before proceeding to any CRUD operations, halting on validation failures.
1119+ #
1120+ # Check if re-indexing is to be suppressed after entity creation.
1121+ try :
1122+ supress_reindex = _suppress_reindex ()
1123+ except Exception as e :
1124+ bad_request_error (e )
1125+
11191126 # Additional validation for Sample entities
11201127 if normalized_entity_type == 'Sample' :
11211128 direct_ancestor_uuid = json_data_dict ['direct_ancestor_uuid' ]
@@ -1237,11 +1244,16 @@ def create_entity(entity_type):
12371244 # Will also filter the result based on schema
12381245 normalized_complete_dict = schema_manager .normalize_entity_result_for_response (complete_dict )
12391246
1240- # Also index the new entity node in elasticsearch via search-api
1241- logger .log (logging .INFO
1242- ,f"Re-indexing for creation of { complete_dict ['entity_type' ]} "
1243- f" with UUID { complete_dict ['uuid' ]} " )
1244- reindex_entity (complete_dict ['uuid' ], user_token )
1247+ if supress_reindex :
1248+ logger .log (level = logging .INFO
1249+ , msg = f"Re-indexing suppressed during creation of { complete_dict ['entity_type' ]} "
1250+ f" with UUID { complete_dict ['uuid' ]} " )
1251+ else :
1252+ # Also index the new entity node in elasticsearch via search-api
1253+ logger .log (level = logging .INFO
1254+ , msg = f"Re-indexing for creation of { complete_dict ['entity_type' ]} "
1255+ f" with UUID { complete_dict ['uuid' ]} " )
1256+ reindex_entity (complete_dict ['uuid' ], user_token )
12451257
12461258 return jsonify (normalized_complete_dict )
12471259
@@ -1412,6 +1424,14 @@ def update_entity(id):
14121424 ValueError ) as e :
14131425 bad_request_error (e )
14141426
1427+ # Check URL parameters before proceeding to any CRUD operations, halting on validation failures.
1428+ #
1429+ # Check if re-indexing is to be suppressed after entity creation.
1430+ try :
1431+ suppress_reindex = _suppress_reindex ()
1432+ except Exception as e :
1433+ bad_request_error (e )
1434+
14151435 # Proceed with per-entity updates after passing any entity-level or property-level validations which
14161436 # would have locked out updates.
14171437 #
@@ -1515,7 +1535,16 @@ def update_entity(id):
15151535 delete_cache (entity_uuid , normalized_entity_type )
15161536
15171537 # Also reindex the updated entity in elasticsearch via search-api
1518- reindex_entity (entity_uuid , user_token )
1538+ if suppress_reindex :
1539+ logger .log (level = logging .INFO
1540+ , msg = f"Re-indexing suppressed during modification of { normalized_entity_type } "
1541+ f" with UUID { entity_uuid } " )
1542+ else :
1543+ # Also index the new entity node in elasticsearch via search-api
1544+ logger .log (level = logging .INFO
1545+ , msg = f"Re-indexing for modification of { normalized_entity_type } "
1546+ f" with UUID { entity_uuid } " )
1547+ reindex_entity (entity_uuid , user_token )
15191548
15201549 # Do not return the updated dict to avoid computing overhead - 7/14/2023 by Zhou
15211550 message_returned = f"The update request on { normalized_entity_type } of { id } has been accepted, the backend may still be processing"
@@ -4049,6 +4078,14 @@ def multiple_components():
40494078 # Add back in dataset_link_abs_dir
40504079 dataset ['dataset_link_abs_dir' ] = dataset_link_abs_dir
40514080
4081+ # Check URL parameters before proceeding to any CRUD operations, halting on validation failures.
4082+ #
4083+ # Check if re-indexing is to be suppressed after entity creation.
4084+ try :
4085+ suppress_reindex = _suppress_reindex ()
4086+ except Exception as e :
4087+ bad_request_error (e )
4088+
40524089 dataset_list = create_multiple_component_details (request , "Dataset" , user_token , json_data_dict .get ('datasets' ), json_data_dict .get ('creation_action' ))
40534090
40544091 # We wait until after the new datasets are linked to their ancestor before performing the remaining post-creation
@@ -4082,20 +4119,22 @@ def multiple_components():
40824119 # Will also filter the result based on schema
40834120 normalized_complete_dict = schema_manager .normalize_entity_result_for_response (complete_dict )
40844121
4085-
4086- # Also index the new entity node in elasticsearch via search-api
4087- logger .log (logging .INFO
4088- ,f"Re-indexing for creation of { complete_dict ['entity_type' ]} "
4089- f" with UUID { complete_dict ['uuid' ]} " )
4090- reindex_entity (complete_dict ['uuid' ], user_token )
4122+ if suppress_reindex :
4123+ logger .log (level = logging .INFO
4124+ , msg = f"Re-indexing suppressed during multiple component creation of { complete_dict ['entity_type' ]} "
4125+ f" with UUID { complete_dict ['uuid' ]} " )
4126+ else :
4127+ # Also index the new entity node in elasticsearch via search-api
4128+ logger .log (level = logging .INFO
4129+ , msg = f"Re-indexing for multiple component creation of { complete_dict ['entity_type' ]} "
4130+ f" with UUID { complete_dict ['uuid' ]} " )
4131+ reindex_entity (complete_dict ['uuid' ], user_token )
40914132 # Add back in dataset_link_abs_dir one last time
40924133 normalized_complete_dict ['dataset_link_abs_dir' ] = dataset_link_abs_dir
40934134 normalized_complete_entity_list .append (normalized_complete_dict )
40944135
40954136 return jsonify (normalized_complete_entity_list )
40964137
4097-
4098-
40994138"""
41004139New endpoints (PUT /datasets and PUT /uploads) to handle the bulk updating of entities see Issue: #698
41014140https://github.com/hubmapconsortium/entity-api/issues/698
@@ -4555,6 +4594,19 @@ def _get_dataset_associated_metadata(dataset_dict, dataset_visibility, valid_use
45554594
45564595 return final_result
45574596
4597+ # Use the Flask request.args MultiDict to see if 'reindex' is a URL parameter passed in with the
4598+ # request and if it indicates reindexing should be supressed. Default to reindexing in all other cases.
4599+ def _suppress_reindex () -> bool :
4600+ if 'reindex' not in request .args :
4601+ return False
4602+ reindex_str = request .args .get ('reindex' ).lower ()
4603+ if reindex_str == 'false' :
4604+ return True
4605+ elif reindex_str == 'true' :
4606+ return False
4607+ raise Exception (f"The value of the 'reindex' parameter must be True or False (case-insensitive)."
4608+ f" '{ request .args .get ('reindex' )} ' is not recognized." )
4609+
45584610"""
45594611Generate 'before_create_triiger' data and create the entity details in Neo4j
45604612
0 commit comments