Skip to content

Commit

Permalink
updates to submission builder in accordance with new direction
Browse files Browse the repository at this point in the history
  • Loading branch information
pennja committed Sep 19, 2024
1 parent f732efe commit 9d638fd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ def run

private

attr_reader :attachments, :benefits_intake_uuid, :file_path, :include_json_archive, :include_manifest,
:include_text_archive, :metadata, :submission
attr_reader :attachments, :benefits_intake_uuid, :file_path, :include_manifest, :metadata, :submission

def default_options
{
attachments: nil, # The confirmation codes of any attachments which were originally submitted
benefits_intake_uuid: nil, # The UUID returned from the Benefits Intake API upon original submission
file_path: nil, # The local path where the submission PDF is stored
include_json_archive: true, # Include the form data as a JSON object
include_manifest: true, # Include a CSV file containing manifest data
include_text_archive: true, # Include the form data as a text file
metadata: nil, # Data appended to the original submission headers
submission: nil # The FormSubmission object representing the original data payload submitted
}
Expand All @@ -49,8 +46,6 @@ def valid_submission_data?(data)

def process_submission_files
write_pdf
write_as_json_archive if include_json_archive
write_as_text_archive if include_text_archive
write_attachments unless attachments && attachments.empty?
write_manifest if include_manifest
write_metadata
Expand All @@ -62,14 +57,6 @@ def write_pdf
write_tempfile(submission_pdf_filename, File.read(file_path))
end

def write_as_json_archive
write_tempfile('form_json_archive.json', JSON.pretty_generate(form_data_hash))
end

def write_as_text_archive
write_tempfile('form_text_archive.txt', form_data_hash.to_s)
end

def write_metadata
write_tempfile('metadata.json', metadata.to_json)
end
Expand Down Expand Up @@ -129,8 +116,11 @@ def form_data_hash
@form_data_hash ||= JSON.parse(submission.form_data)
end

# Name the form PDFs and/or individual submission folders
# uniquely, using a field that also appears in the manifest.
# The recommended format is Formnumber-vagov-submission ID
def submission_pdf_filename
@submission_pdf_filename ||= "form_#{form_data_hash['form_number']}.pdf"
@submission_pdf_filename ||= "#{form_data_hash['form_number']}-vagov-#{benefits_intake_uuid}.pdf"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def handle_error(message, error, **)
end

def temp_directory_path
@temp_directory_path ||= Rails.root.join("tmp/#{benefits_intake_uuid}-#{SecureRandom.hex}/").to_s
@temp_directory_path ||= Rails.root.join("tmp/#{benefits_intake_uuid}-#{SecureRandom.hex}-archive/").to_s
end

def s3_resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
attachments: nil,
benefits_intake_uuid:,
file_path: nil,
include_json_archive: true,
include_manifest: true,
include_text_archive: true,
metadata: nil,
submission: nil
}
Expand Down Expand Up @@ -75,7 +73,7 @@
describe '#run' do
subject(:run) { archive_builder_instance.run }

let(:temp_file_path) { Rails.root.join("tmp/#{benefits_intake_uuid}-random-letters-n-numbers/").to_s }
let(:temp_file_path) { Rails.root.join("tmp/#{benefits_intake_uuid}-random-letters-n-numbers-archive/").to_s }

context 'when properly initialized' do
it 'completes successfully' do
Expand Down

0 comments on commit 9d638fd

Please sign in to comment.