4
4
import logging
5
5
from typing import (
6
6
List ,
7
+ Optional ,
7
8
Tuple ,
8
9
Union ,
9
10
)
@@ -230,6 +231,27 @@ class FolderContainer(BaseModel):
230
231
)
231
232
232
233
234
+ class CreateLibraryItemPayload (BaseModel ):
235
+ from_hda_id : Optional [EncodedDatabaseIdField ] = Field (
236
+ None ,
237
+ title = "HDA Encoded ID" ,
238
+ description = "The encoded identifier of the History Dataset Association instance to add to the library." ,
239
+ )
240
+ ldda_message : Optional [str ] = Field (
241
+ None ,
242
+ title = "LDDA Message" ,
243
+ description = (
244
+ "The new message attribute of the Library Dataset Dataset Association created. "
245
+ "Only applies when specifying `from_hda_id`."
246
+ ),
247
+ )
248
+ from_hdca_id : Optional [EncodedDatabaseIdField ] = Field (
249
+ None ,
250
+ title = "HDCA Encoded ID" ,
251
+ description = "The encoded identifier of the History Dataset Collection Association instance to add to the library." ,
252
+ )
253
+
254
+
233
255
# TODO: refactor and remove UsesLibraryMixinItems then move this class to lib/galaxy/managers/folder_contents.py
234
256
class FolderContentsService (UsesLibraryMixinItems ):
235
257
"""Common interface/service logic for interactions with library folder contents in the context of the API.
@@ -250,7 +272,7 @@ def get_object(self, trans, id, class_name, check_ownership=False, check_accessi
250
272
"""
251
273
return managers_base .get_object (trans , id , class_name , check_ownership = check_ownership , check_accessible = check_accessible , deleted = deleted )
252
274
253
- def index (self , trans , folder_id , limit = None , offset = None , search_text = None , include_deleted = False ) -> FolderContainer :
275
+ def index (self , trans , folder_id : EncodedDatabaseIdField , limit = None , offset = None , search_text = None , include_deleted = False ) -> FolderContainer :
254
276
"""
255
277
Displays a collection (list) of a folder's contents (files and folders). Encoded folder ID is prepended
256
278
with 'F' if it is a folder as opposed to a data set which does not have it. Full path is provided in
@@ -395,9 +417,9 @@ def index(self, trans, folder_id, limit=None, offset=None, search_text=None, inc
395
417
folder_container = dict (metadata = metadata , folder_contents = folder_contents )
396
418
return FolderContainer .parse_obj (folder_container )
397
419
398
- def create (self , trans , encoded_folder_id , payload , ** kwd ):
420
+ def create (self , trans , encoded_folder_id : EncodedDatabaseIdField , payload : CreateLibraryItemPayload ):
399
421
"""
400
- Create a new library file from an HDA.
422
+ Create a new library file from an HDA or HDCA .
401
423
402
424
:param encoded_folder_id: the encoded id of the folder to import dataset(s) to
403
425
:type encoded_folder_id: an encoded id string
@@ -408,8 +430,6 @@ def create(self, trans, encoded_folder_id, payload, **kwd):
408
430
:type from_hdca_id: encoded id
409
431
:param ldda_message: (optional) the new message attribute of the LDDA created
410
432
:type ldda_message: str
411
- :param extended_metadata: (optional) dub-dictionary containing any extended metadata to associate with the item
412
- :type extended_metadata: dict
413
433
:type payload: dict
414
434
415
435
:returns: a dictionary describing the new item if ``from_hda_id`` is supplied or a list of
@@ -421,9 +441,9 @@ def create(self, trans, encoded_folder_id, payload, **kwd):
421
441
InternalServerError
422
442
"""
423
443
encoded_folder_id_16 = self .__decode_library_content_id (trans , encoded_folder_id )
424
- from_hda_id = payload .pop ( ' from_hda_id' , None )
425
- from_hdca_id = payload .pop ( ' from_hdca_id' , None )
426
- ldda_message = payload .pop ( ' ldda_message' , '' )
444
+ from_hda_id = payload .from_hda_id
445
+ from_hdca_id = payload .from_hdca_id
446
+ ldda_message = payload .ldda_message
427
447
try :
428
448
if from_hda_id :
429
449
decoded_hda_id = self ._decode_id (from_hda_id )
@@ -665,4 +685,5 @@ def create(self, trans, encoded_folder_id, payload, **kwd):
665
685
InsufficientPermissionsException, ItemAccessibilityException,
666
686
InternalServerError
667
687
"""
668
- return self .service .create (trans , encoded_folder_id , payload )
688
+ create_payload = CreateLibraryItemPayload (** payload )
689
+ return self .service .create (trans , encoded_folder_id , create_payload )
0 commit comments