-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into MBMS-58688/AddressValidationControllerWith…
…outUserAuthentication
- Loading branch information
Showing
22 changed files
with
563 additions
and
35 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
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
44 changes: 44 additions & 0 deletions
44
app/models/lighthouse/education_benefits/education_benefit.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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'active_support/inflector' | ||
|
||
module Lighthouse | ||
module EducationBenefits | ||
# The EducationBenefit model represents a veteran's education benefit status. | ||
# This model is used to parse and manipulate the data returned from the Lighthouse API. | ||
# Although it includes ActiveModel::Model for some ActiveRecord-like features such as validations and conversions, | ||
# it does not persist any data to a database. | ||
class EducationBenefit | ||
include ActiveModel::Model | ||
attr_accessor :first_name, :last_name, :name_suffix, :date_of_birth, :va_file_number, :active_duty, | ||
:veteran_is_eligible, :regional_processing_office, :eligibility_date, | ||
:percentage_benefit, :original_entitlement, :used_entitlement, | ||
:remaining_entitlement, :delimiting_date | ||
attr_reader :enrollments | ||
|
||
def initialize(attributes = {}) | ||
super(attributes.deep_transform_keys { |key| key.to_s.underscore }) | ||
end | ||
|
||
def enrollments=(values) | ||
@enrollments = values.map do |value| | ||
Enrollment.new(value) | ||
end | ||
end | ||
|
||
# existing data contracts rely on eg `date_of_birth` so we must | ||
# modify some of the field names | ||
def date_time_of_birth=(value) | ||
@date_of_birth = value | ||
end | ||
|
||
def delimiting_date_time=(value) | ||
@delimiting_date = value | ||
end | ||
|
||
def eligibility_date_time=(value) | ||
@eligibility_date = value | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'active_support/inflector' | ||
|
||
module Lighthouse | ||
module EducationBenefits | ||
# The Enrollment class encapsulates the concept of a veteran's enrollment in an education program. | ||
# This model is used to parse and manipulate the data returned from the Lighthouse API. | ||
# Although it includes ActiveModel::Model for some ActiveRecord-like features such as validations and conversions, | ||
# it does not persist any data to a database. | ||
class Enrollment | ||
include ActiveModel::Model | ||
attr_accessor :begin_date, :end_date, :facility_code, :facility_name, :participant_id, | ||
:training_type, :term_id, :hour_type, :full_time_hours, | ||
:full_time_credit_hour_under_grad, :vacation_day_count, :on_campus_hours, | ||
:online_hours, :yellow_ribbon_amount, :status, :amendments | ||
|
||
def initialize(attributes = {}) | ||
super(attributes.deep_transform_keys { |key| key.to_s.underscore }) | ||
end | ||
|
||
# existing data contracts rely on eg `begin_date` so we must | ||
# modify some of the field names | ||
def begin_date_time=(value) | ||
@begin_date = value | ||
end | ||
|
||
def end_date_time=(value) | ||
@end_date = value | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module SchemaContract | ||
class Validation < ApplicationRecord | ||
self.table_name = 'schema_contract_validations' | ||
|
||
attribute :contract_name, :string | ||
attribute :user_uuid, :string | ||
attribute :response, :jsonb | ||
attribute :error_details, :string | ||
|
||
validates :contract_name, presence: true | ||
validates :user_uuid, presence: true | ||
validates :response, presence: true | ||
validates :status, presence: true | ||
|
||
enum status: { initialized: 0, success: 1, schema_errors_found: 2, schema_not_found: 3, error: 4 }, | ||
_default: :initialized | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module SchemaContract | ||
class ValidationInitiator | ||
def self.call(user:, response:, contract_name:) | ||
if response.success? && Flipper.enabled?("schema_contract_#{contract_name}") | ||
return if SchemaContract::Validation.where(contract_name:, created_at: Time.zone.today.all_day).any? | ||
|
||
record = SchemaContract::Validation.create( | ||
contract_name:, user_uuid: user.uuid, response: response.to_json, status: 'initialized' | ||
) | ||
Rails.logger.info('Initiating schema contract validation', { contract_name:, record_id: record.id }) | ||
SchemaContract::ValidationJob.perform_async(record.id) | ||
end | ||
rescue => e | ||
# blanket rescue to avoid blocking main thread execution | ||
message = { response:, contract_name:, error_details: e.message } | ||
Rails.logger.error('Error creating schema contract job', message) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module SchemaContract | ||
class Validator | ||
class SchemaContractValidationError < StandardError; end | ||
|
||
def initialize(record_id) | ||
@record_id = record_id | ||
end | ||
|
||
def validate | ||
errors = JSON::Validator.fully_validate(parsed_schema, record.response) | ||
if errors.any? | ||
@result = :schema_errors_found | ||
record.update(error_details: errors) | ||
detailed_message = { error_type: 'Schema discrepancy found', record_id: @record_id, response: record.response, | ||
details: errors } | ||
raise SchemaContractValidationError, detailed_message | ||
else | ||
@result = :success | ||
end | ||
rescue SchemaContractValidationError => e | ||
raise e | ||
rescue => e | ||
@result = :error | ||
detailed_message = { error_type: 'Unknown', record_id: @record_id, details: e.message } | ||
raise SchemaContractValidationError, detailed_message | ||
ensure | ||
record&.update(status: @result) if defined?(@record) | ||
end | ||
|
||
private | ||
|
||
def record | ||
@record ||= Validation.find(@record_id) | ||
end | ||
|
||
def schema_file | ||
@schema_file ||= begin | ||
path = Settings.schema_contract[record.contract_name] | ||
if path.nil? | ||
@result = :schema_not_found | ||
raise SchemaContractValidationError, "No schema file #{record.contract_name} found." | ||
end | ||
|
||
Rails.root.join(path) | ||
end | ||
end | ||
|
||
def parsed_schema | ||
file_contents = File.read(schema_file) | ||
JSON.parse(file_contents) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module SchemaContract | ||
class ValidationJob | ||
include Sidekiq::Job | ||
|
||
sidekiq_options(retry: false) | ||
|
||
def perform(contract_name) | ||
SchemaContract::Validator.new(contract_name).validate | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1666,3 +1666,6 @@ vye: | |
r: 8 | ||
p: 1 | ||
length: 16 | ||
|
||
schema_contract: | ||
test_index: 'spec/fixtures/schema_contract/test_schema.json' |
5 changes: 5 additions & 0 deletions
5
db/migrate/20240229150823_add_state_to_form_526_submissions.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,5 @@ | ||
class AddStateToForm526Submissions < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :form526_submissions, :aasm_state, :string | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :schema_contract_validation, class: 'SchemaContract::Validation' do | ||
contract_name { 'test_index' } | ||
user_uuid { '1234' } | ||
response { { key: 'value' } } | ||
status { 'initialized' } | ||
end | ||
end |
Oops, something went wrong.