Skip to content
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

CPDNPQ-1188 Create a task to update status fields in the NPQ #819

Merged
merged 28 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c28b10
CPDNPQ-1172 Add in Authentication for new NPQ API Endpoints
javier-npq Jun 20, 2023
9098099
fixed failing specs
javier-npq Jun 22, 2023
b3e0c91
updated migration
javier-npq Jun 23, 2023
6b5fcfa
Created scheduled background job
javier-npq Jun 21, 2023
95debd2
move end point logic to services
javier-npq Jun 22, 2023
ab3b8ad
Updated the service to save participant_outcome_state
javier-npq Jun 23, 2023
75775f5
Fixed rspecs
javier-npq Jun 23, 2023
d58b00e
code refactor
javier-npq Jun 23, 2023
23a4d27
code refactor
javier-npq Jun 23, 2023
bfd8c05
updated application update query
javier-npq Jun 26, 2023
57ab683
review app testing
javier-npq Jun 26, 2023
20bb0ab
added service/job specs alongwith cater schedule enviroment issue
javier-npq Jun 26, 2023
51bb17e
reverted the test code changes
javier-npq Jun 28, 2023
0d12e8a
limit the applications request from NPQ
javier-npq Jun 28, 2023
8ce056b
moved the application update code to background job
javier-npq Jun 28, 2023
b283484
fixed failing rspec
javier-npq Jun 28, 2023
4322a05
removed the payload data code for ecf endpoint
javier-npq Jul 3, 2023
4132379
added display functionality for provider status
javier-npq Jul 3, 2023
f08e36b
ran migration
javier-npq Jul 3, 2023
0ecf775
Managed Background job for single record
javier-npq Jul 5, 2023
eec9228
test purpose changes in schedule.rb
javier-npq Jul 6, 2023
1a5a482
removed index method from url
javier-npq Jul 6, 2023
6a1901e
update job and service names
javier-npq Jul 6, 2023
f450236
Update specs and docker file
javier-npq Jul 7, 2023
c157ac7
Applied feedback changes
javier-npq Jul 7, 2023
52f20db
Added a new container for cron job
javier-npq Jul 7, 2023
09ca92c
updated github_actions.md
javier-npq Jul 10, 2023
451b3e6
Added functionality to display provider details on the account page
javier-npq Jul 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ruby File.read(".ruby-version").chomp
gem "activerecord-session_store"
gem "bootsnap", ">= 1.1.0", require: false
gem "canonical-rails"
gem "daemons"
gem "delayed_job", "~> 4.1"
gem "delayed_job_active_record"
gem "devise", "~> 4.9"
Expand Down Expand Up @@ -37,6 +38,7 @@ gem "sentry-rails"
gem "sentry-ruby"
gem "stimulus-rails"
gem "webpacker"
gem "whenever"

gem "net-imap", require: false
gem "net-pop", require: false
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ GEM
capybara (>= 1.0, < 4)
launchy
childprocess (4.1.0)
chronic (0.10.2)
coderay (1.1.3)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concurrent-ruby (1.2.2)
crack (0.4.5)
rexml
crass (1.0.6)
daemons (1.4.1)
date (3.3.3)
deep_merge (1.2.1)
delayed_job (4.1.11)
Expand Down Expand Up @@ -500,6 +502,8 @@ GEM
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
with_model (2.1.6)
activerecord (>= 5.2)
xpath (3.2.0)
Expand All @@ -521,6 +525,7 @@ DEPENDENCIES
canonical-rails
capybara
capybara-screenshot
daemons
delayed_job (~> 4.1)
delayed_job_active_record
devise (~> 4.9)
Expand Down Expand Up @@ -573,6 +578,7 @@ DEPENDENCIES
webdrivers
webmock
webpacker
whenever
with_model

RUBY VERSION
Expand Down
6 changes: 6 additions & 0 deletions app/jobs/application_synchronization_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ApplicationSynchronizationJob < ApplicationJob
queue_as :default
def perform
Services::Ecf::EcfApplicationSynchronizationService.new.call
end
end
6 changes: 6 additions & 0 deletions app/jobs/npq_application_updater_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class NpqApplicationUpdaterJob < ApplicationJob
queue_as :default
def perform(data)
Services::Ecf::NpqApplicationUpdater.new(data).call
end
end
47 changes: 47 additions & 0 deletions app/lib/services/ecf/ecf_application_synchronization_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Services
module Ecf
class EcfApplicationSynchronizationService
def call
uri = build_uri
request = build_http_get_request(uri)
response = send_http_request(uri, request)
handle_response(response)
rescue StandardError => e
Rails.logger.error "An error occurred during application synchronization: #{e.message}"
end

private

def build_uri
URI.parse("#{ENV['ECF_APP_BASE_URL']}/api/v1/npq/application_synchronizations#index")
end

def build_http_get_request(uri)
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer #{ENV['ECF_APP_BEARER_TOKEN']}"
request
end

def send_http_request(uri, request)
Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(request)
end
end

def handle_response(response)
if response.is_a?(Net::HTTPSuccess)
data = response_data(response)
data["data"].each do |record|
NpqApplicationUpdaterJob.perform_later(record)
end
else
raise "Failed to synchronize application: #{response.message}"
end
end

def response_data(response)
JSON.parse(response.body)
end
end
end
end
18 changes: 18 additions & 0 deletions app/lib/services/ecf/npq_application_updater.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Services
module Ecf
class NpqApplicationUpdater
def initialize(data)
@data = data
end

def call
id = @data["attributes"]["id"]
lead_provider_approval_status = @data["attributes"]["lead_provider_approval_status"]
participant_outcome_state = @data["attributes"]["participant_outcome_state"]

application = Application.find_by(ecf_id: id)
application.update!(lead_provider_approval_status:, participant_outcome_state:) if application.present?
end
end
end
end
4 changes: 4 additions & 0 deletions app/views/accounts/_application_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
{
key: { text: "Provider" },
value: { text: application.lead_provider.name },
},
{
key: { text: "Provider Application" },
value: { text: application.participant_outcome_state ? application.participant_outcome_state : application.lead_provider_approval_status },
}
])
end %>
Expand Down
5 changes: 5 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require File.expand_path(File.join(File.dirname(__FILE__), "..", "config", "environment"))

every 1.day, at: "00:00" do
javier-npq marked this conversation as resolved.
Show resolved Hide resolved
runner "ApplicationSynchronizationJob.perform_now", environment: Rails.env
javier-npq marked this conversation as resolved.
Show resolved Hide resolved
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddLeadProviderApprovalStatusToApplications < ActiveRecord::Migration[6.1]
def change
add_column :applications, :lead_provider_approval_status, :text
add_column :applications, :participant_outcome_state, :text
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_04_14_121939) do
ActiveRecord::Schema.define(version: 2023_06_19_162920) do

# These are extensions that must be enabled in order to support this database
enable_extension "btree_gin"
Expand Down Expand Up @@ -51,6 +51,8 @@
t.integer "number_of_pupils", default: 0
t.boolean "tsf_primary_eligibility", default: false
t.boolean "tsf_primary_plus_eligibility", default: false
t.text "lead_provider_approval_status"
t.text "participant_outcome_state"
t.index ["course_id"], name: "index_applications_on_course_id"
t.index ["lead_provider_id"], name: "index_applications_on_lead_provider_id"
t.index ["user_id"], name: "index_applications_on_user_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
"headteacher_status" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => "100000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
"kind_of_nursery" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"private_childcare_provider_urn" => nil,
"school_urn" => nil,
"targeted_delivery_funding_eligibility" => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
"tsf_primary_plus_eligibility" => false,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"works_in_childcare" => true,
"works_in_nursery" => nil,
"works_in_school" => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
"headteacher_status" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"kind_of_nursery" => "private_nursery",
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => "EY123456",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
"headteacher_status" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"kind_of_nursery" => public_kind_of_nursery_key,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
"kind_of_nursery" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"headteacher_status" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
"kind_of_nursery" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => "100000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
"school_urn" => "100000",
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"targeted_delivery_funding_eligibility" => false,
"teacher_catchment" => "england",
"teacher_catchment_country" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
"funding_choice" => "school",
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"funding_eligiblity_status_code" => "not_in_england",
"headteacher_status" => nil,
"kind_of_nursery" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
"school_urn" => "100000",
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"targeted_delivery_funding_eligibility" => false,
"teacher_catchment" => "england",
"teacher_catchment_country" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@
"kind_of_nursery" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => "100000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
"kind_of_nursery" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => "100000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
"kind_of_nursery" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => "100000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def run_scenario(js:)
"headteacher_status" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => "100000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ def run_scenario(js:)
"kind_of_nursery" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => "100000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def run_scenario(js:)
"funding_choice" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"funding_eligiblity_status_code" => "no_institution",
"headteacher_status" => nil,
"kind_of_nursery" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def run_scenario(js:)
"funding_eligiblity_status_code" => "ineligible_establishment_type",
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"headteacher_status" => nil,
"kind_of_nursery" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def run_scenario(js:)
"funding_choice" => "school",
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"funding_eligiblity_status_code" => "ineligible_establishment_type",
"headteacher_status" => nil,
"kind_of_nursery" => public_kind_of_nursery_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def run_scenario(js:)
"tsf_primary_plus_eligibility" => false,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"works_in_childcare" => false,
"works_in_nursery" => nil,
"works_in_school" => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def run_scenario(js:)
"works_in_school" => false,
"work_setting" => "other",
"lead_mentor" => true,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"itt_provider" => approved_itt_provider_legal_name,
"raw_application_data" => {
"targeted_delivery_funding_eligibility" => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def run_scenario(js:)
"headteacher_status" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => "100000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def run_scenario(js:) # rubocop:disable Lint/UnusedMethodArgument
"school_urn" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"targeted_delivery_funding_eligibility" => false,
"teacher_catchment" => "jersey_guernsey_isle_of_man",
"teacher_catchment_country" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def run_scenario(js:)
"kind_of_nursery" => nil,
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"lead_provider_id" => LeadProvider.find_by(name: "Teach First").id,
"private_childcare_provider_urn" => nil,
"school_urn" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def run_scenario(js:)
"funding_choice" => "self",
"itt_provider" => nil,
"lead_mentor" => false,
"lead_provider_approval_status" => nil,
"participant_outcome_state" => nil,
"funding_eligiblity_status_code" => "previously_funded",
"headteacher_status" => "yes_in_first_five_years",
"kind_of_nursery" => "private_nursery",
Expand Down
Loading