'index( self, trans, library_id, **kwd )
* GET /api/libraries/{library_id}/contents:
Returns a list of library files and folders.
.. note:: May be slow! Returns all content traversing recursively through all folders.
.. seealso:: :class:`galaxy.webapps.galaxy.api.FolderContentsController.index` for a non-recursive solution
:param  library_id: the encoded id of the library
:type   library_id: str
:returns:   list of dictionaries of the form:
* id:   the encoded id of the library item
* name: the \'library path\'
or relationship of the library item to the root
* type: \'file\' or \'folder\'
* url:  the url to get detailed information on the library item
:rtype:     list
:raises:  MalformedId, InconsistentDatabase, RequestParameterInvalidException, InternalServerError'

@expose_api
def index(self, trans, library_id, **kwd):

    rval = []
    current_user_roles = trans.get_current_user_roles()
    def traverse(folder):
        admin = trans.user_is_admin()
        rval = []
        for subfolder in folder.active_folders:
            if (not admin):
                (can_access, folder_ids) = trans.app.security_agent.check_folder_contents(trans.user, current_user_roles, subfolder)
            if ((admin or can_access) and (not subfolder.deleted)):
                subfolder.api_path = ((folder.api_path + '/') + subfolder.name)
                subfolder.api_type = 'folder'
                rval.append(subfolder)
                rval.extend(traverse(subfolder))
        for ld in folder.datasets:
            if (not admin):
                can_access = trans.app.security_agent.can_access_dataset(current_user_roles, ld.library_dataset_dataset_association.dataset)
            if ((admin or can_access) and (not ld.deleted)):
                ld.api_path = ((folder.api_path + '/') + ld.name)
                ld.api_type = 'file'
                rval.append(ld)
        return rval
    try:
        decoded_library_id = self.decode_id(library_id)
    except Exception:
        raise exceptions.MalformedId(('Malformed    library    id    (    %s    )    specified,    unable    to    decode.' % library_id))
    try:
        library = trans.sa_session.query(trans.app.model.Library).filter((trans.app.model.Library.table.c.id == decoded_library_id)).one()
    except MultipleResultsFound:
        raise exceptions.InconsistentDatabase('Multiple    libraries    found    with    the    same    id.')
    except NoResultFound:
        raise exceptions.RequestParameterInvalidException('No    library    found    with    the    id    provided.')
    except Exception as e:
        raise exceptions.InternalServerError(('Error    loading    from    the    database.' + str(e)))
    if (not (trans.user_is_admin() or trans.app.security_agent.can_access_library(current_user_roles, library))):
        raise exceptions.RequestParameterInvalidException('No    library    found    with    the    id    provided.')
    encoded_id = ('F' + trans.security.encode_id(library.root_folder.id))
    rval.append(dict(id=encoded_id, type='folder', name='/', url=url_for('library_content', library_id=library_id, id=encoded_id)))
    library.root_folder.api_path = ''
    for content in traverse(library.root_folder):
        encoded_id = trans.security.encode_id(content.id)
        if (content.api_type == 'folder'):
            encoded_id = ('F' + encoded_id)
        rval.append(dict(id=encoded_id, type=content.api_type, name=content.api_path, url=url_for('library_content', library_id=library_id, id=encoded_id)))
    return rval
