@@ -110,6 +110,25 @@ def add_v1_space_members_to_v2_group(space, group_id, headers):
110110 headers = headers ,
111111 )
112112
113+ def get_clowder_v1_user_collections (headers , user_v1 ):
114+ endpoint = f"{ CLOWDER_V1 } /api/collections"
115+ response = requests .get (endpoint , headers = headers )
116+ return [col for col in response .json () if col ["authorId" ] == user_v1 ["id" ]]
117+
118+ def get_clowder_v1_dataset_collections (headers , user_v1 , dataset_id ):
119+ matching_collections = []
120+ endpoint = f"{ CLOWDER_V1 } /api/collections"
121+ response = requests .get (endpoint , headers = headers )
122+ user_collections = [col for col in response .json () if col ["authorId" ] == user_v1 ["id" ]]
123+ for collection in user_collections :
124+ collection_id = collection ["id" ]
125+ collection_dataset_endpoint = f"{ CLOWDER_V1 } /api/collections/{ collection_id } /datasets"
126+ dataset_response = requests .get (collection_dataset_endpoint , headers )
127+ datasets = dataset_response .json ()
128+ for ds in datasets :
129+ if ds ['id' ] == dataset_id :
130+ matching_collections .append (collection )
131+ return matching_collections
113132
114133def create_local_user (user_v1 ):
115134 """Create a local user in Clowder v2 if they don't already exist, and generate an API key."""
@@ -319,6 +338,11 @@ def process_user_and_resources(user_v1, USER_MAP, DATASET_MAP):
319338 download_and_upload_file (
320339 file , all_dataset_folders , dataset_v2_id , base_user_headers_v2
321340 )
341+ dataset_collections = get_clowder_v1_dataset_collections (headers = clowder_headers_v1 , user_v1 = user_v1 , dataset_id = dataset ['id' ])
342+ # TODO for now taking the first collection, assuming a dataset is in one collection only
343+ dataset_collection = dataset_collections [0 ]
344+ dataset_collection_name = dataset_collection ['collectionname' ]
345+ dataset_collection_id = dataset_collection ['id' ]
322346 return [USER_MAP , DATASET_MAP ]
323347
324348
0 commit comments