Skip to content

Instantly share code, notes, and snippets.

@srawlins
Created September 13, 2012 01:15
Show Gist options
  • Save srawlins/3711178 to your computer and use it in GitHub Desktop.
Save srawlins/3711178 to your computer and use it in GitHub Desktop.
Automated Ad Hoc Router for Kuali Coeus
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'highline/import'
require 'uri'
class AdHoccer
include Capybara::DSL
def initialize(url, recipient)
@uri = URI.parse url
@recipient = recipient
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = "#{@uri.scheme}://#{@uri.host}"
Capybara.default_selector = :xpath # Since we have weird field id's
visit @uri.path
if find_field('NetID:')
# Appears to be a CAS login. Alter this block for different login screen.
username = ask("NetID: ") { |q| q.echo = true } # prompt for netid
password = ask("Password: ") { |q| q.echo = "*" } # prompt for password
fill_in('NetID:', :with => username)
fill_in('Password:', :with => password)
click_on 'LOGIN'
end
end
def fyi(document_number)
find("//a[@title='Document Search']").click
within_frame('iframeportlet') do # Everything happens in the iframe.
fill_in('Document/Notification Id:', :with => document_number)
find("//input[@title='search']").click # search for the T&M document
find_link(document_number).click # open the T&M document
click_on('tab-AdHocRecipients-imageToggle') # open Ad Hoc Recipients tab
find("//input[@id='newAdHocRoutePerson.id']").set(@recipient)
find("//input[@title='Insert Additional Ad Hoc Person']").click
find("//input[@id='adHocRoutePerson[0].id']") # wait for new row to show
find("//input[@title='Send AdHoc Requests']").click
if page.has_content? "AdHoc Requests have been sent."
puts "AdHoc Requests have been sent for #{document_number}."
else
puts "ERROR: I don't think I successfully sent AdHoc Requests for #{document_number}."
exit 2
end
end
end
end
if ARGV.size < 2
puts "Usage: adhoc-fyi.rb recipient_principal_name document_number ...\n"
puts "Requires two rubygems: highline and capybara. Install with:\n\n"
puts " gem install highline capybara"
exit 1
end
recipient = ARGV.shift
adhoccer = AdHoccer.new(INSERT_THE_KC_APP_URL_ON_LINE_59_OF_THIS_SCRIPT, recipient)
adhoccer.fyi(ARGV.shift) until ARGV.empty?

This ruby script requires two Ruby 1.9, and two rubygems: highline and capybara:

gem install highline capybara

Be sure to replace the placeholder at the end of the script with your KC Application URL, like "https://my.kc.app/kra-dev/".

To ad-hoc route (FYI) a list of documents to one individual, just execute:

ruby adhoc-fyi.rb <principal name of recipient> <document id> ...

For example, to FYI documents 75352 and 75350 to user quickstart:

sam@mint6510:~/code/KATTS-810$ ruby adhoc-fyi.rb quickstart 75352 75350
NetID:  srawlins
Password:  ****************
AdHoc Requests have been sent for 75352.
AdHoc Requests have been sent for 75350.

If listing all of your document IDs in a line is difficult, you can instead create a file with newline-separated document IDs, and alter the script to read these in with:

documents = File.readlines(file_name).map(&:chomp)

Or if it's a comma-separated list of document IDs:

documents = File.read(file_name).split(",")

Good luck.

@r351574nc3
Copy link

Why is this better than just writing a struts action that iterates over a list of document numbers and calls sendAdHocRequests() from the document service? Seems like that would go a million times faster and you would have the ability to utilize a system user for sending the requests instead of "srawlins"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment