@@ -273,10 +273,74 @@ def create_admin_user():
273
273
return generate_user_api_key (admin_user , admin_user ["password" ])
274
274
275
275
276
+ def add_dataset_license (v1_license , headers ):
277
+ """Create appropriate license (standard/custom) based on v1 license details"""
278
+ license_id = "CC-BY"
279
+ # standard licenses
280
+ if v1_license ["license_type" ] == "license2" :
281
+ if (
282
+ not v1_license ["ccAllowCommercial" ]
283
+ and not v1_license ["ccAllowDerivative" ]
284
+ and not v1_license ["ccRequireShareAlike" ]
285
+ ):
286
+ license_id = "CC BY-NC-ND"
287
+ elif (
288
+ v1_license ["ccAllowCommercial" ]
289
+ and not v1_license ["ccAllowDerivative" ]
290
+ and not v1_license ["ccRequireShareAlike" ]
291
+ ):
292
+ license_id = "CC BY-ND"
293
+ elif (
294
+ not v1_license ["ccAllowCommercial" ]
295
+ and v1_license ["ccAllowDerivative" ]
296
+ and not v1_license ["ccRequireShareAlike" ]
297
+ ):
298
+ license_id = "CC BY-NC"
299
+ elif (
300
+ not v1_license ["ccAllowCommercial" ]
301
+ and v1_license ["ccAllowDerivative" ]
302
+ and v1_license ["ccRequireShareAlike" ]
303
+ ):
304
+ license_id = "CC BY-NC-SA"
305
+ elif (
306
+ v1_license ["ccAllowCommercial" ]
307
+ and v1_license ["ccAllowDerivative" ]
308
+ and v1_license ["ccRequireShareAlike" ]
309
+ ):
310
+ license_id = "CC BY-SA"
311
+ elif (
312
+ v1_license ["ccAllowCommercial" ]
313
+ and v1_license ["ccAllowDerivative" ]
314
+ and not v1_license ["ccRequireShareAlike" ]
315
+ ):
316
+ license_id = "CC BY"
317
+ elif v1_license ["license_type" ] == "license3" :
318
+ license_id = "CCO Public Domain Dedication"
319
+ else :
320
+ # custom license
321
+ license_body = {
322
+ "name" : v1_license ["license_text" ],
323
+ "url" : v1_license ["license_url" ],
324
+ "holders" : v1_license ["holders" ],
325
+ }
326
+ if license_body ["url" ] == "" :
327
+ license_body ["url" ] = "https://dbpedia.org/page/All_rights_reserved"
328
+ license_v2_endpoint = f"{ CLOWDER_V2 } /api/v2/licenses?"
329
+ response = requests .post (
330
+ license_v2_endpoint , headers = headers , json = license_body
331
+ )
332
+ print (response .json ())
333
+ license_id = response .json ()["id" ]
334
+ return license_id
335
+
336
+
276
337
def create_v2_dataset (dataset , headers ):
277
338
"""Create a dataset in Clowder v2."""
278
339
# TODO: GET correct license
279
- dataset_in_v2_endpoint = f"{ CLOWDER_V2 } /api/v2/datasets?license_id=CC BY"
340
+ print ("Creating dataset license in Clowder v2." )
341
+ v2_license_id = add_dataset_license (dataset ["license" ], headers )
342
+
343
+ dataset_in_v2_endpoint = f"{ CLOWDER_V2 } /api/v2/datasets?license_id={ v2_license_id } "
280
344
dataset_example = {
281
345
"name" : dataset ["name" ],
282
346
"description" : dataset ["description" ],
@@ -592,6 +656,13 @@ def build_collection_hierarchy(collection_id, headers):
592
656
return children
593
657
594
658
659
+ def build_collection_metadata_for_v1_dataset (dataset_id , user_v1 , headers ):
660
+ dataset_collections = get_clowder_v1_dataset_collections (
661
+ headers = headers , user_v1 = user_v1 , dataset_id = dataset_id
662
+ )
663
+ return dataset_collections
664
+
665
+
595
666
def build_collection_space_metadata_for_v1_dataset (dataset , user_v1 , headers ):
596
667
dataset_id = dataset ["id" ]
597
668
dataset_collections = get_clowder_v1_dataset_collections (
@@ -660,6 +731,9 @@ def process_user_and_resources(user_v1, USER_MAP, DATASET_MAP):
660
731
files_result = files_response .json ()
661
732
662
733
for file in files_result :
734
+ file_v2_id = download_and_upload_file (
735
+ file , all_dataset_folders , dataset_v2_id , base_user_headers_v2
736
+ )
663
737
if file_v2_id is not None :
664
738
add_file_metadata (file , file_v2_id , clowder_headers_v1 , user_headers_v2 )
665
739
# posting the collection hierarchy as metadata
@@ -689,6 +763,7 @@ def process_user_and_resources(user_v1, USER_MAP, DATASET_MAP):
689
763
print (
690
764
f"Failed to add collection info as metadata in Clowder v2. Status code: { response .status_code } "
691
765
)
766
+
692
767
if file_v2_id is not None :
693
768
add_file_metadata (file , file_v2_id , clowder_headers_v1 , user_headers_v2 )
694
769
0 commit comments