Skip to content

Commit aaa7b55

Browse files
author
Karl Burke
committed
remove support for /collections/<collection_uuid>/add-datasets route
app.py add_datasets_to_collection(collection_uuid) app_neo4j_queries.py add_datasets_to_collection()
1 parent 750203e commit aaa7b55

File tree

2 files changed

+0
-122
lines changed

2 files changed

+0
-122
lines changed

src/app.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,78 +1956,6 @@ def get_next_revisions(id):
19561956

19571957
return jsonify(final_result)
19581958

1959-
1960-
1961-
"""
1962-
Link the given list of datasets to the target collection
1963-
1964-
JSON request body example:
1965-
{
1966-
"dataset_uuids": [
1967-
"fb6757b606ac35be7fa85062fde9c2e1",
1968-
"81a9fa68b2b4ea3e5f7cb17554149473",
1969-
"3ac0768d61c6c84f0ec59d766e123e05",
1970-
"0576b972e074074b4c51a61c3d17a6e3"
1971-
]
1972-
}
1973-
1974-
Parameters
1975-
----------
1976-
collection_uuid : str
1977-
The UUID of target collection
1978-
1979-
Returns
1980-
-------
1981-
json
1982-
JSON string containing a success message with 200 status code
1983-
"""
1984-
@app.route('/collections/<collection_uuid>/add-datasets', methods = ['PUT'])
1985-
def add_datasets_to_collection(collection_uuid):
1986-
if READ_ONLY_MODE:
1987-
forbidden_error("Access not granted when entity-api in READ-ONLY mode")
1988-
1989-
# Get user token from Authorization header
1990-
user_token = get_user_token(request)
1991-
1992-
# Query target entity against uuid-api and neo4j and return as a dict if exists
1993-
entity_dict = query_target_entity(collection_uuid, user_token)
1994-
if entity_dict['entity_type'] != 'Collection':
1995-
bad_request_error(f"The UUID provided in URL is not a Collection: {collection_uuid}")
1996-
1997-
# Always expect a json body
1998-
require_json(request)
1999-
2000-
# Parse incoming json string into json data(python list object)
2001-
json_data_dict = request.get_json()
2002-
2003-
if 'dataset_uuids' not in json_data_dict:
2004-
bad_request_error("Missing 'dataset_uuids' key in the request JSON.")
2005-
2006-
if not json_data_dict['dataset_uuids']:
2007-
bad_request_error("JSON field 'dataset_uuids' can not be empty list.")
2008-
2009-
# Now we have a list of uuids
2010-
dataset_uuids_list = json_data_dict['dataset_uuids']
2011-
2012-
# Make sure all the given uuids are datasets (or publications 2/17/23 ~Derek Furst)
2013-
for dataset_uuid in dataset_uuids_list:
2014-
entity_dict = query_target_entity(dataset_uuid, user_token)
2015-
if not schema_manager.entity_type_instanceof(entity_dict['entity_type'], 'Dataset'):
2016-
bad_request_error(f"The UUID provided in JSON is not a Dataset or Publication: {dataset_uuid}")
2017-
2018-
try:
2019-
app_neo4j_queries.add_datasets_to_collection(neo4j_driver_instance, collection_uuid, dataset_uuids_list)
2020-
except TransactionError:
2021-
msg = "Failed to create the linkage between the given datasets and the target collection"
2022-
# Log the full stack trace, prepend a line with our message
2023-
logger.exception(msg)
2024-
# Terminate and let the users know
2025-
internal_server_error(msg)
2026-
2027-
# Send response with success message
2028-
return jsonify(message = "Successfully added all the specified datasets to the target collection")
2029-
2030-
20311959
"""
20321960
Redirect a request from a doi service for a dataset or collection
20331961

src/app_neo4j_queries.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -379,56 +379,6 @@ def get_next_revisions(neo4j_driver, uuid, property_key = None):
379379

380380
return results
381381

382-
383-
"""
384-
Link the datasets to the target collection
385-
386-
Parameters
387-
----------
388-
neo4j_driver : neo4j.Driver object
389-
The neo4j database connection pool
390-
collection_uuid : str
391-
The uuid of target collection
392-
dataset_uuids_list : list
393-
A list of dataset uuids to be linked to collection
394-
"""
395-
def add_datasets_to_collection(neo4j_driver, collection_uuid, dataset_uuids_list):
396-
# Join the list of uuids and wrap each string in single quote
397-
joined_str = ', '.join("'{0}'".format(dataset_uuid) for dataset_uuid in dataset_uuids_list)
398-
# Format a string to be used in Cypher query.
399-
# E.g., ['fb6757b606ac35be7fa85062fde9c2e1', 'ku0gd44535be7fa85062fde98gt5']
400-
dataset_uuids_list_str = '[' + joined_str + ']'
401-
402-
try:
403-
with neo4j_driver.session() as session:
404-
tx = session.begin_transaction()
405-
406-
logger.info("Create relationships between the target Collection and the given Datasets")
407-
408-
query = (f"MATCH (c:Collection), (d:Dataset) "
409-
f"WHERE c.uuid = '{collection_uuid}' AND d.uuid IN {dataset_uuids_list_str} "
410-
# Use MERGE instead of CREATE to avoid creating the relationship multiple times
411-
# MERGE creates the relationship only if there is no existing relationship
412-
f"MERGE (c)<-[r:IN_COLLECTION]-(d)")
413-
414-
logger.info("======add_datasets_to_collection() query======")
415-
logger.info(query)
416-
417-
tx.run(query)
418-
tx.commit()
419-
except TransactionError as te:
420-
msg = f"TransactionError from calling add_datasets_to_collection(): {te.value}"
421-
# Log the full stack trace, prepend a line with our message
422-
logger.exception(msg)
423-
424-
if tx.closed() == False:
425-
logger.info("Failed to commit add_datasets_to_collection() transaction, rollback")
426-
427-
tx.rollback()
428-
429-
raise TransactionError(msg)
430-
431-
432382
"""
433383
Retrive the full tree above the given entity
434384

0 commit comments

Comments
 (0)