Skip to content

Commit 109264b

Browse files
committed
Add optional parameters to payload to import collections as single item in libraries.
Or else, use the default behavior of unpacking datasets.
1 parent 345719e commit 109264b

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/galaxy/webapps/galaxy/api/folder_contents.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ class CreateLibraryItemPayload(BaseModel):
250250
title="HDCA Encoded ID",
251251
description="The encoded identifier of the History Dataset Collection Association instance to add to the library.",
252252
)
253+
collection_as_single_item: Optional[bool] = Field(
254+
None,
255+
title="Collection as single item",
256+
description=(
257+
"This will create the collection as a single item in the library instead of unpacking all the datasets."
258+
),
259+
)
253260

254261

255262
# TODO: refactor and remove UsesLibraryMixinItems then move this class to lib/galaxy/managers/folder_contents.py
@@ -450,7 +457,9 @@ def create(self, trans, encoded_folder_id: EncodedDatabaseIdField, payload: Crea
450457
return self._copy_hda_to_library_folder(trans, self.hda_manager, decoded_hda_id, encoded_folder_id_16, ldda_message)
451458
if from_hdca_id:
452459
decoded_hdca_id = self._decode_id(from_hdca_id)
453-
return self._copy_hdca_to_library_folder_single(trans, self.hdca_manager, decoded_hdca_id, encoded_folder_id_16)
460+
if payload.collection_as_single_item:
461+
return self._copy_hdca_to_library_folder_single(trans, self.hdca_manager, decoded_hdca_id, encoded_folder_id_16)
462+
return self._copy_hdca_to_library_folder(trans, self.hda_manager, decoded_hdca_id, encoded_folder_id_16, ldda_message)
454463
except Exception as exc:
455464
# TODO handle exceptions better within the mixins
456465
exc_message = util.unicodify(exc)

lib/galaxy_test/api/test_folder_contents.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,20 @@ def test_create_hda_with_ldda_message(self):
3737
def test_create_hdca(self):
3838
contents = ["dataset01", "dataset02"]
3939
hdca_id = self._create_hdca_with_contents(name="Test Dataset Collection", contents=contents)
40+
ldda_message = "Test message"
41+
data = {
42+
"from_hdca_id": hdca_id,
43+
"ldda_message": ldda_message,
44+
}
45+
lddas = self._create_content_in_folder_with_payload(self.root_folder_id, data)
46+
assert len(contents) == len(lddas)
47+
48+
def test_create_hdca_single_item(self):
49+
contents = ["dataset01", "dataset02"]
50+
hdca_id = self._create_hdca_with_contents(name="Test Dataset Collection Single", contents=contents)
4051
data = {
4152
"from_hdca_id": hdca_id,
53+
"collection_as_single_item": True
4254
}
4355
ldca = self._create_content_in_folder_with_payload(self.root_folder_id, data)
4456
self._assert_has_keys(ldca, "name", "id", "element_count")
@@ -49,7 +61,7 @@ def test_index(self):
4961

5062
self._create_subfolder_in(folder_id)
5163
self._create_dataset_in_folder(folder_id)
52-
self._create_dataset_collection_in_folder(folder_id)
64+
self._create_dataset_collection_in_folder(folder_id, single_item=True)
5365

5466
response = self._get(f"folders/{folder_id}/contents")
5567
self._assert_status_code_is(response, 200)
@@ -85,7 +97,7 @@ def test_index_limit_offset(self):
8597

8698
num_collections = 2
8799
for _ in range(num_collections):
88-
self._create_dataset_collection_in_folder(folder_id)
100+
self._create_dataset_collection_in_folder(folder_id, single_item=True)
89101

90102
num_datasets = 5
91103
for _ in range(num_datasets):
@@ -234,11 +246,12 @@ def _create_dataset_in_folder(self, folder_id: str, name: Optional[str] = None)
234246
ldda = self._create_content_in_folder_with_payload(folder_id, data)
235247
return ldda["id"]
236248

237-
def _create_dataset_collection_in_folder(self, folder_id: str, name: Optional[str] = None, num_items: int = 3) -> str:
249+
def _create_dataset_collection_in_folder(self, folder_id: str, name: Optional[str] = None, num_items: int = 3, single_item: bool = False) -> str:
238250
contents = [f"dataset{index}" for index in range(num_items)]
239251
hdca_id = self._create_hdca_with_contents(name or "Test Dataset Collection", contents)
240252
data = {
241253
"from_hdca_id": hdca_id,
254+
"collection_as_single_item": single_item
242255
}
243256
ldca = self._create_content_in_folder_with_payload(folder_id, data)
244257
return ldca["id"]

0 commit comments

Comments
 (0)