admin_module 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +14 -0
  5. data/Guardfile +24 -0
  6. data/LICENSE +22 -0
  7. data/README.md +281 -0
  8. data/Rakefile +98 -0
  9. data/admin_module.gemspec +34 -0
  10. data/bin/admin_module +13 -0
  11. data/lib/admin_module.rb +260 -0
  12. data/lib/admin_module/cli.rb +54 -0
  13. data/lib/admin_module/cli/cli_guideline.rb +80 -0
  14. data/lib/admin_module/cli/cli_lock.rb +149 -0
  15. data/lib/admin_module/cli/cli_parameter.rb +66 -0
  16. data/lib/admin_module/cli/cli_task.rb +149 -0
  17. data/lib/admin_module/cli_old.rb +92 -0
  18. data/lib/admin_module/client.rb +146 -0
  19. data/lib/admin_module/command.rb +25 -0
  20. data/lib/admin_module/command/client_access.rb +43 -0
  21. data/lib/admin_module/command/config.rb +310 -0
  22. data/lib/admin_module/command/dc.rb +110 -0
  23. data/lib/admin_module/command/gdl.rb +71 -0
  24. data/lib/admin_module/command/lock.rb +110 -0
  25. data/lib/admin_module/command/ppm.rb +142 -0
  26. data/lib/admin_module/command/rule.rb +77 -0
  27. data/lib/admin_module/command/ruleset.rb +56 -0
  28. data/lib/admin_module/command/snapshot.rb +110 -0
  29. data/lib/admin_module/command/stage.rb +131 -0
  30. data/lib/admin_module/command/task.rb +110 -0
  31. data/lib/admin_module/config_helper.rb +33 -0
  32. data/lib/admin_module/dc.rb +133 -0
  33. data/lib/admin_module/guideline.rb +86 -0
  34. data/lib/admin_module/locks.rb +142 -0
  35. data/lib/admin_module/page_factory.rb +55 -0
  36. data/lib/admin_module/pages.rb +120 -0
  37. data/lib/admin_module/pages/dc_definitions_page.rb +73 -0
  38. data/lib/admin_module/pages/dc_detail_page.rb +187 -0
  39. data/lib/admin_module/pages/guideline_page.rb +35 -0
  40. data/lib/admin_module/pages/guideline_version_page.rb +140 -0
  41. data/lib/admin_module/pages/guidelines_page.rb +59 -0
  42. data/lib/admin_module/pages/guidelines_version_all_page.rb +116 -0
  43. data/lib/admin_module/pages/lock_definition_page.rb +178 -0
  44. data/lib/admin_module/pages/lock_definitions_page.rb +69 -0
  45. data/lib/admin_module/pages/login_page.rb +75 -0
  46. data/lib/admin_module/pages/parameter_page.rb +62 -0
  47. data/lib/admin_module/pages/parameters_page.rb +46 -0
  48. data/lib/admin_module/pages/ppms_page.rb +110 -0
  49. data/lib/admin_module/pages/rule_page.rb +68 -0
  50. data/lib/admin_module/pages/rules_page.rb +74 -0
  51. data/lib/admin_module/pages/ruleset_page.rb +64 -0
  52. data/lib/admin_module/pages/rulesets_page.rb +60 -0
  53. data/lib/admin_module/pages/select_list_syncable.rb +64 -0
  54. data/lib/admin_module/pages/snapshot_definitions_page.rb +73 -0
  55. data/lib/admin_module/pages/snapshot_detail_page.rb +246 -0
  56. data/lib/admin_module/pages/workflow_detail_page.rb +451 -0
  57. data/lib/admin_module/pages/workflow_detail_task_addl_detail_page.rb +172 -0
  58. data/lib/admin_module/pages/workflow_detail_task_mappings_page.rb +163 -0
  59. data/lib/admin_module/pages/workflow_detail_task_screens_page.rb +75 -0
  60. data/lib/admin_module/pages/workflow_details_page.rb +67 -0
  61. data/lib/admin_module/pages/workflow_task_page.rb +107 -0
  62. data/lib/admin_module/pages/workflow_tasks_page.rb +111 -0
  63. data/lib/admin_module/ppms.rb +78 -0
  64. data/lib/admin_module/rake.rb +22 -0
  65. data/lib/admin_module/rake/dc_tasks.rb +185 -0
  66. data/lib/admin_module/rake/deploy_task.rb +59 -0
  67. data/lib/admin_module/rake/gdl_tasks.rb +189 -0
  68. data/lib/admin_module/rake/lock_tasks.rb +189 -0
  69. data/lib/admin_module/rake/parameter_task.rb +86 -0
  70. data/lib/admin_module/rake/ppm_tasks.rb +248 -0
  71. data/lib/admin_module/rake/rule_tasks.rb +157 -0
  72. data/lib/admin_module/rake/snapshot_tasks.rb +223 -0
  73. data/lib/admin_module/rake/stage_tasks.rb +197 -0
  74. data/lib/admin_module/rake/stages_task.rb +197 -0
  75. data/lib/admin_module/rake/task_tasks.rb +189 -0
  76. data/lib/admin_module/rules.rb +50 -0
  77. data/lib/admin_module/rulesets.rb +42 -0
  78. data/lib/admin_module/snapshots.rb +133 -0
  79. data/lib/admin_module/stages.rb +171 -0
  80. data/lib/admin_module/tasks.rb +147 -0
  81. data/lib/admin_module/version.rb +3 -0
  82. data/old_spec/lib/admin_module/cli_configuration_spec.rb +126 -0
  83. data/old_spec/lib/admin_module/cli_create_stage_spec.rb +89 -0
  84. data/old_spec/lib/admin_module/cli_delete_rule_spec.rb +57 -0
  85. data/old_spec/lib/admin_module/cli_deploy_spec.rb +57 -0
  86. data/old_spec/lib/admin_module/cli_export_locks_spec.rb +62 -0
  87. data/old_spec/lib/admin_module/cli_export_stages_spec.rb +62 -0
  88. data/old_spec/lib/admin_module/cli_guidelines_version_all_spec.rb +58 -0
  89. data/old_spec/lib/admin_module/cli_import_locks_spec.rb +153 -0
  90. data/old_spec/lib/admin_module/cli_import_stages_spec.rb +173 -0
  91. data/old_spec/lib/admin_module/cli_modify_locks_spec.rb +128 -0
  92. data/old_spec/lib/admin_module/cli_modify_stages_spec.rb +88 -0
  93. data/old_spec/lib/admin_module/cli_rename_rule_spec.rb +53 -0
  94. data/old_spec/lib/admin_module/cli_rename_ruleset_spec.rb +53 -0
  95. data/old_spec/lib/admin_module/cli_var_spec.rb +41 -0
  96. data/old_spec/lib/admin_module/rake/deploy_task_spec.rb +85 -0
  97. data/old_spec/lib/admin_module/rake/parameter_task_spec.rb +58 -0
  98. data/old_spec/lib/admin_module/rake/rules_task_spec.rb +75 -0
  99. data/spec/data/build/test1.xml +0 -0
  100. data/spec/data/build/test2.xml +1 -0
  101. data/spec/data/import_dcs.yml +31 -0
  102. data/spec/data/import_locks.yml +4 -0
  103. data/spec/data/import_snapshots.yml +35 -0
  104. data/spec/data/import_stages.yml +4 -0
  105. data/spec/data/import_tasks.yml +25 -0
  106. data/spec/data/patch-test.xml +1 -0
  107. data/spec/data/remove_test_del_rule.xml +1 -0
  108. data/spec/data/stages.yml +518 -0
  109. data/spec/data/test_del_rule.xml +1 -0
  110. data/spec/lib/admin_module/admin_module_spec.rb +175 -0
  111. data/spec/lib/admin_module/cli_spec.rb +36 -0
  112. data/spec/lib/admin_module/client_spec.rb +158 -0
  113. data/spec/lib/admin_module/command/config_spec.rb +477 -0
  114. data/spec/lib/admin_module/command/dc_spec.rb +202 -0
  115. data/spec/lib/admin_module/command/gdl_spec.rb +139 -0
  116. data/spec/lib/admin_module/command/lock_spec.rb +207 -0
  117. data/spec/lib/admin_module/command/rule_spec.rb +163 -0
  118. data/spec/lib/admin_module/command/ruleset_spec.rb +124 -0
  119. data/spec/lib/admin_module/command/snapshot_spec.rb +202 -0
  120. data/spec/lib/admin_module/command/stage_spec.rb +259 -0
  121. data/spec/lib/admin_module/command/task_spec.rb +207 -0
  122. data/spec/lib/admin_module/dc_spec.rb +192 -0
  123. data/spec/lib/admin_module/guideline_spec.rb +177 -0
  124. data/spec/lib/admin_module/locks_spec.rb +188 -0
  125. data/spec/lib/admin_module/rules_spec.rb +110 -0
  126. data/spec/lib/admin_module/rulesets_spec.rb +85 -0
  127. data/spec/lib/admin_module/snapshot_spec.rb +192 -0
  128. data/spec/lib/admin_module/stages_spec.rb +179 -0
  129. data/spec/lib/admin_module/tasks_spec.rb +196 -0
  130. data/spec/spec_helper.rb +54 -0
  131. data/spec/support/asserts.rb +13 -0
  132. data/spec/support/data_clearing.rb +28 -0
  133. data/spec/support/dirs.rb +54 -0
  134. data/spec/support/helpers.rb +83 -0
  135. data/spec/support/lock.rb +23 -0
  136. data/spec/support/mocks.rb +213 -0
  137. data/spec/support/snapshot.rb +28 -0
  138. data/spec/support/stage.rb +22 -0
  139. data/spec/support/stage_factory.rb +138 -0
  140. data/spec/support/task.rb +23 -0
  141. metadata +381 -0
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'admin_module/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "admin_module"
8
+ spec.version = AdminModule::VERSION
9
+ spec.authors = ["Jeff McAffee"]
10
+ spec.email = ["jeff@ktechsystems.com"]
11
+ spec.description = %q{Command line interface for Admin Module}
12
+ spec.summary = %q{Admin Module CLI}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "cucumber", "~> 1.3.9"
24
+ spec.add_development_dependency "rspec", "~> 3.2.0"
25
+ spec.add_development_dependency "guard"
26
+ spec.add_development_dependency "guard-rspec"
27
+ #spec.add_development_dependency "pry-byebug", "~> 1.3.3"
28
+ spec.add_development_dependency "pry", "~> 0.10"
29
+
30
+ spec.add_runtime_dependency "nokogiri"
31
+ spec.add_runtime_dependency "page-object"
32
+ spec.add_runtime_dependency "thor"
33
+ spec.add_runtime_dependency "ktutils"
34
+ end
data/bin/admin_module ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+
7
+ # Exit cleanly from an early interrupt
8
+ Signal.trap("INT") { exit 1 }
9
+
10
+ require 'admin_module'
11
+
12
+ AdminModule::Runner.new(ARGV.dup).execute!
13
+
@@ -0,0 +1,260 @@
1
+ require "admin_module/version"
2
+ require 'admin_module/config_helper'
3
+ require "admin_module/cli"
4
+ require 'admin_module/page_factory'
5
+ require 'admin_module/pages'
6
+ require 'admin_module/guideline'
7
+ require 'admin_module/rulesets'
8
+ require 'admin_module/rules'
9
+ require 'admin_module/stages'
10
+ require 'admin_module/locks'
11
+ require 'admin_module/dc'
12
+ require 'admin_module/snapshots'
13
+ require 'admin_module/tasks'
14
+ require 'admin_module/ppms'
15
+ require 'admin_module/client'
16
+
17
+ if ENV['DEBUG'].nil?
18
+ $debug = false
19
+ else
20
+ $debug = true
21
+ end
22
+
23
+ class AuthenticationRequired < StandardError
24
+ end
25
+
26
+ module AdminModule
27
+ CONFIG_FILE_NAME = '.admin_module'
28
+
29
+ class << self
30
+ attr_accessor :configuration
31
+ attr_accessor :client
32
+ end
33
+
34
+ ##
35
+ # Setup admin_module configuration
36
+ #
37
+ # Attempts to find and load a configuration file the first time
38
+ # it's requested. If a config file cannot be found on in the current
39
+ # directory tree (moving towards trunk, not the leaves), a default
40
+ # configuration object is created.
41
+ #
42
+ # If a block is provided, the configuration object is yielded to the block
43
+ # after the configuration is loaded/created.
44
+ #
45
+
46
+ def self.configure
47
+ if self.configuration.nil?
48
+ unless self.load_configuration
49
+ self.configuration = Configuration.new
50
+ end
51
+ end
52
+ yield(configuration) if block_given?
53
+ end
54
+
55
+ ##
56
+ # Walk up the directory tree from current working dir (pwd) till a file
57
+ # named .admin_module is found
58
+ #
59
+ # Returns file path if found, nil if not.
60
+ #
61
+
62
+ def self.find_config_path
63
+ path = Pathname(Pathname.pwd).ascend{|d| h=d+CONFIG_FILE_NAME; break h if h.file?}
64
+ end
65
+
66
+ ##
67
+ # Write configuration to disk
68
+ #
69
+ # Writes to current working dir (pwd) if path is nil
70
+ #
71
+ # Returns path of emitted file
72
+ #
73
+
74
+ def self.save_configuration(path = nil)
75
+ # If no path provided, see if we can find one in the dir tree.
76
+ if path.nil?
77
+ path = find_config_path
78
+ end
79
+
80
+ # Still no path? Use the current working dir.
81
+ if path.nil?
82
+ path = Pathname.pwd
83
+ end
84
+
85
+ unless path.to_s.end_with?('/' + CONFIG_FILE_NAME)
86
+ path = Pathname(path) + CONFIG_FILE_NAME
87
+ end
88
+
89
+ path = Pathname(path).expand_path
90
+ File.write(path, YAML.dump(configuration))
91
+
92
+ path
93
+ end
94
+
95
+ ##
96
+ # Load the configuration from disk
97
+ #
98
+ # Returns true if config file found and loaded, false otherwise.
99
+ #
100
+
101
+ def self.load_configuration(path = nil)
102
+ # If no path provided, see if we can find one in the dir tree.
103
+ if path.nil?
104
+ path = find_config_path
105
+ end
106
+
107
+ return false if path.nil?
108
+ return false unless Pathname(path).exist?
109
+
110
+ File.open(path, 'r') do |f|
111
+ self.configuration = YAML.load(f)
112
+ puts "configuration loaded from #{path}" if $debug
113
+ end
114
+
115
+ true
116
+ end
117
+
118
+ class Configuration
119
+ attr_accessor :default_environment
120
+ attr_accessor :default_comment
121
+ attr_accessor :credentials
122
+ attr_accessor :base_urls
123
+ attr_accessor :xmlmaps
124
+ attr_accessor :aliases
125
+ attr_accessor :page_urls
126
+
127
+ # Browser timeout in seconds. Default: 360 (6 mins).
128
+ attr_accessor :browser_timeout
129
+
130
+
131
+ def initialize
132
+ reset
133
+ end
134
+
135
+ def reset
136
+ @default_environment = :dev
137
+ @current_env = nil
138
+
139
+ @default_comment = 'no comment'
140
+
141
+ @credentials = {}
142
+ #@credentials = { dev: [ ENV['HSBC_DEV_USER'], ENV['HSBC_DEV_PASSWORD'] ],
143
+ # dev2: [ ENV['HSBC_DEV2_USER'], ENV['HSBC_DEV2_PASSWORD'] ],
144
+ # sit: [ ENV['HSBC_SIT_USER'], ENV['HSBC_SIT_PASSWORD'] ],
145
+ # uat: [ ENV['HSBC_UAT_USER'], ENV['HSBC_UAT_PASSWORD'] ] }
146
+
147
+ @base_urls = { dev: "http://207.38.119.211/fap2Dev/Admin",
148
+ dev2: "http://207.38.119.211/fap2Dev2/Admin",
149
+ sit: "http://207.38.119.211/fap2SIT/Admin",
150
+ uat: "http://207.38.119.211/fap2UAT/Admin" }
151
+
152
+ @xmlmaps = {}
153
+
154
+ @aliases = {}
155
+
156
+ @page_urls = {
157
+ 'ParametersPage' => "/admin/decision/parameters.aspx",
158
+ 'ParameterPage' => "/admin/decision/parameter.aspx",
159
+ }
160
+
161
+ @browser_timeout = 360
162
+ end
163
+
164
+ ##
165
+ # Set the current environment.
166
+ #
167
+
168
+ def current_env=(env)
169
+ env = env.to_sym
170
+
171
+ fail "Cannot set current_env to un-configured environment: #{env}" unless @base_urls.key? env
172
+
173
+ # This value is NOT included when dumping to YAML.
174
+ # See Configurtion#encode_with
175
+ @current_env = env.to_sym
176
+ end
177
+
178
+ ##
179
+ # Return the current environment.
180
+ # Will return the default environment if current environment is not set.
181
+ #
182
+
183
+ def current_env
184
+ return @default_environment if @current_env.nil?
185
+ @current_env
186
+ end
187
+
188
+ def base_url
189
+ @base_urls[current_env]
190
+ end
191
+
192
+ def url page_class
193
+ suffix = @page_urls[page_class.to_s.split('::').last]
194
+ raise "Unkown page [#{page_class.to_s}]" if suffix.nil?
195
+ base_url + suffix
196
+ end
197
+
198
+ def xmlmap xmlfile
199
+ gdlname = xmlmaps[File.basename(xmlfile, '.xml')]
200
+ if gdlname.nil?
201
+ errmsg = "No guideline has been mapped for #{File.basename(xmlfile)}"
202
+ trymsg = "Have you configured your gdl mappings?"
203
+ trymsg2= " Try: admin_module config add xmlmap <xmlfile> <gdlname>"
204
+ fail("#{errmsg}\n\n#{trymsg}\n#{trymsg2}") if gdlname.nil?
205
+ end
206
+ gdlname
207
+ end
208
+
209
+ def user_credentials
210
+ @credentials[current_env]
211
+ end
212
+
213
+ ##
214
+ # Control which instance vars are emitted when dumped to YAML.
215
+ #
216
+
217
+ def encode_with(coder)
218
+ vars = instance_variables.map { |x| x.to_s }
219
+ vars = vars - ["@current_env"]
220
+
221
+ vars.each do |var|
222
+ var_val = eval(var)
223
+ coder[var.gsub('@', '')] = var_val
224
+ end
225
+ end
226
+ end # Configuration
227
+
228
+
229
+ class Runner
230
+ def initialize(argv, client = AdminModule::Client.new, exit_code = true)
231
+ @argv = argv
232
+ AdminModule.client = client
233
+ @exit_code = exit_code
234
+ end
235
+
236
+ def execute!
237
+ exit_code = begin
238
+
239
+ # Run the Thor app
240
+ AdminModule::CLI.start(@argv)
241
+
242
+ # Thor::Base#start does not have a return value,
243
+ # assume success if no exception is thrown.
244
+ 0
245
+ rescue StandardError => e
246
+ b = e.backtrace
247
+ b.unshift("#{b.shift}: #{e.message} (#{e.class})")
248
+ puts(b.map { |s| "\tfrom #{s}"}.join("\n"))
249
+ 1
250
+ end
251
+
252
+ # Return the exit code
253
+ exit(exit_code) if @exit_code
254
+ end
255
+ end
256
+ end
257
+
258
+ # Call configure to force creation of the configuration object.
259
+ AdminModule.configure
260
+
@@ -0,0 +1,54 @@
1
+ ##############################################################################
2
+ # File:: cli.rb
3
+ # Purpose:: Admin Module command line interface
4
+ #
5
+ # Author:: Jeff McAffee 06/28/2014
6
+ #
7
+ ##############################################################################
8
+
9
+ require 'thor'
10
+ require 'admin_module/command'
11
+
12
+
13
+ module AdminModule
14
+ class CLI < Thor
15
+
16
+ def self.start(*)
17
+ super
18
+ rescue Exception => e
19
+ raise e
20
+ end
21
+
22
+ def initialize(*args)
23
+ super
24
+ end
25
+
26
+ desc "gdl [COMMAND]", "run a guideline command"
27
+ subcommand "gdl", AdminModule::Command::Gdl
28
+
29
+ desc "config [COMMAND]", "modify configuration values"
30
+ subcommand "config", AdminModule::Command::Config
31
+
32
+ desc "ruleset [COMMAND]", "run a ruleset command"
33
+ subcommand "ruleset", AdminModule::Command::Ruleset
34
+
35
+ desc "rule [COMMAND]", "run a rule command"
36
+ subcommand "rule", AdminModule::Command::Rule
37
+
38
+ desc "lock [COMMAND]", "run a lock command"
39
+ subcommand "lock", AdminModule::Command::Lock
40
+
41
+ desc "stage [COMMAND]", "run a stage command"
42
+ subcommand "stage", AdminModule::Command::Stage
43
+
44
+ desc "dc [COMMAND]", "run a data clearing command"
45
+ subcommand "dc", AdminModule::Command::Dc
46
+
47
+ desc "snapshot [COMMAND]", "run a snapshot command"
48
+ subcommand "snapshot", AdminModule::Command::Snapshot
49
+
50
+ desc "task [COMMAND]", "run a task command"
51
+ subcommand "task", AdminModule::Command::Task
52
+ end # CLI
53
+ end # AdminModule
54
+
@@ -0,0 +1,80 @@
1
+ ##############################################################################
2
+ # File:: cli.rb
3
+ # Purpose:: filedescription
4
+ #
5
+ # Author:: Jeff McAffee 11/15/2013
6
+ # Copyright:: Copyright (c) 2013, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'admin_module/pages'
11
+
12
+
13
+ class AdminModule::CLI
14
+ include AdminModule::Pages
15
+
16
+
17
+ ##
18
+ # Deploy an array of source files to the current environment.
19
+ #
20
+ # +source_files+ array of files, each file's basename must be in the configured aliases.
21
+ # +comments+ to be added to Version Notes area. Defaults to 'auto upload'
22
+
23
+ def deploy_files source_files, comments = nil
24
+ source_files.each do |src|
25
+ deploy src, File.basename(src, '.xml'), comments
26
+ end
27
+ end
28
+
29
+ ##
30
+ # Deploy a source file to a guideline in the current environment.
31
+ #
32
+ # +source_file+ full path to xml file to upload
33
+ # +gdl_name_or_alias+ guideline name (or alias) to version
34
+ # +comments+ to be added to Version Notes area. Defaults to 'auto upload'
35
+
36
+ def deploy source_file, gdl_name_or_alias, comments = nil
37
+ source_file = Array(source_file)[0]
38
+ raise IOError.new("Missing source file [#{source_file}]") unless File.exists? source_file
39
+ source_file = File.expand_path(source_file)
40
+
41
+ gdl_name_or_alias = File.basename(source_file, '.xml') if gdl_name_or_alias.nil?
42
+
43
+ login
44
+
45
+ gdl_name = alias_to_name(gdl_name_or_alias)
46
+
47
+ gdl_page_url = GuidelinesPage.new(browser, base_url).
48
+ open_guideline(gdl_name)
49
+
50
+ version_gdl_url = GuidelinePage.new(browser, gdl_page_url).
51
+ add_version()
52
+
53
+ GuidelineVersionPage.new(browser, version_gdl_url).
54
+ upload(source_file, comments)
55
+ end
56
+
57
+ ##
58
+ # Retrieve a guideline name from the configured aliases
59
+
60
+ def alias_to_name gdl_name_or_alias
61
+ aliases = AdminModule.configuration.aliases
62
+
63
+ gdl_name = aliases[gdl_name_or_alias]
64
+ gdl_name = gdl_name_or_alias if gdl_name.nil?
65
+
66
+ gdl_name
67
+ end
68
+
69
+ ###
70
+ # Version all guidelines
71
+
72
+ def version_all gdl_names, comments = nil
73
+ login
74
+
75
+ version_all_page_url = GuidelinesPage.new(browser, base_url).version_all
76
+ page = GuidelinesVersionAllPage.new(browser, version_all_page_url)
77
+
78
+ page.version gdl_names, comments
79
+ end
80
+ end
@@ -0,0 +1,149 @@
1
+ ##############################################################################
2
+ # File:: cli_lock.rb
3
+ # Purpose:: filedescription
4
+ #
5
+ # Author:: Jeff McAffee 11/15/2013
6
+ # Copyright:: Copyright (c) 2013, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'admin_module/pages'
11
+
12
+
13
+ class AdminModule::CLI
14
+ include AdminModule::Pages
15
+
16
+
17
+ ##
18
+ # Retrieve lock configuration data from the current environment
19
+
20
+ def get_lock lock_name
21
+ login
22
+
23
+ begin
24
+ lock_def_url = LockDefinitionsPage.new(browser, base_url).
25
+ modify_lock(lock_name)
26
+ rescue Watir::Exception::NoValueFoundException => e
27
+ raise ArgumentError, "Lock [#{lock_name}] not found.\n\n#{e.message}"
28
+ end
29
+
30
+ lock_data = LockDefinitionPage.new(browser, lock_def_url).get_lock_data
31
+ end
32
+
33
+ ##
34
+ # Return a list of lock names in the current environment
35
+
36
+ def current_lock_names
37
+ login
38
+ LockDefinitionsPage.new(browser, base_url).locks_options
39
+ end
40
+
41
+ ##
42
+ # Return configuration data for all locks in the current environment
43
+
44
+ def all_locks
45
+ locks = {}
46
+
47
+ current_lock_names.each do |name|
48
+ locks[name] = get_lock(name)
49
+ end
50
+
51
+ locks
52
+ end
53
+
54
+ ##
55
+ # Test lock data structure for validity
56
+ #
57
+ # Required:
58
+ # at least 1 parameter OR dts
59
+
60
+ def valid_lock_data? lock_data
61
+ if !lock_data.key?(:parameters) || lock_data[:parameters].empty?
62
+ if !lock_data.key?(:dts) || lock_data[:dts].empty?
63
+ return false
64
+ end
65
+ end
66
+ true
67
+ end
68
+
69
+ ##
70
+ # Test lock data structure for valid name
71
+ #
72
+
73
+ def lock_data_has_name? lock_data
74
+ return false unless lock_data.key?(:name)
75
+ return false if lock_data[:name].empty?
76
+ true
77
+ end
78
+
79
+ ##
80
+ # Create a lock in the current environment
81
+
82
+ def create_lock lock_data
83
+ raise ArgumentError, "Invalid lock data: #{lock_data.inspect}" unless valid_lock_data?(lock_data)
84
+ raise ArgumentError, "Missing lock name: #{lock_data.inspect}" unless lock_data_has_name?(lock_data)
85
+
86
+ login
87
+
88
+ lock_def_url = LockDefinitionsPage.new(browser, base_url).
89
+ create_lock(lock_data)
90
+
91
+ LockDefinitionPage.new(browser, lock_def_url).set_lock_data lock_data
92
+ end
93
+
94
+ ##
95
+ # Modify an existing lock in the current environment
96
+
97
+ def modify_lock lock_data, lock_name = nil
98
+ lock_name ||= lock_data[:name]
99
+ raise ArgumentError, "Invalid lock data: #{lock_data.inspect}" unless valid_lock_data?(lock_data)
100
+ raise ArgumentError, "Missing lock name" if (lock_name.nil? || lock_name.empty?)
101
+
102
+ # Make sure we populate the data's name param if empty so we don't try to write
103
+ # and save an empty name.
104
+ if lock_data[:name].nil? || lock_data[:name].empty?
105
+ lock_data[:name] = lock_name
106
+ end
107
+
108
+ login
109
+
110
+ lock_def_url = LockDefinitionsPage.new(browser, base_url).
111
+ modify_lock(lock_name)
112
+
113
+ LockDefinitionPage.new(browser, lock_def_url).set_lock_data lock_data
114
+ end
115
+
116
+ ##
117
+ # Export all lock configurations in the current environment to a file.
118
+
119
+ def export_locks file_name
120
+ FileUtils.mkdir_p File.dirname(file_name)
121
+ File.open(file_name, 'w') do |f|
122
+ # Write array of lock hashes.
123
+ f << YAML.dump(all_locks)
124
+ end
125
+ end
126
+
127
+ ##
128
+ # Import lock configurations into the current environment from a file.
129
+
130
+ def import_locks file_name
131
+ raise IOError, "File not found: #{file_name}" unless File.exists?(file_name)
132
+
133
+ locks = {}
134
+ File.open(file_name, 'r') do |f|
135
+ # Write array of lock hashes.
136
+ locks = YAML.load(f)
137
+ end
138
+
139
+ existing_locks = current_lock_names
140
+
141
+ locks.each do |name, data|
142
+ if existing_locks.include?(name)
143
+ modify_lock(data, name)
144
+ else
145
+ create_lock(data)
146
+ end
147
+ end
148
+ end
149
+ end