Class: RazorRisk::Cassini::Applications::RouteVerbAdaptors::Portfolios::ItemPost
- Inherits:
-
RESTFramework::VerbHandler
- Object
- RESTFramework::VerbHandler
- RazorRisk::Cassini::Applications::RouteVerbAdaptors::Portfolios::ItemPost
- Includes:
- Pantheios, Utilities::Portfolios, RazorRisk::Core::Diagnostics::Logger, Razor::Connectivity::Razor3::EntityConnectors
- Defined in:
- lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/item_post.rb
Overview
########################################################################## classes
Constant Summary collapse
- HTTP_VERB =
:post
- HTTP_CONTENT_TYPES =
%w{ application/xml text/xml }
- HTTP_ACCEPTS =
%w{ application/xml application/json text/xml }
- QUERY_PARAMETERS =
[]
Instance Method Summary collapse
Methods included from Utilities::Portfolios
Instance Method Details
#handle(env, params, request, response) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/item_post.rb', line 55 def handle env, params, request, response # trace trace ParamNames[ :env, :params, :request, :response ], env, params, request, response # read request body (XML) # # NOTE: For this handler, the input is required to be XML, and it # is required that the document has a single top-level node # 'portfolios' request.body.rewind body_text = request.body.read rq_body = nil case request.content_type when 'application/xml', 'text/xml' rq_body = ::Nokogiri.XML body_text else log :violation, "unexpected content-type '#{request.content_type}'" end rq_body = validate_request_body rq_body, require_id: false # get credentials cr = get_required_credentials # get requester rr = settings.razor_requester # get connector ec = PortfoliosConnector.new(rr, credentials: cr) # issue request qr = ec.insert_portfolio rq_body, indicate_result_by: :qualified_result unless qr.succeeded? log :warning, "failed to post portfolio: #{qr.failure_qualifier.reasons.join(':')}" if r = qr.failure_qualifier.reasons.lookup?('RZ0011') halt 404, {}, "#{r.message}: #{r.details}" else halt 422, {}, "failed to post portfolio" end end status 201 portfolio_id = qr.result and return %Q{<portfolio id="#{portfolio_id}" />} halt 500, {}, "returned response from Razor is not well formed" end |