class AdminModule::CLI
Public Class Methods
# File lib/admin_module/cli.rb, line 22 def initialize(*args) super end
# File lib/admin_module/cli.rb, line 16 def self.start(*) super rescue Exception => e raise e end
Public Instance Methods
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
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
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
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 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 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
Return the credentials for the current environment
# File lib/admin_module/cli_old.rb, line 50 def credentials return AdminModule.configuration.credentials[environment] end
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
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 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 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
Return the current environment
# File lib/admin_module/cli_old.rb, line 42 def environment @env ||= AdminModule.configuration.default_environment @env end
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 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 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
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
# 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
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 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 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
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 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
# File lib/admin_module/cli_old.rb, line 77 def logout @login_page.logout @login_page = nil end
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 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
Close the browser
# File lib/admin_module/cli_old.rb, line 85 def quit unless @browser.nil? logout @browser.close @browser = nil end end
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 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
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
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 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