Browse Source

Fix lettings allocation (cbl, chr, cap) import (#665)

* Fix lettings allocation (cbl, chr, cap) import

* Add task to fix existing logs

* Map value on export

* Run workflow on push to PR
pull/670/head v0.1.19
baarkerlounger 3 years ago committed by GitHub
parent
commit
8986896288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .github/workflows/staging_pipeline.yml
  2. 4
      app/services/exports/case_log_export_service.rb
  3. 38
      app/services/imports/case_logs_field_import_service.rb
  4. 15
      app/services/imports/case_logs_import_service.rb
  5. 2
      spec/fixtures/exports/case_logs.csv
  6. 2
      spec/fixtures/exports/case_logs.xml
  7. 4
      spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml
  8. 2
      spec/fixtures/softwire_imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml
  9. 2
      spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml
  10. 91
      spec/services/imports/case_logs_field_import_service_spec.rb

1
.github/workflows/staging_pipeline.yml

@ -8,6 +8,7 @@ on:
types: types:
- opened - opened
- ready_for_review - ready_for_review
- synchronize
workflow_dispatch: workflow_dispatch:
defaults: defaults:

4
app/services/exports/case_log_export_service.rb

@ -182,6 +182,10 @@ module Exports
attribute_hash["tenancycode"] = attribute_hash["tenant_code"] attribute_hash["tenancycode"] = attribute_hash["tenant_code"]
attribute_hash["ppcodenk"] = attribute_hash["previous_postcode_known"] attribute_hash["ppcodenk"] = attribute_hash["previous_postcode_known"]
attribute_hash["cbl"] = 2 if attribute_hash["cbl"]&.zero?
attribute_hash["cap"] = 2 if attribute_hash["cap"]&.zero?
attribute_hash["chr"] = 2 if attribute_hash["chr"]&.zero?
# Age refused # Age refused
(1..8).each do |index| (1..8).each do |index|
attribute_hash["age#{index}"] = -9 if attribute_hash["age#{index}_known"] == 1 attribute_hash["age#{index}"] = -9 if attribute_hash["age#{index}_known"] == 1

38
app/services/imports/case_logs_field_import_service.rb

@ -6,6 +6,8 @@ module Imports
import_from(folder, :update_tenant_code) import_from(folder, :update_tenant_code)
when "major_repairs" when "major_repairs"
import_from(folder, :update_major_repairs) import_from(folder, :update_major_repairs)
when "lettings_allocation"
import_from(folder, :update_lettings_allocation)
else else
raise "Updating #{field} is not supported by the field import service" raise "Updating #{field} is not supported by the field import service"
end end
@ -13,6 +15,32 @@ module Imports
private private
def update_lettings_allocation(xml_doc)
old_id = field_value(xml_doc, "meta", "document-id")
previous_status = field_value(xml_doc, "meta", "status")
record = CaseLog.find_by(old_id:)
if record.present? && previous_status.include?("submitted")
cbl = unsafe_string_as_integer(xml_doc, "Q15CBL")
chr = unsafe_string_as_integer(xml_doc, "Q15CHR")
cap = unsafe_string_as_integer(xml_doc, "Q15CAP")
if cbl == 2 && record.cbl == 1
record.update!(cbl: 0)
@logger.info("Case Log #{record.id}'s cbl value has been updated'")
end
if chr == 2 && record.chr == 1
record.update!(chr: 0)
@logger.info("Case Log #{record.id}'s chr value has been updated'")
end
if cap == 2 && record.cap == 1
record.update!(cap: 0)
@logger.info("Case Log #{record.id}'s cap value has been updated'")
end
else
@logger.warn("Could not find record matching legacy ID #{old_id}")
end
end
def update_major_repairs(xml_doc) def update_major_repairs(xml_doc)
old_id = field_value(xml_doc, "meta", "document-id") old_id = field_value(xml_doc, "meta", "document-id")
record = CaseLog.find_by(old_id:) record = CaseLog.find_by(old_id:)
@ -67,5 +95,15 @@ module Imports
str = field_value(xml_doc, "xmlns", attribute) str = field_value(xml_doc, "xmlns", attribute)
str.presence str.presence
end end
# Unsafe: A string that has more than just the integer value
def unsafe_string_as_integer(xml_doc, attribute)
str = string_or_nil(xml_doc, attribute)
if str.nil?
nil
else
str.to_i
end
end
end end
end end

15
app/services/imports/case_logs_import_service.rb

@ -123,9 +123,9 @@ module Imports
attributes["rp_hardship"] = unsafe_string_as_integer(xml_doc, "Q14b4").present? ? 1 : nil attributes["rp_hardship"] = unsafe_string_as_integer(xml_doc, "Q14b4").present? ? 1 : nil
attributes["rp_dontknow"] = unsafe_string_as_integer(xml_doc, "Q14b5").present? ? 1 : nil attributes["rp_dontknow"] = unsafe_string_as_integer(xml_doc, "Q14b5").present? ? 1 : nil
attributes["cbl"] = unsafe_string_as_integer(xml_doc, "Q15CBL").present? ? 1 : nil attributes["cbl"] = allocation_system(unsafe_string_as_integer(xml_doc, "Q15CBL"))
attributes["chr"] = unsafe_string_as_integer(xml_doc, "Q15CHR").present? ? 1 : nil attributes["chr"] = allocation_system(unsafe_string_as_integer(xml_doc, "Q15CHR"))
attributes["cap"] = unsafe_string_as_integer(xml_doc, "Q15CAP").present? ? 1 : nil attributes["cap"] = allocation_system(unsafe_string_as_integer(xml_doc, "Q15CAP"))
attributes["referral"] = unsafe_string_as_integer(xml_doc, "Q16") attributes["referral"] = unsafe_string_as_integer(xml_doc, "Q16")
attributes["period"] = unsafe_string_as_integer(xml_doc, "Q17") attributes["period"] = unsafe_string_as_integer(xml_doc, "Q17")
@ -553,6 +553,15 @@ module Imports
end end
end end
def allocation_system(value)
case value
when 1
1
when 2
0
end
end
def apply_date_consistency!(attributes) def apply_date_consistency!(attributes)
return if attributes["voiddate"].nil? || attributes["startdate"].nil? return if attributes["voiddate"].nil? || attributes["startdate"].nil?

2
spec/fixtures/exports/case_logs.csv vendored

@ -1,2 +1,2 @@
status,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,shelteredaccom,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate,tenancycode,ppcodenk status,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,shelteredaccom,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate,tenancycode,ppcodenk
2,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,0,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,0,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,,200.0,50.0,40.0,35.0,325.0,12.0,,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC,BZ737,1 2,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,0,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,,200.0,50.0,40.0,35.0,325.0,12.0,,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC,BZ737,1

1 status age1 sex1 ethnic national prevten ecstat1 hhmemb age2 sex2 ecstat2 age3 sex3 ecstat3 age4 sex4 ecstat4 age5 sex5 ecstat5 age6 sex6 ecstat6 age7 sex7 ecstat7 age8 sex8 ecstat8 homeless underoccupation_benefitcap leftreg reservist illness preg_occ startertenancy tenancylength tenancy ppostcode_full rsnvac unittype_gn beds offered wchair earnings incfreq benefits period layear waityear postcode_full reasonpref cbl chr cap reasonother housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_g housingneeds_h illness_type_1 illness_type_2 illness_type_3 illness_type_4 illness_type_8 illness_type_5 illness_type_6 illness_type_7 illness_type_9 illness_type_10 rp_homeless rp_insan_unsat rp_medwel rp_hardship rp_dontknow tenancyother irproduct_other reason propcode la prevloc hb hbrentshortfall mrcdate incref startdate armedforces unitletas builtype voiddate renttype needstype lettype totchild totelder totadult nocharge referral brent scharge pscharge supcharg tcharge tshortfall chcharge has_benefits renewal wrent wscharge wpschrge wsupchrg wtcharge wtshortfall refused housingneeds wchchrg newprop relat2 relat3 relat4 relat5 relat6 relat7 relat8 lar irproduct joint shelteredaccom form owningorgid owningorgname hcnum maningorgid maningorgname manhcnum createddate uploaddate tenancycode ppcodenk
2 2 35 F 2 4 6 0 2 32 M 6 1 0 1 0 1 2 0 5 1 SE26RT 6 7 3 2 1 68 1 1 2 2 1 NW15TY 1 1 1 0 2 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 4 123 E09000003 E07000105 6 1 2020-05-05 10:36:49 UTC 0 2022-02-02 10:36:49 UTC 1 2 1 2019-11-03 00:00:00 UTC 2 1 7 0 0 2 0 200.0 50.0 40.0 35.0 325.0 12.0 1 0 100.0 25.0 20.0 17.5 162.5 6.0 0 1 2 P 0 {id} {owning_org_id} DLUHC 1234 {managing_org_id} DLUHC 1234 2022-02-08 16:52:15 UTC 2022-02-08 16:52:15 UTC BZ737 1

2
spec/fixtures/exports/case_logs.xml vendored

@ -55,7 +55,7 @@
<reasonpref>1</reasonpref> <reasonpref>1</reasonpref>
<cbl>1</cbl> <cbl>1</cbl>
<chr>1</chr> <chr>1</chr>
<cap>0</cap> <cap>2</cap>
<reasonother/> <reasonother/>
<housingneeds_a>1</housingneeds_a> <housingneeds_a>1</housingneeds_a>
<housingneeds_b>0</housingneeds_b> <housingneeds_b>0</housingneeds_b>

4
spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml vendored

@ -2,7 +2,7 @@
<meta:metadata xmlns:es="http://www.ecmascript.org/" xmlns:xqx="http://www.w3.org/2005/XQueryX" xmlns:XSLT="http://www.w3.org/1999/XSL/Transform/compile"> <meta:metadata xmlns:es="http://www.ecmascript.org/" xmlns:xqx="http://www.w3.org/2005/XQueryX" xmlns:XSLT="http://www.w3.org/1999/XSL/Transform/compile">
<meta:form-name>2021-CORE-IR-GN</meta:form-name> <meta:form-name>2021-CORE-IR-GN</meta:form-name>
<meta:document-id>166fc004-392e-47a8-acb8-1c018734882b</meta:document-id> <meta:document-id>166fc004-392e-47a8-acb8-1c018734882b</meta:document-id>
<meta:owner-user-id>e29c492473446dca4d50224f2bb7cf965a261d6f</meta:owner-user-id> <meta:owner-user-id>c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa</meta:owner-user-id>
<meta:owner-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:owner-institution-id> <meta:owner-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:owner-institution-id>
<meta:managing-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:managing-institution-id> <meta:managing-institution-id>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</meta:managing-institution-id>
<meta:created-date>2022-04-12T14:10:59.953121Z</meta:created-date> <meta:created-date>2022-04-12T14:10:59.953121Z</meta:created-date>
@ -133,7 +133,7 @@
<Group> <Group>
<Q15CBL>2 No</Q15CBL> <Q15CBL>2 No</Q15CBL>
<Q15CHR>2 No</Q15CHR> <Q15CHR>2 No</Q15CHR>
<Q15CAP>2 No</Q15CAP> <Q15CAP>1 Yes</Q15CAP>
</Group> </Group>
<Group> <Group>
<Q16>10 Other social landlord</Q16> <Q16>10 Other social landlord</Q16>

2
spec/fixtures/softwire_imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml vendored

@ -131,7 +131,7 @@
<Q14b5/> <Q14b5/>
</Group> </Group>
<Group> <Group>
<Q15CBL>2 No</Q15CBL> <Q15CBL>1 Yes</Q15CBL>
<Q15CHR>2 No</Q15CHR> <Q15CHR>2 No</Q15CHR>
<Q15CAP>2 No</Q15CAP> <Q15CAP>2 No</Q15CAP>
</Group> </Group>

2
spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml vendored

@ -132,7 +132,7 @@
</Group> </Group>
<Group> <Group>
<Q15CBL>2 No</Q15CBL> <Q15CBL>2 No</Q15CBL>
<Q15CHR>2 No</Q15CHR> <Q15CHR>1 Yes</Q15CHR>
<Q15CAP>2 No</Q15CAP> <Q15CAP>2 No</Q15CAP>
</Group> </Group>
<Group> <Group>

91
spec/services/imports/case_logs_field_import_service_spec.rb

@ -74,6 +74,97 @@ RSpec.describe Imports::CaseLogsFieldImportService do
end end
end end
context "when updating letings allocation values" do
let(:field) { "lettings_allocation" }
let(:case_log) { CaseLog.find_by(old_id: case_log_id) }
before do
Imports::CaseLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
case_log_file.rewind
end
context "when cbl" do
let(:case_log_id) { "166fc004-392e-47a8-acb8-1c018734882b" }
context "when it was incorrectly set" do
before do
case_log.update!(cbl: 1)
end
it "updates the value" do
expect(logger).to receive(:info).with(/Case Log \d+'s cbl value has been updated/)
expect { import_service.send(:update_field, field, remote_folder) }
.to(change { case_log.reload.cbl }.from(1).to(0))
end
end
context "when it was correctly set" do
before do
case_log.update!(cbl: 0)
end
it "does not update the value" do
expect { import_service.send(:update_field, field, remote_folder) }
.not_to(change { case_log.reload.cbl })
end
end
end
context "when chr" do
let(:case_log_id) { "166fc004-392e-47a8-acb8-1c018734882b" }
context "when it was incorrectly set" do
before do
case_log.update!(chr: 1)
end
it "updates the value" do
expect(logger).to receive(:info).with(/Case Log \d+'s chr value has been updated/)
expect { import_service.send(:update_field, field, remote_folder) }
.to(change { case_log.reload.chr }.from(1).to(0))
end
end
context "when it was correctly set" do
before do
case_log.update!(chr: 0)
end
it "does not update the value" do
expect { import_service.send(:update_field, field, remote_folder) }
.not_to(change { case_log.reload.chr })
end
end
end
context "when cap" do
let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
context "when it was incorrectly set" do
before do
case_log.update!(cap: 1)
end
it "updates the value" do
expect(logger).to receive(:info).with(/Case Log \d+'s cap value has been updated/)
expect { import_service.send(:update_field, field, remote_folder) }
.to(change { case_log.reload.cap }.from(1).to(0))
end
end
context "when it was correctly set" do
before do
case_log.update!(cap: 0)
end
it "does not update the value" do
expect { import_service.send(:update_field, field, remote_folder) }
.not_to(change { case_log.reload.cap })
end
end
end
end
context "when updating major repairs" do context "when updating major repairs" do
let(:field) { "major_repairs" } let(:field) { "major_repairs" }

Loading…
Cancel
Save