From 6091a1e82f54390c43de798dce1e734673b6ca38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Tue, 24 May 2022 11:33:22 +0100 Subject: [PATCH] Import should not create an organisation when the legacy ID is missing --- .../imports/case_logs_import_service.rb | 18 ++++-------------- .../00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml | 16 ++++++++-------- .../0ead17cb-1668-442d-898c-0d52879ff592.xml | 12 ++++++------ .../166fc004-392e-47a8-acb8-1c018734882b.xml | 12 ++++++------ .../imports/case_logs_import_service_spec.rb | 1 + 5 files changed, 25 insertions(+), 34 deletions(-) diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb index 123cacc93..b3edab25b 100644 --- a/app/services/imports/case_logs_import_service.rb +++ b/app/services/imports/case_logs_import_service.rb @@ -47,8 +47,8 @@ module Imports # Required fields for status complete or logic to work # Note: order matters when we derive from previous values (attributes parameter) attributes["startdate"] = compose_date(xml_doc, "DAY", "MONTH", "YEAR") - attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID", "OWNINGORGNAME", "HCNUM") - attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "MANINGORGID", "MANINGORGNAME", "MANHCNUM") + attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID") + attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "MANINGORGID") attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint") attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a") attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b") @@ -306,23 +306,13 @@ module Imports end end - def find_organisation_id(xml_doc, id_field, name_field, reg_field) + def find_organisation_id(xml_doc, id_field) old_visible_id = unsafe_string_as_integer(xml_doc, id_field) organisation = Organisation.find_by(old_visible_id:) # Quick hack: should be removed when all organisations are imported # Will fail in the future if the organisation is missing if organisation.nil? - organisation = Organisation.new - organisation.old_visible_id = old_visible_id - let_type = unsafe_string_as_integer(xml_doc, "landlord") - organisation.provider_type = if let_type == PRP_LA[:local_authority] - 1 - else - 2 - end - organisation.name = string_or_nil(xml_doc, name_field) - organisation.housing_registration_no = string_or_nil(xml_doc, reg_field) - organisation.save! + raise "Organisation not found with legacy ID #{old_visible_id}" end organisation.id end diff --git a/spec/fixtures/softwire_imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml b/spec/fixtures/softwire_imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml index f5a5c87e4..e9835d1e1 100644 --- a/spec/fixtures/softwire_imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml +++ b/spec/fixtures/softwire_imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml @@ -3,8 +3,8 @@ 2022-CORE-SR-GN 00d2343e-d5fa-4c89-8400-ec3854b0f2b4 c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa - 35459cb12d312a472d8585b97b865917e8f2144e - 35459cb12d312a472d8585b97b865917e8f2144e + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 2022-04-14T16:01:30.369241Z 2022-04-14T16:01:30.369241Z submitted-valid @@ -407,13 +407,13 @@ E12000001 - 107178 - Believe Housing Ltd. - Believe Housing Ltd. - 8076 - 8076 + 1 + DLUHC + DLUHC + 655 + 655 - 107178 + 1 3 diff --git a/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml b/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml index d34952c31..8413abb7e 100644 --- a/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml +++ b/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml @@ -431,13 +431,13 @@ E12000003 - 1034 - LEEDS & YORKSHIRE HA Ltd - LEEDS & YORKSHIRE HA Ltd - LH0704 - LH0704 + 1 + DLUHC + DLUHC + 655 + 655 - 1034 + 1 diff --git a/spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml b/spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml index bb351d7e7..631f41cae 100644 --- a/spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml +++ b/spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml @@ -3,8 +3,8 @@ 2021-CORE-IR-GN 166fc004-392e-47a8-acb8-1c018734882b e29c492473446dca4d50224f2bb7cf965a261d6f - 26139d1be7a44ebb1af23d3f8882c14025e9903c - 26139d1be7a44ebb1af23d3f8882c14025e9903c + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 2022-04-12T14:10:59.953121Z 2022-04-12T14:10:59.953121Z submitted-valid @@ -411,13 +411,13 @@ E12000008 - 107138 - 1 Test - 1 Test + 1 + DLUHC + DLUHC 655 655 - 107138 + 1 diff --git a/spec/services/imports/case_logs_import_service_spec.rb b/spec/services/imports/case_logs_import_service_spec.rb index 82f05472c..eb8382cd8 100644 --- a/spec/services/imports/case_logs_import_service_spec.rb +++ b/spec/services/imports/case_logs_import_service_spec.rb @@ -40,6 +40,7 @@ RSpec.describe Imports::CaseLogsImportService do FactoryBot.create(:user, old_user_id: "c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa") FactoryBot.create(:user, old_user_id: "e29c492473446dca4d50224f2bb7cf965a261d6f") + FactoryBot.create(:organisation, old_visible_id: "1", provider_type: "PRP") end it "successfully create all case logs" do