|
|
|
@ -59,8 +59,16 @@ class Log < ApplicationRecord |
|
|
|
|
|
|
|
|
|
|
|
def process_uprn_change! |
|
|
|
def process_uprn_change! |
|
|
|
if uprn.present? |
|
|
|
if uprn.present? |
|
|
|
presenter = uprn_presenter |
|
|
|
service = UprnClient.new(uprn) |
|
|
|
return if presenter.nil? |
|
|
|
service.call |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if service.error.present? |
|
|
|
|
|
|
|
errors.add(:uprn, :uprn_error, message: service.error) |
|
|
|
|
|
|
|
errors.add(:uprn_selection, :uprn_error, message: service.error) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
presenter = UprnDataPresenter.new(service.result) |
|
|
|
|
|
|
|
|
|
|
|
self.uprn_known = 1 |
|
|
|
self.uprn_known = 1 |
|
|
|
self.uprn_confirmed = nil unless skip_update_uprn_confirmed |
|
|
|
self.uprn_confirmed = nil unless skip_update_uprn_confirmed |
|
|
|
@ -74,28 +82,14 @@ class Log < ApplicationRecord |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def uprn_presenter |
|
|
|
|
|
|
|
@uprn_presenter ||= begin |
|
|
|
|
|
|
|
service = UprnClient.new(uprn) |
|
|
|
|
|
|
|
service.call |
|
|
|
|
|
|
|
return if service.result.blank? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if service.error.present? |
|
|
|
|
|
|
|
errors.add(:uprn, :uprn_error, message: service.error) |
|
|
|
|
|
|
|
errors.add(:uprn_selection, :uprn_error, message: service.error) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UprnDataPresenter.new(service.result) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_address_change! |
|
|
|
def process_address_change! |
|
|
|
if uprn_selection.present? || select_best_address_match.present? |
|
|
|
if uprn_selection.present? || select_best_address_match.present? |
|
|
|
if select_best_address_match |
|
|
|
if select_best_address_match |
|
|
|
presenter = address_presenter |
|
|
|
service = AddressClient.new(address_string) |
|
|
|
return nil if presenter.nil? |
|
|
|
service.call |
|
|
|
|
|
|
|
return nil if service.result.blank? || service.error.present? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
presenter = AddressDataPresenter.new(service.result.first) |
|
|
|
os_match_threshold_for_bulk_upload = 0.7 |
|
|
|
os_match_threshold_for_bulk_upload = 0.7 |
|
|
|
if presenter.match >= os_match_threshold_for_bulk_upload |
|
|
|
if presenter.match >= os_match_threshold_for_bulk_upload |
|
|
|
self.uprn_selection = presenter.uprn |
|
|
|
self.uprn_selection = presenter.uprn |
|
|
|
@ -122,21 +116,6 @@ class Log < ApplicationRecord |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def address_presenter |
|
|
|
|
|
|
|
@address_presenter ||= begin |
|
|
|
|
|
|
|
service = AddressClient.new(address_string) |
|
|
|
|
|
|
|
service.call |
|
|
|
|
|
|
|
return nil if service.result.blank? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if service.error.present? |
|
|
|
|
|
|
|
errors.add(:address_line1_input, :address_error, message: service.error) |
|
|
|
|
|
|
|
errors.add(:postcode_full_input, :address_error, message: service.error) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
AddressDataPresenter.new(service.result.first) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def address_string |
|
|
|
def address_string |
|
|
|
"#{address_line1_input}, #{postcode_full_input}" |
|
|
|
"#{address_line1_input}, #{postcode_full_input}" |
|
|
|
end |
|
|
|
end |
|
|
|
@ -298,7 +277,7 @@ class Log < ApplicationRecord |
|
|
|
nationality_all_group&.zero? || nationality_all_group == 826 |
|
|
|
nationality_all_group&.zero? || nationality_all_group == 826 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
# Handle logs that are older than previous collection start date |
|
|
|
# Handle logs that are older than previous collection start date |
|
|
|
def older_than_previous_collection_year? |
|
|
|
def older_than_previous_collection_year? |
|
|
|
|