'delete( self, trans, library_id, id, **kwd )
* DELETE /api/libraries/{library_id}/contents/{id}
delete the LibraryDataset with the given ``id``
:type   id:     str
:param  id:     the encoded id of the library dataset to delete
:type   kwd:    dict
:param  kwd:    (optional) dictionary structure containing:
* payload:     a dictionary itself containing:
* purge:   if True, purge the LD
:rtype:     dict
:returns:   an error object if an error occurred or a dictionary containing:
* id:         the encoded id of the library dataset,
* deleted:    if the library dataset was marked as deleted,
* purged:     if the library dataset was purged'

@web.expose_api
def delete(self, trans, library_id, id, **kwd):

    purge = False
    if kwd.get('payload', None):
        purge = util.string_as_bool(kwd['payload'].get('purge', False))
    rval = {'id': id}
    try:
        ld = self.get_library_dataset(trans, id, check_ownership=False, check_accessible=True)
        user_is_admin = trans.user_is_admin()
        can_modify = trans.app.security_agent.can_modify_library_item(trans.user.all_roles(), ld)
        log.debug('is_admin:    %s,    can_modify:    %s', user_is_admin, can_modify)
        if (not (user_is_admin or can_modify)):
            trans.response.status = 403
            rval.update({'error': 'Unauthorized    to    delete    or    purge    this    library    dataset'})
            return rval
        ld.deleted = True
        if purge:
            ld.purged = True
            trans.sa_session.add(ld)
            trans.sa_session.flush()
            dataset = ld.library_dataset_dataset_association.dataset
            no_history_assoc = (len(dataset.history_associations) == len(dataset.purged_history_associations))
            no_library_assoc = (dataset.library_associations == [ld.library_dataset_dataset_association])
            can_purge_dataset = ((not dataset.purged) and no_history_assoc and no_library_assoc)
            if can_purge_dataset:
                try:
                    ld.library_dataset_dataset_association.dataset.full_delete()
                    trans.sa_session.add(ld.dataset)
                except:
                    pass
                trans.sa_session.flush()
            rval['purged'] = True
        trans.sa_session.flush()
        rval['deleted'] = True
    except exceptions.httpexceptions.HTTPInternalServerError:
        log.exception('Library_contents    API,    delete:    uncaught    HTTPInternalServerError:    %s,    %s', id, str(kwd))
        raise
    except exceptions.httpexceptions.HTTPException:
        raise
    except Exception as exc:
        log.exception('library_contents    API,    delete:    uncaught    exception:    %s,    %s', id, str(kwd))
        trans.response.status = 500
        rval.update({'error': str(exc)})
    return rval
