@@ -136,9 +136,30 @@ def get_clowder_v1_dataset_collections(headers, user_v1, dataset_id):
136136 matching_collections .append (collection )
137137 return matching_collections
138138
139- def get_clowder_v1_parent_collection (collection_id , headers ):
139+ def get_clowder_v1_collection (collection_id , headers ):
140+ endpoint = (
141+ f"{ CLOWDER_V1 } /api/collections/{ collection_id } "
142+ )
143+ response = requests .get (endpoint , headers = headers )
144+ return response .json ()
145+
146+ def get_clowder_v1_collection_self_and_ancestors (collection_id , self_and_ancestors , headers ):
147+ endpoint = (
148+ f"{ CLOWDER_V1 } /api/collections/{ collection_id } "
149+ )
150+ response = requests .get (endpoint , headers = headers )
151+ self = response .json ()
152+ self_and_ancestors .append (self )
153+ parents = get_clowder_v1_parent_collection (self , headers = headers )
154+ self_and_ancestors .append (parents )
155+ for parent in parents :
156+ get_clowder_v1_collection_self_and_ancestors (parent ['id' ],self_and_ancestors , headers = headers )
157+ print ("got parents" )
158+
159+ def get_clowder_v1_parent_collection (current_collection , headers ):
160+ parents = []
140161 all_collections_v1_endpoint = (
141- f"{ CLOWDER_V1 } /api/collections/allCollections"
162+ f"{ CLOWDER_V1 } /api/collections/allCollections?limit=0&showAll=true "
142163 )
143164 response = requests .get (all_collections_v1_endpoint , headers = headers )
144165 all_collections = response .json ()
@@ -148,24 +169,16 @@ def get_clowder_v1_parent_collection(collection_id, headers):
148169 children_entry = children_entry .rstrip (')' )
149170 child_ids = children_entry .split (',' )
150171 for child in child_ids :
151- if child == collection_id :
172+ if child == current_collection [ 'id' ] :
152173 collection_endpoint = (
153174 f"{ CLOWDER_V1 } /api/collections/{ child } "
154175 )
155176 collection_response = requests .get (collection_endpoint , headers = headers )
156177 parent_collection = collection_response .json ()
157- return parent_collection
158- return None
178+ # result = get_clowder_v1_parent_collection(parent_collection, headers=headers)
179+ parents .append (collection )
180+ return parents
159181
160- # this route takes a collection and gets the collections that contain it up to the root level
161- # it will return a json object
162- def get_clowder_v1_collection_hierarchy (collection_id , headers ):
163- all_collections_v1_endpoint = (
164- f"{ CLOWDER_V1 } /api/collections/allCollections"
165- )
166- response = requests .get (all_collections_v1_endpoint , headers = headers )
167- all_collections = response .json ()
168- for collection in all_collections :
169182
170183def create_local_user (user_v1 ):
171184 """Create a local user in Clowder v2 if they don't already exist, and generate an API key."""
@@ -407,6 +420,10 @@ def process_user_and_resources(user_v1, USER_MAP, DATASET_MAP):
407420
408421if __name__ == "__main__" :
409422 # users_v1 = get_clowder_v1_users()
423+ current_hierarch = {}
424+ current_collection = get_clowder_v1_collection ('66cf6e4ecc50c8c5f1c067bf' , headers = clowder_headers_v1 )
425+ collection_entry = {'collection_id' : current_collection ['id' ], 'collection_name' : current_collection ['name' ]}
426+ hierarchy = get_clowder_v1_collection_self_and_ancestors (current_collection ['id' ], [], headers = base_headers_v1 )
410427 USER_MAP = {}
411428 DATASET_MAP = {}
412429 users_v1 = [
0 commit comments