def create(self, validated_data): try: minids = json.loads(validated_data['minids']) bagit_bags = fetch_bags(self.context['request'].user, minids) transfer_label = validated_data.pop('transfer_label') bag_dirs = validated_data.pop('bag_dirs') catalog, error_catalog = catalog_transfer_manifest( bagit_bags, bag_dirs=bag_dirs) task_ids = transfer_catalog( self.context['request'].user, catalog, validated_data['destination_endpoint'], validated_data['destination_path_prefix'], label=transfer_label) stage_bag_data = { 'user': self.context['request'].user, 'transfer_catalog': json.dumps(catalog), 'error_catalog': json.dumps(error_catalog), 'transfer_task_ids': json.dumps(task_ids), } stage_bag_data.update(validated_data) return StageBag.objects.create(**stage_bag_data) except globus_sdk.exc.TransferAPIError as te: log.debug(te) raise GlobusTransferException(detail={ 'error': te.message, 'code': te.code })
def test_catalog_transfer_manifest_no_bag_dirs(testbag, scratch_space_dir): bagit_bag = utils.extract_bag(testbag) catalog, err_catalog = utils.catalog_transfer_manifest([bagit_bag], bag_dirs=False) assert err_catalog == {} assert isinstance(catalog, dict) print(list(catalog.values())) for src, dest in list(catalog.values())[0]: assert src == dest
def create(self, validated_data): try: bagit_bags = fetch_bags(json.loads(validated_data['bag_minids'])) catalog, error_catalog = catalog_transfer_manifest(bagit_bags) task_ids = transfer_catalog( catalog, validated_data['destination_endpoint'], validated_data['destination_path_prefix'], validated_data['transfer_token'] ) stage_bag_data = {'user': self.context['request'].user, 'transfer_catalog': json.dumps(catalog), 'error_catalog': json.dumps(error_catalog), 'transfer_task_ids': json.dumps(task_ids), } stage_bag_data.update(validated_data) return StageBag.objects.create(**stage_bag_data) except globus_sdk.exc.TransferAPIError as te: raise GlobusTransferException(detail={'error': te.message, 'code': te.code})