Browse Source

feat: import org relationships in initial imports

full-import-optimisation
natdeanlewissoftwire 1 year ago
parent
commit
1953bf2f70
  1. 9
      app/services/imports/lettings_logs_import_service.rb
  2. 18
      app/services/imports/organisation_relationship_import_service.rb
  3. 1
      lib/tasks/full_import.rake

9
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

18
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

1
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"),

Loading…
Cancel
Save