|
|
|
@ -35,7 +35,6 @@ module Imports |
|
|
|
primary_client_group: attributes["primary_client_group"], |
|
|
|
primary_client_group: attributes["primary_client_group"], |
|
|
|
secondary_client_group: attributes["secondary_client_group"], |
|
|
|
secondary_client_group: attributes["secondary_client_group"], |
|
|
|
sensitive: attributes["sensitive"], |
|
|
|
sensitive: attributes["sensitive"], |
|
|
|
end_date: attributes["end_date"], |
|
|
|
|
|
|
|
# These values were set by the scheme import (management groups) |
|
|
|
# These values were set by the scheme import (management groups) |
|
|
|
owning_organisation_id: source_scheme.owning_organisation_id, |
|
|
|
owning_organisation_id: source_scheme.owning_organisation_id, |
|
|
|
service_name: source_scheme.service_name, |
|
|
|
service_name: source_scheme.service_name, |
|
|
|
@ -43,7 +42,7 @@ module Imports |
|
|
|
old_id: source_scheme.old_id, |
|
|
|
old_id: source_scheme.old_id, |
|
|
|
old_visible_id: source_scheme.old_visible_id, |
|
|
|
old_visible_id: source_scheme.old_visible_id, |
|
|
|
) |
|
|
|
) |
|
|
|
confirm_scheme(scheme) |
|
|
|
confirm_scheme_or_location(scheme) |
|
|
|
scheme.save! && scheme |
|
|
|
scheme.save! && scheme |
|
|
|
rescue ActiveRecord::RecordInvalid |
|
|
|
rescue ActiveRecord::RecordInvalid |
|
|
|
@logger.error("Scheme #{source_scheme.old_visible_id}: Failed to import") |
|
|
|
@logger.error("Scheme #{source_scheme.old_visible_id}: Failed to import") |
|
|
|
@ -59,18 +58,17 @@ module Imports |
|
|
|
primary_client_group: attributes["primary_client_group"], |
|
|
|
primary_client_group: attributes["primary_client_group"], |
|
|
|
secondary_client_group: attributes["secondary_client_group"], |
|
|
|
secondary_client_group: attributes["secondary_client_group"], |
|
|
|
sensitive: attributes["sensitive"], |
|
|
|
sensitive: attributes["sensitive"], |
|
|
|
end_date: attributes["end_date"], |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
confirm_scheme(scheme) |
|
|
|
confirm_scheme_or_location(scheme) |
|
|
|
scheme.save! && scheme |
|
|
|
scheme.save! && scheme |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def confirm_scheme(scheme) |
|
|
|
def confirm_scheme_or_location(obj) |
|
|
|
scheme.confirmed = true |
|
|
|
obj.confirmed = true |
|
|
|
scheme.validate_confirmed |
|
|
|
obj.validate_confirmed |
|
|
|
unless scheme.errors.empty? |
|
|
|
unless obj.errors.empty? |
|
|
|
scheme.confirmed = false |
|
|
|
obj.confirmed = false |
|
|
|
scheme.errors.clear |
|
|
|
obj.errors.clear |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -99,7 +97,7 @@ module Imports |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def add_location(scheme, attributes) |
|
|
|
def add_location(scheme, attributes) |
|
|
|
Location.create!( |
|
|
|
location = Location.new( |
|
|
|
name: attributes["location_name"], |
|
|
|
name: attributes["location_name"], |
|
|
|
postcode: attributes["postcode"], |
|
|
|
postcode: attributes["postcode"], |
|
|
|
mobility_type: attributes["mobility_type"], |
|
|
|
mobility_type: attributes["mobility_type"], |
|
|
|
@ -110,6 +108,11 @@ module Imports |
|
|
|
startdate: attributes["start_date"], |
|
|
|
startdate: attributes["start_date"], |
|
|
|
scheme:, |
|
|
|
scheme:, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
confirm_scheme_or_location(location) |
|
|
|
|
|
|
|
location.save! |
|
|
|
|
|
|
|
if attributes["end_date"] |
|
|
|
|
|
|
|
location.location_deactivation_periods.create!(deactivation_date: attributes["end_date"]) |
|
|
|
|
|
|
|
end |
|
|
|
rescue ActiveRecord::RecordNotUnique |
|
|
|
rescue ActiveRecord::RecordNotUnique |
|
|
|
@logger.warn("Location is already present with legacy ID #{attributes['location_old_id']}, skipping") |
|
|
|
@logger.warn("Location is already present with legacy ID #{attributes['location_old_id']}, skipping") |
|
|
|
rescue ActiveRecord::RecordInvalid |
|
|
|
rescue ActiveRecord::RecordInvalid |
|
|
|
|