razorrisk-razor-connectivity 0.14.10

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,273 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/razor/connectivity/razor_3/header_maker.rb
5
+ #
6
+ # Purpose: ::RazorRisk::Razor::Connectivity::Razor3::HeaderMaker class
7
+ #
8
+ # Created: 26th July 2017
9
+ # Updated: 24th August 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2017-2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+
19
+ # ######################################################################## #
20
+ # requires
21
+
22
+ require 'pantheios'
23
+ require 'recls'
24
+ require 'xqsr3/quality/parameter_checking'
25
+
26
+ =begin
27
+ =end
28
+
29
+ module RazorRisk
30
+ module Razor
31
+ module Connectivity
32
+ module Razor3
33
+
34
+ class HeaderMaker
35
+
36
+ module HeaderMaker_Constants
37
+
38
+ def self.DefaultAttributes **options
39
+
40
+ da = {}
41
+
42
+ da[:async] = false unless options[:no_async]
43
+ da[:caller] = Recls.stat($0, Recls::DETAILS_LATER).stem unless options[:no_caller_name]
44
+ da[:callerPid] = Process.pid unless options[:no_caller_pid]
45
+ da[:callerThread] = Thread.current.object_id unless options[:no_caller_thread]
46
+ da[:replicate] = true unless options[:no_replicate]
47
+
48
+ da
49
+ end
50
+
51
+ private
52
+ RequestTypes_ = [ :riskQ, :razorInbound ]
53
+ public
54
+ RequestTypes = RequestTypes_ + RequestTypes_.map { |s| s.to_s }
55
+
56
+ AcceptedOptions = %w{
57
+
58
+ body
59
+ body_attributes
60
+ caller
61
+ request_mode
62
+ request_name
63
+ request_type
64
+ response_mode
65
+ return_type
66
+ server
67
+ user_id
68
+
69
+ no_async
70
+ no_caller_name
71
+ no_caller_pid
72
+ no_caller_thread
73
+ no_replicate
74
+ }.map { |s| s.to_sym }
75
+ end
76
+
77
+ include ::Pantheios
78
+ include ::Xqsr3::Quality::ParameterChecking
79
+
80
+ def initialize environment, isdodiffallow = true, **options
81
+
82
+ trace ParamNames[ :environment, :isdodiffallow, :options ], environment, isdodiffallow, options
83
+
84
+ @environment = environment
85
+ @isdodiffallow = isdodiffallow
86
+ @options = options.clone
87
+ end
88
+
89
+ attr_reader :environment
90
+ attr_reader :isdodiffallow
91
+ attr_reader :options
92
+
93
+ # See class method for explanation for options
94
+ def prepare_inbound_header **options
95
+
96
+ trace
97
+
98
+ opts = self.options.merge options
99
+
100
+ self.class.prepare_inbound_header environment, isdodiffallow, **opts
101
+ end
102
+
103
+ # Prepares a Razor inbound (XML) header, returned as either a string
104
+ # or an XML node
105
+ #
106
+ # @param environment (String) The environment name. May not be +nil+
107
+ # @param options (Hash) Options that alter the behaviour
108
+ #
109
+ # @option +:request_type+ (Symbol, String) Mandatory option that
110
+ # designates the type of the header. Currently supports the values
111
+ # +:riskQ+ and +:razorInbound+. No default
112
+ # @option +:return_type+ (Symbol, String) Determines the type of the
113
+ # return value. Must be one of { +:string+, +:string_array+, or
114
+ # +:xml+ }. Defaults to +:string+
115
+ # @option +:request+ NO LONGER SUPPORTED
116
+ # @option +:request_name+ (String, Symbol) The name of the request, e.g.
117
+ # "selectPortfolios"
118
+ # @option +:response_mode+ (String, Symbol) The response mode, e.g.
119
+ # "binary", "xml"
120
+ # @option +:body+ (::Nokogiri::XML::Element, ::String, nil) Optional
121
+ # request body. If +nil+ no <body/> element is specified. If empty an
122
+ # empty <body/> element is specified. Otherwise, the given content is
123
+ # placed within a <body> element
124
+ # @option +:body_attributes+ (Hash, nil) Optional request body
125
+ # attributes. If specified, then a <body> element will always be
126
+ # created. Current version ignores this value if +:body+ option is an
127
+ # instance of +::Nokogiri::XML::Element+
128
+ # @option +:caller+ (String, Symbol, nil) The value for the "caller"
129
+ # element in the request document node atributes
130
+ # @option +:server+ (String, Symbol, nil) The value for the "server"
131
+ # element in the request document node atributes
132
+ # @option +:no_caller_name+ (boolean) Prevents the default value for
133
+ # *callerName* from being included
134
+ # @option +:no_caller_pid+ (boolean) Prevents the default value for
135
+ # *callerPid* from being included
136
+ # @option +:no_caller_thread+ (boolean) Prevents the default value for
137
+ # *callerThread* from being included
138
+ # @option +:no_caller_version+ (boolean) Prevents the default value for
139
+ # *callerVersion* from being included
140
+ # @option +:no_replicate+ (boolean) Prevents the default value for
141
+ # *replicate* from being included
142
+ #
143
+ # @return (String, Array[String, String], Nokogiri::XML::Node) The
144
+ # inbound header, which will be a string, a pair of strings (in an
145
+ # array), or an XML node
146
+ def self.prepare_inbound_header environment, isdodiffallow = true, **options
147
+
148
+ trace ParamNames[ :environment, :isdodiffallow, :options ], environment, isdodiffallow, options
149
+
150
+ raise ArgumentError, "option :request is no longer supported; use :request_name instead" if options.has_key? :request
151
+
152
+ unrecognised = options.keys.find { |k| !HeaderMaker_Constants::AcceptedOptions.include?(k) } and raise ArgumentError, "option #{::Symbol === unrecognised ? ':' : ''}#{unrecognised} is not recognised"
153
+
154
+ request_name = check_option options, :request_name, types: [ ::Symbol, ::String ], reject_empty: true
155
+
156
+ request_type = check_option options, :request_type, types: [ ::Symbol, ::String ], values: HeaderMaker_Constants::RequestTypes, reject_empty: true
157
+
158
+ response_mode = check_option options, :response_mode, types: [ ::Symbol, ::String ], reject_empty: true
159
+
160
+ return_type = check_option options, :return_type, types: [ ::String, ::Symbol ], values: [ :string, :string_array, :xml ] || :string
161
+
162
+ body = check_option options, :body, types: [ ::Nokogiri::XML::Element, ::String ], allow_nil: true, reject_empty: false
163
+ body_attributes = check_option options, :body_attributes, type: ::Hash, allow_nil: true
164
+ caller_name = check_option options, :caller, types: [ ::Symbol, ::String ], allow_nil: true, reject_empty: true
165
+
166
+ body ||= '' if body_attributes
167
+
168
+ server = check_option options, :server, types: [ ::Symbol, ::String ], allow_nil: true, reject_empty: true
169
+ server ||= ''
170
+ user_id = check_option options, :user_id, types: [ ::String ], allow_nil: true, reject_empty: true
171
+
172
+ attributes = HeaderMaker_Constants.DefaultAttributes(**options)
173
+
174
+ attributes[:environment] = environment
175
+ attributes[:request] = request_name
176
+ attributes[:responseMode] = response_mode
177
+ attributes[:caller] = caller_name if caller_name
178
+ attributes[:server] = server if server
179
+ attributes[:userId] = user_id if user_id
180
+ attributes[:doDiffs] = isdodiffallow
181
+
182
+ attributes = Hash[attributes.sort_by { |k, v| k }]
183
+
184
+ attributes = attributes.map do |name, value|
185
+
186
+ %Q< #{name}="#{value}">
187
+ end.join "\n"
188
+
189
+ case return_type
190
+ when :string, :xml
191
+
192
+ r = []
193
+
194
+ r << <<END_OF_first
195
+ <?xml version="1.0" encoding="utf-8"?>
196
+ <#{request_type}
197
+ #{attributes}
198
+ END_OF_first
199
+
200
+ case body
201
+ when ::Nokogiri::XML::Element
202
+
203
+ r << <<END_OF_last
204
+ >
205
+ END_OF_last
206
+
207
+ r << body.to_xml
208
+
209
+ r << <<END_OF_last
210
+ </#{request_type}>
211
+ END_OF_last
212
+ when ::String
213
+
214
+ b_a = body_attributes ? body_attributes.map { |n, v| %Q< #{n}="#{v}"> }.join('') : ''
215
+
216
+ if body.empty?
217
+
218
+ r << <<END_OF_last
219
+ >
220
+ <body#{b_a} />
221
+ </#{request_type}>
222
+ END_OF_last
223
+ else
224
+ r << <<END_OF_last
225
+ >
226
+ <body#{b_a}>
227
+ #{body}
228
+ </body>
229
+ </#{request_type}>
230
+ END_OF_last
231
+ end
232
+ else
233
+
234
+ r << <<END_OF_last
235
+ />
236
+ END_OF_last
237
+ end
238
+
239
+ r = r.join "\n"
240
+
241
+ r = ::Nokogiri.XML(r) if return_type == :xml
242
+
243
+ r
244
+ when :string_array
245
+
246
+ r = []
247
+
248
+ r << <<END_OF_first
249
+ <?xml version="1.0" encoding="utf-8"?>
250
+ <#{request_type}
251
+ #{attributes}>
252
+ END_OF_first
253
+
254
+ r << body if body
255
+
256
+ r << <<END_OF_last
257
+ </#{request_type}
258
+ END_OF_last
259
+
260
+ r
261
+ end
262
+
263
+ end
264
+ end # class HeaderMaker
265
+
266
+ end # module Razor3
267
+ end # module Connectivity
268
+ end # module Razor
269
+ end # module RazorRisk
270
+
271
+ # ############################## end of file ############################# #
272
+
273
+
@@ -0,0 +1,156 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/razor/connectivity/razor_3/message_map.rb
5
+ #
6
+ # Purpose: MessageMap class
7
+ #
8
+ # Created: 2nd January 2018
9
+ # Updated: 15th January 2019
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+
19
+ # ######################################################################## #
20
+ # requires
21
+
22
+ require 'pantheios'
23
+ require 'recls'
24
+ require 'xqsr3/quality/parameter_checking'
25
+
26
+ =begin
27
+ =end
28
+
29
+ module RazorRisk
30
+ module Razor
31
+ module Connectivity
32
+ module Razor3
33
+
34
+ # Class that provides the corresponding server instance for a Razor (3)
35
+ # message
36
+ #
37
+ # The class supports configuration-based operation, by initialising an
38
+ # instance from a mapping object, and fixed (hard-coded) mapping using the
39
+ # DefaultInstance constant
40
+ class MessageMap
41
+
42
+ include ::Pantheios
43
+ include ::Xqsr3::Quality::ParameterChecking
44
+
45
+ module MessageMap_Constants
46
+
47
+ CreditRiskServer = 'CreditRiskServer'
48
+ DataServer = 'DataServer'
49
+ PortfolioExposureServer = 'PortfolioExposureServer'
50
+ SessionManager = 'SessionManager'
51
+ SnapshotServer = 'SnapshotServer'
52
+
53
+ DefaultMappings_Reverse = {
54
+
55
+ CreditRiskServer => %w{
56
+
57
+ selectTrades
58
+
59
+ statusEnquiry
60
+
61
+ tradeContributionEnquiry
62
+
63
+ processIntraday
64
+ batchSummaries
65
+ razorLog
66
+ },
67
+
68
+ DataServer => %w{
69
+
70
+ select
71
+ writeCapabilityStructure
72
+ writeUserProfiles
73
+ },
74
+
75
+ PortfolioExposureServer => %w{
76
+
77
+ selectNettingAgreements
78
+
79
+ deletePortfolio
80
+ insertPortfolios
81
+ selectPortfolios
82
+ updatePortfolio
83
+
84
+ lookupRiskPointRecord
85
+ selectRiskPointTree
86
+ updateRiskPointStructure
87
+ selectRiskPointRecordRequest
88
+ selectRiskPointStructure
89
+ },
90
+
91
+ SessionManager => %w{
92
+
93
+ closeSession
94
+ getSession
95
+ openSession
96
+
97
+ refreshUserProfile
98
+ },
99
+
100
+ SnapshotServer => %w{
101
+ snapshotProgressRequest
102
+ },
103
+ }
104
+ end
105
+
106
+ # Initialises an instance from given +mappings+
107
+ #
108
+ # @param mappings [::Hash]
109
+ # @param options [::Hash]
110
+ #
111
+ def initialize mappings, **options
112
+
113
+ trace ParamNames[ :mappings, :options ], mappings, options unless options[:no_trace]
114
+
115
+ check_parameter mappings, 'mappings', type: ::Hash, allow_nil: true
116
+
117
+ unless mappings
118
+
119
+ mappings = {}
120
+
121
+ MessageMap_Constants::DefaultMappings_Reverse.each do |server_name, message_list|
122
+
123
+ message_list.each do |message|
124
+
125
+ message_name = message.to_s.strip.downcase
126
+
127
+ mappings[message_name] = server_name
128
+ end
129
+ end
130
+ end
131
+
132
+ @mappings = mappings
133
+ end
134
+
135
+ DefaultInstance = self.new nil, no_trace: true
136
+
137
+ def lookup_server request_name, **options
138
+
139
+ trace ParamNames[ :request_name, :options ], request_name, options
140
+
141
+ check_parameter request_name, 'request_name', types: [ ::String, ::Symbol ], reject_empty: true
142
+
143
+ request_name = request_name.to_s.strip.downcase
144
+
145
+ return @mappings[request_name]
146
+ end
147
+ end # class MessageMap
148
+
149
+ end # module Razor3
150
+ end # module Connectivity
151
+ end # module Razor
152
+ end # module RazorRisk
153
+
154
+ # ############################## end of file ############################# #
155
+
156
+