@@ -136,6 +136,36 @@ 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 ):
140+ all_collections_v1_endpoint = (
141+ f"{ CLOWDER_V1 } /api/collections/allCollections"
142+ )
143+ response = requests .get (all_collections_v1_endpoint , headers = headers )
144+ all_collections = response .json ()
145+ for collection in all_collections :
146+ children_entry = collection ['child_collection_ids' ]
147+ children_entry = children_entry .lstrip ('List(' )
148+ children_entry = children_entry .rstrip (')' )
149+ child_ids = children_entry .split (',' )
150+ for child in child_ids :
151+ if child == collection_id :
152+ collection_endpoint = (
153+ f"{ CLOWDER_V1 } /api/collections/{ child } "
154+ )
155+ collection_response = requests .get (collection_endpoint , headers = headers )
156+ parent_collection = collection_response .json ()
157+ return parent_collection
158+ return None
159+
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 :
139169
140170def create_local_user (user_v1 ):
141171 """Create a local user in Clowder v2 if they don't already exist, and generate an API key."""
@@ -369,6 +399,11 @@ def process_user_and_resources(user_v1, USER_MAP, DATASET_MAP):
369399 print ("Successfully uploaded collection metadata" )
370400 return [USER_MAP , DATASET_MAP ]
371401
402+ migration_listener_info = {'name' :'clowder.v1.migration' ,
403+ 'version' :'1.0' ,
404+ 'description' : 'migration script to migrate data from v1 to v2' }
405+
406+ {'context_url' : 'https://clowder.ncsa.illinois.edu/contexts/metadata.jsonld' , 'content' : {'lines' : '47' , 'words' : '225' , 'characters' : '2154' }, 'contents' : {'lines' : '47' , 'words' : '225' , 'characters' : '2154' }, 'listener' : {'name' : 'ncsa.wordcount' , 'version' : '2.0' , 'description' : '2.0' }}
372407
373408if __name__ == "__main__" :
374409 # users_v1 = get_clowder_v1_users()
0 commit comments