'Copies hda ``from_hda_id`` to library folder ``folder_id``, optionally
adding ``ldda_message`` to the new ldda\'s ``message``.
``library_contents.create`` will branch to this if called with \'from_hda_id\'
in its payload.'

def _copy_hda_to_library_folder(self, trans, hda_manager, from_hda_id, folder_id, ldda_message='', element_identifier=None):

    log.debug(('_copy_hda_to_library_folder:    %s' % str((from_hda_id, folder_id, ldda_message))))
    if ldda_message:
        ldda_message = util.sanitize_html.sanitize_html(ldda_message, 'utf-8')
    hda = hda_manager.get_owned(from_hda_id, trans.user, current_history=trans.history)
    hda = hda_manager.error_if_uploading(hda)
    folder = self.get_library_folder(trans, folder_id, check_accessible=True)
    if folder.parent_library.deleted:
        raise exceptions.ObjectAttributeInvalidException('You    cannot    add    datasets    into    deleted    library.    Undelete    it    first.')
    if (not self.can_current_user_add_to_library_item(trans, folder)):
        raise exceptions.InsufficientPermissionsException('You    do    not    have    proper    permissions    to    add    a    dataset    to    this    folder,')
    ldda = self.copy_hda_to_library_folder(trans, hda, folder, ldda_message=ldda_message, element_identifier=element_identifier)
    ldda.visible = True
    trans.sa_session.flush()
    ldda_dict = ldda.to_dict()
    rval = trans.security.encode_dict_ids(ldda_dict)
    update_time = ldda.update_time.strftime('%Y-%m-%d    %I:%M    %p')
    rval['update_time'] = update_time
    return rval
