Class: MPI::Responses::AddParser

Inherits:
ParserBase show all
Includes:
Identity::Parsers::GCIds, SentryLogging
Defined in:
lib/mpi/responses/add_parser.rb

Overview

Parses an MVI response and returns an MviProfile

Constant Summary collapse

ACKNOWLEDGEMENT_DETAIL_CODE_XPATH =
'acknowledgement/acknowledgementDetail/code'
ACKNOWLEDGEMENT_DETAIL_TEXT_XPATH =
'acknowledgement/acknowledgementDetail/text'
ACKNOWLEDGEMENT_TARGET_MESSAGE_ID_EXTENSION_XPATH =
'acknowledgement/targetMessage/id/@extension'
BODY_XPATH =
'env:Envelope/env:Body/idm:MCCI_IN000002UV01'
CODE_XPATH =
'acknowledgement/typeCode/@code'

Constants included from Identity::Parsers::GCIdsConstants

Identity::Parsers::GCIdsConstants::ACTIVE_MHV_IDS_REGEX, Identity::Parsers::GCIdsConstants::BIRLS_IDS_REGEX, Identity::Parsers::GCIdsConstants::CERNER_FACILITY_IDS_REGEX, Identity::Parsers::GCIdsConstants::CERNER_ID_REGEX, Identity::Parsers::GCIdsConstants::DOD_ROOT_OID, Identity::Parsers::GCIdsConstants::EDIPI_REGEX, Identity::Parsers::GCIdsConstants::ICN_ASSIGNING_AUTHORITY_ID, Identity::Parsers::GCIdsConstants::ICN_REGEX, Identity::Parsers::GCIdsConstants::IDENTIFIERS_SPLIT_TOKEN, Identity::Parsers::GCIdsConstants::IDME_ID_REGEX, Identity::Parsers::GCIdsConstants::IDS_SPLIT_TOKEN, Identity::Parsers::GCIdsConstants::ID_MAPPINGS, Identity::Parsers::GCIdsConstants::LOGINGOV_ID_REGEX, Identity::Parsers::GCIdsConstants::MHV_IDS_REGEX, Identity::Parsers::GCIdsConstants::MHV_IEN_REGEX, Identity::Parsers::GCIdsConstants::PERMANENT_ICN_REGEX, Identity::Parsers::GCIdsConstants::SEC_ID_REGEX, Identity::Parsers::GCIdsConstants::VA_ROOT_OID, Identity::Parsers::GCIdsConstants::VBA_CORP_ID_REGEX, Identity::Parsers::GCIdsConstants::VET360_ID_REGEX, Identity::Parsers::GCIdsConstants::VHA_FACILITY_IDS_REGEX

Constants inherited from ParserBase

ParserBase::EXTERNAL_RESPONSE_CODES

Instance Method Summary collapse

Methods included from Identity::Parsers::GCIds

#build_hash, #parse_string_gcids, #parse_xml_gcids, #select, #select_extension, #select_icn_with_aaid, #select_token_position

Methods included from Identity::Parsers::GCIdsHelper

#sanitize_edipi, #sanitize_id, #sanitize_id_array

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods inherited from ParserBase

#failed_or_invalid?, #failed_request?, #invalid_request?, #locate_element, #locate_elements, #unknown_error?

Constructor Details

#initialize(response) ⇒ ProfileParser

Creates a new parser instance.

Parameters:

  • response (struct Faraday::Env)

    the Faraday response



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mpi/responses/add_parser.rb', line 24

def initialize(response)
  @original_body = locate_element(response.body, BODY_XPATH)
  @code = locate_element(@original_body, CODE_XPATH)
  @transaction_id = response.response_headers['x-global-transaction-id']

  if failed_or_invalid?
    PersonalInformationLog.create(
      error_class: 'MPI::Errors',
      data: {
        payload: response.body
      }
    )
  end
end

Instance Method Details

#error_details(mpi_codes) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mpi/responses/add_parser.rb', line 50

def error_details(mpi_codes)
  error_details = {
    ack_detail_code: @code,
    id_extension: locate_element(@original_body, ACKNOWLEDGEMENT_TARGET_MESSAGE_ID_EXTENSION_XPATH),
    error_texts: []
  }
  error_text_nodes = locate_elements(@original_body, ACKNOWLEDGEMENT_DETAIL_TEXT_XPATH)
  if error_text_nodes.nil?
    error_details[:error_texts] = error_text_nodes
  else
    error_text_nodes.each do |node|
      error_text = node.text || node&.nodes&.first&.value
      error_details[:error_texts].append(error_text) unless error_details[:error_texts].include?(error_text)
    end
  end
  mpi_codes[:error_details] = error_details
  mpi_codes
rescue
  mpi_codes
end

#parseArray

Parse the response.

Returns:

  • (Array)

    Possible list of codes associated with request



42
43
44
45
46
47
48
# File 'lib/mpi/responses/add_parser.rb', line 42

def parse
  raw_codes = locate_elements(@original_body, ACKNOWLEDGEMENT_DETAIL_CODE_XPATH)
  return [] unless raw_codes

  attributes = raw_codes.map(&:attributes)
  parse_ids(attributes).merge({ transaction_id: @transaction_id })
end

#parse_ids(attributes) ⇒ Object (private)

rubocop:disable Metrics/MethodLength



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
# File 'lib/mpi/responses/add_parser.rb', line 78

def parse_ids(attributes)
  codes = { other: [] }
  attributes.each do |attribute|
    case attribute[:code]
    when /BRLS/
      codes[:birls_id] = sanitize_id(attribute[:code])
    when /CORP/
      codes[:participant_id] = sanitize_id(attribute[:code])
    when /200VIDM/
      codes[:idme_uuid] = sanitize_uuid(attribute[:code])
    when /200VLGN/
      codes[:logingov_uuid] = sanitize_uuid(attribute[:code])
    when /200DOD/
      codes[:edipi] = sanitize_edipi(attribute[:code])
    else
      if attribute[:displayName] == 'ICN'
        codes[:icn] = attribute[:code]
      else
        codes[:other].append(attribute)
      end
    end
  end
  codes.delete(:other) if codes[:other].empty?
  codes
end

#sanitize_uuid(full_identifier) ⇒ Object (private)



73
74
75
# File 'lib/mpi/responses/add_parser.rb', line 73

def sanitize_uuid(full_identifier)
  full_identifier.split(IDENTIFIERS_SPLIT_TOKEN).first
end