iab-Oil 0.1.2

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.
@@ -0,0 +1,87 @@
1
+ require 'DSLContext'
2
+
3
+ class RatingEngineResolver < DslContext
4
+
5
+ bubble :than, :is, :list, :the, :to, :at, :it
6
+
7
+ def dictionary(*args)
8
+ xml = "<?xml version='1.0' encoding='UTF-8'?>"
9
+ xml << "<PolMessage Type='TransactionRequestConfig' Version='1'>" if args[0] == "XML"
10
+ xml << "<PolMessage Type='TransactionRequest' Version='1'>" if args[0] != "XML"
11
+ xml << "<Dictionary DictType='#{args[0]}' DictName='#{args[1]}' DictId='#{args[2]}' DictVer='#{args[3]}'/>"
12
+ xml << "<Transaction TranName='QuotationRequest' EffectiveDate='2007-04-30'/>" if args[0] == "XML"
13
+ xml << "<Transaction TranName='QuoteDetail' EffectiveDate='17/7/2007'/>" if args[0] != "XML"
14
+ xml << "<Schemes><Scheme Ref='#{args[4]}'/></Schemes>"
15
+ @dictHeader=xml
16
+ end
17
+
18
+ def rating_engine(*args)
19
+ @ratingEngine = args[0]
20
+ @responseContent = args[1]
21
+ if (args[2] != nil) then
22
+ @inboundTransform = args[2]
23
+ else
24
+ @inboundTransform = nil
25
+ end
26
+ if (args[3] != nil) then
27
+ @outboundTransform = args[3]
28
+ else
29
+ @outboundTransform = nil
30
+ end
31
+ if (args[4] != nil) then
32
+ @mockFile = args[4]
33
+ else
34
+ @mockFile = nil
35
+ end
36
+ end
37
+
38
+ def getResult
39
+ if (@ratingEngine == 'Mock') then
40
+ closure = "lambda {|xml| "
41
+ closure << "response = SBroker.GetMockRatingResponse('#{@mockFile}'); response"
42
+ closure << "}"
43
+ "#{closure}"
44
+ else
45
+ closure = "lambda {|xml| "
46
+ closure << "keep_xml = xml;"
47
+ if (@inboundTransform != nil) then
48
+ closure << "xml = SBroker.ApplyTransform(xml,'#{@inboundTransform}',nil); "
49
+ end
50
+ closure << "msg = \""
51
+ closure << @dictHeader
52
+ closure << "<PolData Type='Request' Selection='#{@responseContent}'/>"
53
+ closure << "<PolData Type='Input'>"
54
+ closure << "\""
55
+ closure << '+ xml +'
56
+ closure << "\""
57
+ closure << "</PolData></PolMessage>"
58
+ #puts '----------\n';p msg;puts '====\n';p response;
59
+ closure << "\"; response = SBroker.InvokeRTE(msg);"
60
+ closure << "if (partial) then premium = SBroker.ExtractSectionPremium(keep_xml,response);premium else response end"
61
+ closure << "}"
62
+ "#{closure}"
63
+ end
64
+ end
65
+
66
+ def product(name)
67
+ puts "say the product is #{name}"
68
+ end
69
+
70
+ def supported_channels(*args)
71
+ puts "say supported channels are "
72
+ args.each do |arg|
73
+ puts "say "+arg
74
+ end
75
+ end
76
+
77
+ def supported_processes(*args)
78
+ puts "say supported processes are "
79
+ args.each do |arg|
80
+ puts "say "+arg
81
+ end
82
+ end
83
+
84
+ def channel(name)
85
+ puts " say it has a #{name} channel"
86
+ end
87
+ end
@@ -0,0 +1,65 @@
1
+ require 'set'
2
+ require File.join(File.dirname(__FILE__),'DSLContext')
3
+
4
+ class SiteProcessInterpreter < DslContext
5
+ def initialize
6
+ @cmds = []
7
+ @processes = Hash.new #list of all the processes with the value of the first step being stored
8
+ @result = []
9
+ @result[0] = Hash.new
10
+ @result[1] = Array.new
11
+ @result[2] = Set.new
12
+ end
13
+
14
+ def getResult
15
+ #massage result[0] so that all navigation that related to processes are replaced with the 1st step of the process
16
+ #rather than the process name
17
+ #...
18
+ @result
19
+ end
20
+
21
+ def siteprocesses(*args)
22
+ end
23
+
24
+ def endsiteprocesses(*args)
25
+ end
26
+
27
+ def reference_datamodel(*args)
28
+ end
29
+
30
+ def process(*args)
31
+ @current_process = args[0]
32
+ @processes[@current_process.to_sym] = :FirstStepUnknown
33
+ @cmds.push :process
34
+ end
35
+
36
+ def endprocess(*args)
37
+ end
38
+
39
+ def products(*args)
40
+ end
41
+
42
+ def endproducts(*args)
43
+ end
44
+
45
+ def product(*args)
46
+ @result[1].push args[0]
47
+ end
48
+
49
+ def endproduct(*args)
50
+ end
51
+
52
+ #from here we can derive the product process DSL
53
+ #and also the layout files
54
+ def flow(*args)
55
+ if (@cmds.last == :process)
56
+ @processes[@current_process.to_sym] = args[0]
57
+ end
58
+ @cmds.push :flow
59
+
60
+ @result[0]["#{args[0]}".to_sym] = args[1]
61
+ args[1][:data_model].each do |e|
62
+ @result[2].add?(e.to_sym)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,216 @@
1
+ require File.join(File.dirname(__FILE__),'DSLContext')
2
+ require 'yaml'
3
+
4
+ #create class that fills in for the RAILS class when rails is not around, e.g. when testing
5
+ #when RAILS is around this will have no effect
6
+ class HashWithIndifferentAccess < Hash
7
+ end
8
+
9
+ class VPMSComponentSchemaInterpreter < DslContext
10
+
11
+ #ToDo: Sends in an xpath statement to set up a referenceable context for the node
12
+ #in the transformation - i.e. when duplicating complex types
13
+
14
+ bubble :than, :is, :list, :the, :to, :at, :it, :end
15
+
16
+ VPMS_SCHEMA_INTERPRETER_ROOT = File.dirname(__FILE__)
17
+ XSL_ROOT = File.join(VPMS_SCHEMA_INTERPRETER_ROOT, 'xslt')
18
+ MOCK_ROOT = File.join(VPMS_SCHEMA_INTERPRETER_ROOT, 'mocks')
19
+
20
+ def initialize(*args)
21
+ @props = args
22
+ @useDynamicFileMapping = (args.length > 0) ? true : false
23
+ @hashesRoot = (args.length > 0) ? OIL_HASH_ROOT : ENTITY_DEF_ROOT
24
+ end
25
+
26
+ def getResult
27
+ getResult = ""
28
+ getResult << startSchema
29
+ @erbAry.each do |a|
30
+ b = a.first
31
+ #a.to_s
32
+ getResult << "\t"
33
+ getResult << processXPath(a, b)
34
+ end
35
+ getResult << endSchema
36
+ getResult
37
+ end
38
+
39
+ def processXPath(*args)
40
+ processXpath = ""
41
+ xpath = args[0]
42
+ boolEndOfPath = (args[0].length == 1)
43
+ processXpath << "\t"
44
+ processXpath << startElement(args[0].first, args[1], boolEndOfPath)
45
+ xpath.delete_at(0)
46
+ if xpath.length > 0
47
+ processXpath << startComplexType
48
+ processXpath << processXPath(xpath, args[1])
49
+ processXpath << endComplexType
50
+ end
51
+ processXpath << endElement
52
+ processXpath
53
+ end
54
+
55
+ def applyTransform(*args)
56
+ require 'rexml/document'
57
+ require 'xml/xslt'
58
+ xslt = XML::XSLT.new()
59
+ string = args[0]
60
+ doc = REXML::Document.new(string)
61
+ xslt.xml = doc
62
+ xslt.xsl = File.join(XSL_ROOT, "VPMSSchemaInterpreter.xsl")
63
+ transformed_xml = xslt.serve()
64
+ transformed_xml
65
+ end
66
+
67
+ def startSchema
68
+ #ToDo: Make this a widget - a schema open widget for example
69
+ openSchema = ""
70
+ openSchema << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
71
+ openSchema << "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
72
+ openSchema
73
+ end
74
+
75
+ def endSchema
76
+ endSchema = ""
77
+ endSchema << "</xs:schema>\n"
78
+ endSchema
79
+ end
80
+
81
+ def startElement(*args)
82
+ #ToDo: Make this a widget - an element open widget for example
83
+ openElement = ""
84
+ openElement << "<xs:element name=\"#{args[0]}\""
85
+ #ToDo: do something better to get type info -
86
+ #if this is the ultimate point in the xpath, this pushes in a data type of string - thats all
87
+ if (args[2] == true) then
88
+ openElement << " type=\"xs:string\">\n"
89
+ else
90
+ openElement << ">\n"
91
+ end
92
+ #ToDo: Read the element type and other atts off the MD hash metadata.
93
+ #args 1 is the full xpath of the element used potentially to key into the md hash
94
+ #Potentially do this if args 2 is true (it's the last xpath step) and use args 1 for the key
95
+ #args 2 represents a key into a hash
96
+ #the @metaProps hash for example - see 'coverage'
97
+ #If there is an entry in that hash for this element's xpath, then a type attribute can be
98
+ #determined for it and gets used from the md hash - When the element is nesting a ct, there's no type attribute
99
+ #This key would be used to read off values in that hash, if it is a hash of hashes -
100
+ #i.e. if the buildingsCoverSumInsuredAmount key in the metaProps referenced a hash of metadata:
101
+ #It would also be possible to reference entries for this element in the existing
102
+ #xml dictionary, which is keyed on this element's xpath
103
+ openElement
104
+ end
105
+
106
+ def endElement
107
+ endElement = ""
108
+ endElement << "</xs:element>\n"
109
+ endElement
110
+ end
111
+
112
+ def startComplexType
113
+ #ToDo: Make this a widget - a schema open widget for example
114
+ openElement = ""
115
+ openElement << "<xs:complexType>\n"
116
+ openElement << startSequence
117
+ openElement
118
+ end
119
+
120
+ def endComplexType
121
+ endElement = ""
122
+ endElement << endSequence
123
+ endElement << "</xs:complexType>\n"
124
+ endElement
125
+ end
126
+
127
+ def startSequence
128
+ #ToDo: Make this a widget - a schema open widget for example
129
+ openElement = ""
130
+ openElement << "<xs:sequence>\n"
131
+ openElement
132
+ end
133
+
134
+ def endSequence
135
+ endElement = ""
136
+ endElement << "</xs:sequence>\n"
137
+ endElement
138
+ end
139
+
140
+ def coverage(*args)
141
+ @erbAry = []
142
+ @erb = ""
143
+ @argName = "#{args[0]}"
144
+ @useDynamicFileMapping == true ? io = open(File.join(@hashesRoot,"/coverages/#{@argName}PropertyHash"),'r' ) : io = open(File.join(COVERAGE_DEF_ROOT,"/#{@argName}PropertyHash"),'r' )
145
+ @prdhash = YAML::load(io)
146
+ end
147
+
148
+ def endcoverage(*args)
149
+ end
150
+
151
+ def entity(*args)
152
+ @erbAry = []
153
+ @erb = ""
154
+ @argName = "#{args[0]}"
155
+ @useDynamicFileMapping == true ? io = open(File.join(@hashesRoot,"/entities/#{@argName}PropertyHash"),'r' ) : io = open(File.join(ENTITY_DEF_ROOT,"/#{@argName}PropertyHash"),'r' )
156
+ @prdhash = YAML::load(io)
157
+ end
158
+
159
+ def endentity(*args)
160
+ end
161
+
162
+ def use(*args)
163
+
164
+ h = ""
165
+ lasth = ""
166
+ lasta = ""
167
+ args.each do |a|
168
+ unless a.class == Hash
169
+ lasth = String.new(h)
170
+ h << "#{a}"
171
+ lasta = a
172
+ end
173
+ end
174
+
175
+ hashname = @argName + h
176
+
177
+ #now figure out whether the last arg above leads to an empty hash
178
+ #i.e. it is really a single value field
179
+ #if so backup a level and read the property whose name = the last arg value passed in
180
+
181
+ specificProperty = false
182
+
183
+ if !@prdhash.has_key?(hashname)
184
+ puts "missing key for #{hashname} when processing:use #{args}"
185
+ end
186
+ myHash = @prdhash["#{hashname}"].clone
187
+ if (myHash.length == 1)
188
+ hashname = @argName + lasth
189
+ specificProperty = true
190
+ if !@prdhash.has_key?(hashname)
191
+ puts "missing key for #{hashname} when processing:use #{args}"
192
+ end
193
+ myHash = @prdhash["#{hashname}"].clone
194
+ end
195
+
196
+ @erb << myHash["#{'xpath'}"]
197
+
198
+ myHash.each do |property, value|
199
+ if (property != 'xpath' and (property =~ /MD$/) == nil) then
200
+ if (value == "" && (!specificProperty || (specificProperty && property == "#{lasta}"))) then
201
+ @erb << "/"
202
+ @erb << property
203
+ #In progress
204
+ #@metaprop = @erb.sub('/', '') stands as an xpath key to the metadata in the 'element properties' hash
205
+
206
+ end
207
+ end
208
+ end
209
+
210
+ erbTemp = @erb.split('/')
211
+ @erbAry.push(erbTemp)
212
+ @erb = ""
213
+
214
+ end
215
+ end
216
+
@@ -0,0 +1,102 @@
1
+ require File.join(File.dirname(__FILE__),'DSLContext')
2
+ require File.join(File.dirname(__FILE__),'VPMSComponentSchemaInterpreter')
3
+ require File.join(File.dirname(__FILE__),'CollesceProductInterpreter')
4
+ require 'yaml'
5
+
6
+ #create class that fills in for the RAILS class when rails is not around, e.g. when testing
7
+ #when RAILS is around this will have no effect
8
+ class HashWithIndifferentAccess < Hash
9
+ end
10
+
11
+ class VPMSPackageSchemaInterpreter < DslContext
12
+
13
+ bubble :than, :is, :list, :the, :to, :at, :it, :end
14
+
15
+ VPMS_SCHEMA_INTERPRETER_ROOT = File.dirname(__FILE__)
16
+ XSL_ROOT = File.join(VPMS_SCHEMA_INTERPRETER_ROOT, 'xslt')
17
+ MOCK_ROOT = File.join(VPMS_SCHEMA_INTERPRETER_ROOT, 'mocks')
18
+
19
+ def getResult
20
+ @entities = Hash.new
21
+ @coverages = Hash.new
22
+ getResult = ""
23
+ getResult << startSchema
24
+ if (@arProductsSplit != nil) then
25
+ @arProductsSplit.each do |a|
26
+ open(File.join(a,"/product.oil")) {|f| @contents = f.read }
27
+ dsl = @contents.to_s
28
+ h = CollesceProductInterpreter.execute(dsl)
29
+ @entities.merge!(h[0])
30
+ @coverages.merge!(h[1])
31
+ #open(File.join(a,"/product.oil")) {|f| @contents = f.read }
32
+ #dsl = @contents.to_s
33
+ #frag = VPMSProductSchemaInterpreter.execute(dsl,a)
34
+ #getResult << applyTransform(frag)
35
+ end
36
+ collescedProduct = "product :CommercialProperty\n"
37
+ collescedProduct << "entities\n"
38
+ @entities.each do |k,v|
39
+ collescedProduct << "#{v} :#{k}\n"
40
+ end
41
+ collescedProduct << "entities\n"
42
+ collescedProduct << "coverages\n"
43
+ @coverages.each do |k,v|
44
+ collescedProduct << "#{v} :#{k}\n"
45
+ end
46
+ collescedProduct << "coverages\n"
47
+ collescedProduct << "endproduct"
48
+ #puts collescedProduct
49
+ frag = VPMSProductSchemaInterpreter.execute(collescedProduct,"#{OIL_DSL_ROOT.gsub('*','')}Retailer/DSL")
50
+ getResult << applyTransform(frag)
51
+ end
52
+ getResult << endSchema
53
+ end
54
+
55
+ def package(*args)
56
+ theDir = "#{OIL_DSL_ROOT}"
57
+ @schemaFragments = ""
58
+ @arProductsSplit = Array.new
59
+ Dir.glob(File.join(theDir, '*'), File::FNM_PATHNAME) do |p|
60
+ if File.directory?(p)
61
+ @arProductsSplit.push(p)
62
+ end
63
+ end
64
+ end
65
+
66
+ def endpackage
67
+ end
68
+
69
+ def startSchema
70
+ #ToDo: Make this a widget - a schema open widget for example
71
+ openSchema = ""
72
+ openSchema << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
73
+ openSchema << "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
74
+ openSchema << "<xs:element xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" name=\"CommercialProperty\">\n"
75
+ openSchema << "<xs:complexType>\n"
76
+ openSchema << "<xs:sequence>\n"
77
+ openSchema
78
+ end
79
+
80
+ def endSchema
81
+ endSchema = ""
82
+ endSchema << "</xs:sequence>\n"
83
+ endSchema << "</xs:complexType>\n"
84
+ endSchema << "</xs:element>\n"
85
+ endSchema << "</xs:schema>\n"
86
+ endSchema
87
+ end
88
+
89
+ def applyTransform(*args)
90
+ require 'rexml/document'
91
+ require 'xml/xslt'
92
+ xslt = XML::XSLT.new()
93
+ string = args[0]
94
+ doc = REXML::Document.new(string)
95
+ xslt.xml = doc
96
+ xslt.xsl = File.join(XSL_ROOT, "VPMSPackageSchemaInterpreter.xsl")
97
+ transformed_xml = xslt.serve()
98
+ transformed_xml
99
+ end
100
+
101
+ end
102
+
@@ -0,0 +1,155 @@
1
+ require File.join(File.dirname(__FILE__),'DSLContext')
2
+ require File.join(File.dirname(__FILE__),'VPMSComponentSchemaInterpreter')
3
+ require 'yaml'
4
+
5
+ #create class that fills in for the RAILS class when rails is not around, e.g. when testing
6
+ #when RAILS is around this will have no effect
7
+ class HashWithIndifferentAccess < Hash
8
+ end
9
+
10
+ class VPMSProductSchemaInterpreter < DslContext
11
+
12
+ bubble :than, :is, :list, :the, :to, :at, :it, :end
13
+
14
+ VPMS_SCHEMA_INTERPRETER_ROOT = File.dirname(__FILE__)
15
+ XSL_ROOT = File.join(VPMS_SCHEMA_INTERPRETER_ROOT, 'xslt')
16
+ MOCK_ROOT = File.join(VPMS_SCHEMA_INTERPRETER_ROOT, 'mocks')
17
+
18
+ def initialize(*args)
19
+ @props = args
20
+ @useDynamicFileMapping = (args.length > 0) ? true : false
21
+ @productDSLRoot = (args.length > 0) ? args[0] : ENTITY_DSL_ROOT
22
+ end
23
+
24
+ def getResult
25
+ @getResult = ""
26
+ @getResult << getDenormalisedSchema
27
+ end
28
+
29
+ def getDenormalisedSchema
30
+ getSchema = ""
31
+ getSchema << startSchema
32
+ getSchema << startRoot(@classDef)
33
+ getSchema << @schemaFragments
34
+ getSchema << endRoot
35
+ getSchema << endSchema
36
+ getSchema
37
+ end
38
+
39
+ def applyTransform(*args)
40
+ require 'rexml/document'
41
+ require 'xml/xslt'
42
+ xslt = XML::XSLT.new()
43
+ string = args[0]
44
+ doc = REXML::Document.new(string)
45
+ xslt.xml = doc
46
+ xslt.xsl = File.join(XSL_ROOT, "VPMSSchemaInterpreter.xsl")
47
+ transformed_xml = xslt.serve()
48
+ transformed_xml
49
+ end
50
+
51
+ def startSchema
52
+ #ToDo: Make this a widget - a schema open widget for example
53
+ openSchema = ""
54
+ openSchema << "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
55
+ openSchema
56
+ end
57
+
58
+ def endSchema
59
+ endSchema = ""
60
+ endSchema << "</xs:schema>\n"
61
+ endSchema
62
+ end
63
+
64
+ def startRoot(*args)
65
+ #ToDo: Make this a widget - an element open widget for example
66
+ openElement = ""
67
+ openElement << "<xs:element name=\"#{args[0]}\">\n"
68
+ openElement << "<xs:complexType>\n"
69
+ openElement << "<xs:sequence>\n"
70
+ openElement << "<xs:element name=\"Brand\" type=\"xs:string\"/>\n"
71
+ openElement << "<xs:element name=\"Package\" type=\"xs:string\"/>\n"
72
+ openElement
73
+ end
74
+
75
+ def endRoot
76
+ endElement = ""
77
+ endElement << "</xs:sequence>\n"
78
+ endElement << "</xs:complexType>\n"
79
+ endElement << "</xs:element>\n"
80
+ endElement
81
+ end
82
+
83
+ def product(*args)
84
+ @requires = ""
85
+ @schemaFragments = ""
86
+ @classDef = "#{args[0]}"
87
+ end
88
+
89
+ def endproduct
90
+
91
+ end
92
+
93
+ def entities(*args)
94
+ @libtype = "entities"
95
+ end
96
+
97
+ def endentities
98
+
99
+ end
100
+
101
+ def coverages(*args)
102
+ @libtype = "coverages"
103
+ end
104
+
105
+ def endcoverages
106
+
107
+ end
108
+
109
+ def for_ABI_codes(*args)
110
+ end
111
+
112
+ def conditional_on(*args)
113
+ end
114
+
115
+ def has_one(*args)
116
+ has(args)
117
+ end
118
+
119
+ def has_many(*args)
120
+ has(args)
121
+ end
122
+
123
+ def has(*args)
124
+ if (@useDynamicFileMapping == true) then
125
+ open(File.join(@productDSLRoot,"#{@libtype}/#{args[0]}.oil")) {|f| @contents = f.read }
126
+ else
127
+ open(File.join(@productDSLRoot,"/#{args[0]}.oil")) {|f| @contents = f.read }
128
+ end
129
+ dsl = @contents.to_s
130
+ # todo: bit clumsy but need it working
131
+ if (@useDynamicFileMapping == true) then
132
+ frag = VPMSComponentSchemaInterpreter.execute(dsl,@useDynamicFileMapping)
133
+ else
134
+ frag = VPMSComponentSchemaInterpreter.execute(dsl)
135
+ end
136
+ @schemaFragments << applyTransform(frag)
137
+ end
138
+
139
+ def has_between(*args)
140
+ if (@useDynamicFileMapping == true) then
141
+ open(File.join(@productDSLRoot,"#{@libtype}/#{args[2]}.oil")) {|f| @contents = f.read }
142
+ else
143
+ open(File.join(@productDSLRoot,"/#{args[0]}.oil")) {|f| @contents = f.read }
144
+ end
145
+ dsl = @contents.to_s
146
+ # todo: bit clumsy but need it working
147
+ if (@useDynamicFileMapping == true) then
148
+ frag = VPMSComponentSchemaInterpreter.execute(dsl,@useDynamicFileMapping)
149
+ else
150
+ frag = VPMSComponentSchemaInterpreter.execute(dsl)
151
+ end
152
+ @schemaFragments << applyTransform(frag)
153
+ end
154
+
155
+ end