Class: HCA::BaseSubmissionJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/hca/base_submission_job.rb

Direct Known Subclasses

AnonSubmissionJob, SubmissionJob

Constant Summary collapse

VALIDATION_ERROR =
HCA::SOAPParser::ValidationError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decrypt_form(encrypted_form) ⇒ Object



11
12
13
# File 'app/sidekiq/hca/base_submission_job.rb', line 11

def self.decrypt_form(encrypted_form)
  JSON.parse(HealthCareApplication::LOCKBOX.decrypt(encrypted_form))
end

Instance Method Details

#perform(user_identifier, encrypted_form, health_care_application_id, google_analytics_client_id) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/sidekiq/hca/base_submission_job.rb', line 33

def perform(user_identifier, encrypted_form, health_care_application_id, google_analytics_client_id)
  @health_care_application = HealthCareApplication.find(health_care_application_id)
  form = self.class.decrypt_form(encrypted_form)

  result = submit(user_identifier, form, google_analytics_client_id)
  return unless result

  Rails.logger.info "SubmissionID=#{result[:formSubmissionId]}"

  @health_care_application.set_result_on_success!(result)
end

#submit(user_identifier, form, google_analytics_client_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/sidekiq/hca/base_submission_job.rb', line 15

def submit(user_identifier, form, google_analytics_client_id)
  begin
    result = HCA::Service.new(user_identifier).submit_form(form)
  rescue VALIDATION_ERROR
    PersonalInformationLog.create!(data: { form: }, error_class: VALIDATION_ERROR.to_s)

    @health_care_application.update!(
      state: 'failed',
      form: form.to_json,
      google_analytics_client_id:
    )

    return false
  end

  result
end