restful-riskpointdata-domains 0.6.13

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,199 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/applications/route_verb_adaptors/risk_point_data/domains/item_get.rb
5
+ #
6
+ # Purpose: Adaptor for RPD microservice's item GET verb
7
+ #
8
+ # Author: Matthew Wilson
9
+ #
10
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
11
+ # All rights reserved.
12
+ #
13
+ # ######################################################################## #
14
+
15
+
16
+ # ##########################################################################
17
+ # requires
18
+
19
+ require 'razor_risk/cassini/applications/route_verb_adaptors/utilities/risk_point_data/domains'
20
+ require 'razor_risk/cassini/applications/rest_framework/verb_handler'
21
+
22
+ require 'razor_risk/cassini/util/conversion_util'
23
+
24
+ require 'razor_risk/razor/connectivity/razor_3/entity_connectors/risk_point_data/domains_connector'
25
+
26
+ require 'razor_risk/core/diagnostics/logger'
27
+
28
+ require 'active_support/core_ext/hash'
29
+ require 'json'
30
+ require 'nokogiri'
31
+ require 'pantheios'
32
+
33
+ # ##########################################################################
34
+ # module
35
+
36
+ module RazorRisk
37
+ module Cassini
38
+ module Applications
39
+ module RouteVerbAdaptors
40
+ module RiskPointData
41
+ module Domains
42
+
43
+ # ##########################################################################
44
+ # classes
45
+
46
+ class ItemAuditGet < RESTFramework::VerbHandler
47
+
48
+ include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utilities::RiskPointData::Domains
49
+
50
+ include ::RazorRisk::Cassini::Util::ConversionUtil
51
+
52
+ include ::RazorRisk::Razor::Connectivity::Razor3::EntityConnectors::RiskPointData
53
+
54
+ include ::RazorRisk::Core::Diagnostics::Logger
55
+
56
+ include ::Pantheios
57
+
58
+ HTTP_VERB = :get
59
+
60
+ HTTP_ACCEPTS = %w{ application/xml application/json text/xml }
61
+
62
+ ROUTE_VARIABLES = %w{
63
+
64
+ domain
65
+ id
66
+ }
67
+
68
+ QUERY_PARAMETERS = %w{
69
+
70
+ result-form
71
+ }
72
+
73
+ def handle env, params, request, response
74
+
75
+ trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
76
+
77
+ # params
78
+
79
+ dom = infer_domain(params)
80
+
81
+ id = infer_id(params)
82
+ rf = case rf = (params['result-form'] || '').to_s
83
+ when '', 'default'
84
+ :body
85
+ when 'summary'
86
+ :rpd_summary
87
+ when 'rpd'
88
+ :rpd
89
+ else
90
+ log(:warning) { "unrecognised result-form '#{rf}'" }
91
+ :body
92
+ end
93
+
94
+ # get credentials
95
+
96
+ cr = get_required_credentials
97
+
98
+ # get requester
99
+
100
+ rr = settings.razor_requester
101
+
102
+ # get connector
103
+
104
+ ec = DomainsConnector.new(rr, credentials: cr)
105
+
106
+ # issue request
107
+
108
+ qr = ec.get_audit_record dom, id, indicate_result_by: :qualified_result, result_form: rf
109
+
110
+ log :debug1, "qr(#{qr.class})='#{qr}'"
111
+
112
+ unless qr.succeeded?
113
+
114
+ if false
115
+
116
+ ;
117
+ elsif qr.result.nil?
118
+
119
+ log :debug1, "failed to retrieve risk point data with domain '#{dom}' and id '#{id}'"
120
+
121
+ halt *[ 404, {}, "risk-point-data domain with '#{dom}' and id '#{id}' does not exist" ]
122
+ elsif r = qr.failure_qualifier.reasons.lookup?('RZ0011')
123
+
124
+ log :debug1, "failed to retrieve risk point data with domain '#{dom}' and id '#{id}'"
125
+
126
+ halt *[ 404, {}, "#{r.message}: #{r.details}" ]
127
+ else
128
+
129
+ log :warning, "failed to retrieve risk point data with domain '#{dom}' and id '#{id}'"
130
+
131
+ halt *[ 500, {}, qr.failure_qualifier.reasons.join("\n") ]
132
+ end
133
+ end
134
+
135
+ r = qr.result.to_s
136
+
137
+ # return result
138
+
139
+ status 200
140
+
141
+ if false
142
+ elsif request.accept?('application/xml')
143
+
144
+ log :debug1, 'application/xml'
145
+
146
+ content_type 'application/xml'
147
+
148
+ r
149
+ elsif request.accept?('application/json')
150
+
151
+ log :debug1, 'application/json'
152
+
153
+ content_type 'application/json'
154
+
155
+ # TODO: this switch should be removed. This is a temporary fix
156
+ # for continuation of UI development only. This code is repeated
157
+ # in item_get.rb where it must also be removed.
158
+ unless ENV['RR_TOOL_WEBAPI_RISKPOINTDATA_DOMAINS_JSON_OUTPUT_FORMAT_SWITCH']
159
+
160
+ xml = ::Nokogiri::XML(r)
161
+ xml.xpath('//field').each { |e| e.name = e['id'] }
162
+ resp_hash = Hash.from_xml xml.to_xml
163
+
164
+ resp_json = resp_hash
165
+
166
+ JSON.generate resp_json
167
+ else
168
+
169
+ convert_XML_to_JSON r, { scheme: :gdata }
170
+ end
171
+ elsif request.accept?('text/xml')
172
+
173
+ log :debug1, 'text/xml'
174
+
175
+ content_type 'text/xml'
176
+
177
+ r
178
+ else
179
+
180
+ log :violation, "unexpected failure to match given 'Accept' header '#{request.accept}'"
181
+
182
+ status 500
183
+ end
184
+ end
185
+ end # class ItemGet
186
+
187
+ # ##########################################################################
188
+ # module
189
+
190
+ end # module Domains
191
+ end # module RiskPointData
192
+ end # module RouteVerbAdaptors
193
+ end # module Applications
194
+ end # module Cassini
195
+ end # module RazorRisk
196
+
197
+ # ############################## end of file ############################# #
198
+
199
+
@@ -0,0 +1,121 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/applications/route_verb_adaptors/risk_point_data/domains/item_delete.rb
5
+ #
6
+ # Purpose: Adaptor for RPD microservice's item DELETE verb
7
+ #
8
+ # Author: Matthew Wilson
9
+ #
10
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
11
+ # All rights reserved.
12
+ #
13
+ # ######################################################################## #
14
+
15
+
16
+ # ##########################################################################
17
+ # requires
18
+
19
+ require 'razor_risk/cassini/applications/route_verb_adaptors/utilities/risk_point_data/domains'
20
+
21
+ require 'razor_risk/cassini/applications/rest_framework/verb_handler'
22
+
23
+ require 'razor_risk/razor/connectivity/razor_3/entity_connectors/risk_point_data/domains_connector'
24
+
25
+ require 'razor_risk/core/diagnostics/logger'
26
+
27
+ require 'pantheios'
28
+
29
+ # ##########################################################################
30
+ # module
31
+
32
+ module RazorRisk
33
+ module Cassini
34
+ module Applications
35
+ module RouteVerbAdaptors
36
+ module RiskPointData
37
+ module Domains
38
+
39
+ # ##########################################################################
40
+ # classes
41
+
42
+ class ItemDelete < RESTFramework::VerbHandler
43
+
44
+ include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utilities::RiskPointData::Domains
45
+
46
+ include ::RazorRisk::Razor::Connectivity::Razor3::EntityConnectors::RiskPointData
47
+
48
+ include ::RazorRisk::Core::Diagnostics::Logger
49
+
50
+ include ::Pantheios
51
+
52
+ HTTP_VERB = :delete
53
+
54
+ HTTP_ACCEPTS = %w{ application/xml application/json text/xml }
55
+
56
+ ROUTE_VARIABLES = %w{
57
+
58
+ domain
59
+ id
60
+ }
61
+
62
+ QUERY_PARAMETERS = []
63
+
64
+ def handle env, params, request, response
65
+
66
+ # trace
67
+
68
+ trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
69
+
70
+ # parameters
71
+
72
+ dom = infer_domain(params)
73
+
74
+ id = infer_id(params)
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 = DomainsConnector.new(rr, credentials: cr)
87
+
88
+ # issue request
89
+
90
+ qr = ec.delete_record dom, id, indicate_result_by: :qualified_result
91
+
92
+ log :debug1, "qr(#{qr.class})='#{qr}'"
93
+
94
+ unless qr.succeeded?
95
+
96
+ log :warning, "failed to delete risk point data with domain '#{dom}' and id '#{id}'"
97
+
98
+ if r = qr.failure_qualifier.reasons.lookup?('RZ0011')
99
+
100
+ halt *[ 404, {}, "#{r.message}: #{r.details}" ]
101
+ else
102
+
103
+ halt *[ 500, {}, qr.failure_qualifier.reasons.join("\n") ]
104
+ end
105
+ end
106
+ end
107
+ end # class ItemDelete
108
+
109
+ # ##########################################################################
110
+ # module
111
+
112
+ end # module Domains
113
+ end # module RiskPointData
114
+ end # module RouteVerbAdaptors
115
+ end # module Applications
116
+ end # module Cassini
117
+ end # module RazorRisk
118
+
119
+ # ############################## end of file ############################# #
120
+
121
+
@@ -0,0 +1,198 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/applications/route_verb_adaptors/risk_point_data/domains/item_get.rb
5
+ #
6
+ # Purpose: Adaptor for RPD microservice's item GET verb
7
+ #
8
+ # Author: Matthew Wilson
9
+ #
10
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
11
+ # All rights reserved.
12
+ #
13
+ # ######################################################################## #
14
+
15
+
16
+ # ##########################################################################
17
+ # requires
18
+
19
+ require 'razor_risk/cassini/applications/route_verb_adaptors/utilities/risk_point_data/domains'
20
+ require 'razor_risk/cassini/applications/rest_framework/verb_handler'
21
+
22
+ require 'razor_risk/cassini/util/conversion_util'
23
+
24
+ require 'razor_risk/razor/connectivity/razor_3/entity_connectors/risk_point_data/domains_connector'
25
+ require 'razor_risk/core/diagnostics/logger'
26
+
27
+ require 'active_support/core_ext/hash'
28
+ require 'json'
29
+ require 'nokogiri'
30
+ require 'pantheios'
31
+
32
+ # ##########################################################################
33
+ # module
34
+
35
+ module RazorRisk
36
+ module Cassini
37
+ module Applications
38
+ module RouteVerbAdaptors
39
+ module RiskPointData
40
+ module Domains
41
+
42
+ # ##########################################################################
43
+ # classes
44
+
45
+ class ItemGet < RESTFramework::VerbHandler
46
+
47
+ include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utilities::RiskPointData::Domains
48
+
49
+ include ::RazorRisk::Cassini::Util::ConversionUtil
50
+
51
+ include ::RazorRisk::Razor::Connectivity::Razor3::EntityConnectors::RiskPointData
52
+
53
+ include ::RazorRisk::Core::Diagnostics::Logger
54
+
55
+ include ::Pantheios
56
+
57
+ HTTP_VERB = :get
58
+
59
+ HTTP_ACCEPTS = %w{ application/xml application/json text/xml }
60
+
61
+ ROUTE_VARIABLES = %w{
62
+
63
+ domain
64
+ id
65
+ }
66
+
67
+ QUERY_PARAMETERS = %w{
68
+
69
+ result-form
70
+ }
71
+
72
+ def handle env, params, request, response
73
+
74
+ trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
75
+
76
+ # params
77
+
78
+ dom = infer_domain(params)
79
+
80
+ id = infer_id(params)
81
+ rf = case rf = (params['result-form'] || '').to_s
82
+ when '', 'default'
83
+ :body
84
+ when 'summary'
85
+ :rpd_summary
86
+ when 'rpd'
87
+ :rpd
88
+ else
89
+ log(:warning) { "unrecognised result-form '#{rf}'" }
90
+ :body
91
+ end
92
+
93
+ # get credentials
94
+
95
+ cr = get_required_credentials
96
+
97
+ # get requester
98
+
99
+ rr = settings.razor_requester
100
+
101
+ # get connector
102
+
103
+ ec = DomainsConnector.new(rr, credentials: cr)
104
+
105
+ # issue request
106
+
107
+ qr = ec.get_record dom, id, indicate_result_by: :qualified_result, result_form: rf
108
+
109
+ log :debug1, "qr(#{qr.class})='#{qr}'"
110
+
111
+ unless qr.succeeded?
112
+
113
+ if false
114
+
115
+ ;
116
+ elsif qr.result.nil?
117
+
118
+ log :debug1, "failed to retrieve risk point data with domain '#{dom}' and id '#{id}'"
119
+
120
+ halt *[ 404, {}, "risk-point-data domain with '#{dom}' and id '#{id}' does not exist" ]
121
+ elsif r = qr.failure_qualifier.reasons.lookup?('RZ0011')
122
+
123
+ log :debug1, "failed to retrieve risk point data with domain '#{dom}' and id '#{id}'"
124
+
125
+ halt *[ 404, {}, "#{r.message}: #{r.details}" ]
126
+ else
127
+
128
+ log :warning, "failed to retrieve risk point data with domain '#{dom}' and id '#{id}'"
129
+
130
+ halt *[ 500, {}, qr.failure_qualifier.reasons.join("\n") ]
131
+ end
132
+ end
133
+
134
+ r = qr.result.to_s
135
+
136
+ # return result
137
+
138
+ status 200
139
+
140
+ if false
141
+ elsif request.accept?('application/xml')
142
+
143
+ log :debug1, 'application/xml'
144
+
145
+ content_type 'application/xml'
146
+
147
+ r
148
+ elsif request.accept?('application/json')
149
+
150
+ log :debug1, 'application/json'
151
+
152
+ content_type 'application/json'
153
+
154
+ # TODO: this switch should be removed. This is a temporary fix
155
+ # for continuation of UI development only. This code is repeated
156
+ # in item_get.rb where it must also be removed.
157
+ unless ENV['RR_TOOL_WEBAPI_RISKPOINTDATA_DOMAINS_JSON_OUTPUT_FORMAT_SWITCH']
158
+
159
+ xml = ::Nokogiri::XML(r)
160
+ xml.xpath('//field').each { |e| e.name = e['id'] }
161
+ resp_hash = Hash.from_xml xml.to_xml
162
+
163
+ resp_json = resp_hash
164
+
165
+ JSON.generate resp_json
166
+ else
167
+
168
+ convert_XML_to_JSON r, { scheme: :gdata }
169
+ end
170
+ elsif request.accept?('text/xml')
171
+
172
+ log :debug1, 'text/xml'
173
+
174
+ content_type 'text/xml'
175
+
176
+ r
177
+ else
178
+
179
+ log :violation, "unexpected failure to match given 'Accept' header '#{request.accept}'"
180
+
181
+ status 500
182
+ end
183
+ end
184
+ end # class ItemGet
185
+
186
+ # ##########################################################################
187
+ # module
188
+
189
+ end # module Domains
190
+ end # module RiskPointData
191
+ end # module RouteVerbAdaptors
192
+ end # module Applications
193
+ end # module Cassini
194
+ end # module RazorRisk
195
+
196
+ # ############################## end of file ############################# #
197
+
198
+
@@ -0,0 +1,153 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/applications/route_verb_adaptors/risk_point_data/domains/item_post.rb
5
+ #
6
+ # Purpose: Adaptor for RPD microservice's item POST verb
7
+ #
8
+ # Author: Julian Green, Matthew Wilson
9
+ #
10
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
11
+ # All rights reserved.
12
+ #
13
+ # ######################################################################## #
14
+
15
+
16
+ # ##########################################################################
17
+ # requires
18
+
19
+ require 'razor_risk/cassini/applications/route_verb_adaptors/utilities/risk_point_data/domains'
20
+
21
+ require 'razor_risk/cassini/applications/rest_framework/verb_handler'
22
+
23
+ require 'razor_risk/razor/connectivity/razor_3/entity_connectors/risk_point_data/domains_connector'
24
+
25
+ require 'razor_risk/core/diagnostics/logger'
26
+
27
+ require 'pantheios'
28
+
29
+ # ##########################################################################
30
+ # module
31
+
32
+ module RazorRisk
33
+ module Cassini
34
+ module Applications
35
+ module RouteVerbAdaptors
36
+ module RiskPointData
37
+ module Domains
38
+
39
+ # ##########################################################################
40
+ # classes
41
+
42
+ class ItemPost < RESTFramework::VerbHandler
43
+
44
+ include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utilities::RiskPointData::Domains
45
+
46
+ include ::RazorRisk::Razor::Connectivity::Razor3::EntityConnectors::RiskPointData
47
+
48
+ include ::RazorRisk::Core::Diagnostics::Logger
49
+
50
+ include ::Pantheios
51
+
52
+ HTTP_VERB = :post
53
+
54
+ HTTP_CONTENT_TYPES = %w{ application/xml text/xml }
55
+
56
+ HTTP_ACCEPTS = %w{ application/xml application/json text/xml }
57
+
58
+ ROUTE_VARIABLES = %w{
59
+
60
+ domain
61
+ }
62
+
63
+ QUERY_PARAMETERS = []
64
+
65
+ def handle env, params, request, response
66
+
67
+ # trace
68
+
69
+ trace ParamNames[ :env, :params, :request, :response ], env, params, request, response
70
+
71
+ # parameters
72
+
73
+ dom = infer_domain(params)
74
+
75
+ # read request body (XML)
76
+ #
77
+ # NOTE: For this handler, the input is required to be XML, and it
78
+ # is required that the document has a single top-level node
79
+ # 'updateRiskPointDomainRecords'
80
+
81
+ request.body.rewind
82
+
83
+ body_text = request.body.read
84
+ rq_body = nil
85
+
86
+ case request.content_type
87
+ when 'application/xml', 'text/xml'
88
+
89
+ rq_body = ::Nokogiri.XML body_text
90
+ else
91
+
92
+ log :violation, "unexpected content-type '#{request.content_type}'"
93
+ end
94
+
95
+ case rq_body.children.count
96
+ when 0
97
+
98
+ halt 400, {}, 'not a valid body'
99
+ when 1
100
+ else
101
+
102
+ halt 400, {}, 'too many children'
103
+ end
104
+
105
+ # get credentials
106
+
107
+ cr = get_required_credentials
108
+
109
+ # get requester
110
+
111
+ rr = settings.razor_requester
112
+
113
+ # get connector
114
+
115
+ ec = DomainsConnector.new(rr, credentials: cr)
116
+
117
+ # issue request
118
+
119
+ qr = ec.insert_record dom, rq_body, indicate_result_by: :qualified_result
120
+
121
+ log :debug1, "qr(#{qr.class})='#{qr}'"
122
+
123
+ unless qr.succeeded?
124
+
125
+ log :warning, "failed to update risk point data with domain '#{dom}'"
126
+
127
+ if r = qr.failure_qualifier.reasons.lookup?('RZ0011')
128
+
129
+ halt 404, {}, "#{r.message}: #{r.details}"
130
+ else
131
+
132
+ halt 422, {}, "failed to update risk point data with domain '#{dom}'"
133
+ end
134
+ end
135
+
136
+ status 201
137
+ end
138
+ end # class ItemPost
139
+
140
+ # ##########################################################################
141
+ # module
142
+
143
+ end # module Domains
144
+ end # module RiskPointData
145
+ end # module RouteVerbAdaptors
146
+ end # module Applications
147
+ end # module Cassini
148
+ end # module RazorRisk
149
+
150
+ # ############################## end of file ############################# #
151
+
152
+
153
+