Skip to content

Commit

Permalink
Merge pull request #6164 from ministryofjustice/ap-4716/update-applic…
Browse files Browse the repository at this point in the history
…ant_search_response_parser

AP-4716: Update applicant search response parser
  • Loading branch information
colinbruce authored Jan 4, 2024
2 parents 748bdef + eb0a8ba commit b9761ba
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 213 deletions.
7 changes: 7 additions & 0 deletions app/lib/message_logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module MessageLogger
def log_message(message)
message = "#{self.class}:: #{message}"
message = Time.zone.now.strftime("%F %T.%L ") + message if Rails.env.development?
Rails.logger.info message
end
end
10 changes: 6 additions & 4 deletions app/services/ccms/parsers/applicant_search_response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def applicant_ccms_reference
private

def process_ccms_reference
return nil if text_from(MATCH_LEVEL_IND_PATH) == "Number Not Matched"
first_match = ni_number_match?(MATCH_LEVEL_IND_PATH)
log_message("Records Matched: #{extracted_record_count}, MatchLevelInds: #{text_from(MATCH_LEVEL_IND_PATH)}, ChosenMatch: #{first_match}")
return nil if first_match.nil?

parse(:extracted_applicant_ccms_reference)
parse(:extracted_applicant_ccms_reference, first_match)
end

def response_type
Expand All @@ -34,8 +36,8 @@ def extracted_record_count
text_from(RECORD_COUNT_PATH)
end

def extracted_applicant_ccms_reference
doc.xpath(APPLICANT_CCMS_REFERENCE_PATH).first&.text
def extracted_applicant_ccms_reference(index = 0)
doc.xpath(APPLICANT_CCMS_REFERENCE_PATH)[index]&.text
end
end
end
Expand Down
14 changes: 12 additions & 2 deletions app/services/ccms/parsers/base_response_parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module CCMS
module Parsers
class BaseResponseParser
include MessageLogger
attr_reader :transaction_request_id, :response, :success, :message

def initialize(tx_request_id, response)
Expand All @@ -14,11 +15,11 @@ def doc
@doc ||= Nokogiri::XML(response.to_s).remove_namespaces!
end

def parse(data_method)
def parse(data_method, *)
check_matching_transaction_request_ids if expect_transaction_request_id_in_response?

extract_result_status
__send__(data_method)
__send__(data_method, *)
end

def extracted_id_matches_request_id?
Expand All @@ -29,6 +30,15 @@ def text_from(xpath)
doc.xpath(xpath).text
end

def ni_number_match?(xpath)
matches = doc.xpath(xpath).map(&:text)
if matches.all?("Number Not Matched")
nil
else
matches.each_index.find { |i| matches[i].include? "Number Matched" }
end
end

private

def expect_transaction_request_id_in_response?
Expand Down
1 change: 1 addition & 0 deletions app/services/ccms/submitters/base_submission_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module CCMS

module Submitters
class BaseSubmissionService
include MessageLogger
attr_accessor :submission

def initialize(submission)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def applicant_search_requestor
def process_records(parser)
applicant_ccms_reference = parser.applicant_ccms_reference
if applicant_ccms_reference.nil?
create_history(:case_ref_obtained, submission.aasm_state, xml_request, response)
history = create_history(:case_ref_obtained, submission.aasm_state, xml_request, response)
log_message("SubmissionHistory: #{history.id}: Creating new applicant in CCMS")
CCMS::Submitters::AddApplicantService.new(submission).call
else
submission.applicant_ccms_reference = applicant_ccms_reference
submission.save!
create_history(:case_ref_obtained, submission.aasm_state, xml_request, response) if submission.obtain_applicant_ref!
history = create_history(:case_ref_obtained, submission.aasm_state, xml_request, response) if submission.obtain_applicant_ref!
log_message("SubmissionHistory: #{history.id}: using existing applicant reference #{applicant_ccms_reference}")
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<env:Header>
<instra:tracking.ecid wsa:IsReferenceParameter="1" xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0" xmlns:wsa="http://www.w3.org/2005/08/addressing">be91808f-e069-40a9-8858-8f2fe35ded25-001db0f4</instra:tracking.ecid>
<instra:tracking.parentComponentInstanceId wsa:IsReferenceParameter="1" xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0" xmlns:wsa="http://www.w3.org/2005/08/addressing">mediator:233108951</instra:tracking.parentComponentInstanceId>
<instra:tracking.parentReferenceId wsa:IsReferenceParameter="1" xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0" xmlns:wsa="http://www.w3.org/2005/08/addressing">mediator:233108951:dbc7479a-3dad-11ed-9fed-0a58a9feac03:req</instra:tracking.parentReferenceId>
<instra:tracking.FlowEventId wsa:IsReferenceParameter="1" xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0" xmlns:wsa="http://www.w3.org/2005/08/addressing">597852472</instra:tracking.FlowEventId>
<instra:tracking.FlowId wsa:IsReferenceParameter="1" xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0" xmlns:wsa="http://www.w3.org/2005/08/addressing">24180278</instra:tracking.FlowId>
<instra:tracking.CorrelationFlowId wsa:IsReferenceParameter="1" xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0" xmlns:wsa="http://www.w3.org/2005/08/addressing">0000ODuNCW9EoId5PfS4yd1Z6CJA001^Aa</instra:tracking.CorrelationFlowId>
<instra:tracking.quiescing.SCAEntityId wsa:IsReferenceParameter="1" xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0" xmlns:wsa="http://www.w3.org/2005/08/addressing">10064</instra:tracking.quiescing.SCAEntityId>
<instra:tracking.ecid xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">be91808f-e069-40a9-8858-8f2fe35ded25-001db0f4</instra:tracking.ecid>
<instra:tracking.FlowEventId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">597852532</instra:tracking.FlowEventId>
<instra:tracking.FlowId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">24180278</instra:tracking.FlowId>
<instra:tracking.CorrelationFlowId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">0000ODuNCW9EoId5PfS4yd1Z6CJA001^Aa</instra:tracking.CorrelationFlowId>
<instra:tracking.quiescing.SCAEntityId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">10064</instra:tracking.quiescing.SCAEntityId>
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
<wsa:Action>process</wsa:Action>
<wsa:MessageID>urn:e7cafda1-3dad-11ed-9fed-0a58a9feac03</wsa:MessageID>
<wsa:RelatesTo>urn:dbc76eae-3dad-11ed-9fed-0a58a9feac03</wsa:RelatesTo>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
<wsa:ReferenceParameters>
<instra:tracking.ecid xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">be91808f-e069-40a9-8858-8f2fe35ded25-001db0f4</instra:tracking.ecid>
<instra:tracking.conversationId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">urn:dbc76eae-3dad-11ed-9fed-0a58a9feac03</instra:tracking.conversationId>
<instra:tracking.FlowEventId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">597852536</instra:tracking.FlowEventId>
<instra:tracking.FlowId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">24180278</instra:tracking.FlowId>
<instra:tracking.CorrelationFlowId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">0000ODuNCW9EoId5PfS4yd1Z6CJA001^Aa</instra:tracking.CorrelationFlowId>
<instra:tracking.quiescing.SCAEntityId xmlns:instra="http://xmlns.oracle.com/sca/tracking/1.0">10064</instra:tracking.quiescing.SCAEntityId>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:FaultTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:FaultTo>
</env:Header>
<env:Body>
<ClientInqRS xmlns="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIM" xmlns:msg="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIM" xmlns:oracle-xsl-mapper="http://www.oracle.com/xsl/mapper/schemas" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<header:HeaderRS xmlns:header="http://legalservices.gov.uk/Enterprise/Common/1.0/Header">
<header:TransactionID>202209261614043422799016219</header:TransactionID>
<header:RequestDetails>
<header:TransactionRequestID>202209261614043422799016219</header:TransactionRequestID>
<header:Language>ENG</header:Language>
<header:UserLoginID>my_login</header:UserLoginID>
<header:UserRole>my_role</header:UserRole>
</header:RequestDetails>
<header:Status>
<header:Status>Success</header:Status>
<header:StatusFreeText>End of Get Party details process.</header:StatusFreeText>
</header:Status>
</header:HeaderRS>
<msg:RecordCount>
<common:MaxRecordsToFetch xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">200</common:MaxRecordsToFetch>
<common:RecordsFetched xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">2</common:RecordsFetched>
<common:RetriveDataOnMaxCount xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">false</common:RetriveDataOnMaxCount>
</msg:RecordCount>
<msg:ClientList>
<msg:Client>
<client:Name xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">
<common:Title xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">MS.</common:Title>
<common:Surname xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">SHORT</common:Surname>
<common:FirstName xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">carla</common:FirstName>
<common:MiddleName xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">JENNA</common:MiddleName>
<common:SurnameAtBirth xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">short</common:SurnameAtBirth>
<common:FullName xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">carla SHORT</common:FullName>
</client:Name>
<client:DateOfBirth xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">1987-07-26</client:DateOfBirth>
<client:Gender xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">Female</client:Gender>
<client:PostalCode xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">CV34 8YA</client:PostalCode>
<client:ClientReferenceNumber xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">5590639</client:ClientReferenceNumber>
<client:HomeOfficeReference xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">NA</client:HomeOfficeReference>
<client:NINumber xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">BR123456C</client:NINumber>
<client:MatchLevelInd xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">Number Not Matched</client:MatchLevelInd>
</msg:Client>
<msg:Client>
<client:Name xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">
<common:Title xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">MS.</common:Title>
<common:Surname xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">Short</common:Surname>
<common:FirstName xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">CARLA</common:FirstName>
<common:SurnameAtBirth xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">SHORT</common:SurnameAtBirth>
<common:FullName xmlns:common="http://legalservices.gov.uk/Enterprise/Common/1.0/Common">CARLA Short</common:FullName>
</client:Name>
<client:DateOfBirth xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">1987-07-26</client:DateOfBirth>
<client:Gender xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">Female</client:Gender>
<client:PostalCode xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">DE56 9DS</client:PostalCode>
<client:ClientReferenceNumber xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">2499559</client:ClientReferenceNumber>
<client:HomeOfficeReference xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">07597530156</client:HomeOfficeReference>
<client:NINumber xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">BR123456C</client:NINumber>
<client:MatchLevelInd xmlns:client="http://legalservices.gov.uk/CCMS/ClientManagement/Client/1.0/ClientBIO">Number Not Matched</client:MatchLevelInd>
</msg:Client>
</msg:ClientList>
</ClientInqRS>
</env:Body>
</env:Envelope>
Loading

0 comments on commit b9761ba

Please sign in to comment.