-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt FormRemediation for 526 #21348
Open
Thrillberg
wants to merge
8
commits into
master
Choose a base branch
from
0781-remediation-rake-task
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad5bdf8
WIP on adapting FormRemediation for 526
Thrillberg 1035d4f
fill and stamp PDF
Thrillberg 17d3d54
Push to S3
Thrillberg 5a8740f
add config
Thrillberg d13edb7
typos
Thrillberg 46b98d1
typos
Thrillberg 598c0af
fix bucket name
Thrillberg 5c27eab
Merge branch 'master' into 0781-remediation-rake-task
gabezurita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
27 changes: 27 additions & 0 deletions
27
lib/simple_forms_api/form_remediation/configuration/form_0781_config.rb
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'simple_forms_api/form_remediation/configuration/base' | ||
|
||
module SimpleFormsApi | ||
module FormRemediation | ||
module Configuration | ||
class Form0781Config < Base | ||
def submission_archive_class | ||
SimpleFormsApi::FormRemediation::Form526SubmissionArchive | ||
end | ||
|
||
def remediation_data_class | ||
SimpleFormsApi::FormRemediation::Form0781SubmissionRemediationData | ||
end | ||
|
||
def temp_directory_path | ||
Rails.root.join("tmp/#{SecureRandom.hex}-archive").to_s | ||
end | ||
|
||
def s3_settings | ||
Settings.form0781_remediation.aws | ||
end | ||
end | ||
end | ||
end | ||
end |
61 changes: 61 additions & 0 deletions
61
...pi/app/services/simple_forms_api/form_remediation/form0781_submission_remediation_data.rb
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,61 @@ | ||
# frozen_string_literal: true | ||
|
||
module SimpleFormsApi | ||
module FormRemediation | ||
class Form0781 | ||
def submission_date_stamps(timestamp) | ||
[ | ||
{ | ||
coords: [460, 710], | ||
text: 'Application Submitted:', | ||
page: 0, | ||
font_size: 12 | ||
}, | ||
{ | ||
coords: [460, 690], | ||
text: timestamp.in_time_zone('UTC').strftime('%H:%M %Z %D'), | ||
page: 0, | ||
font_size: 12 | ||
} | ||
] | ||
end | ||
|
||
def desired_stamps | ||
[] | ||
end | ||
end | ||
|
||
class Form0781SubmissionRemediationData < SubmissionRemediationData | ||
def hydrate! | ||
form_content = JSON.parse(submission.form_to_json(Form526Submission::FORM_0781))['form0781a'] | ||
submitted_claim_id = submission.submitted_claim_id | ||
submission_date = submission&.created_at | ||
form_content = form_content.merge( | ||
{ 'signatureDate' => submission_date&.in_time_zone('Central Time (US & Canada)') } | ||
) | ||
@file_path = PdfFill::Filler.fill_ancillary_form( | ||
form_content, | ||
submitted_claim_id, | ||
EVSS::DisabilityCompensationForm::SubmitForm0781::FORM_ID_0781A | ||
) | ||
SimpleFormsApi::PdfStamper.new( | ||
stamped_template_path: file_path, | ||
form: Form0781.new, | ||
timestamp: submission_date | ||
).stamp_pdf | ||
|
||
self | ||
rescue => e | ||
config.handle_error('Error hydrating submission', e) | ||
end | ||
|
||
private | ||
|
||
attr_reader :config | ||
|
||
def fetch_submission(id) | ||
@submission = Form526Submission.find(id) | ||
end | ||
end | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
...le_forms_api/app/services/simple_forms_api/form_remediation/form526_submission_archive.rb
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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module SimpleFormsApi | ||
module FormRemediation | ||
class Form526SubmissionArchive < SubmissionArchive | ||
def hydrate_submission_data | ||
raise "No #{config.id_type} was provided" unless id | ||
|
||
built_submission = config.remediation_data_class.new(id:, config:).hydrate! | ||
|
||
initialize_data( | ||
attachments: built_submission.attachments, | ||
file_path: built_submission.file_path, | ||
id: built_submission.submission.id, | ||
metadata: built_submission.metadata, | ||
submission: built_submission.submission, | ||
type: archive_type | ||
) | ||
end | ||
|
||
private | ||
|
||
def submission_file_name | ||
@submission_file_name ||= unique_file_name('526', id) | ||
end | ||
|
||
def manifest_entry | ||
[ | ||
submission.created_at, | ||
'526', | ||
id | ||
] | ||
end | ||
end | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
modules/simple_forms_api/lib/tasks/remediate_0781_submissions.rake
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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'simple_forms_api/form_remediation/configuration/form_0781_config' | ||
require_relative '../../app/services/simple_forms_api/form_remediation/jobs/archive_batch_processing_job' | ||
|
||
# Invoke this as follows: | ||
# Passing just form526_submission_ids (will use default type): | ||
# bundle exec rails simple_forms_api:remediate_0781_submissions[123 456] | ||
|
||
def validate_input!(form526_submission_ids) | ||
raise Common::Exceptions::ParameterMissing, 'form526_submission_ids' unless form526_submission_ids&.any? | ||
end | ||
|
||
namespace :simple_forms_api do | ||
desc 'Kick off the ArchiveBatchProcessingJob to archive 0781 submissions to S3 and print presigned URLs' | ||
task :remediate_0781_submissions, %i[form526_submission_ids] => :environment do |_, args| | ||
form526_submission_ids = args[:form526_submission_ids].to_s.split(/[,\s]+/) | ||
type = :remediation | ||
|
||
begin | ||
validate_input!(form526_submission_ids) | ||
|
||
Rails.logger.info( | ||
"Starting ArchiveBatchProcessingJob for form 526 ids: #{form526_submission_ids.join(', ')} using type: #{type}" | ||
) | ||
|
||
# Call the service object synchronously and get the presigned URLs | ||
config = SimpleFormsApi::FormRemediation::Configuration::Form0781Config.new | ||
job = SimpleFormsApi::FormRemediation::Jobs::ArchiveBatchProcessingJob.new | ||
job.perform(ids: form526_submission_ids, config:, type: type.to_sym) | ||
|
||
Rails.logger.info('Task successfully completed.') | ||
rescue Common::Exceptions::ParameterMissing => e | ||
raise e | ||
rescue => e | ||
Rails.logger.error("Error occurred while archiving submissions: #{e.message}") | ||
puts 'An error occurred. Check logs for more details.' | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would any of the logic in hydrate! benefit from an async job? Is Form0781SubmissionRemediationData.new(submission).hydrate! used in a request flow at all? If so, it might benefit from a background job potentially
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all gets kicked off from a invocation to
SimpleFormsApi::FormRemediation::Jobs::ArchiveBatchProcessingJob
, which is a Sidekiq job. Do you recommend another job triggered by the first job?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is basically plugging in custom pieces to the pattern established in the form remediation work (README here)