parse_decision 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE +22 -0
  6. data/README.md +71 -0
  7. data/bin/parse_decision +126 -0
  8. data/lib/parse_decision/config.rb +90 -0
  9. data/lib/parse_decision/controller.rb +142 -0
  10. data/lib/parse_decision/parsedecisiontask.rb +31 -0
  11. data/lib/parse_decision/parser.rb +194 -0
  12. data/lib/parse_decision/pd_context.rb +148 -0
  13. data/lib/parse_decision/plugin/application.rb +48 -0
  14. data/lib/parse_decision/plugin/plugin.rb +56 -0
  15. data/lib/parse_decision/plugin/ppm_xpath.rb +70 -0
  16. data/lib/parse_decision/plugin/pre_decision_guideline.rb +177 -0
  17. data/lib/parse_decision/plugin/product.rb +176 -0
  18. data/lib/parse_decision/plugin/product_xpath.rb +52 -0
  19. data/lib/parse_decision/plugin/web_product.rb +179 -0
  20. data/lib/parse_decision/plugin.rb +50 -0
  21. data/lib/parse_decision/version.rb +5 -0
  22. data/lib/parse_decision.rb +59 -0
  23. data/parse_decision.gemspec +27 -0
  24. data/rakefile.rb +58 -0
  25. data/spec/context_spec.rb +21 -0
  26. data/spec/data/multiproduct.decision.txt +1481 -0
  27. data/spec/data/prod.decision.txt +3957 -0
  28. data/spec/data/reference/multiproduct/001-APP.xml +1 -0
  29. data/spec/data/reference/multiproduct/001-Mod-Forbear-PRODUCT.xml +357 -0
  30. data/spec/data/reference/multiproduct/001-Mod-Forgive-PRODUCT.xml +361 -0
  31. data/spec/data/reference/multiproduct/001-Mod-RateTerm-PRODUCT.xml +353 -0
  32. data/spec/data/reference/multiproduct/001-Mod-SAM-PRODUCT.xml +365 -0
  33. data/spec/data/reference/product/001-APP.xml +1 -0
  34. data/spec/data/reference/product/001-Validation-Rules.xml +536 -0
  35. data/spec/data/reference/product/002-APP.xml +1 -0
  36. data/spec/data/reference/product/002-FAPIILoanModification-PRODUCT.xml +1770 -0
  37. data/spec/data/reference/web/001-APP.xml +1 -0
  38. data/spec/data/reference/web/001-Product01-PRODUCT.xml +1088 -0
  39. data/spec/data/reference/web/002-APP.xml +1 -0
  40. data/spec/data/reference/web/002-Product01-PRODUCT.xml +15 -0
  41. data/spec/data/reference/workflow/001-APP.xml +1 -0
  42. data/spec/data/reference/workflow/001-WF-DataClearing-Pre-Rules.xml +37 -0
  43. data/spec/data/reference/workflow-2/001-APP.xml +1 -0
  44. data/spec/data/reference/workflow-2/001-WF-ProdSel-Post-Rules.xml +699 -0
  45. data/spec/data/test.rb +13 -0
  46. data/spec/data/validation.decision.txt +1199 -0
  47. data/spec/data/web.decision.txt +1128 -0
  48. data/spec/data/wf.decision.txt +43 -0
  49. data/spec/data/wf2.decision.txt +705 -0
  50. data/spec/parser_spec.rb +308 -0
  51. data/spec/plugin_app_spec.rb +40 -0
  52. data/spec/plugin_ppmxpath_spec.rb +74 -0
  53. data/spec/plugin_predecision_spec.rb +81 -0
  54. data/spec/plugin_product_spec.rb +117 -0
  55. data/spec/plugin_productxpath_spec.rb +76 -0
  56. data/spec/plugin_spec.rb +54 -0
  57. data/spec/spec_helper.rb +81 -0
  58. data/test/data/2.2.decision-multiple.txt +1391 -0
  59. data/test/data/2.2.decision.txt +1128 -0
  60. data/test/data/2.decision.txt +1481 -0
  61. data/test/plugins/test_plugin_predecisionguideline.rb +120 -0
  62. data/test/plugins/test_plugin_product.rb +120 -0
  63. data/test/test_config.rb +90 -0
  64. data/test/test_context.rb +103 -0
  65. data/test/test_parse_webdecision.rb +121 -0
  66. data/test/test_parser.rb +69 -0
  67. data/test/test_parser_parse.rb +110 -0
  68. metadata +225 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44dd7989c8b375f3969f1fcab82d69b779be844e
4
+ data.tar.gz: a85f3fbb7cd654cea7f07fd697605ca9eae24583
5
+ SHA512:
6
+ metadata.gz: f975f2e85859524dd6b1d31c25da927b0677d3ac6914fae5212a17cb1121b6abf5fc4bb00fdc868dc81e9272a6ae1ce12cfc60e36c267f95b865398d61cac2c0
7
+ data.tar.gz: 6e658f113693f199de98d02f99ed218d6b8124b584244e10019b2d4496cbed07bfc5e7a124754f8d3ac830d5bb3883f8dbc6db479e529da9e7c469d8cbb8511d
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ # Files and directories that should be ignored
2
+
3
+ # Specific files to ignore
4
+ /buildgem
5
+ /buildgem.cmd
6
+ /pdconfig.yml
7
+
8
+ # Dir to ignore
9
+ pkg/
10
+ test/data/output/
11
+ test/data/output-webdecision/
12
+ test/data/pdconfig.yml
13
+ tmp/
14
+ trace.log
15
+
16
+ # Don't checkin Gemfile.lock
17
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format doc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'ktcommon', :git => 'ssh://git@bitbucket.org/ktechsystems/ktcommon.git'
4
+
5
+ # Specify your gem's dependencies in test.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jeff McAffee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # ParseDecision Documentation
2
+
3
+ ## Usage
4
+
5
+ ParseDecision provides both a command line application and a rake task
6
+ that is used to parse decision logs generated by the Commerce Velocity
7
+ AMS application.
8
+
9
+ ### Rake Task Usage
10
+
11
+ The rake task can be included in a rakefile by requiring parse_decision like so:
12
+
13
+ require 'parse_decision'
14
+
15
+ and called as:
16
+
17
+ ParseDecisionTask.new.execute( logSrcPath, destDir )
18
+
19
+ The parser will parse the decision log out to a destination directory. Each **product**
20
+ within the log will be parsed into a separate file. The APP XML is also parsed to a
21
+ separate file for each product.
22
+
23
+ Both the product and the APP XML file names will be prefixed with the same number.
24
+ The number indicates the order that the data was found within the decision log.
25
+
26
+ A copy of the decision log (pre-parse) is also copied to the destination folder for
27
+ archiving purposes.
28
+
29
+ ### Command Line Application
30
+
31
+ Usage info can be retrieved from the application by calling it with the -h or --help
32
+ options:
33
+
34
+ $ parse_decision --help
35
+
36
+
37
+ ## Notes
38
+ + The decision log doesn't produce valid XML in many situations.
39
+ + In the interest of preserving any data the log may contain, the resulting XML is **not** cleaned.
40
+ + As a result of the previous notes, the parsed files are not guaranteed to be valid XML.
41
+
42
+ ## Version Control
43
+
44
+ This repo includes submodules.
45
+
46
+ To property initialize the repo, after cloning it, run
47
+
48
+ $ git submodule init
49
+ $ git submodule update
50
+
51
+ After pulling in the submodules, you may want to configure git to ignore
52
+ changes (dirty) in the submodules. This can be done by adding a `ignore = all`
53
+ statement to each submodule section in `.gitmodules`
54
+
55
+ # Example:
56
+ [submodule "common"]
57
+ path = common
58
+ url = git@cerberus:/home/git/ams/common.git
59
+ ignore = all
60
+
61
+ Be sure to commit your changes to `.gitmodules`.
62
+
63
+ Submodules used in this repo:
64
+
65
+ + none currently
66
+
67
+
68
+
69
+ **Website:** http://ktechsystems.com
70
+
71
+ _Copyright (c) 2011, kTech Systems LLC. All rights reserved._
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ ##############################################################################
3
+ # File:: parse_decision.rb
4
+ # Purpose:: Utility to ...
5
+ #
6
+ # Author:: Jeff McAffee 03/12/2010
7
+ # Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
8
+ # Website:: http://ktechsystems.com
9
+ ##############################################################################
10
+
11
+ require 'parse_decision'
12
+ require 'user-choices'
13
+
14
+
15
+ class ParseDecisionApp < UserChoices::Command
16
+ include UserChoices
17
+
18
+
19
+ def initialize()
20
+ super
21
+ @controller = ParseDecision::Controller.new
22
+ end
23
+
24
+
25
+ def add_sources(builder)
26
+ builder.add_source(CommandLineSource, :usage,
27
+ "Usage: #{File.basename($0)} [options] [OUTPUT_DIR]",
28
+ "\n\tParseDecision is used to break decision log files out into their parts.",
29
+ "\tOUTPUT_DIR [optional] Dir to place generated files.")
30
+ end # def add_sources
31
+
32
+
33
+ def add_choices(builder)
34
+ # Arguments
35
+ #builder.add_choice(:cmdArg, :length=>1) { |command_line| # Use length to REQUIRE args.
36
+ builder.add_choice(:cmdArg) { |command_line|
37
+ command_line.uses_arglist
38
+ }
39
+
40
+ # Switches
41
+ #builder.add_choice(:aswitch, :type=>:boolean, :default=>false) { |command_line|
42
+ # command_line.uses_switch("-a", "--aswitch",
43
+ # "Switch description.")
44
+ #}
45
+
46
+ builder.add_choice(:logging, :type=>:boolean, :default=>false) { |command_line|
47
+ command_line.uses_switch("--logging",
48
+ "Turn logging to file on/off.")
49
+ }
50
+
51
+ builder.add_choice(:reset, :type=>:boolean, :default=>false) { |command_line|
52
+ command_line.uses_switch("-r", "--reset",
53
+ "Reset config file to defaults.")
54
+ }
55
+
56
+ builder.add_choice(:verbose, :type=>:boolean, :default=>false) { |command_line|
57
+ command_line.uses_switch("-v", "--verbose",
58
+ "Lots of output.")
59
+ }
60
+
61
+ builder.add_choice(:version, :type=>:boolean, :default=>false) { |command_line|
62
+ command_line.uses_switch("--version",
63
+ "Application version.")
64
+ }
65
+
66
+ builder.add_choice(:which, :type=>:boolean, :default=>false) { |command_line|
67
+ command_line.uses_switch("--which",
68
+ "Display the Application's location.\n")
69
+ }
70
+
71
+ # Options
72
+ builder.add_choice(:file, :type=>:string) { |command_line|
73
+ command_line.uses_option("-f", "--file ARG",
74
+ "Name of decision file","(default: 2.decision.txt)")
75
+ }
76
+
77
+ builder.add_choice(:outdir, :type=>:string) { |command_line|
78
+ command_line.uses_option("-o", "--outdir ARG",
79
+ "Dir to place generated files in.", "(Will be created if it doesn't exist)")
80
+ }
81
+
82
+ builder.add_choice(:srcdir, :type=>:string) { |command_line|
83
+ command_line.uses_option("-s", "--srcdir ARG",
84
+ "Dir of src decision file.")
85
+ }
86
+
87
+ end # def add_choices
88
+
89
+
90
+ # Execute the ParseDecision application.
91
+ # This method is called automatically when 'parse_decision(.rb)' is executed from the command line.
92
+ def execute
93
+ $LOG.debug "ParseDecisionApp::execute"
94
+
95
+ options = @user_choices
96
+ if(!options[:logging])
97
+ options[:logging] = false
98
+ end
99
+
100
+ if(@user_choices[:which])
101
+ puts "Location: #{$0}"
102
+ return
103
+ end
104
+
105
+ @controller.setOptions(options)
106
+
107
+ if(@user_choices[:cmdArg].empty?) # If no cmd line arg...
108
+ if( !@controller.noCmdLineArg() )
109
+ return
110
+ end
111
+ else
112
+ if( !@controller.executeWithCmdLineArg(@user_choices[:cmdArg]) )
113
+ return
114
+ end
115
+ end
116
+
117
+ @controller.execute()
118
+ end # def execute
119
+
120
+
121
+ end # class ParseDecisionApp
122
+
123
+
124
+ #if $0 == __FILE__
125
+ ParseDecisionApp.new.execute
126
+ #end
@@ -0,0 +1,90 @@
1
+ ##############################################################################
2
+ # File:: config.rb
3
+ # Purpose:: ParseDecision configuration file reader/writer class.
4
+ #
5
+ # Author:: Jeff McAffee 03/12/2010
6
+ # Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'ktcommon/ktcfg'
11
+ require 'parse_decision/version'
12
+
13
+ ##############################################################################
14
+ # Everything is contained in module ParseDecision
15
+ module ParseDecision
16
+
17
+ ##########################################################################
18
+ # Controller class handles interactions bewteen the view (cmdline script)
19
+ # and the model (Tool).
20
+ class Config < KtCfg::CfgFile
21
+
22
+ attr_accessor :cfg
23
+
24
+ def initialize(rootDir=nil)
25
+ $LOG.debug "Config::initialize"
26
+ super
27
+ @cfg = {}
28
+
29
+ setDefaults()
30
+ end
31
+
32
+ def setDefaults
33
+ $LOG.debug "Config::setDefaults"
34
+
35
+ # Blow away the existing cfg hash
36
+ @cfg = {}
37
+
38
+ # Notes about APPDATA paths:
39
+ # Local app data should be used when an app's data is too
40
+ # big to move around. Or is specific to the machine running
41
+ # the application.
42
+ #
43
+ # Roaming app data files could be pushed to a server (in a
44
+ # domain environment) and downloaded onto a different work
45
+ # station.
46
+ #
47
+ # LocalLow is used for data that must be sandboxed. Currently
48
+ # it is only used by IE for addons and storing data from
49
+ # untrusted sources (as far as I know).
50
+ #
51
+
52
+
53
+ #appDataPath = ENV["APPDATA"] # APPDATA returns AppData\Roaming on Vista/W7
54
+ appDataPath = ENV["LOCALAPPDATA"] # LOCALAPPDATA returns AppData\Local on Vista/W7
55
+ appDataPath ||= ENV["HOME"]
56
+ @cfg[:appPath] = File.rubypath(File.join(appDataPath, "parse_decision"))
57
+ @cfg[:version] = ParseDecision::VERSION
58
+ @cfg[:file] = "2.decision.txt"
59
+ @cfg[:logging] = false
60
+ end
61
+
62
+ # Load the YAML configuration file.
63
+ # returns:: a hash containing configuration info.
64
+ def load
65
+ $LOG.debug "Config::load"
66
+
67
+ filepath = cfgFilePath("pdconfig.yml")
68
+ if(!File.exists?( filepath )) # TODO: This needs to be moved into KtCfg.
69
+ $LOG.debug "Config file does not exist. Returning default config obj."
70
+ return @cfg
71
+ end
72
+
73
+ @cfg = read("pdconfig.yml")
74
+ end
75
+
76
+ # Save the @cfg hash to a YAML file.
77
+ def save(cfg=nil)
78
+ $LOG.debug "Config::save( cfg )"
79
+ if( nil != cfg )
80
+ @cfg = cfg
81
+ end
82
+ write("pdconfig.yml", @cfg)
83
+ end
84
+
85
+ def addKeyValue(key, value)
86
+ $LOG.debug "Config::addKeyValue( #{key.to_s}, #{value} )"
87
+ @cfg[key] = value
88
+ end
89
+ end # class Config
90
+ end # module ParseDecision
@@ -0,0 +1,142 @@
1
+ ##############################################################################
2
+ # File:: controller.rb
3
+ # Purpose:: Main Controller object for ParseDecision utility
4
+ #
5
+ # Author:: Jeff McAffee 03/12/2010
6
+ # Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'ktcommon/ktpath'
11
+ require 'ktcommon/ktcmdline'
12
+
13
+ ##############################################################################
14
+ # Everything is contained in Module ParseDecision
15
+ module ParseDecision
16
+
17
+ ##########################################################################
18
+ # Controller class handles interactions bewteen the view (cmdline script)
19
+ # and the model (Tool).
20
+ class Controller
21
+
22
+ def initialize()
23
+ $LOG.debug "Controller::initialize"
24
+ @cfg = Config.new.load
25
+ @cfg = Config.new.load
26
+ @model = Parser.new
27
+ end
28
+
29
+
30
+ # Save the current config values and start the parse.
31
+ def execute()
32
+ $LOG.debug "Controller::execute"
33
+
34
+ # Save current cfg
35
+ Config.new.save( @cfg )
36
+ @model.parseCfg( @cfg )
37
+ end
38
+
39
+ # Set switches with values from a hash. This should only be
40
+ # called from +setOptions+.
41
+ def setSwitches(options={})
42
+ $LOG.debug "Controller::setSwitches( options={} )"
43
+
44
+ if(options.length)
45
+ options.each do |opt, arg|
46
+ case opt
47
+ when :logging
48
+ cfgCtrl = Config.new
49
+ cfgCtrl.load
50
+ cfgCtrl.addKeyValue(:logging, arg)
51
+ cfgCtrl.save
52
+
53
+ when :reset
54
+ cfgCtrl = Config.new
55
+ cfgCtrl.save
56
+
57
+ when :verbose
58
+ # Set verbose flag
59
+ @cfg[:verbose] = true
60
+
61
+ when :version
62
+ # Print the version and exit.
63
+ verStr1 = "#{ParseDecision::APPNAME} v#{@model.version}"
64
+ verStr2 = "#{ParseDecision::COPYRIGHT}"
65
+ puts verStr1
66
+ puts verStr2
67
+ puts
68
+ exit
69
+
70
+ else
71
+ # Don't know what you want but I don't recognize it.
72
+
73
+ end # case opt
74
+ end # options.each
75
+ end # if more than 1 option
76
+ end
77
+ private :setSwitches
78
+
79
+ # Set all options and switches with values from a hash.
80
+ def setOptions(options={})
81
+ $LOG.debug "Controller::setOptions( options={} )"
82
+
83
+ setSwitches(options)
84
+
85
+ if(options.length)
86
+ options.each do |opt, arg|
87
+ case opt
88
+ when :file
89
+ # Set cfg decision file name
90
+ @cfg[:file] = arg
91
+
92
+ when :outdir
93
+ # Set context output dir
94
+ @cfg[:outdir] = arg
95
+
96
+ when :srcdir
97
+ # Set context src dir
98
+ @cfg[:srcdir] = arg
99
+
100
+ else
101
+ # Don't know what you want but I don't recognize it.
102
+
103
+ end
104
+ end # options.each
105
+
106
+ cfgCtrl = Config.new
107
+ cfgCtrl.load
108
+ cfgCtrl.cfg.merge!(@cfg)
109
+ cfgCtrl.save
110
+ end # if more than 1 option
111
+ end
112
+
113
+
114
+ # Command line arg will be used as the +outdir+.
115
+ def executeWithCmdLineArg(arg)
116
+ $LOG.debug "Controller::executeWithCmdLineArg( #{arg} )"
117
+ @cfg[:outdir] = arg
118
+ return true # if ok to continue, false to exit app.
119
+ end
120
+
121
+
122
+ # Make sure +outdir+ has been set.
123
+ # Returns true as long as outdir is set one way or the other.
124
+ def noCmdLineArg()
125
+ $LOG.debug "Controller::noCmdLineArg"
126
+ if( @cfg.key?(:outdir) && !@cfg[:outdir].empty? )
127
+ return true # if ok to continue, false to exit app.
128
+ end
129
+
130
+ puts "Missing output directory argument."
131
+ puts
132
+ puts "The outdir needs to be set at least one time."
133
+ puts "Use the -o option or supply the output directory path on the command line."
134
+ puts "Use -h for help."
135
+ return false # to exit app.
136
+ end
137
+
138
+
139
+ end # class Controller
140
+
141
+
142
+ end # module ParseDecision
@@ -0,0 +1,31 @@
1
+ ##############################################################################
2
+ # File:: parsedecisiontask.rb
3
+ # Purpose:: Rake Task for running the application
4
+ #
5
+ # Author:: Jeff McAffee 04/16/2010
6
+ # Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'parse_decision'
11
+ class ParseDecisionTask
12
+
13
+ def execute(logSrcPath, destDir, verbose=false)
14
+
15
+ dsnFile = File.basename(logSrcPath)
16
+ dsnDir = File.dirname(logSrcPath)
17
+
18
+ app = ParseDecision::Controller.new
19
+
20
+ options = { :reset => true, # Set switches
21
+ :verbose => verbose,
22
+ :file => dsnFile, # Set options
23
+ :srcdir => dsnDir,
24
+ :outdir => destDir, }
25
+
26
+ app.setOptions( options )
27
+ app.execute()
28
+ end
29
+ end # class ParseDecisionTask
30
+
31
+