Handle QrMatching response - mock
This commit is contained in:
@@ -8,22 +8,25 @@ class MatchAppearanceReleasesJob < ApplicationJob
|
|||||||
|
|
||||||
payload = { request_id: matching_request.id, bucket: aws_bucket_name, files: attachments}
|
payload = { request_id: matching_request.id, bucket: aws_bucket_name, files: attachments}
|
||||||
response = BrayniacAI::AppearanceReleaseMatching.match_attachments payload
|
response = BrayniacAI::AppearanceReleaseMatching.match_attachments payload
|
||||||
|
# BrayniacAI::QrMatching.enable_logging
|
||||||
|
# response = BrayniacAI::QrMatching.create! payload
|
||||||
|
|
||||||
matches = response[:matches] || []
|
matches = response[:matches] || []
|
||||||
errors = response[:errors] || []
|
|
||||||
|
|
||||||
handle_matches matches, project
|
handle_matches matches, project
|
||||||
handle_errors errors
|
matching_request.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def handle_matches(matches, project)
|
def handle_matches(matches, project)
|
||||||
matches.each do |match|
|
matches.each do |match|
|
||||||
contract = match[:contract]
|
contract = match[:contracts].blank? ? nil : match[:contracts].first
|
||||||
headshot = match[:headshot]
|
headshot = match[:headshots].blank? ? nil : match[:headshots].first
|
||||||
identifier = match[:identifier]
|
identifier = match[:identifier]
|
||||||
|
|
||||||
|
next if contract.nil? && headshot.nil?
|
||||||
|
|
||||||
identified_release = identifier.blank? ? nil : AppearanceRelease.find_by(identifier: identifier)
|
identified_release = identifier.blank? ? nil : AppearanceRelease.find_by(identifier: identifier)
|
||||||
if identified_release.nil?
|
if identified_release.nil?
|
||||||
create_release project, contract, headshot, identifier
|
create_release project, contract, headshot, identifier
|
||||||
@@ -33,13 +36,6 @@ class MatchAppearanceReleasesJob < ApplicationJob
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_errors(errors)
|
|
||||||
logger.error "== MATCHING ERRORS ==" unless errors.empty?
|
|
||||||
errors.each do |error|
|
|
||||||
logger.error "[#{error[:error_code]}] #{error[:file]}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_release(project, contract, headshot, identifier)
|
def create_release(project, contract, headshot, identifier)
|
||||||
random_contract_no = AppearanceRelease.random_contract_number.to_s
|
random_contract_no = AppearanceRelease.random_contract_number.to_s
|
||||||
is_incomplete = contract.nil? || headshot.nil?
|
is_incomplete = contract.nil? || headshot.nil?
|
||||||
|
|||||||
@@ -15,12 +15,17 @@ module BrayniacAI
|
|||||||
pdfs = []
|
pdfs = []
|
||||||
images = []
|
images = []
|
||||||
matches = []
|
matches = []
|
||||||
errors = []
|
|
||||||
|
|
||||||
# Use first file for the error entry
|
# Use first file for the error entry
|
||||||
first_attachment = attachments.shift
|
first_attachment = attachments.shift
|
||||||
unless first_attachment.nil?
|
|
||||||
errors << { file: first_attachment, error_code: 1 }
|
if first_attachment.present?
|
||||||
|
matches << {
|
||||||
|
headshots: [],
|
||||||
|
contracts: [],
|
||||||
|
unknowns: [first_attachment],
|
||||||
|
identifier: ''
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
attachments.each do |attachment|
|
attachments.each do |attachment|
|
||||||
@@ -45,18 +50,20 @@ module BrayniacAI
|
|||||||
pdf = pair_element2
|
pdf = pair_element2
|
||||||
image = pair_element1
|
image = pair_element1
|
||||||
end
|
end
|
||||||
if pdf.nil? || image.nil?
|
headshots = image.present? ? [image] : []
|
||||||
matches << { headshot: image } if pdf.nil?
|
contracts = pdf.present? ? [pdf] : []
|
||||||
matches << { contract: pdf } if image.nil?
|
|
||||||
else
|
matches << {
|
||||||
matches << { headshot: image, contract: pdf, identifier: '' }
|
headshots: headshots,
|
||||||
end
|
contracts: contracts,
|
||||||
|
unknowns: [],
|
||||||
|
identifier: ''
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
{
|
{
|
||||||
request_id: request_data[:request_id],
|
request_id: request_data[:request_id],
|
||||||
matches: matches,
|
matches: matches
|
||||||
errors: errors
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user