Browse Source

Allow exporting users individually

pull/2652/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
da82ad6c05
  1. 30
      app/services/exports/export_service.rb
  2. 4
      lib/tasks/data_export.rake
  3. 92
      spec/services/exports/export_service_spec.rb

30
app/services/exports/export_service.rb

@ -7,15 +7,23 @@ module Exports
@logger = logger
end
def export_xml(full_update: false, collection_year: nil)
def export_xml(full_update: false, collection: nil)
start_time = Time.zone.now
daily_run_number = get_daily_run_number
lettings_archives_for_manifest = {}
users_archives_for_manifest = {}
lettings_export_service = Exports::LettingsLogExportService.new(@storage_service, start_time)
lettings_archives_for_manifest = lettings_export_service.export_xml_lettings_logs(full_update:, collection_year:)
users_export_service = Exports::UserExportService.new(@storage_service, start_time)
users_archives_for_manifest = users_export_service.export_xml_users(full_update:)
if collection.present?
case collection
when "users"
users_archives_for_manifest = get_user_archives(start_time, full_update)
else
lettings_archives_for_manifest = get_lettings_archives(start_time, full_update, collection)
end
else
users_archives_for_manifest = get_user_archives(start_time, full_update)
lettings_archives_for_manifest = get_lettings_archives(start_time, full_update, collection)
end
write_master_manifest(daily_run_number, lettings_archives_for_manifest.merge(users_archives_for_manifest))
end
@ -47,5 +55,15 @@ module Exports
end
StringIO.new(csv_string)
end
def get_user_archives(start_time, full_update)
users_export_service = Exports::UserExportService.new(@storage_service, start_time)
users_export_service.export_xml_users(full_update:)
end
def get_lettings_archives(start_time, full_update, collection)
lettings_export_service = Exports::LettingsLogExportService.new(@storage_service, start_time)
lettings_export_service.export_xml_lettings_logs(full_update:, collection_year: collection)
end
end
end

4
lib/tasks/data_export.rake

@ -8,10 +8,10 @@ namespace :core do
desc "Export all data XMLs for import into Central Data System (CDS)"
task :full_data_export_xml, %i[year] => :environment do |_task, args|
collection_year = args[:year].present? ? args[:year].to_i : nil
collection = args[:year].present? ? args[:year].to_i : nil
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["EXPORT_BUCKET"])
export_service = Exports::ExportService.new(storage_service)
export_service.export_xml(full_update: true, collection_year:)
export_service.export_xml(full_update: true, collection:)
end
end

92
spec/services/exports/export_service_spec.rb

@ -141,4 +141,96 @@ RSpec.describe Exports::ExportService do
end
end
end
context "when exporting specific lettings log collection" do
context "and no lettings archives get created in lettings logs export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: {}) }
context "and user archive gets created in user export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: { "some_user_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml(full_update: true, collection: "2022")
end
it "does not write user data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml(full_update: true, collection: "2022")
expect(actual_content).to eq(expected_content)
end
end
end
context "and lettings archive gets created in lettings logs export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) }
context "and user archive gets created in user export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: { "some_user_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml(full_update: true, collection: "2023")
end
it "does not write user data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\nsome_file_base_name,2022-05-01 00:00:00 +0100,some_file_base_name.zip\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml(full_update: true, collection: "2023")
expect(actual_content).to eq(expected_content)
end
end
end
end
context "when exporting user collection" do
context "and no user archives get created in users export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: {}) }
context "and lettings log archive gets created in lettings logs export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml(full_update: true, collection: "users")
end
it "does not write lettings log data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml(full_update: true, collection: "users")
expect(actual_content).to eq(expected_content)
end
end
end
context "and users archive gets created in users export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) }
context "and lettings log archive gets created in lettings log export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: { "some_user_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml(full_update: true, collection: "users")
end
it "does not write lettings log data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\nsome_user_file_base_name,2022-05-01 00:00:00 +0100,some_user_file_base_name.zip\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml(full_update: true, collection: "users")
expect(actual_content).to eq(expected_content)
end
end
end
end
end

Loading…
Cancel
Save