Forum OpenACS Development: Re: Heads-up: New Workflow Package

Collapse
Posted by Dan Wickstrom on
Tillman,

Below is a sample form which uses comments throughout. The form is used to register a news feed soap service.


ad_form -name register-service -form {

    # primary key for news feed
    news_feed_id:key(news_feed_from_seq_id)

    # fully qualified url of news instance on remote server
    {news_instance_url:text(text) {label "Remote News Instance URL (e.g. https://openacs.org/news/)"} {html {size 40}}}

    # soap service url on remote server
    {service_url:text(text) {label "Remote Web Service URL"} {html {size 40}}}

    # authentication token
    {token:text(text) {label "Registration Token"} {html {size 40}}}
}

# create option list for news instances on this server

set options [db_list_of_lists get_options {
    
        select '--' as url, null::integer as object_id, 1 as orderby
         union 
        select site_node__url(n.node_id) as url, n.object_id, 2 as orderby
          from apm_packages p, site_nodes n 
         where p.package_id = n.object_id     
           and p.package_key = 'news'
      order by orderby
    }]

# add widget for selecting news instance to be used as the destination 
# for the news feed

ad_form -extend -name register-service -form [list \
    [list package_id:text(select) [list options $options] {label {Select News Destination}}] \
                    ] -validate {

    # make sure the user select a news instance source                    
    {package_id {![string equal $package_id ""]}
     "A Valid News Instance Destination on this Server must be Selected"
    }

    # make sure the news instance url is a fully qualified url
    {news_instance_url {[string match http://* $news_instance_url]}
     "The remote news instance URL must be a fully qualified URL that starts with http://"
    }

    # make sure that the soap service url is fully qualified
    {service_url {[string match http://* $service_url]}
     "The remote Web Service URL must be a fully qualified URL that starts with http://"
    }

} -new_data {

    # convert the news instance url to a fully qualified url
    db_1row get_dest "select 'http://[ad_host][ad_port]' || site_node__url(node_id) as dest_url from site_nodes where object_id = :package_id"

    if ![string equal [string index $news_instance_url end] "/"] {
        append news_instance_url "/"
    }

    # get the service locator
    set nfs [nsjava::new org.nsjava.nsaxis.openacs.news.NewsFeedServiceLocator]

    # get the news service client stub and invoke registration on remote server
    set url [nsjava::new {java.net.URL String} $service_url]
    set stub [$nfs {getNewsFeed java.net.URL} $url]

    set result f
    nsjava::try {

        # soap call to register the news feed
        set result [$stub {enableRemoteNewsFeed String String String String} $news_instance_url $dest_url $token [ns_conn peeraddr]]

    } catch {java.rmi.RemoteException e} {

        # if registration fails, we will retry later
        ns_log Notice "registration failed: [$e toString]"

    } finally {

        set person_id [ad_conn user_id]

        # save registration info.  If registration fails, we will retry later.
        db_dml set_feed_frominfo {

            insert into news_feed_from 
            (news_feed_from_id, package_id, service_url, news_instance_url, token, registered_p, person_id) 
            values 
            (:news_feed_id, :package_id, :service_url, :news_instance_url, :token, :result, :person_id)
        }
    }

    ad_returnredirect index
}