Skip to content

Commit

Permalink
Consider Codelist items optional
Browse files Browse the repository at this point in the history
  • Loading branch information
eronisko committed May 8, 2017
1 parent bc39f0a commit 7b29764
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/jobs/ra/fetch_changes_batch_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def build_property_registration_number_change(tag)
when :BuildingTypeCode
codelist = parse_codelist(ch.children.first)
fail unless codelist[:code] == 'CL010143'
payload[:building_type_code] = Ra::BuildingTypeCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
if codelist[:item]
payload[:building_type_code] = Ra::BuildingTypeCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
end
else
fail "Don't know how to handle #{ch.name}"
end
Expand Down Expand Up @@ -198,7 +200,9 @@ def build_region_change(tag)
when :Region
codelist = parse_codelist(child.children.first)
fail unless codelist[:code] == 'CL000023'
payload[:region_code] = Ra::RegionCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
if codelist[:item]
payload[:region_code] = Ra::RegionCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
end
else
fail "Don't know how to handle #{child.name}"
end
Expand All @@ -223,7 +227,9 @@ def build_county_change(tag)
when :County
codelist = parse_codelist(child.children.first)
fail unless codelist[:code] == 'CL000024'
payload[:county_code] = Ra::CountyCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
if codelist[:item]
payload[:county_code] = Ra::CountyCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
end
else
fail "Don't know how to handle #{child.name}"
end
Expand Down Expand Up @@ -253,7 +259,9 @@ def build_municipality_change(tag)
when :Municipality
codelist = parse_codelist(child.children.first)
fail unless codelist[:code] == 'CL000025'
payload[:municipality_code] = Ra::MunicipalityCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
if codelist[:item]
payload[:municipality_code] = Ra::MunicipalityCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
end
else
fail "Don't know how to handle #{child.name}"
end
Expand All @@ -279,7 +287,9 @@ def build_district_change(tag)
payload[:unique_numbering] = child.attrs[:UniqueNumbering] == 'true'
codelist = parse_codelist(child.children.first)
fail unless codelist[:code] == 'CL010141'
payload[:district_code] = Ra::DistrictCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
if codelist[:item]
payload[:district_code] = Ra::DistrictCode.find_or_create_by!(code: codelist[:item][:code], name: codelist[:item][:name])
end
else
fail "Don't know how to handle #{child.name}"
end
Expand Down

0 comments on commit 7b29764

Please sign in to comment.