'* POST /api/libraries/datasets
Load dataset from the given source into the library.
Source can be:
user directory - root folder specified in galaxy.ini as "$user_library_import_dir"
example path: path/to/galaxy/$user_library_import_dir/user@example.com/{user can browse everything here}
the folder with the user login has to be created beforehand
(admin)import directory - root folder specified in galaxy ini as "$library_import_dir"
example path: path/to/galaxy/$library_import_dir/{admin can browse everything here}
(admin)any absolute or relative path - option allowed with "allow_library_path_paste" in galaxy.ini
:param   payload: dictionary structure containing:
:param  encoded_folder_id:      the encoded id of the folder to import dataset(s) to
:type   encoded_folder_id:      an encoded id string
:param  source:                 source the datasets should be loaded from
:type   source:                 str
:param  link_data:              flag whether to link the dataset to data or copy it to Galaxy, defaults to copy
while linking is set to True all symlinks will be resolved _once_
:type   link_data:              bool
:param  preserve_dirs:          flag whether to preserve the directory structure when importing dir
if False only datasets will be imported
:type   preserve_dirs:          bool
:param  file_type:              file type of the loaded datasets, defaults to \'auto\' (autodetect)
:type   file_type:              str
:param  dbkey:                  dbkey of the loaded genome, defaults to \'?\' (unknown)
:type   dbkey:                  str
:param  tag_using_filenames:    flag whether to generate dataset tags from filenames
:type   tag_using_filenames:    bool
:type   dictionary
:returns:   dict containing information about the created upload job
:rtype:     dictionary
:raises: RequestParameterMissingException, AdminRequiredException, ConfigDoesNotAllowException, RequestParameterInvalidException
InsufficientPermissionsException, ObjectNotFound'

@expose_api
def load(self, trans, payload=None, **kwd):

    if payload:
        kwd.update(payload)
    kwd['space_to_tab'] = False
    kwd['to_posix_lines'] = True
    kwd['dbkey'] = kwd.get('dbkey', '?')
    kwd['file_type'] = kwd.get('file_type', 'auto')
    kwd['link_data_only'] = ('link_to_files' if util.string_as_bool(kwd.get('link_data', False)) else 'copy_files')
    kwd['tag_using_filenames'] = util.string_as_bool(kwd.get('tag_using_filenames', None))
    encoded_folder_id = kwd.get('encoded_folder_id', None)
    if (encoded_folder_id is not None):
        folder_id = self.folder_manager.cut_and_decode(trans, encoded_folder_id)
    else:
        raise exceptions.RequestParameterMissingException('The    required    attribute    encoded_folder_id    is    missing.')
    path = kwd.get('path', None)
    if (path is None):
        raise exceptions.RequestParameterMissingException('The    required    attribute    path    is    missing.')
    folder = self.folder_manager.get(trans, folder_id)
    source = kwd.get('source', None)
    if (source not in ['userdir_file', 'userdir_folder', 'importdir_file', 'importdir_folder', 'admin_path']):
        raise exceptions.RequestParameterMissingException('You    have    to    specify    "source"    parameter.    Possible    values    are    "userdir_file",    "userdir_folder",    "admin_path",    "importdir_file"    and    "importdir_folder".    ')
    if (source in ['importdir_file', 'importdir_folder']):
        if (not trans.user_is_admin):
            raise exceptions.AdminRequiredException('Only    admins    can    import    from    importdir.')
        if (not trans.app.config.library_import_dir):
            raise exceptions.ConfigDoesNotAllowException('The    configuration    of    this    Galaxy    instance    does    not    allow    admins    to    import    into    library    from    importdir.')
        import_base_dir = trans.app.config.library_import_dir
        path = os.path.join(import_base_dir, path)
    if (source in ['userdir_file', 'userdir_folder']):
        user_login = trans.user.email
        user_base_dir = trans.app.config.user_library_import_dir
        if (user_base_dir is None):
            raise exceptions.ConfigDoesNotAllowException('The    configuration    of    this    Galaxy    instance    does    not    allow    upload    from    user    directories.')
        full_dir = os.path.join(user_base_dir, user_login)
        if (not path.lower().startswith(full_dir.lower())):
            path = os.path.join(full_dir, path)
        if (not os.path.exists(path)):
            raise exceptions.RequestParameterInvalidException('Given    path    does    not    exist    on    the    host.')
        if (not self.folder_manager.can_add_item(trans, folder)):
            raise exceptions.InsufficientPermissionsException('You    do    not    have    proper    permission    to    add    items    to    the    given    folder.')
    if (source == 'admin_path'):
        if (not trans.app.config.allow_library_path_paste):
            raise exceptions.ConfigDoesNotAllowException('The    configuration    of    this    Galaxy    instance    does    not    allow    admins    to    import    into    library    from    path.')
        if (not trans.user_is_admin):
            raise exceptions.AdminRequiredException('Only    admins    can    import    from    path.')
    tool_id = 'upload1'
    tool = trans.app.toolbox.get_tool(tool_id)
    state = tool.new_state(trans)
    populate_state(trans, tool.inputs, kwd, state.inputs)
    tool_params = state.inputs
    dataset_upload_inputs = []
    for input in tool.inputs.itervalues():
        if (input.type == 'upload_dataset'):
            dataset_upload_inputs.append(input)
    library_bunch = upload_common.handle_library_params(trans, {}, trans.security.encode_id(folder.id))
    abspath_datasets = []
    kwd['filesystem_paths'] = path
    if (source in ['importdir_folder']):
        kwd['filesystem_paths'] = os.path.join(import_base_dir, path)
    if (source in ['userdir_file', 'importdir_file']):
        file = os.path.abspath(path)
        abspath_datasets.append(trans.webapp.controllers['library_common'].make_library_uploaded_dataset(trans, 'api', kwd, os.path.basename(file), file, 'server_dir', library_bunch))
    if (source == 'userdir_folder'):
        uploaded_datasets_bunch = trans.webapp.controllers['library_common'].get_path_paste_uploaded_datasets(trans, 'api', kwd, library_bunch, 200, '')
        uploaded_datasets = uploaded_datasets_bunch[0]
        if (uploaded_datasets is None):
            raise exceptions.ObjectNotFound('Given    folder    does    not    contain    any    datasets.')
        for ud in uploaded_datasets:
            ud.path = os.path.abspath(ud.path)
            abspath_datasets.append(ud)
    if (source in ['admin_path', 'importdir_folder']):
        uploaded_datasets_bunch = trans.webapp.controllers['library_common'].get_path_paste_uploaded_datasets(trans, 'api', kwd, library_bunch, 200, '')
        uploaded_datasets = uploaded_datasets_bunch[0]
        if (uploaded_datasets is None):
            raise exceptions.ObjectNotFound('Given    folder    does    not    contain    any    datasets.')
        for ud in uploaded_datasets:
            ud.path = os.path.abspath(ud.path)
            abspath_datasets.append(ud)
    json_file_path = upload_common.create_paramfile(trans, abspath_datasets)
    data_list = [ud.data for ud in abspath_datasets]
    job_params = {}
    job_params['link_data_only'] = dumps(kwd.get('link_data_only', 'copy_files'))
    job_params['uuid'] = dumps(kwd.get('uuid', None))
    (job, output) = upload_common.create_job(trans, tool_params, tool, json_file_path, data_list, folder=folder, job_params=job_params)
    trans.sa_session.add(job)
    trans.sa_session.flush()
    job_dict = job.to_dict()
    job_dict['id'] = trans.security.encode_id(job_dict['id'])
    return job_dict
