1111from dclab .rtdc_dataset .check import IntegrityChecker
1212from dclab .cli import compress
1313
14- from ..api import dataset_activate , resource_add , resource_exists
14+ from ..api import CKANAPI , dataset_activate , resource_add , resource_exists
1515from ..common import is_dc_file , sha256sum
1616
1717
@@ -48,9 +48,15 @@ class AtLeastOneDCResourceRequiredPerDatasetError(BaseException):
4848
4949
5050class UploadJob :
51- def __init__ (self , api , dataset_id , resource_paths ,
52- resource_names = None , resource_supplements = None ,
53- task_id = None , cache_dir = None ):
51+ def __init__ (self ,
52+ api : CKANAPI ,
53+ dataset_id : str ,
54+ resource_paths : list [str | pathlib .Path ],
55+ resource_names : list [str ] = None ,
56+ resource_supplements : list [dict ] = None ,
57+ collections : list [str ] = None ,
58+ task_id : str = None ,
59+ cache_dir : str | pathlib .Path = None ):
5460 """Wrapper for resource uploads
5561
5662 This job is meant to be run from a separate thread.
@@ -73,6 +79,9 @@ def __init__(self, api, dataset_id, resource_paths,
7379 on DCOR
7480 resource_supplements: list of dict
7581 Supplementary resource information
82+ collections: list of strings
83+ List of unique identifiers of collections that this
84+ dataset should be appended to
7685 task_id: str
7786 Unique task ID (used for identifying jobs uploaded already)
7887 cache_dir: str or pathlib.Path
@@ -86,6 +95,16 @@ def __init__(self, api, dataset_id, resource_paths,
8695
8796 self .api = api .copy () # create a copy of the API
8897 self .dataset_id = dataset_id
98+ self .collections = []
99+ # add dataset to collections
100+ for col in collections or []:
101+ col_dict = self .api .require_collection (col )
102+ self .collections .append (col_dict )
103+ if self .collections :
104+ revise_dict = {
105+ "match" : {"id" : dataset_id },
106+ "update" : {"groups" : self .collections }}
107+ api .post ("package_revise" , revise_dict )
89108
90109 # Check whether at least one DC resource is present in the list.
91110 # This is a hard DCOR requirement.
0 commit comments