Browse Source

Import should not create an organisation when the legacy ID is missing

pull/604/head
Stéphane Meny 3 years ago
parent
commit
6091a1e82f
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 18
      app/services/imports/case_logs_import_service.rb
  2. 16
      spec/fixtures/softwire_imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml
  3. 12
      spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
  4. 12
      spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml
  5. 1
      spec/services/imports/case_logs_import_service_spec.rb

18
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

16
spec/fixtures/softwire_imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml vendored

@ -3,8 +3,8 @@
<meta:form-name>2022-CORE-SR-GN</meta:form-name>
<meta:document-id>00d2343e-d5fa-4c89-8400-ec3854b0f2b4</meta:document-id>
<meta:owner-user-id>c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa</meta:owner-user-id>
<meta:owner-institution-id>35459cb12d312a472d8585b97b865917e8f2144e</meta:owner-institution-id>
<meta:managing-institution-id>35459cb12d312a472d8585b97b865917e8f2144e</meta:managing-institution-id>
<meta:owner-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:owner-institution-id>
<meta:managing-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:managing-institution-id>
<meta:created-date>2022-04-14T16:01:30.369241Z</meta:created-date>
<meta:modified-date>2022-04-14T16:01:30.369241Z</meta:modified-date>
<meta:status>submitted-valid</meta:status>
@ -407,13 +407,13 @@
<PLOACODE/>
<OACODE/>
<GOVREG>E12000001</GOVREG>
<OWNINGORGID>107178</OWNINGORGID>
<OWNINGORGNAME>Believe Housing Ltd.</OWNINGORGNAME>
<MANINGORGNAME>Believe Housing Ltd.</MANINGORGNAME>
<HCNUM>8076</HCNUM>
<MANHCNUM>8076</MANHCNUM>
<OWNINGORGID>1</OWNINGORGID>
<OWNINGORGNAME>DLUHC</OWNINGORGNAME>
<MANINGORGNAME>DLUHC</MANINGORGNAME>
<HCNUM>655</HCNUM>
<MANHCNUM>655</MANHCNUM>
<LAHA/>
<MANINGORGID>107178</MANINGORGID>
<MANINGORGID>1</MANINGORGID>
<HBTYPE1/>
<HBTYPE2/>
<HBTYPE3>3</HBTYPE3>

12
spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml vendored

@ -431,13 +431,13 @@
<PLOACODE/>
<OACODE/>
<GOVREG>E12000003</GOVREG>
<OWNINGORGID>1034</OWNINGORGID>
<OWNINGORGNAME>LEEDS &amp; YORKSHIRE HA Ltd</OWNINGORGNAME>
<MANINGORGNAME>LEEDS &amp; YORKSHIRE HA Ltd</MANINGORGNAME>
<HCNUM>LH0704</HCNUM>
<MANHCNUM>LH0704</MANHCNUM>
<OWNINGORGID>1</OWNINGORGID>
<OWNINGORGNAME>DLUHC</OWNINGORGNAME>
<MANINGORGNAME>DLUHC</MANINGORGNAME>
<HCNUM>655</HCNUM>
<MANHCNUM>655</MANHCNUM>
<LAHA/>
<MANINGORGID>1034</MANINGORGID>
<MANINGORGID>1</MANINGORGID>
<HBTYPE1/>
<HBTYPE2/>
<HBTYPE3/>

12
spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml vendored

@ -3,8 +3,8 @@
<meta:form-name>2021-CORE-IR-GN</meta:form-name>
<meta:document-id>166fc004-392e-47a8-acb8-1c018734882b</meta:document-id>
<meta:owner-user-id>e29c492473446dca4d50224f2bb7cf965a261d6f</meta:owner-user-id>
<meta:owner-institution-id>26139d1be7a44ebb1af23d3f8882c14025e9903c</meta:owner-institution-id>
<meta:managing-institution-id>26139d1be7a44ebb1af23d3f8882c14025e9903c</meta:managing-institution-id>
<meta:owner-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:owner-institution-id>
<meta:managing-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:managing-institution-id>
<meta:created-date>2022-04-12T14:10:59.953121Z</meta:created-date>
<meta:modified-date>2022-04-12T14:10:59.953121Z</meta:modified-date>
<meta:status>submitted-valid</meta:status>
@ -411,13 +411,13 @@
<PLOACODE/>
<OACODE/>
<GOVREG>E12000008</GOVREG>
<OWNINGORGID>107138</OWNINGORGID>
<OWNINGORGNAME>1 Test</OWNINGORGNAME>
<MANINGORGNAME>1 Test</MANINGORGNAME>
<OWNINGORGID>1</OWNINGORGID>
<OWNINGORGNAME>DLUHC</OWNINGORGNAME>
<MANINGORGNAME>DLUHC</MANINGORGNAME>
<HCNUM>655</HCNUM>
<MANHCNUM>655</MANHCNUM>
<LAHA/>
<MANINGORGID>107138</MANINGORGID>
<MANINGORGID>1</MANINGORGID>
<HBTYPE1/>
<HBTYPE2/>
<HBTYPE3/>

1
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

Loading…
Cancel
Save