class AdminModule::CLI

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/admin_module/cli.rb, line 22
def initialize(*args)
  super
end
start(*) click to toggle source
Calls superclass method
# File lib/admin_module/cli.rb, line 16
def self.start(*)
  super
rescue Exception => e
  raise e
end

Public Instance Methods

alias_to_name(gdl_name_or_alias) click to toggle source

Retrieve a guideline name from the configured aliases

# File lib/admin_module/cli/cli_guideline.rb, line 60
def alias_to_name gdl_name_or_alias
  aliases = AdminModule.configuration.aliases

  gdl_name = aliases[gdl_name_or_alias]
  gdl_name = gdl_name_or_alias if gdl_name.nil?

  gdl_name
end
all_locks() click to toggle source

Return configuration data for all locks in the current environment

# File lib/admin_module/cli/cli_lock.rb, line 44
def all_locks
  locks = {}

  current_lock_names.each do |name|
    locks[name] = get_lock(name)
  end

  locks
end
all_tasks() click to toggle source

Return configuration data for all tasks in the current environment

# File lib/admin_module/cli/cli_task.rb, line 44
def all_tasks
  tasks = {}

  current_task_names.each do |name|
    tasks[name] = get_task(name)
  end

  tasks
end
base_url() click to toggle source

Return the base url for the current environment

# File lib/admin_module/cli_old.rb, line 57
def base_url
  return AdminModule.configuration.base_urls[environment]
end
create_lock(lock_data) click to toggle source

Create a lock in the current environment

# File lib/admin_module/cli/cli_lock.rb, line 82
def create_lock lock_data
  raise ArgumentError, "Invalid lock data: #{lock_data.inspect}" unless valid_lock_data?(lock_data)
  raise ArgumentError, "Missing lock name: #{lock_data.inspect}" unless lock_data_has_name?(lock_data)

  login

  lock_def_url = LockDefinitionsPage.new(browser, base_url).
    create_lock(lock_data)

  LockDefinitionPage.new(browser, lock_def_url).set_lock_data lock_data
end
create_task(task_data) click to toggle source

Create a task in the current environment

# File lib/admin_module/cli/cli_task.rb, line 82
def create_task task_data
  raise ArgumentError, "Invalid task data: #{task_data.inspect}" unless valid_task_data?(task_data)
  raise ArgumentError, "Missing task name: #{task_data.inspect}" unless task_data_has_name?(task_data)

  login

  task_def_url = TaskDefinitionsPage.new(browser, base_url).
    create_task(task_data)

  WorkflowTasksPage.new(browser, task_def_url).set_task_data task_data
end
credentials() click to toggle source

Return the credentials for the current environment

# File lib/admin_module/cli_old.rb, line 50
def credentials
  return AdminModule.configuration.credentials[environment]
end
current_lock_names() click to toggle source

Return a list of lock names in the current environment

# File lib/admin_module/cli/cli_lock.rb, line 36
def current_lock_names
  login
  LockDefinitionsPage.new(browser, base_url).locks_options
end
current_task_names() click to toggle source

Return a list of task names in the current environment

# File lib/admin_module/cli/cli_task.rb, line 36
def current_task_names
  login
  TaskDefinitionsPage.new(browser, base_url).tasks_options
end
deploy(source_file, gdl_name_or_alias, comments = nil) click to toggle source

Deploy a source file to a guideline in the current environment.

source_file full path to xml file to upload gdl_name_or_alias guideline name (or alias) to version comments to be added to Version Notes area. Defaults to ‘auto upload’

# File lib/admin_module/cli/cli_guideline.rb, line 36
def deploy source_file, gdl_name_or_alias, comments = nil
  source_file = Array(source_file)[0]
  raise IOError.new("Missing source file [#{source_file}]") unless File.exists? source_file
  source_file = File.expand_path(source_file)

  gdl_name_or_alias = File.basename(source_file, '.xml') if gdl_name_or_alias.nil?

  login

  gdl_name = alias_to_name(gdl_name_or_alias)

  gdl_page_url = GuidelinesPage.new(browser, base_url).
    open_guideline(gdl_name)

  version_gdl_url = GuidelinePage.new(browser, gdl_page_url).
    add_version()

  GuidelineVersionPage.new(browser, version_gdl_url).
    upload(source_file, comments)
end
deploy_files(source_files, comments = nil) click to toggle source

Deploy an array of source files to the current environment.

source_files array of files, each file’s basename must be in the configured aliases. comments to be added to Version Notes area. Defaults to ‘auto upload’

# File lib/admin_module/cli/cli_guideline.rb, line 23
def deploy_files source_files, comments = nil
  source_files.each do |src|
    deploy src, File.basename(src, '.xml'), comments
  end
end
environment() click to toggle source

Return the current environment

# File lib/admin_module/cli_old.rb, line 42
def environment
  @env ||= AdminModule.configuration.default_environment
  @env
end
environment=(env) click to toggle source

Set the current environment

# File lib/admin_module/cli_old.rb, line 31
def environment=(env)
  raise "Unknown environment [#{env}]" unless AdminModule.configuration.credentials.key?(env)
  @env = env
  AdminModule.configure do |config|
    config.default_environment = env
  end
end
export_locks(file_name) click to toggle source

Export all lock configurations in the current environment to a file.

# File lib/admin_module/cli/cli_lock.rb, line 119
def export_locks file_name
  FileUtils.mkdir_p File.dirname(file_name)
  File.open(file_name, 'w') do |f|
    # Write array of lock hashes.
    f << YAML.dump(all_locks)
  end
end
export_tasks(file_name) click to toggle source

Export all task configurations in the current environment to a file.

# File lib/admin_module/cli/cli_task.rb, line 119
def export_tasks file_name
  FileUtils.mkdir_p File.dirname(file_name)
  File.open(file_name, 'w') do |f|
    # Write array of task hashes.
    f << YAML.dump(all_tasks)
  end
end
get_lock(lock_name) click to toggle source

Retrieve lock configuration data from the current environment

# File lib/admin_module/cli/cli_lock.rb, line 20
def get_lock lock_name
  login

  begin
    lock_def_url = LockDefinitionsPage.new(browser, base_url).
      modify_lock(lock_name)
  rescue Watir::Exception::NoValueFoundException => e
    raise ArgumentError, "Lock [#{lock_name}] not found.\n\n#{e.message}"
  end

  lock_data = LockDefinitionPage.new(browser, lock_def_url).get_lock_data
end
get_parameters() click to toggle source
# File lib/admin_module/cli/cli_parameter.rb, line 16
def get_parameters
  login

  parameters_page = ParametersPage.new(browser, base_url)
  variables = parameters_page.get_parameters
end
get_task(task_name) click to toggle source

Retrieve task configuration data from the current environment

# File lib/admin_module/cli/cli_task.rb, line 20
def get_task task_name
  login

  begin
    task_def_url = TaskDefinitionsPage.new(browser, base_url).
      modify_task(task_name)
  rescue Watir::Exception::NoValueFoundException => e
    raise ArgumentError, "Task [#{task_name}] not found.\n\n#{e.message}"
  end

  task_data = WorkflowTasksPage.new(browser, task_def_url).get_task_data
end
import_locks(file_name) click to toggle source

Import lock configurations into the current environment from a file.

# File lib/admin_module/cli/cli_lock.rb, line 130
def import_locks file_name
  raise IOError, "File not found: #{file_name}" unless File.exists?(file_name)

  locks = {}
  File.open(file_name, 'r') do |f|
    # Write array of lock hashes.
    locks = YAML.load(f)
  end

  existing_locks = current_lock_names

  locks.each do |name, data|
    if existing_locks.include?(name)
      modify_lock(data, name)
    else
      create_lock(data)
    end
  end
end
import_tasks(file_name) click to toggle source

Import task configurations into the current environment from a file.

# File lib/admin_module/cli/cli_task.rb, line 130
def import_tasks file_name
  raise IOError, "File not found: #{file_name}" unless File.exists?(file_name)

  tasks = {}
  File.open(file_name, 'r') do |f|
    # Write array of task hashes.
    tasks = YAML.load(f)
  end

  existing_tasks = current_task_names

  tasks.each do |name, data|
    if existing_tasks.include?(name)
      modify_task(data, name)
    else
      create_task(data)
    end
  end
end
lock_data_has_name?(lock_data) click to toggle source

Test lock data structure for valid name

# File lib/admin_module/cli/cli_lock.rb, line 73
def lock_data_has_name? lock_data
  return false unless lock_data.key?(:name)
  return false if lock_data[:name].empty?
  true
end
login(force = false) click to toggle source

Login to the Admin Module

If we’re already logged in, do nothing unless the force flag is true.

force force a re-login if we’ve already logged in

# File lib/admin_module/cli_old.rb, line 68
def login(force = false)
  if force || @login_page.nil?
    @login_page = LoginPage.new(browser, base_url)
    @login_page.login_as(*credentials)
  end

  @login_page
end
logout() click to toggle source
# File lib/admin_module/cli_old.rb, line 77
def logout
  @login_page.logout
  @login_page = nil
end
modify_lock(lock_data, lock_name = nil) click to toggle source

Modify an existing lock in the current environment

# File lib/admin_module/cli/cli_lock.rb, line 97
def modify_lock lock_data, lock_name = nil
  lock_name ||= lock_data[:name]
  raise ArgumentError, "Invalid lock data: #{lock_data.inspect}" unless valid_lock_data?(lock_data)
  raise ArgumentError, "Missing lock name" if (lock_name.nil? || lock_name.empty?)

  # Make sure we populate the data's name param if empty so we don't try to write
  # and save an empty name.
  if lock_data[:name].nil? || lock_data[:name].empty?
    lock_data[:name] = lock_name
  end

  login

  lock_def_url = LockDefinitionsPage.new(browser, base_url).
    modify_lock(lock_name)

  LockDefinitionPage.new(browser, lock_def_url).set_lock_data lock_data
end
modify_task(task_data, task_name = nil) click to toggle source

Modify an existing task in the current environment

# File lib/admin_module/cli/cli_task.rb, line 97
def modify_task task_data, task_name = nil
  task_name ||= task_data[:name]
  raise ArgumentError, "Invalid task data: #{task_data.inspect}" unless valid_task_data?(task_data)
  raise ArgumentError, "Missing task name" if (task_name.nil? || task_name.empty?)

  # Make sure we populate the data's name param if empty so we don't try to write
  # and save an empty name.
  if task_data[:name].nil? || task_data[:name].empty?
    task_data[:name] = task_name
  end

  login

  task_def_url = TaskDefinitionsPage.new(browser, base_url).
    modify_task(task_name)

  WorkflowTasksPage.new(browser, task_def_url).set_task_data task_data
end
quit() click to toggle source

Close the browser

# File lib/admin_module/cli_old.rb, line 85
def quit
  unless @browser.nil?
    logout
    @browser.close
    @browser = nil
  end
end
task_data_has_name?(task_data) click to toggle source

Test task data structure for valid name

# File lib/admin_module/cli/cli_task.rb, line 73
def task_data_has_name? task_data
  return false unless task_data.key?(:name)
  return false if task_data[:name].empty?
  true
end
update_parameter(var_name, params) click to toggle source

Update a parameter’s config values.

  • var_name name of parameter to update

  • params hash of values to update where:

    • :name is name of parameter

    • :type is Boolean, Date, DateTime, Money, Numeric, Percentage, or Text (case sensitive)

    • :decision is DSM when true, DPM when false

    • :order Fixnum value

    • :precision Only valid if :type is Numeric

    • :include include in app XML if true

# File lib/admin_module/cli/cli_parameter.rb, line 34
def update_parameter(var_name, params)
  raise "Missing params" unless params.size > 0

  login

  parameters_page_url = ParametersPage.new(browser, base_url).edit_parameter(var_name)
  page = ParameterPage.new(browser, false)

  page.parameter_name = params.delete(:name) if params.key?(:name)
  page.parameter_type = params.delete(:type) if params.key?(:type)

  if ! params.key?(:decision).nil?
    page.decision_parameter = params[:decision] ? 'Yes' : 'No'
    params.delete(:decision)
  end

  page.parameter_order = params.delete(:order) if params.key?(:order)
  page.precision = params.delete(:precision) if params.key?(:precision)

  if ! params.key?(:include).nil?

    if params[:include]
      page.check_include_in_application_xml
    else
      page.uncheck_include_in_application_xml
    end
  end
  params.delete(:include)
  raise ArgumentError, "Unexpected params: #{params.inspect}" unless params.size == 0

  page.save
end
valid_lock_data?(lock_data) click to toggle source

Test lock data structure for validity

Required:

at least 1 parameter OR dts
# File lib/admin_module/cli/cli_lock.rb, line 60
def valid_lock_data? lock_data
  if !lock_data.key?(:parameters) || lock_data[:parameters].empty?
    if !lock_data.key?(:dts) || lock_data[:dts].empty?
      return false
    end
  end
  true
end
valid_task_data?(task_data) click to toggle source

Test task data structure for validity

Required:

at least 1 parameter OR dts
# File lib/admin_module/cli/cli_task.rb, line 60
def valid_task_data? task_data
  if !task_data.key?(:parameters) || task_data[:parameters].empty?
    if !task_data.key?(:dts) || task_data[:dts].empty?
      return false
    end
  end
  true
end
version_all(gdl_names, comments = nil) click to toggle source

Version all guidelines

# File lib/admin_module/cli/cli_guideline.rb, line 72
def version_all gdl_names, comments = nil
  login

  version_all_page_url = GuidelinesPage.new(browser, base_url).version_all
  page = GuidelinesVersionAllPage.new(browser, version_all_page_url)

  page.version gdl_names, comments
end