restful-riskview 0.0.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.
- checksums.yaml +7 -0
- data/bin/razorrisk-microservice-riskview +45 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/risk_view/app.rb +242 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/risk_view/version.rb +50 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/risk_view.rb +19 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/risk_view/item_get.rb +349 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/risk_view.rb +18 -0
- metadata +248 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ef860dbae91c2be20b03d673ff39e4eda794926
|
4
|
+
data.tar.gz: 9dd6335e15d2d1be03518fd5f01d00eaa360240e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2668646615d323f027c6a3d9d1578ddeed2f24191dc2ba3fffbc77b98be120167fe28c86513ab865b297da8fb6ebff7db75fed372ed7ca7934770252a0d794c8
|
7
|
+
data.tar.gz: 5a85feef719778bee488c9ee2b7dc8079ecbb01bcc09b0f2dbd507b225e1c6c08c4d9ae02541b651a0d96bf24ec4d9e05c063704e79aeebc8e0b51d5ea6bd7c1
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# ######################################################################## #
|
5
|
+
#
|
6
|
+
# Main module/entry file for the RiskView Microservice
|
7
|
+
#
|
8
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
9
|
+
#
|
10
|
+
# ######################################################################## #
|
11
|
+
|
12
|
+
|
13
|
+
# ##########################################################################
|
14
|
+
# requires
|
15
|
+
|
16
|
+
require 'razor_risk/cassini/diagnostics/zeroth_include'
|
17
|
+
|
18
|
+
require 'razor_risk/cassini/applications/microservices/restful/risk_view'
|
19
|
+
require 'razor_risk/cassini/main'
|
20
|
+
|
21
|
+
# TODO: This needs to be added to cassini/main
|
22
|
+
require 'razor_risk/cassini/common/version'
|
23
|
+
|
24
|
+
|
25
|
+
# ##########################################################################
|
26
|
+
# includes
|
27
|
+
|
28
|
+
include ::RazorRisk::Cassini::Applications::Microservices::RESTful
|
29
|
+
|
30
|
+
|
31
|
+
# ##########################################################################
|
32
|
+
# constants
|
33
|
+
|
34
|
+
PROGRAM_VERSION = RiskView::VERSION
|
35
|
+
|
36
|
+
|
37
|
+
# ##########################################################################
|
38
|
+
# main section
|
39
|
+
|
40
|
+
TheApp = RiskView::RiskViewApp
|
41
|
+
|
42
|
+
|
43
|
+
# ############################## end of file ############################# #
|
44
|
+
|
45
|
+
|
@@ -0,0 +1,242 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# ######################################################################## #
|
5
|
+
#
|
6
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
7
|
+
#
|
8
|
+
# ######################################################################## #
|
9
|
+
|
10
|
+
|
11
|
+
# ##########################################################################
|
12
|
+
# requires
|
13
|
+
|
14
|
+
require 'razor_risk/cassini/applications/rest_framework/route_verb_dispatcher'
|
15
|
+
require 'razor_risk/cassini/applications/route_verb_adaptors/risk_view'
|
16
|
+
require 'razor_risk/cassini/applications/secured_microservice'
|
17
|
+
require 'razor_risk/cassini/mixin/razor_response_validator'
|
18
|
+
|
19
|
+
require 'pantheios'
|
20
|
+
|
21
|
+
require 'csv'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
|
25
|
+
# ##########################################################################
|
26
|
+
# modules
|
27
|
+
|
28
|
+
module RazorRisk
|
29
|
+
module Cassini
|
30
|
+
module Applications
|
31
|
+
module Microservices
|
32
|
+
module RESTful
|
33
|
+
module RiskView
|
34
|
+
|
35
|
+
|
36
|
+
# ##########################################################################
|
37
|
+
# includes
|
38
|
+
|
39
|
+
include ::RazorRisk::Cassini::Applications
|
40
|
+
|
41
|
+
|
42
|
+
# ##########################################################################
|
43
|
+
# application
|
44
|
+
|
45
|
+
# Sinatra Application for the Risk-View Microservice.
|
46
|
+
class RiskViewApp < SecuredMicroservice
|
47
|
+
|
48
|
+
include RouteVerbAdaptors::RiskView
|
49
|
+
include RESTFramework::RouteVerbDispatch
|
50
|
+
include Cassini::Mixin::RazorResponseValidator
|
51
|
+
|
52
|
+
include ::Pantheios
|
53
|
+
|
54
|
+
FULL_DESIGNATION = 'RiskView'
|
55
|
+
SHORT_DESIGNATION = 'risk_view'
|
56
|
+
SERVICE_TYPE = :microservice
|
57
|
+
PROGRAM_FEATURES = {
|
58
|
+
has_web_server: true,
|
59
|
+
has_host_and_port: true,
|
60
|
+
has_razor_connectivity: true,
|
61
|
+
authentication: true,
|
62
|
+
copyright_year: 2019,
|
63
|
+
}
|
64
|
+
SUPPORTED_ROUTES = [
|
65
|
+
[ '/:domain/:id', :get, 'gets the specified risk-view', ],
|
66
|
+
]
|
67
|
+
HTTP_ACCEPTS = %w{
|
68
|
+
text/html
|
69
|
+
application/json
|
70
|
+
application/xml
|
71
|
+
text/xml
|
72
|
+
text/csv
|
73
|
+
text/plain
|
74
|
+
text/tab-separated-values
|
75
|
+
text/tsv
|
76
|
+
}
|
77
|
+
|
78
|
+
def self.on_init_service options
|
79
|
+
|
80
|
+
trace ParamNames[ :options ], options
|
81
|
+
|
82
|
+
raise ArgumentError.new(
|
83
|
+
'missing keyword: razor_requester'
|
84
|
+
) unless options.has_key? :razor_requester
|
85
|
+
|
86
|
+
request_options = options[:request_options]
|
87
|
+
|
88
|
+
set :razor_requester, options[:razor_requester]
|
89
|
+
set :request_options, request_options
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def sec
|
94
|
+
|
95
|
+
return '' if credentials.empty?
|
96
|
+
" (for #{credentials.join(':')})"
|
97
|
+
end
|
98
|
+
public
|
99
|
+
|
100
|
+
get '/:domain/:id/?' do
|
101
|
+
|
102
|
+
trace ParamNames[ :request, :params ], request, params
|
103
|
+
|
104
|
+
dispatch ItemGet
|
105
|
+
end
|
106
|
+
|
107
|
+
get '/' do
|
108
|
+
|
109
|
+
HTTP_ACCEPTS.each do |accept_type|
|
110
|
+
|
111
|
+
if request.accept? accept_type
|
112
|
+
|
113
|
+
content_type accept_type
|
114
|
+
|
115
|
+
case accept_type
|
116
|
+
when 'application/json'
|
117
|
+
r = make_JSON_routes SUPPORTED_ROUTES
|
118
|
+
when 'application/xml', 'text/xml'
|
119
|
+
r = make_XML_routes SUPPORTED_ROUTES
|
120
|
+
when 'text/csv'
|
121
|
+
r = make_CSV_routes SUPPORTED_ROUTES
|
122
|
+
when 'text/html'
|
123
|
+
r = make_HTML_routes SUPPORTED_ROUTES
|
124
|
+
when 'text/plain'
|
125
|
+
r = make_Plain_routes SUPPORTED_ROUTES
|
126
|
+
when 'text/tsv', 'text/tab-separated-values'
|
127
|
+
r = make_TSV_routes SUPPORTED_ROUTES
|
128
|
+
else
|
129
|
+
log :violation, "unrecognised accept type '#{accept_type}'"
|
130
|
+
halt(
|
131
|
+
500,
|
132
|
+
{},
|
133
|
+
'internal server failure'
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
return r
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
halt(
|
142
|
+
406,
|
143
|
+
{},
|
144
|
+
"supports only the Accept types #{HTTP_ACCEPTS.map do |t|
|
145
|
+
%Q<'#{t}'>
|
146
|
+
end.join(', ')}"
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
define_catch_all_handlers
|
151
|
+
|
152
|
+
|
153
|
+
# ##########################################################
|
154
|
+
# routes helpers
|
155
|
+
|
156
|
+
# These methods provide a list of supported routes for this microservice.
|
157
|
+
# However, when running the WebAPI through the CES these cannot be reached. They
|
158
|
+
# are still included here as legacy code and likely should be removed in the
|
159
|
+
# future.
|
160
|
+
|
161
|
+
def make_CSV_routes routes
|
162
|
+
CSV.generate do |csv|
|
163
|
+
routes.each do |ar|
|
164
|
+
csv << ar
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def make_HTML_routes routes, **options
|
170
|
+
routes = routes.map do |ar|
|
171
|
+
<<END_OF_tr
|
172
|
+
<tr>
|
173
|
+
<td>#{ar[0]}</td>
|
174
|
+
<td>#{ar[1]}</td>
|
175
|
+
<td>#{ar[2]}</td>
|
176
|
+
</tr>
|
177
|
+
END_OF_tr
|
178
|
+
end
|
179
|
+
|
180
|
+
<<END_OF_html
|
181
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.we.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
182
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
183
|
+
<head>
|
184
|
+
<title>Razor Risk Web Service API - Internal Microservice - Capabilities</title>
|
185
|
+
<meta name="revisit-after" content="24 hours" />
|
186
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
187
|
+
</head>
|
188
|
+
<body>
|
189
|
+
<h1>Routes</h1>
|
190
|
+
<table>
|
191
|
+
<tr>
|
192
|
+
<th>Route</th>
|
193
|
+
<th>Verb</th>
|
194
|
+
<th>Description</th>
|
195
|
+
</tr>
|
196
|
+
#{routes.map { |r| r.chomp("\n") }.join("\n")}
|
197
|
+
</table>
|
198
|
+
</body>
|
199
|
+
</html>
|
200
|
+
END_OF_html
|
201
|
+
end
|
202
|
+
|
203
|
+
def make_JSON_routes routes, **options
|
204
|
+
r = {
|
205
|
+
'routes' => []
|
206
|
+
}
|
207
|
+
r['routes'] = SUPPORTED_ROUTES.map { |ar| { route: ar[0], verb: ar[1].to_s.upcase, description: ar[2] } }
|
208
|
+
r.to_json
|
209
|
+
end
|
210
|
+
|
211
|
+
def make_Plain_routes routes
|
212
|
+
make_TSV_routes routes
|
213
|
+
end
|
214
|
+
|
215
|
+
def make_TSV_routes routes
|
216
|
+
routes.map { |ar| "#{ar[0]}\t#{ar[1]}\t#{ar[2]}\n" }
|
217
|
+
end
|
218
|
+
|
219
|
+
def make_XML_routes routes
|
220
|
+
<<END_OF_xml
|
221
|
+
<?xml version="1.0">
|
222
|
+
<routes>#{routes.map { |ar| %Q{ <route route="#{ar[0]}" verb="#{ar[1].to_s.upcase}" description="#{ar[2]}"/>}}.join(%Q{\n})}
|
223
|
+
</routes>
|
224
|
+
END_OF_xml
|
225
|
+
end
|
226
|
+
|
227
|
+
end # class App
|
228
|
+
|
229
|
+
|
230
|
+
# ##########################################################################
|
231
|
+
# modules
|
232
|
+
|
233
|
+
end # module RiskView
|
234
|
+
end # module RESTful
|
235
|
+
end # module Microservices
|
236
|
+
end # module Applications
|
237
|
+
end # module Cassini
|
238
|
+
end # module RazorRisk
|
239
|
+
|
240
|
+
# ############################## end of file ############################# #
|
241
|
+
|
242
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Version for RazorRisk.Cassini.Microservices.RESTful.RiskView library
|
6
|
+
#
|
7
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
8
|
+
#
|
9
|
+
# ######################################################################## #
|
10
|
+
|
11
|
+
module RazorRisk
|
12
|
+
module Cassini
|
13
|
+
module Applications
|
14
|
+
module Microservices
|
15
|
+
module RESTful
|
16
|
+
|
17
|
+
module RiskView
|
18
|
+
|
19
|
+
# Current version of the RazorRisk.Cassini.Microservices.RESTful.RiskView library
|
20
|
+
VERSION = '0.0.4'
|
21
|
+
|
22
|
+
private
|
23
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
24
|
+
public
|
25
|
+
# Major version of the RazorRisk.Cassini.Microservices.RESTful.RiskView library
|
26
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
27
|
+
# Minor version of the RazorRisk.Cassini.Microservices.RESTful.RiskView library
|
28
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
29
|
+
# Patch version of the RazorRisk.Cassini.Microservices.RESTful.RiskView library
|
30
|
+
VERSION_PATCH = VERSION_PARTS_[2] # :nodoc:
|
31
|
+
# Commit version of the RazorRisk.Cassini.Microservices.RESTful.RiskView library
|
32
|
+
VERSION_COMMIT = VERSION_PARTS_[3] || 0 # :nodoc:
|
33
|
+
|
34
|
+
|
35
|
+
# The description of the framework
|
36
|
+
DESCRIPTION = "Razor Risk's Cassini Web-framework's RiskView RESTful microservice"
|
37
|
+
|
38
|
+
# [DEPRECATED] Instead use +DESCRIPTION+
|
39
|
+
FRAMEWORK_DESCRIPTION = DESCRIPTION
|
40
|
+
end # module RiskView
|
41
|
+
|
42
|
+
end # module RESTful
|
43
|
+
end # module Microservices
|
44
|
+
end # module Applications
|
45
|
+
end # module Cassini
|
46
|
+
end # module RazorRisk
|
47
|
+
|
48
|
+
# ############################## end of file ############################# #
|
49
|
+
|
50
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# ##########################################################################
|
4
|
+
#
|
5
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
6
|
+
#
|
7
|
+
# ##########################################################################
|
8
|
+
|
9
|
+
|
10
|
+
# ##########################################################
|
11
|
+
# requires
|
12
|
+
|
13
|
+
require 'razor_risk/cassini/applications/microservices/restful/risk_view/version'
|
14
|
+
require 'razor_risk/cassini/applications/microservices/restful/risk_view/app'
|
15
|
+
|
16
|
+
|
17
|
+
# ############################## end of file ############################# #
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,349 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Adaptor for RiskView microservice's hierarchy GET verb
|
6
|
+
#
|
7
|
+
# Copyright (c) 2018 Razor Risk Technologies Pty Limited. All rights reserved.
|
8
|
+
#
|
9
|
+
# ######################################################################## #
|
10
|
+
|
11
|
+
|
12
|
+
# ##########################################################################
|
13
|
+
# requires
|
14
|
+
|
15
|
+
require 'razor_risk/cassini/applications/rest_framework/verb_handler'
|
16
|
+
require 'razor_risk/cassini/mixin/razor_response_validator'
|
17
|
+
require 'razor_risk/cassini/util/conversion_util'
|
18
|
+
|
19
|
+
require 'razor_risk/razor/connectivity/razor_3/razor_requester'
|
20
|
+
require 'razor_risk/razor/connectivity/razor_3/entity_connectors/portfolios_connector'
|
21
|
+
|
22
|
+
require 'pantheios'
|
23
|
+
require 'xqsr3/conversion/integer_parser'
|
24
|
+
|
25
|
+
|
26
|
+
# ##########################################################################
|
27
|
+
# module
|
28
|
+
|
29
|
+
module RazorRisk
|
30
|
+
module Cassini
|
31
|
+
module Applications
|
32
|
+
module RouteVerbAdaptors
|
33
|
+
module RiskView
|
34
|
+
|
35
|
+
|
36
|
+
# ##########################################################################
|
37
|
+
# classes
|
38
|
+
|
39
|
+
class ItemGet < RESTFramework::VerbHandler
|
40
|
+
|
41
|
+
# ##########################################################
|
42
|
+
# includes
|
43
|
+
|
44
|
+
include Cassini::Mixin::RazorResponseValidator
|
45
|
+
include Cassini::Util::ConversionUtil
|
46
|
+
|
47
|
+
include Razor::Connectivity::EntityConnectors::Exceptions
|
48
|
+
include Razor::Connectivity::Razor3
|
49
|
+
include Razor::Connectivity::Razor3::EntityConnectors
|
50
|
+
|
51
|
+
include ::Pantheios
|
52
|
+
|
53
|
+
|
54
|
+
# ##########################################################
|
55
|
+
# Constants
|
56
|
+
|
57
|
+
private
|
58
|
+
module Constants
|
59
|
+
|
60
|
+
VALID_DOMAINS = [ 'Counterparty', 'Country', 'GroupCounterparty' ]
|
61
|
+
|
62
|
+
FieldXpathFormatString = 'fields/field[@id="%s"]'
|
63
|
+
|
64
|
+
RPD_YES = 'YES'
|
65
|
+
RPD_NO = 'NO'
|
66
|
+
end
|
67
|
+
|
68
|
+
public
|
69
|
+
HTTP_VERB = :get
|
70
|
+
HTTP_ACCEPTS = [
|
71
|
+
'application/xml',
|
72
|
+
'application/json',
|
73
|
+
'text/xml',
|
74
|
+
]
|
75
|
+
QUERY_PARAMETERS = [
|
76
|
+
'page-base',
|
77
|
+
'page-extent',
|
78
|
+
'group',
|
79
|
+
]
|
80
|
+
ROUTE_VARIABLES = [
|
81
|
+
'domain',
|
82
|
+
'id',
|
83
|
+
]
|
84
|
+
|
85
|
+
def initialize *args, **options
|
86
|
+
|
87
|
+
@ptf_connector_class = options[:ptf_connector_class] || PortfoliosConnector
|
88
|
+
@rpd_connector_class = options[:rpd_connector_class] || RiskPointData::DomainsConnector
|
89
|
+
super
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
# Finds the ID of the group leader.
|
94
|
+
#
|
95
|
+
# @param id [String] the ID of the counterpary
|
96
|
+
#
|
97
|
+
# @return [String] the ID of the group leader if one is found
|
98
|
+
# @return [nil] if the group leader is not found
|
99
|
+
def find_group_leader_ id
|
100
|
+
|
101
|
+
domain = 'GroupLimitRelations'
|
102
|
+
cr = get_required_credentials
|
103
|
+
rr = settings.razor_requester
|
104
|
+
ec = @rpd_connector_class.new(rr, credentials: cr)
|
105
|
+
qr = ec.get_records domain, indicate_result_by: :qualified_result
|
106
|
+
|
107
|
+
validate_qualified_razor_response qr
|
108
|
+
|
109
|
+
unless qr.succeeded?
|
110
|
+
log :warning, 'Failed to get GroupLimitRelations'
|
111
|
+
error(
|
112
|
+
HTTP_STATUS_NAMES::INTERNAL_SERVER_ERROR,
|
113
|
+
'Oop! Something went wrong!'
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
qr.result.xpath('//record').each do |r|
|
118
|
+
parent = r.at_xpath(
|
119
|
+
Constants::FieldXpathFormatString % 'GLParentCounterparty'
|
120
|
+
).text
|
121
|
+
child = r.at_xpath(
|
122
|
+
Constants::FieldXpathFormatString % 'ChildCpty'
|
123
|
+
).text
|
124
|
+
type = r.at_xpath(
|
125
|
+
Constants::FieldXpathFormatString % 'GroupLimitType'
|
126
|
+
).text
|
127
|
+
|
128
|
+
if 'STANDARD' == type and [ parent, child ].include?(id)
|
129
|
+
return parent
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
nil
|
134
|
+
end
|
135
|
+
|
136
|
+
def get_limit_types_
|
137
|
+
|
138
|
+
domain = 'LimitType'
|
139
|
+
cr = get_required_credentials
|
140
|
+
rr = settings.razor_requester
|
141
|
+
ec = @rpd_connector_class.new(rr, credentials: cr)
|
142
|
+
qr = ec.get_records domain, indicate_result_by: :qualified_result
|
143
|
+
|
144
|
+
validate_qualified_razor_response qr
|
145
|
+
|
146
|
+
unless qr.succeeded?
|
147
|
+
log :warning, 'Failed to get LimitType'
|
148
|
+
error(
|
149
|
+
HTTP_STATUS_NAMES::INTERNAL_SERVER_ERROR,
|
150
|
+
'Oops! Something went wrong!'
|
151
|
+
)
|
152
|
+
end
|
153
|
+
|
154
|
+
records = qr.result.xpath('//record')
|
155
|
+
|
156
|
+
limit_types = {
|
157
|
+
counterparty: [],
|
158
|
+
country: [],
|
159
|
+
counterparty_group: [],
|
160
|
+
}
|
161
|
+
|
162
|
+
records.each do |record|
|
163
|
+
id = record.at_xpath('@id').value
|
164
|
+
counterparty = Constants::RPD_YES == record.at_xpath(
|
165
|
+
Constants::FieldXpathFormatString % 'IsCounterpartyRelevant'
|
166
|
+
)&.text
|
167
|
+
country = Constants::RPD_YES == record.at_xpath(
|
168
|
+
Constants::FieldXpathFormatString % 'IsCountryRelevant'
|
169
|
+
)&.text
|
170
|
+
group = Constants::RPD_YES == record.at_xpath(
|
171
|
+
Constants::FieldXpathFormatString % 'IsGroupLimitRelevant'
|
172
|
+
)&.text
|
173
|
+
|
174
|
+
if counterparty
|
175
|
+
if group
|
176
|
+
limit_types[:counterparty_group] << id
|
177
|
+
else
|
178
|
+
limit_types[:counterparty] << id
|
179
|
+
end
|
180
|
+
elsif country
|
181
|
+
limit_types[:country] << id
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
limit_types
|
186
|
+
end
|
187
|
+
public
|
188
|
+
|
189
|
+
|
190
|
+
# ##########################################################
|
191
|
+
# Handler
|
192
|
+
|
193
|
+
def handle env, params, request, response
|
194
|
+
|
195
|
+
trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
|
196
|
+
|
197
|
+
domain = check_option(
|
198
|
+
params,
|
199
|
+
'domain',
|
200
|
+
strip_str_whitespace: true,
|
201
|
+
values: Constants::VALID_DOMAINS,
|
202
|
+
nothrow: true,
|
203
|
+
) || error(HTTP_STATUS_NAMES::UNPROCESSABLE_ENTITY, 'Invalid domain')
|
204
|
+
|
205
|
+
id = check_option(
|
206
|
+
params,
|
207
|
+
'id',
|
208
|
+
strip_str_whitespace: true,
|
209
|
+
reject_empty: true,
|
210
|
+
nothrow: true,
|
211
|
+
) || error(HTTP_STATUS_NAMES::UNPROCESSABLE_ENTITY, 'Invalid ID')
|
212
|
+
|
213
|
+
page_base = ::Xqsr3::Conversion::IntegerParser.to_integer(
|
214
|
+
params['page-base'] || 0
|
215
|
+
) do |x, arg|
|
216
|
+
error(
|
217
|
+
HTTP_STATUS_NAMES::UNPROCESSABLE_ENTITY,
|
218
|
+
"invalid page specifier: 'page-base'=#{arg}"
|
219
|
+
)
|
220
|
+
end
|
221
|
+
page_extent = ::Xqsr3::Conversion::IntegerParser.to_integer(
|
222
|
+
params['page-extent'] || 1000
|
223
|
+
) do |x, arg|
|
224
|
+
error(
|
225
|
+
HTTP_STATUS_NAMES::UNPROCESSABLE_ENTITY,
|
226
|
+
"invalid page specifier: 'page-extent'=#{arg}"
|
227
|
+
)
|
228
|
+
end
|
229
|
+
|
230
|
+
if page_base < 0 || page_extent < 1
|
231
|
+
error(
|
232
|
+
HTTP_STATUS_NAMES::RANGE_NOT_SATISFIABLE,
|
233
|
+
"invalid page specifier: 'page-base'=#{page_base}; 'page-extent'=#{page_extent}"
|
234
|
+
)
|
235
|
+
end
|
236
|
+
|
237
|
+
group = 0 == (
|
238
|
+
/^t(rue)?$/i =~ check_option(
|
239
|
+
params,
|
240
|
+
'group',
|
241
|
+
strip_str_whitespace: true,
|
242
|
+
reject_empty: true,
|
243
|
+
nothrow: true,
|
244
|
+
)
|
245
|
+
)
|
246
|
+
|
247
|
+
if group
|
248
|
+
leader_id = find_group_leader_(id)
|
249
|
+
if leader_id
|
250
|
+
id = leader_id
|
251
|
+
else
|
252
|
+
log :debug1, "Counterpary #{id} is not part of a group"
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
limit_types = get_limit_types_
|
257
|
+
|
258
|
+
# Handle Globals
|
259
|
+
risk_view = { domain => id }
|
260
|
+
if 'Counterparty' == domain
|
261
|
+
if group
|
262
|
+
risk_view['LimitType'] = limit_types[:counterparty_group]
|
263
|
+
else
|
264
|
+
risk_view['LimitType'] = limit_types[:counterparty]
|
265
|
+
end
|
266
|
+
elsif 'Country' == domain
|
267
|
+
risk_view['LimitType'] = limit_types[:country]
|
268
|
+
end
|
269
|
+
|
270
|
+
rq_opts = {
|
271
|
+
:page_base => page_base,
|
272
|
+
:page_extent => page_extent,
|
273
|
+
:risk_view => risk_view,
|
274
|
+
:is_group => group,
|
275
|
+
}
|
276
|
+
|
277
|
+
cr = get_required_credentials
|
278
|
+
rr = settings.razor_requester
|
279
|
+
ec = @ptf_connector_class.new(rr, credentials: cr, **rq_opts)
|
280
|
+
|
281
|
+
# TODO: allow these exceptions to be handled by the frame work. This
|
282
|
+
# will require significant change to the unit tests.
|
283
|
+
begin
|
284
|
+
qr = ec.get_hierarchy indicate_result_by: :qualified_result
|
285
|
+
rescue ::ArgumentError, ::NameError, ::NoMethodError, ::TypeError => x
|
286
|
+
log(:violation) { "(#{x.class}): #{x.message}" }
|
287
|
+
raise
|
288
|
+
rescue RazorRequester::InvalidCredentialsException => x
|
289
|
+
log(:failure) { "exception (#{x.class}): #{x}" }
|
290
|
+
error HTTP_STATUS_NAMES::UNAUTHORIZED, 'Invalid credentials'
|
291
|
+
rescue DataNotFoundException => x
|
292
|
+
log(:failure) { "exception (#{x.class}): #{x}" }
|
293
|
+
error HTTP_STATUS_NAMES::NOT_FOUND, x.message
|
294
|
+
rescue => x
|
295
|
+
log(:failure) { "exception (#{x.class}): #{x}" }
|
296
|
+
error HTTP_STATUS_NAMES::INTERNAL_SERVER_ERROR, x.message
|
297
|
+
end
|
298
|
+
|
299
|
+
log :debug1, "qr(#{qr.class})='#{qr}'"
|
300
|
+
|
301
|
+
validate_qualified_razor_response qr
|
302
|
+
|
303
|
+
unless qr.succeeded?
|
304
|
+
log :warning, "Failed to retrieve risk-view for '#{id}' for an unkown reason."
|
305
|
+
error(
|
306
|
+
HTTP_STATUS_NAMES::INTERNAL_SERVER_ERROR,
|
307
|
+
'Oops! Something went wrong!'
|
308
|
+
)
|
309
|
+
end
|
310
|
+
|
311
|
+
r = qr.result.to_s
|
312
|
+
|
313
|
+
status HTTP_STATUS_NAMES::OK
|
314
|
+
|
315
|
+
if request.accept?('application/xml')
|
316
|
+
log :debug1, 'application/xml'
|
317
|
+
content_type 'application/xml'
|
318
|
+
r
|
319
|
+
elsif request.accept?('text/xml')
|
320
|
+
log :debug1, 'text/xml'
|
321
|
+
content_type 'text/xml'
|
322
|
+
r
|
323
|
+
elsif request.accept?('application/json')
|
324
|
+
log :debug1, 'application/json'
|
325
|
+
content_type 'application/json'
|
326
|
+
convert_XML_to_JSON r, { scheme: :gdata }
|
327
|
+
else
|
328
|
+
log :violation, "unexpected failure to match given 'Accept' header '#{request.accept}'"
|
329
|
+
error(
|
330
|
+
HTTP_STATUS_NAMES::INTERNAL_SERVER_ERROR,
|
331
|
+
'Oops! Something went wrong!'
|
332
|
+
)
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end # class ItemGet
|
336
|
+
|
337
|
+
|
338
|
+
# ##########################################################################
|
339
|
+
# module
|
340
|
+
|
341
|
+
end # module RiskView
|
342
|
+
end # module RouteVerbAdaptors
|
343
|
+
end # module Applications
|
344
|
+
end # module Cassini
|
345
|
+
end # module RazorRisk
|
346
|
+
|
347
|
+
# ############################## end of file ############################# #
|
348
|
+
|
349
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# ##########################################################################
|
4
|
+
#
|
5
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
6
|
+
#
|
7
|
+
# ##########################################################################
|
8
|
+
|
9
|
+
|
10
|
+
# ##########################################################
|
11
|
+
# requires
|
12
|
+
|
13
|
+
require 'razor_risk/cassini/applications/route_verb_adaptors/risk_view/item_get'
|
14
|
+
|
15
|
+
|
16
|
+
# ############################## end of file ############################# #
|
17
|
+
|
18
|
+
|
metadata
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: restful-riskview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Razor Risk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: razorrisk-cassini-common
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.26.24
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.26.24
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: razorrisk-razor-connectivity
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.11.2
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.11.2
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: razorrisk-razor-connectivity-entityconnectors
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.26.17
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.26.17
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '1.0'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: razorrisk-razor-connectivity-search
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.1.3
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.1.3
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '1.0'
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: razorrisk-core-diagnostics-extensions
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0.2'
|
100
|
+
type: :runtime
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - "~>"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0.2'
|
107
|
+
- !ruby/object:Gem::Dependency
|
108
|
+
name: clasp-ruby
|
109
|
+
requirement: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0.14'
|
114
|
+
type: :runtime
|
115
|
+
prerelease: false
|
116
|
+
version_requirements: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - "~>"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0.14'
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: json
|
123
|
+
requirement: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '1.8'
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.8.3
|
131
|
+
type: :runtime
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.8'
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 1.8.3
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: libclimate-ruby
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0.10'
|
148
|
+
type: :runtime
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - "~>"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0.10'
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: nokogiri
|
157
|
+
requirement: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - "~>"
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '1.6'
|
162
|
+
type: :runtime
|
163
|
+
prerelease: false
|
164
|
+
version_requirements: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - "~>"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '1.6'
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: pantheios-ruby
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - "~>"
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: 0.20.2
|
176
|
+
type: :runtime
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - "~>"
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: 0.20.2
|
183
|
+
- !ruby/object:Gem::Dependency
|
184
|
+
name: sinatra
|
185
|
+
requirement: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - "~>"
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 1.4.8
|
190
|
+
type: :runtime
|
191
|
+
prerelease: false
|
192
|
+
version_requirements: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - "~>"
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: 1.4.8
|
197
|
+
- !ruby/object:Gem::Dependency
|
198
|
+
name: xqsr3
|
199
|
+
requirement: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - "~>"
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0.30'
|
204
|
+
type: :runtime
|
205
|
+
prerelease: false
|
206
|
+
version_requirements: !ruby/object:Gem::Requirement
|
207
|
+
requirements:
|
208
|
+
- - "~>"
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: '0.30'
|
211
|
+
description: Razor Risk's Cassini Web-framework's RiskView RESTful microservice
|
212
|
+
email: operations@razor-risk.com
|
213
|
+
executables:
|
214
|
+
- razorrisk-microservice-riskview
|
215
|
+
extensions: []
|
216
|
+
extra_rdoc_files: []
|
217
|
+
files:
|
218
|
+
- bin/razorrisk-microservice-riskview
|
219
|
+
- lib/razor_risk/cassini/applications/microservices/restful/risk_view.rb
|
220
|
+
- lib/razor_risk/cassini/applications/microservices/restful/risk_view/app.rb
|
221
|
+
- lib/razor_risk/cassini/applications/microservices/restful/risk_view/version.rb
|
222
|
+
- lib/razor_risk/cassini/applications/route_verb_adaptors/risk_view.rb
|
223
|
+
- lib/razor_risk/cassini/applications/route_verb_adaptors/risk_view/item_get.rb
|
224
|
+
homepage: https://razor-risk.com/
|
225
|
+
licenses:
|
226
|
+
- Nonstandard
|
227
|
+
metadata: {}
|
228
|
+
post_install_message:
|
229
|
+
rdoc_options: []
|
230
|
+
require_paths:
|
231
|
+
- lib
|
232
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '2.0'
|
237
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
|
+
requirements:
|
239
|
+
- - ">="
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
version: '0'
|
242
|
+
requirements: []
|
243
|
+
rubyforge_project:
|
244
|
+
rubygems_version: 2.6.14
|
245
|
+
signing_key:
|
246
|
+
specification_version: 4
|
247
|
+
summary: Razor Risk Cassini Risk-View RESTful microservice
|
248
|
+
test_files: []
|