Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VI-920] updates to MPI add_person_proxy & orchestrated search methods #20221

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions app/models/mpi_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,10 @@ def mpi_response_is_cached?(user_key: get_user_key)
end

# The status of the MPI Add Person Proxy Add call. An Orchestrated MVI Search needs to be made before an
# MPI add person proxy addcall is made. The response is recached afterwards so the new ids can be accessed
# on the next call.
# MPI add person proxy add call is made.
def add_person_proxy
search_response = mpi_service.find_profile_by_attributes_with_orch_search(first_name: user_first_name,
last_name: user_last_name,
birth_date: user_birth_date,
ssn: user_ssn,
search_response = mpi_service.find_profile_by_identifier_with_orch_search(identifier: user_icn,
identifier_type: MPI::Constants::ICN,
edipi: user_edipi)
if search_response.ok?
@mvi_response = search_response
Expand Down Expand Up @@ -232,11 +229,11 @@ def find_profile
end

def add_ids(response)
# set new ids in the profile and recache the response
# set new ids in the profile and delete the cached response
profile.birls_id = response.parsed_codes[:birls_id].presence
profile.participant_id = response.parsed_codes[:participant_id].presence

cache(user_uuid, mvi_response) if mvi_response.cache?
delete_cached_response if mvi_response.cache?
end

def response_from_redis_or_service(user_key:)
Expand All @@ -248,6 +245,11 @@ def response_from_redis_or_service(user_key:)
end
end

def delete_cached_response
self.class.delete(get_user_key)
@mvi_response = nil
end

def mpi_service
@service ||= MPI::Service.new
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mpi/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ module Constants
UPDATE_PROFILE_TYPE = 'update_profile'
FIND_PROFILE_TYPE = 'find_profile'
FIND_PROFILE_BY_IDENTIFIER_TYPE = 'find_profile_by_identifier'
FIND_PROFILE_BY_IDENTIFIER_ORCH_SEARCH_TYPE = 'find_profile_by_identifier_orch_search'
FIND_PROFILE_BY_EDIPI_TYPE = 'find_profile_by_edipi'
FIND_PROFILE_BY_ATTRIBUTES_TYPE = 'find_profile_by_attributes'
FIND_PROFILE_BY_ATTRIBUTES_ORCH_SEARCH_TYPE = 'find_profile_by_attributes_orch_search'
FIND_PROFILE_BY_FACILITY_TYPE = 'find_profile_by_facility'

QUERY_IDENTIFIERS = [ICN = 'ICN', IDME_UUID = 'idme', LOGINGOV_UUID = 'logingov', MHV_UUID = 'mhv'].freeze
Expand Down
26 changes: 22 additions & 4 deletions lib/mpi/messages/find_profile_by_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
module MPI
module Messages
class FindProfileByIdentifier
attr_reader :identifier, :identifier_type, :search_type
attr_reader :identifier, :identifier_type, :edipi, :orch_search, :search_type

def initialize(identifier:, identifier_type:, search_type: Constants::CORRELATION_WITH_RELATIONSHIP_DATA)
def initialize(identifier:, identifier_type:, edipi: nil, orch_search: false,
search_type: Constants::CORRELATION_WITH_RELATIONSHIP_DATA)
@identifier = identifier
@identifier_type = identifier_type
@orch_search = orch_search
@edipi = edipi
@search_type = search_type
end

def perform
validate_types
validate_required_fields
Messages::RequestBuilder.new(extension: Constants::FIND_PROFILE, body: build_body).perform
rescue => e
Rails.logger.error "[FindProfileByIdentifier] Failed to build request: #{e.message}"
Expand All @@ -25,10 +28,11 @@ def perform

private

def validate_types
def validate_required_fields
unless Constants::QUERY_IDENTIFIERS.include?(identifier_type)
raise Errors::ArgumentError, "Identifier type is not supported, identifier_type=#{identifier_type}"
end
raise Errors::ArgumentError, 'EDIPI is required for orch_search' if edipi.blank? && orch_search
end

def correlation_identifier
Expand All @@ -47,6 +51,7 @@ def correlation_identifier
def build_body
body = RequestHelper.build_control_act_process_element
body << RequestHelper.build_code(code: Constants::FIND_PROFILE_CONTROL_ACT_PROCESS)
body << build_data_enterer if orch_search
body << query_by_parameter
body
end
Expand All @@ -59,6 +64,19 @@ def query_by_parameter
def build_parameter_list
el = RequestHelper.build_parameter_list_element
el << RequestHelper.build_identifier(identifier: correlation_identifier, root:)
el << RequestHelper.build_vba_orchestration if orch_search
el
end

def build_data_enterer
element = RequestHelper.build_data_enterer_element
element << build_assigned_person
end

def build_assigned_person
element = RequestHelper.build_assigned_person_element
element << RequestHelper.build_represented_organization(edipi:)
element
end

def root
Expand Down
42 changes: 20 additions & 22 deletions lib/mpi/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ def find_profile_by_identifier(identifier:,
MPI::Services::FindProfileResponseCreator.new(type: Constants::FIND_PROFILE_BY_IDENTIFIER_TYPE, error: e).perform
end

def find_profile_by_identifier_with_orch_search(identifier:,
identifier_type:,
edipi:,
search_type: Constants::CORRELATION_WITH_RELATIONSHIP_DATA)
with_monitoring do
raw_response = perform(:post, '',
MPI::Messages::FindProfileByIdentifier.new(identifier:,
identifier_type:,
edipi:,
orch_search: true,
search_type:).perform,
soapaction: Constants::FIND_PROFILE)
MPI::Services::FindProfileResponseCreator.new(type: Constants::FIND_PROFILE_BY_IDENTIFIER_ORCH_SEARCH_TYPE,
response: raw_response).perform
end
rescue *CONNECTION_ERRORS => e
MPI::Services::FindProfileResponseCreator.new(type: Constants::FIND_PROFILE_BY_IDENTIFIER_ORCH_SEARCH_TYPE,
error: e).perform
end

def find_profile_by_edipi(edipi:, search_type: Constants::CORRELATION_WITH_RELATIONSHIP_DATA)
with_monitoring do
raw_response = perform(:post, '',
Expand Down Expand Up @@ -126,28 +146,6 @@ def find_profile_by_facility(facility_id:, vista_id:, search_type: Constants::CO
MPI::Services::FindProfileResponseCreator.new(type: Constants::FIND_PROFILE_BY_FACILITY_TYPE, error: e).perform
end

def find_profile_by_attributes_with_orch_search(first_name:,
last_name:,
birth_date:,
ssn:,
edipi:)
with_monitoring do
raw_response = perform(:post, '',
MPI::Messages::FindProfileByAttributes.new(first_name:,
last_name:,
birth_date:,
ssn:,
orch_search: true,
edipi:).perform,
soapaction: Constants::FIND_PROFILE)
MPI::Services::FindProfileResponseCreator.new(type: Constants::FIND_PROFILE_BY_ATTRIBUTES_ORCH_SEARCH_TYPE,
response: raw_response).perform
end
rescue *CONNECTION_ERRORS => e
MPI::Services::FindProfileResponseCreator.new(type: Constants::FIND_PROFILE_BY_ATTRIBUTES_ORCH_SEARCH_TYPE,
error: e).perform
end

def find_profile_by_attributes(first_name:,
last_name:,
birth_date:,
Expand Down
8 changes: 2 additions & 6 deletions modules/claims_api/spec/requests/v1/forms/526_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1317,13 +1317,9 @@ def obj.class
VCR.use_cassette('claims_api/bgs/claims/claims') do
VCR.use_cassette('claims_api/brd/countries') do
VCR.use_cassette('claims_api/mpi/add_person/add_person_success') do
VCR.use_cassette('claims_api/mpi/find_candidate/orch_search_with_attributes') do
VCR.use_cassette('claims_api/mpi/find_candidate/orch_search_with_identifier') do
allow_any_instance_of(MPIData)
.to receive(:mvi_response).and_return(multi_profile)
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_identifier)
.and_return(mpi_profile_response)
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_attributes_with_orch_search)
.and_return(mpi_profile_response)

post path, params: data, headers: auth_header

Expand All @@ -1340,7 +1336,7 @@ def obj.class
VCR.use_cassette('claims_api/bgs/claims/claims') do
VCR.use_cassette('claims_api/brd/countries') do
VCR.use_cassette('claims_api/mpi/add_person/add_person_success') do
VCR.use_cassette('claims_api/mpi/find_candidate/orch_search_with_attributes') do
VCR.use_cassette('claims_api/mpi/find_candidate/orch_search_with_identifier') do
allow_any_instance_of(ClaimsApi::Veteran).to receive(:mpi_record?).and_return(true)
allow_any_instance_of(MPIData).to receive(:mvi_response)
.and_return(profile_with_edipi)
Expand Down
22 changes: 10 additions & 12 deletions spec/lib/mpi/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -840,27 +840,25 @@
end
end

describe '#find_profile_by_attributes_with_orch_search' do
describe '#find_profile_by_identifier_with_orch_search' do
subject do
mpi_service.find_profile_by_attributes_with_orch_search(first_name:,
last_name:,
birth_date:,
ssn:,
edipi:)
mpi_service.find_profile_by_identifier_with_orch_search(identifier:,
identifier_type:,
edipi:,
search_type:)
end

let(:statsd_caller) { 'find_profile_by_attributes_with_orch_search' }
let(:first_name) { 'some-first-name' }
let(:last_name) { 'some-last-name' }
let(:birth_date) { '19700101' }
let(:ssn) { 'some-ssn' }
let(:statsd_caller) { 'find_profile_by_identifier_with_orch_search' }
let(:identifier) { 'some-icn' }
let(:identifier_type) { MPI::Constants::ICN }
let(:edipi) { 'some-edipi' }
let(:search_type) { 'some-search-type' }

context 'malformed request' do
let(:edipi) { nil }
let(:missing_keys) { [:edipi] }
let(:expected_error) { MPI::Errors::ArgumentError }
let(:expected_error_message) { "Required values missing: #{missing_keys}" }
let(:expected_error_message) { 'EDIPI is required for orch_search' }

it 'raises a required values missing error' do
expect { subject }.to raise_error(expected_error, expected_error_message)
Expand Down
13 changes: 10 additions & 3 deletions spec/models/mpi_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
end

before do
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_attributes_with_orch_search)
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_identifier_with_orch_search)
.and_return(profile_response)
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_identifier).and_return(profile_response)
allow_any_instance_of(MPI::Service).to receive(:add_person_proxy).and_return(add_response)
Expand All @@ -96,14 +96,21 @@
expect(mpi_data.participant_id).to eq(participant_id)
end

it 'clears the cached MPI response' do
mpi_data.status
expect(mpi_data).to be_mpi_response_is_cached
subject
expect(mpi_data).not_to be_mpi_response_is_cached
end

it 'returns the successful response' do
expect(subject.ok?).to be(true)
end
end

context 'with a failed search' do
before do
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_attributes_with_orch_search)
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_identifier_with_orch_search)
.and_return(profile_response_error)
end

Expand All @@ -117,7 +124,7 @@
let(:add_response_error) { create(:add_person_server_error_response) }

before do
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_attributes_with_orch_search)
allow_any_instance_of(MPI::Service).to receive(:find_profile_by_identifier_with_orch_search)
.and_return(profile_response)
allow_any_instance_of(MPI::Service).to receive(:add_person_proxy).and_return(add_response_error)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@

it 'when correct form id is passed, it supports creating mvi user' do
VCR.use_cassette('mpi/add_person/add_person_success') do
VCR.use_cassette('mpi/find_candidate/orch_search_with_attributes') do
VCR.use_cassette('mpi/find_candidate/orch_search_with_identifier') do
expect(subject).to validate(:post, '/v0/mvi_users/{id}', 200, headers.merge('id' => '21-0966'))
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/v0/mvi_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

it 'return 200, add user to MPI' do
VCR.use_cassette('mpi/add_person/add_person_success') do
VCR.use_cassette('mpi/find_candidate/orch_search_with_attributes') do
VCR.use_cassette('mpi/find_candidate/orch_search_with_identifier') do
# expect success to be achieved by calling MPI's add_person_proxy
expect_any_instance_of(MPIData).to receive(:add_person_proxy).once.and_call_original
post "/v0/mvi_users/#{valid_form_id}"
Expand Down
Loading
Loading