diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index f1a86c023..17d290923 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -257,7 +257,6 @@ module Imports apply_date_consistency!(attributes) apply_household_consistency!(attributes) - create_organisation_relationship!(attributes) lettings_log = save_lettings_log(attributes, previous_status) compute_differences(lettings_log, attributes) @@ -642,13 +641,5 @@ module Imports 0 end end - - def create_organisation_relationship!(attributes) - parent_organisation_id = attributes["owning_organisation_id"] - child_organisation_id = attributes["managing_organisation_id"] - return if parent_organisation_id == child_organisation_id - - OrganisationRelationship.find_or_create_by!(parent_organisation_id:, child_organisation_id:) - end end end diff --git a/app/services/imports/organisation_relationship_import_service.rb b/app/services/imports/organisation_relationship_import_service.rb new file mode 100644 index 000000000..4873da539 --- /dev/null +++ b/app/services/imports/organisation_relationship_import_service.rb @@ -0,0 +1,18 @@ +module Imports + class OrganisationRelationshipImportService < ImportService + def create_organisation_relationships(folder) + import_from(folder, :create_organisation_relationships) + end + + private + + def create_organisation_relationship(xml_document) + parent_organisation_id = find_organisation_id(xml_document, "parent-institution") + child_organisation_id = find_organisation_id(xml_document, "child-institution") + + return if parent_organisation_id == child_organisation_id + + OrganisationRelationship.find_or_create_by!(parent_organisation_id:, child_organisation_id:) + end + end +end diff --git a/lib/tasks/full_import.rake b/lib/tasks/full_import.rake index 3d10630bc..9c41ac85b 100644 --- a/lib/tasks/full_import.rake +++ b/lib/tasks/full_import.rake @@ -12,6 +12,7 @@ namespace :import do initial_import_list = [ Import.new(Imports::OrganisationImportService, :create_organisations, "institution"), + Import.new(Imports::OrganisationRelationshipImportService, :create_organisation_relationships, "institution-link"), Import.new(Imports::SchemeImportService, :create_schemes, "mgmtgroups"), Import.new(Imports::SchemeLocationImportService, :create_scheme_locations, "schemes"), Import.new(Imports::UserImportService, :create_users, "user"),