-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HomeOffice report uses Excel template
This template now loads a report template from the database along with the header mappings and sheet to update. A validator is also added to has all the required info to generate report successfully
- Loading branch information
1 parent
093f1d3
commit 6f6810b
Showing
11 changed files
with
277 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,3 +83,5 @@ gem "sidekiq", "~> 6.5" | |
gem "sidekiq-cron", "~> 1.10" | ||
|
||
gem "mail-notify", "~> 1.1" | ||
|
||
gem "rubyXL", "~> 3.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Example config | ||
# config: | ||
# { | ||
# worksheet_name: "Data", | ||
# header_mapping: { | ||
# "ID (Mandatory)" => %w[urn], | ||
# "Full Name/ Organisation Name" => %w[applicants.given_name applicants.middle_name applicants.family_name], | ||
# "DOB" => %w[applicants.date_of_birth], | ||
# "Nationality" => %w[applicants.nationality], | ||
# "Passport Number" => %w[applicants.passport_number], | ||
# } | ||
# } | ||
# | ||
|
||
class HomeOfficeReportConfigValidator | ||
def initialize(record) | ||
@record = record | ||
end | ||
|
||
def validate | ||
return if record.report_class != Reports::HomeOffice.name | ||
|
||
validate_workbook | ||
validate_config_worksheet_name | ||
validate_worksheet | ||
validate_config_header_mappings | ||
end | ||
|
||
private | ||
|
||
attr_reader :record, :workbook | ||
|
||
def validate_workbook | ||
@workbook = ::RubyXL::Parser.parse_buffer(record.file.dup) | ||
rescue StandardError | ||
record.errors.add(:file, :ho_invalid) | ||
end | ||
|
||
def validate_worksheet | ||
return if workbook.blank? | ||
|
||
record.errors.add(:config, :ho_invalid_worksheet_name) if workbook[record.config.fetch(Reports::HomeOffice::WORKSHEET_NAME_KEY, nil)].blank? | ||
end | ||
|
||
def validate_config_worksheet_name | ||
record.errors.add(:config, :ho_missing_worksheet_name) if record.config.fetch(Reports::HomeOffice::WORKSHEET_NAME_KEY, nil).blank? | ||
end | ||
|
||
def validate_config_header_mappings | ||
record.errors.add(:config, :ho_missing_header_mappings) if record.config.fetch(Reports::HomeOffice::HEADER_MAPPINGS_KEY, nil).blank? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.