Disable import
This commit is contained in:
parent
ac3d9adae3
commit
a40b7a4cd2
10 changed files with 0 additions and 488 deletions
|
@ -1,35 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ImportAll
|
||||
include Interactor
|
||||
|
||||
def dirname
|
||||
@dirname ||= Pathname.new(context.dirname).realpath.freeze
|
||||
end
|
||||
|
||||
def call
|
||||
import 'LPR_REGIONAL_DEPTS_ALL.csv', ImportRegionalOffice
|
||||
import 'LPR_PEOPLE_ALL.csv', ImportPerson
|
||||
import 'LPR_CONTACTS_ALL.csv', ImportContact
|
||||
import 'LPR_PARTY_MEMBERS_ALL.csv', ImportRelationship
|
||||
|
||||
# Imported in "db/seeds.rb":
|
||||
#
|
||||
# LPR_CONTACT_NETWORKS_ALL.csv
|
||||
# LPR_REGIONS_ALL.csv
|
||||
|
||||
# Unnecessary:
|
||||
#
|
||||
# LPR_EVENTS_ALL.csv
|
||||
# LPR_STATUSES_ALL.csv
|
||||
# LPR_USERS.csv
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def import(filename, interactor)
|
||||
CSV.read(dirname.join(filename), col_sep: ';').drop(1).each do |row|
|
||||
interactor.call row: row
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ImportContact
|
||||
include Interactor
|
||||
|
||||
def call
|
||||
return if person_id.nil?
|
||||
|
||||
person = Person.find person_id
|
||||
contact_network = ContactNetwork.find contact_network_id
|
||||
|
||||
context.contact = Contact.where(id: contact_id).lock(true).first_or_create!(
|
||||
contact_list: person.contact_list,
|
||||
contact_network: contact_network,
|
||||
value: value,
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def contact_id
|
||||
context.row[0].presence
|
||||
end
|
||||
|
||||
def person_id
|
||||
context.row[1].presence
|
||||
end
|
||||
|
||||
def contact_network_id
|
||||
context.row[2].presence
|
||||
end
|
||||
|
||||
def value
|
||||
context.row[3].presence
|
||||
end
|
||||
end
|
|
@ -1,222 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ImportPerson # rubocop:disable Metrics/ClassLength
|
||||
include Interactor
|
||||
|
||||
def call # rubocop:disable Metrics/MethodLength
|
||||
ActiveRecord::Base.transaction do
|
||||
create_person
|
||||
create_passport
|
||||
create_general_comments_person_comment
|
||||
create_first_contact_date_person_comment
|
||||
create_latest_contact_date_person_comment
|
||||
create_human_readable_id_person_comment
|
||||
create_past_experience_person_comment
|
||||
create_aid_at_2014_elections_person_comment
|
||||
create_aid_at_2015_elections_person_comment
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_person
|
||||
context.person = Person.where(id: person_id).lock(true).first_or_create!(
|
||||
person_attributes.reverse_merge(
|
||||
contact_list: ContactList.new,
|
||||
),
|
||||
)
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
|
||||
def create_passport # rubocop:disable Metrics/MethodLength
|
||||
return if passport_attributes[:number].blank?
|
||||
|
||||
context.passport =
|
||||
Passport
|
||||
.where(person_id: context.person.id).lock(true).first_or_initialize
|
||||
|
||||
context.passport.federal_subject = FederalSubject.find_by id: region_id
|
||||
|
||||
passport_attributes.each do |(key, value)|
|
||||
context.passport.public_send "#{key}=", value
|
||||
end
|
||||
|
||||
context.passport.save!
|
||||
rescue
|
||||
context.passport = nil
|
||||
end
|
||||
|
||||
def create_general_comments_person_comment
|
||||
return if general_comments.blank?
|
||||
|
||||
context.general_comments_person_comment =
|
||||
context
|
||||
.person.person_comments.where(origin: :general_comments).lock(true)
|
||||
.first_or_initialize
|
||||
|
||||
context.general_comments_person_comment.text = general_comments
|
||||
|
||||
context.general_comments_person_comment.save!
|
||||
end
|
||||
|
||||
def create_first_contact_date_person_comment
|
||||
return if first_contact_date.blank?
|
||||
|
||||
context.first_contact_date_person_comment =
|
||||
context
|
||||
.person.person_comments.where(origin: :first_contact_date).lock(true)
|
||||
.first_or_initialize
|
||||
|
||||
context.first_contact_date_person_comment.text = first_contact_date
|
||||
|
||||
context.first_contact_date_person_comment.save!
|
||||
end
|
||||
|
||||
def create_latest_contact_date_person_comment
|
||||
return if latest_contact_date.blank?
|
||||
|
||||
context.latest_contact_date_person_comment =
|
||||
context
|
||||
.person.person_comments.where(origin: :latest_contact_date).lock(true)
|
||||
.first_or_initialize
|
||||
|
||||
context.latest_contact_date_person_comment.text = latest_contact_date
|
||||
|
||||
context.latest_contact_date_person_comment.save!
|
||||
end
|
||||
|
||||
def create_human_readable_id_person_comment
|
||||
return if human_readable_id.blank?
|
||||
|
||||
context.human_readable_id_person_comment =
|
||||
context
|
||||
.person.person_comments.where(origin: :human_readable_id).lock(true)
|
||||
.first_or_initialize
|
||||
|
||||
context.human_readable_id_person_comment.text = human_readable_id
|
||||
|
||||
context.human_readable_id_person_comment.save!
|
||||
end
|
||||
|
||||
def create_past_experience_person_comment
|
||||
return if past_experience.blank?
|
||||
|
||||
context.past_experience_person_comment =
|
||||
context
|
||||
.person.person_comments.where(origin: :past_experience).lock(true)
|
||||
.first_or_initialize
|
||||
|
||||
context.past_experience_person_comment.text = past_experience
|
||||
|
||||
context.past_experience_person_comment.save!
|
||||
end
|
||||
|
||||
def create_aid_at_2014_elections_person_comment
|
||||
return if aid_at_2014_elections.blank?
|
||||
|
||||
context.aid_at_2014_elections_person_comment =
|
||||
context
|
||||
.person.person_comments.where(origin: :aid_at_2014_elections).lock(true)
|
||||
.first_or_initialize
|
||||
|
||||
context.aid_at_2014_elections_person_comment.text = aid_at_2014_elections
|
||||
|
||||
context.aid_at_2014_elections_person_comment.save!
|
||||
end
|
||||
|
||||
def create_aid_at_2015_elections_person_comment
|
||||
return if aid_at_2015_elections.blank?
|
||||
|
||||
context.aid_at_2015_elections_person_comment =
|
||||
context
|
||||
.person.person_comments.where(origin: :aid_at_2015_elections).lock(true)
|
||||
.first_or_initialize
|
||||
|
||||
context.aid_at_2015_elections_person_comment.text = aid_at_2015_elections
|
||||
|
||||
context.aid_at_2015_elections_person_comment.save!
|
||||
end
|
||||
|
||||
def person_id
|
||||
context.row[0].presence
|
||||
end
|
||||
|
||||
def region_id
|
||||
context.row[14].presence
|
||||
end
|
||||
|
||||
def person_attributes
|
||||
{
|
||||
last_name: context.row[2].presence,
|
||||
first_name: context.row[1].presence,
|
||||
middle_name: context.row[3].presence,
|
||||
sex: nil,
|
||||
date_of_birth: context.row[8].presence,
|
||||
place_of_birth: context.row[9].presence,
|
||||
}
|
||||
end
|
||||
|
||||
def passport_attributes # rubocop:disable Metrics/MethodLength
|
||||
{
|
||||
last_name: context.row[2].presence,
|
||||
first_name: context.row[1].presence,
|
||||
middle_name: context.row[3].presence,
|
||||
sex: :male,
|
||||
date_of_birth: context.row[8].presence,
|
||||
place_of_birth: context.row[9].presence,
|
||||
|
||||
series: context.row[38].presence,
|
||||
number: context.row[10].presence,
|
||||
issued_by: context.row[11].presence,
|
||||
unit_code: context.row[12].presence,
|
||||
date_of_issue: context.row[13].presence,
|
||||
zip_code: context.row[15].presence,
|
||||
|
||||
town_type: context.row[20].presence,
|
||||
town_name: context.row[21].presence,
|
||||
settlement_type: context.row[22].presence,
|
||||
settlement_name: context.row[23].presence,
|
||||
district_type: context.row[18].presence,
|
||||
district_name: context.row[19].presence,
|
||||
street_type: context.row[16].presence,
|
||||
street_name: context.row[17].presence,
|
||||
residence_type: context.row[24].presence,
|
||||
residence_name: context.row[25].presence,
|
||||
building_type: context.row[26].presence,
|
||||
building_name: context.row[27].presence,
|
||||
apartment_type: context.row[28].presence,
|
||||
apartment_name: context.row[29].presence,
|
||||
}
|
||||
end
|
||||
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def general_comments
|
||||
context.row[5].presence
|
||||
end
|
||||
|
||||
def first_contact_date
|
||||
context.row[6].presence
|
||||
end
|
||||
|
||||
def latest_contact_date
|
||||
context.row[7].presence
|
||||
end
|
||||
|
||||
def human_readable_id
|
||||
context.row[34].presence
|
||||
end
|
||||
|
||||
def past_experience
|
||||
context.row[35].presence
|
||||
end
|
||||
|
||||
def aid_at_2014_elections
|
||||
context.row[36].presence
|
||||
end
|
||||
|
||||
def aid_at_2015_elections
|
||||
context.row[37].presence
|
||||
end
|
||||
end
|
|
@ -1,29 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ImportRegionalOffice
|
||||
include Interactor
|
||||
|
||||
def call
|
||||
federal_subject = FederalSubject.find federal_subject_id
|
||||
|
||||
context.regional_office =
|
||||
RegionalOffice.where(id: regional_office_id).first_or_create!(
|
||||
federal_subject: federal_subject,
|
||||
name: name,
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def regional_office_id
|
||||
context.row[0].presence
|
||||
end
|
||||
|
||||
def federal_subject_id
|
||||
context.row[2].presence
|
||||
end
|
||||
|
||||
def name
|
||||
context.row[1].presence
|
||||
end
|
||||
end
|
|
@ -1,131 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ImportRelationship
|
||||
include Interactor
|
||||
|
||||
def call
|
||||
return if status.nil? || regional_office_id.nil?
|
||||
|
||||
case status
|
||||
when :supporter then create_supporter_relationship
|
||||
when :member then create_member_relationship
|
||||
when :excluded then create_excluded_relationship
|
||||
else raise "Invalid status: #{status.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def person
|
||||
@person ||= Person.find person_id
|
||||
end
|
||||
|
||||
def regional_office
|
||||
@regional_office ||= RegionalOffice.find regional_office_id
|
||||
end
|
||||
|
||||
def create_supporter_relationship
|
||||
return if supporter_from_date.nil?
|
||||
|
||||
Relationship.where(id: supporter_relationship_id).first_or_create!(
|
||||
person: person,
|
||||
regional_office: regional_office,
|
||||
from_date: supporter_from_date,
|
||||
status: :supporter,
|
||||
)
|
||||
end
|
||||
|
||||
def create_member_relationship
|
||||
return if member_from_date.nil?
|
||||
|
||||
Relationship.where(id: member_relationship_id).first_or_create!(
|
||||
person: person,
|
||||
regional_office: regional_office,
|
||||
from_date: member_from_date,
|
||||
status: :member,
|
||||
role: member_role,
|
||||
)
|
||||
end
|
||||
|
||||
def create_excluded_relationship
|
||||
return if excluded_from_date.nil?
|
||||
|
||||
Relationship.where(id: excluded_relationship_id).first_or_create!(
|
||||
person: person,
|
||||
regional_office: regional_office,
|
||||
from_date: excluded_from_date,
|
||||
status: :excluded,
|
||||
)
|
||||
end
|
||||
|
||||
def supporter_relationship_id
|
||||
Integer(context.row[0]) * 5 + 0
|
||||
end
|
||||
|
||||
def member_relationship_id
|
||||
Integer(context.row[0]) * 5 + 1
|
||||
end
|
||||
|
||||
def excluded_relationship_id
|
||||
Integer(context.row[0]) * 5 + 2
|
||||
end
|
||||
|
||||
def person_id
|
||||
context.row[1].presence
|
||||
end
|
||||
|
||||
def regional_office_id
|
||||
context.row[2].presence
|
||||
end
|
||||
|
||||
def status
|
||||
case context.row[3].to_i
|
||||
when 1 then :member
|
||||
when 3 then :supporter
|
||||
when 4 then :excluded
|
||||
end
|
||||
end
|
||||
|
||||
def supporter_from_date
|
||||
member_from_date
|
||||
end
|
||||
|
||||
def member_from_date
|
||||
m = /\A(\d\d)\.(\d\d)\.(\d\d\d\d)\z/.match context.row[4]
|
||||
return if m.nil?
|
||||
|
||||
Date.new m[3].to_i, m[2].to_i, m[1].to_i
|
||||
end
|
||||
|
||||
def excluded_from_date
|
||||
m = /\A(\d\d)\.(\d\d)\.(\d\d\d\d)\z/.match context.row[6]
|
||||
return if m.nil?
|
||||
|
||||
Date.new m[3].to_i, m[2].to_i, m[1].to_i
|
||||
end
|
||||
|
||||
def comment
|
||||
context.row[7].presence
|
||||
end
|
||||
|
||||
def secretary?
|
||||
context.row[5] == 'Y'
|
||||
end
|
||||
|
||||
def manager?
|
||||
secretary? || context.row[16] == 'Y'
|
||||
end
|
||||
|
||||
def supervisor?
|
||||
context.row[15] == 'Y'
|
||||
end
|
||||
|
||||
def member_role
|
||||
return :regional_supervisor if supervisor?
|
||||
return :regional_manager if manager?
|
||||
end
|
||||
|
||||
def member_regional_secretary_flag
|
||||
return :regional_secretary if secretary?
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ImportAll do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ImportContact do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ImportPerson do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ImportRegionalOffice do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ImportRelationship do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Reference in a new issue