restful-portfolios 0.13.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/razorrisk-microservice-portfolios +390 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/portfolios/version.rb +51 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/portfolios.rb +2 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/collection_get.rb +253 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/hierarchy_get.rb +207 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/item_delete.rb +112 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/item_get.rb +169 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/item_post.rb +130 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/item_put.rb +138 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios.rb +8 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/utilities/portfolios.rb +85 -0
- metadata +260 -0
@@ -0,0 +1,207 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Adaptor for Portfolios 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/applications/route_verb_adaptors/utilities/collection_get_helper'
|
17
|
+
require 'razor_risk/cassini/applications/route_verb_adaptors/utilities/portfolios'
|
18
|
+
require 'razor_risk/cassini/util/conversion_util'
|
19
|
+
|
20
|
+
require 'razor_risk/razor/connectivity/entity_connectors/exceptions'
|
21
|
+
require 'razor_risk/razor/connectivity/razor_3/entity_connectors/portfolios_connector'
|
22
|
+
|
23
|
+
require 'razor_risk/core/diagnostics/exceptions/rrcs_base_exception'
|
24
|
+
|
25
|
+
require 'razor_risk/core/diagnostics/logger'
|
26
|
+
|
27
|
+
require 'pantheios'
|
28
|
+
require 'xqsr3/conversion/integer_parser'
|
29
|
+
|
30
|
+
# ##########################################################################
|
31
|
+
# module
|
32
|
+
|
33
|
+
module RazorRisk
|
34
|
+
module Cassini
|
35
|
+
module Applications
|
36
|
+
module RouteVerbAdaptors
|
37
|
+
module Portfolios
|
38
|
+
|
39
|
+
# ##########################################################################
|
40
|
+
# classes
|
41
|
+
|
42
|
+
class HierarchyGet < RESTFramework::VerbHandler
|
43
|
+
|
44
|
+
include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utilities::CollectionGetHelper
|
45
|
+
include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utilities::Portfolios
|
46
|
+
include ::RazorRisk::Cassini::Util::ConversionUtil
|
47
|
+
|
48
|
+
include ::RazorRisk::Razor::Connectivity::EntityConnectors::Exceptions
|
49
|
+
include ::RazorRisk::Razor::Connectivity::Razor3
|
50
|
+
include ::RazorRisk::Razor::Connectivity::Razor3::EntityConnectors
|
51
|
+
|
52
|
+
include ::RazorRisk::Core::Diagnostics::Exceptions
|
53
|
+
|
54
|
+
include ::Pantheios
|
55
|
+
|
56
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
57
|
+
|
58
|
+
HTTP_VERB = :get
|
59
|
+
|
60
|
+
HTTP_ACCEPTS = %w{ application/xml application/json text/xml }
|
61
|
+
|
62
|
+
QUERY_PARAMETERS = %w{
|
63
|
+
|
64
|
+
filter-name
|
65
|
+
|
66
|
+
page-base
|
67
|
+
page-extent
|
68
|
+
|
69
|
+
key-search
|
70
|
+
}
|
71
|
+
|
72
|
+
def handle env, params, request, response
|
73
|
+
|
74
|
+
trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
|
75
|
+
# params
|
76
|
+
|
77
|
+
filter_name = params['filter-name'].to_s.strip
|
78
|
+
filter_name = nil if filter_name.empty?
|
79
|
+
page_base = ::Xqsr3::Conversion::IntegerParser.to_integer(
|
80
|
+
params['page-base'] || 0
|
81
|
+
) do |x, arg|
|
82
|
+
halt 422, {'Content-Type' => 'text/plain'}, "invalid page specifier: 'page-base'=#{arg}"
|
83
|
+
end
|
84
|
+
page_extent = ::Xqsr3::Conversion::IntegerParser.to_integer(
|
85
|
+
params['page-extent'] || 1000
|
86
|
+
) do |x, arg|
|
87
|
+
halt 422, {'Content-Type' => 'text/plain'}, "invalid page specifier: 'page-extent'=#{arg}"
|
88
|
+
end
|
89
|
+
key_search = params['key-search']
|
90
|
+
key_search = nil if key_search.to_s.strip.empty?
|
91
|
+
|
92
|
+
if page_base < 0 || page_extent < 1
|
93
|
+
|
94
|
+
halt 416, {'Content-Type' => 'text/plain'}, "invalid page specifier: 'page-base'=#{page_base}; 'page-extent'=#{page_extent}"
|
95
|
+
end
|
96
|
+
|
97
|
+
if key_search
|
98
|
+
begin
|
99
|
+
key_search = MultiValueConjunctionParser.new.parse_conjunction_list key_search
|
100
|
+
rescue MultiValueConjunctionParser::SyntaxError => x
|
101
|
+
halt 422, {'Content-Type' => 'text/plain'}, x.message
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
rq_opts = {
|
106
|
+
:filter_name => filter_name,
|
107
|
+
:page_base => page_base,
|
108
|
+
:page_extent => page_extent,
|
109
|
+
:key_search => key_search,
|
110
|
+
}
|
111
|
+
|
112
|
+
# get credentials
|
113
|
+
|
114
|
+
cr = get_required_credentials
|
115
|
+
|
116
|
+
# get requester
|
117
|
+
|
118
|
+
rr = settings.razor_requester
|
119
|
+
|
120
|
+
# get connector
|
121
|
+
|
122
|
+
ec = PortfoliosConnector.new(rr, credentials: cr, **rq_opts)
|
123
|
+
|
124
|
+
# issue request
|
125
|
+
|
126
|
+
begin
|
127
|
+
|
128
|
+
qr = ec.get_hierarchy indicate_result_by: :qualified_result
|
129
|
+
rescue ::ArgumentError, ::NameError, ::NoMethodError, ::TypeError => x
|
130
|
+
|
131
|
+
log(:violation) { "(#{x.class}): #{x.message}" }
|
132
|
+
raise
|
133
|
+
rescue RazorRequester::InvalidCredentialsException => x
|
134
|
+
|
135
|
+
log(:failure) { "exception (#{x.class}): #{x}" }
|
136
|
+
halt 401, { 'Content-Type' => 'text/plain' }, 'Invalid credentials'
|
137
|
+
rescue DataNotFoundException => x
|
138
|
+
|
139
|
+
log(:failure) { "exception (#{x.class}): #{x}" }
|
140
|
+
halt 404, { 'Content-Type' => 'text/plain' }, x.message
|
141
|
+
rescue RRCSBaseException => x
|
142
|
+
|
143
|
+
log(:failure) { "exception (#{x.class}): #{x}" }
|
144
|
+
halt 500, { 'Content-Type' => 'text/plain' }, x.message
|
145
|
+
end
|
146
|
+
|
147
|
+
log :debug1, "qr(#{qr.class})='#{qr}'"
|
148
|
+
|
149
|
+
unless qr.succeeded?
|
150
|
+
|
151
|
+
if :no_such_filter == qr.result
|
152
|
+
|
153
|
+
log :debug1, "failed to retrieve portfolios: no such filter '#{filter_name}'"
|
154
|
+
halt 422, { 'Content-Type' => 'text/plain' }, "no such filter '#{filter_name}'"
|
155
|
+
elsif r = qr.failure_qualifier.reasons.lookup?('RZ0011')
|
156
|
+
|
157
|
+
log :debug1, 'failed to retrieve portfolios'
|
158
|
+
halt 404, { 'Content-Type' => 'text/plain' }, "#{r.message}: #{r.details}"
|
159
|
+
else
|
160
|
+
|
161
|
+
log :warning, 'failed to retrieve portfolios'
|
162
|
+
halt 500, { 'Content-Type' => 'text/plain' }, qr.failure_qualifier.reasons.join("\n")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
r = qr.result.to_s
|
167
|
+
|
168
|
+
# return result
|
169
|
+
|
170
|
+
status 200
|
171
|
+
|
172
|
+
if false
|
173
|
+
elsif request.accept?('application/xml')
|
174
|
+
|
175
|
+
log :debug1, 'application/xml'
|
176
|
+
content_type 'application/xml'
|
177
|
+
r
|
178
|
+
elsif request.accept?('application/json')
|
179
|
+
|
180
|
+
log :debug1, 'application/json'
|
181
|
+
content_type 'application/json'
|
182
|
+
convert_XML_to_JSON r, { scheme: :gdata }
|
183
|
+
elsif request.accept?('text/xml')
|
184
|
+
|
185
|
+
log :debug1, 'text/xml'
|
186
|
+
content_type 'text/xml'
|
187
|
+
r
|
188
|
+
else
|
189
|
+
|
190
|
+
log :violation, "unexpected failure to match given 'Accept' header '#{request.accept}'"
|
191
|
+
status 500
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end # class CollectionGet
|
195
|
+
|
196
|
+
# ##########################################################################
|
197
|
+
# module
|
198
|
+
|
199
|
+
end # module Portfolios
|
200
|
+
end # module RouteVerbAdaptors
|
201
|
+
end # module Applications
|
202
|
+
end # module Cassini
|
203
|
+
end # module RazorRisk
|
204
|
+
|
205
|
+
# ############################## end of file ############################# #
|
206
|
+
|
207
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Adaptor for Portfolios microservice's item DELETE 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
|
+
|
17
|
+
require 'razor_risk/razor/connectivity/razor_3/entity_connectors/portfolios_connector'
|
18
|
+
|
19
|
+
require 'razor_risk/core/diagnostics/logger'
|
20
|
+
|
21
|
+
require 'pantheios'
|
22
|
+
|
23
|
+
require 'xqsr3/conversion/integer_parser'
|
24
|
+
|
25
|
+
# ##########################################################################
|
26
|
+
# module
|
27
|
+
|
28
|
+
module RazorRisk
|
29
|
+
module Cassini
|
30
|
+
module Applications
|
31
|
+
module RouteVerbAdaptors
|
32
|
+
module Portfolios
|
33
|
+
|
34
|
+
# ##########################################################################
|
35
|
+
# classes
|
36
|
+
|
37
|
+
class ItemDelete < RESTFramework::VerbHandler
|
38
|
+
|
39
|
+
include ::RazorRisk::Razor::Connectivity::Razor3::EntityConnectors
|
40
|
+
|
41
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
42
|
+
|
43
|
+
include ::Pantheios
|
44
|
+
|
45
|
+
include ::Xqsr3::Conversion
|
46
|
+
|
47
|
+
HTTP_VERB = :delete
|
48
|
+
|
49
|
+
HTTP_ACCEPTS = %w{ application/xml application/json text/xml }
|
50
|
+
|
51
|
+
ROUTE_VARIABLES = %w{
|
52
|
+
|
53
|
+
id
|
54
|
+
}
|
55
|
+
|
56
|
+
QUERY_PARAMETERS = []
|
57
|
+
|
58
|
+
def handle env, params, request, response
|
59
|
+
|
60
|
+
# trace
|
61
|
+
|
62
|
+
trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
|
63
|
+
|
64
|
+
# parameters
|
65
|
+
|
66
|
+
id = IntegerParser.to_integer(params['id'], allow_nil: true) { halt *[ 404, {}, 'invalid identifier for DELETE verb - must be an integer' ] }
|
67
|
+
|
68
|
+
# get credentials
|
69
|
+
|
70
|
+
cr = get_required_credentials
|
71
|
+
|
72
|
+
# get requester
|
73
|
+
|
74
|
+
rr = settings.razor_requester
|
75
|
+
|
76
|
+
# get connector
|
77
|
+
|
78
|
+
ec = PortfoliosConnector.new(rr, credentials: cr)
|
79
|
+
|
80
|
+
# issue request
|
81
|
+
|
82
|
+
qr = ec.delete_portfolio id, indicate_result_by: :qualified_result
|
83
|
+
|
84
|
+
log :debug1, "qr(#{qr.class})='#{qr}'"
|
85
|
+
|
86
|
+
unless qr.succeeded?
|
87
|
+
|
88
|
+
log :warning, "failed to delete portfolio with id '#{id}'"
|
89
|
+
|
90
|
+
if r = qr.failure_qualifier.reasons.lookup?('RZ0011')
|
91
|
+
|
92
|
+
halt *[ 404, {}, "#{r.message}: #{r.details}" ]
|
93
|
+
else
|
94
|
+
|
95
|
+
halt *[ 500, {}, qr.failure_qualifier.reasons.join("\n") ]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end # class ItemDelete
|
100
|
+
|
101
|
+
# ##########################################################################
|
102
|
+
# module
|
103
|
+
|
104
|
+
end # module Portfolios
|
105
|
+
end # module RouteVerbAdaptors
|
106
|
+
end # module Applications
|
107
|
+
end # module Cassini
|
108
|
+
end # module RazorRisk
|
109
|
+
|
110
|
+
# ############################## end of file ############################# #
|
111
|
+
|
112
|
+
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Adaptor for Portfolios microservice's item 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
|
+
|
17
|
+
require 'razor_risk/razor/connectivity/razor_3/entity_connectors/portfolios_connector'
|
18
|
+
|
19
|
+
require 'razor_risk/core/diagnostics/logger'
|
20
|
+
|
21
|
+
require 'pantheios'
|
22
|
+
|
23
|
+
# ##########################################################################
|
24
|
+
# module
|
25
|
+
|
26
|
+
module RazorRisk
|
27
|
+
module Cassini
|
28
|
+
module Applications
|
29
|
+
module RouteVerbAdaptors
|
30
|
+
module Portfolios
|
31
|
+
|
32
|
+
# ##########################################################################
|
33
|
+
# classes
|
34
|
+
|
35
|
+
class ItemGet < RESTFramework::VerbHandler
|
36
|
+
|
37
|
+
include ::RazorRisk::Razor::Connectivity::Razor3::EntityConnectors
|
38
|
+
|
39
|
+
include ::Pantheios
|
40
|
+
|
41
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
42
|
+
|
43
|
+
HTTP_VERB = :get
|
44
|
+
|
45
|
+
HTTP_ACCEPTS = %w{ application/xml application/json text/xml }
|
46
|
+
|
47
|
+
ROUTE_VARIABLES = %w{
|
48
|
+
|
49
|
+
id
|
50
|
+
}
|
51
|
+
|
52
|
+
QUERY_PARAMETERS = %w{
|
53
|
+
|
54
|
+
result-form
|
55
|
+
}
|
56
|
+
|
57
|
+
def handle env, params, request, response
|
58
|
+
|
59
|
+
trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
|
60
|
+
|
61
|
+
# params
|
62
|
+
|
63
|
+
id = Integer(params['id']) { halt *[ 404, {}, 'invalid identifier for GET verb - must be an integer' ] }
|
64
|
+
rf = case rf = (params['result-form'] || '').to_s
|
65
|
+
when '', 'default'
|
66
|
+
:body
|
67
|
+
when 'summary'
|
68
|
+
:portfolio_summary
|
69
|
+
when 'portfolio'
|
70
|
+
:portfolio
|
71
|
+
else
|
72
|
+
log(:warning) { "unrecognised result-form '#{rf}'" }
|
73
|
+
:body
|
74
|
+
end
|
75
|
+
|
76
|
+
# get credentials
|
77
|
+
|
78
|
+
cr = get_required_credentials
|
79
|
+
|
80
|
+
# get requester
|
81
|
+
|
82
|
+
rr = settings.razor_requester
|
83
|
+
|
84
|
+
# get connector
|
85
|
+
|
86
|
+
ec = PortfoliosConnector.new(rr, credentials: cr)
|
87
|
+
|
88
|
+
# issue request
|
89
|
+
|
90
|
+
qr = ec.get_portfolio id, indicate_result_by: :qualified_result, result_form: rf
|
91
|
+
|
92
|
+
log :debug1, "qr(#{qr.class})='#{qr}'"
|
93
|
+
|
94
|
+
unless qr.succeeded?
|
95
|
+
|
96
|
+
if false
|
97
|
+
|
98
|
+
;
|
99
|
+
elsif qr.result.nil?
|
100
|
+
|
101
|
+
log :debug1, 'failed to retrieve portfolio'
|
102
|
+
|
103
|
+
halt *[ 404, {}, "portfolio with id '#{id}' does not exist" ]
|
104
|
+
elsif r = qr.failure_qualifier.reasons.lookup?('RZ0011')
|
105
|
+
|
106
|
+
log :debug1, 'failed to retrieve portfolio'
|
107
|
+
|
108
|
+
halt *[ 404, {}, "#{r.message}: #{r.details}" ]
|
109
|
+
else
|
110
|
+
|
111
|
+
log :warning, 'failed to retrieve portfolio'
|
112
|
+
|
113
|
+
halt *[ 500, {}, qr.failure_qualifier.reasons.join("\n") ]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
r = qr.result.to_s
|
118
|
+
|
119
|
+
# return result
|
120
|
+
|
121
|
+
status 200
|
122
|
+
|
123
|
+
if false
|
124
|
+
elsif request.accept?('application/xml')
|
125
|
+
|
126
|
+
log :debug1, 'application/xml'
|
127
|
+
|
128
|
+
content_type 'application/xml'
|
129
|
+
|
130
|
+
r
|
131
|
+
elsif request.accept?('application/json')
|
132
|
+
|
133
|
+
log :debug1, 'application/json'
|
134
|
+
|
135
|
+
content_type 'application/json'
|
136
|
+
|
137
|
+
resp_hash = Hash.from_xml r
|
138
|
+
|
139
|
+
resp_json = resp_hash
|
140
|
+
|
141
|
+
JSON.generate resp_json
|
142
|
+
elsif request.accept?('text/xml')
|
143
|
+
|
144
|
+
log :debug1, 'text/xml'
|
145
|
+
|
146
|
+
content_type 'text/xml'
|
147
|
+
|
148
|
+
r
|
149
|
+
else
|
150
|
+
|
151
|
+
log :violation, "unexpected failure to match given 'Accept' header '#{request.accept}'"
|
152
|
+
|
153
|
+
status 500
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end # class ItemGet
|
157
|
+
|
158
|
+
# ##########################################################################
|
159
|
+
# module
|
160
|
+
|
161
|
+
end # module Portfolios
|
162
|
+
end # module RouteVerbAdaptors
|
163
|
+
end # module Applications
|
164
|
+
end # module Cassini
|
165
|
+
end # module RazorRisk
|
166
|
+
|
167
|
+
# ############################## end of file ############################# #
|
168
|
+
|
169
|
+
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Adapter for Portfolios microservice's item POST 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/route_verb_adaptors/utilities/portfolios'
|
16
|
+
|
17
|
+
require 'razor_risk/cassini/applications/rest_framework/verb_handler'
|
18
|
+
|
19
|
+
require 'razor_risk/razor/connectivity/razor_3/entity_connectors/portfolios_connector'
|
20
|
+
|
21
|
+
require 'razor_risk/core/diagnostics/logger'
|
22
|
+
|
23
|
+
require 'pantheios'
|
24
|
+
|
25
|
+
# ##########################################################################
|
26
|
+
# module
|
27
|
+
|
28
|
+
module RazorRisk
|
29
|
+
module Cassini
|
30
|
+
module Applications
|
31
|
+
module RouteVerbAdaptors
|
32
|
+
module Portfolios
|
33
|
+
|
34
|
+
# ##########################################################################
|
35
|
+
# classes
|
36
|
+
|
37
|
+
class ItemPost < RESTFramework::VerbHandler
|
38
|
+
|
39
|
+
include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utilities::Portfolios
|
40
|
+
|
41
|
+
include ::RazorRisk::Razor::Connectivity::Razor3::EntityConnectors
|
42
|
+
|
43
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
44
|
+
|
45
|
+
include ::Pantheios
|
46
|
+
|
47
|
+
HTTP_VERB = :post
|
48
|
+
|
49
|
+
HTTP_CONTENT_TYPES = %w{ application/xml text/xml }
|
50
|
+
|
51
|
+
HTTP_ACCEPTS = %w{ application/xml application/json text/xml }
|
52
|
+
|
53
|
+
QUERY_PARAMETERS = []
|
54
|
+
|
55
|
+
def handle env, params, request, response
|
56
|
+
|
57
|
+
# trace
|
58
|
+
|
59
|
+
trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
|
60
|
+
|
61
|
+
# read request body (XML)
|
62
|
+
#
|
63
|
+
# NOTE: For this handler, the input is required to be XML, and it
|
64
|
+
# is required that the document has a single top-level node
|
65
|
+
# 'portfolios'
|
66
|
+
|
67
|
+
request.body.rewind
|
68
|
+
|
69
|
+
body_text = request.body.read
|
70
|
+
rq_body = nil
|
71
|
+
|
72
|
+
case request.content_type
|
73
|
+
when 'application/xml', 'text/xml'
|
74
|
+
|
75
|
+
rq_body = ::Nokogiri.XML body_text
|
76
|
+
else
|
77
|
+
|
78
|
+
log :violation, "unexpected content-type '#{request.content_type}'"
|
79
|
+
end
|
80
|
+
|
81
|
+
rq_body = validate_request_body rq_body, require_id: false
|
82
|
+
|
83
|
+
# get credentials
|
84
|
+
|
85
|
+
cr = get_required_credentials
|
86
|
+
|
87
|
+
# get requester
|
88
|
+
|
89
|
+
rr = settings.razor_requester
|
90
|
+
|
91
|
+
# get connector
|
92
|
+
|
93
|
+
ec = PortfoliosConnector.new(rr, credentials: cr)
|
94
|
+
|
95
|
+
# issue request
|
96
|
+
|
97
|
+
qr = ec.insert_portfolio rq_body, indicate_result_by: :qualified_result
|
98
|
+
|
99
|
+
unless qr.succeeded?
|
100
|
+
|
101
|
+
log :warning, "failed to post portfolio: #{qr.failure_qualifier.reasons.join(':')}"
|
102
|
+
|
103
|
+
if r = qr.failure_qualifier.reasons.lookup?('RZ0011')
|
104
|
+
|
105
|
+
halt 404, {}, "#{r.message}: #{r.details}"
|
106
|
+
else
|
107
|
+
|
108
|
+
halt 422, {}, "failed to post portfolio"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
status 201
|
113
|
+
portfolio_id = qr.result and return %Q{<portfolio id="#{portfolio_id}" />}
|
114
|
+
|
115
|
+
halt 500, {}, "returned response from Razor is not well formed"
|
116
|
+
end
|
117
|
+
end # class ItemPost
|
118
|
+
|
119
|
+
# ##########################################################################
|
120
|
+
# module
|
121
|
+
|
122
|
+
end # module Portfolios
|
123
|
+
end # module RouteVerbAdaptors
|
124
|
+
end # module Applications
|
125
|
+
end # module Cassini
|
126
|
+
end # module RazorRisk
|
127
|
+
|
128
|
+
# ############################## end of file ############################# #
|
129
|
+
|
130
|
+
|