@@ -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"""
20321960Redirect a request from a doi service for a dataset or collection
20331961
0 commit comments