Class: PartySearchFact

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/party_search_fact.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.destroy_search_fact(party) ⇒ Object



45
46
47
48
49
50
51
# File 'app/models/party_search_fact.rb', line 45

def self.destroy_search_fact(party)
  sf = PartySearchFact.find(:first, :conditions => ["party_id = ?", party.id])

  return if sf.nil?

  sf.destroy
end

.update_search_fact(party) ⇒ Object



38
39
40
41
42
43
# File 'app/models/party_search_fact.rb', line 38

def self.update_search_fact(party)    
  sf = PartySearchFact.find(:first, :conditions => ["party_id = ?", party.id])

  sf = PartySearchFact.create(:party_id => party.id) if sf.nil?
  sf.update_search_fact(party)
end

Instance Method Details

#sunspot_commitObject



80
81
82
# File 'app/models/party_search_fact.rb', line 80

def sunspot_commit
  Sunspot.commit    
end

#update_search_fact(party) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/party_search_fact.rb', line 53

def update_search_fact(party)
  self.update_attributes(
      :party_id => party.id,
      :eid => party.enterprise_identifier,
      :roles => (party.user.roles.map { |role| role.internal_identifier }.join(',') rescue ''),
      :party_description => party.description,
      :party_business_party_type => party.business_party_type,
      :user_login => (party.user.username rescue ''),
      :individual_current_last_name => (party.business_party.current_last_name rescue ''),
      :individual_current_first_name => (party.business_party.current_first_name rescue ''),
      :individual_current_middle_name => (party.business_party.current_middle_name rescue ''),
      :individual_birth_date => (party.business_party.birth_date rescue ''),
      :individual_ssn => (party.business_party.ssn_last_four rescue ''),
      :party_phone_number => (party.personal_phone_number.phone_number rescue ''),
      :party_email_address => (party.personal_email_address.email_address rescue ''),
      :party_address_1 => (party.home_postal_address.address_line_1 rescue ''),
      :party_address_2 => (party.home_postal_address.address_line_2 rescue ''),
      :party_primary_address_city => (party.home_postal_address.city rescue ''),
      :party_primary_address_state => (party.home_postal_address.state rescue ''),
      :party_primary_address_zip => (party.home_postal_address.zip rescue ''),
      :party_primary_address_country => (party.home_postal_address.country rescue ''),
      :user_enabled => (party.user.enabled rescue false),
      :user_type => (party.user.attributes['type'] rescue '')
      )
  Sunspot.commit
end