Skip to content

Commit

Permalink
reformatted, no other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ij committed Jul 2, 2022
1 parent baebfb8 commit dd60973
Show file tree
Hide file tree
Showing 12 changed files with 728 additions and 703 deletions.
216 changes: 109 additions & 107 deletions lib/sf/account.rb
Original file line number Diff line number Diff line change
@@ -1,123 +1,125 @@
class Sf::Account
include Sf::Base
# frozen_string_literal: true

FIELDS = ['Id', 'Name', 'Member_Type__c', 'Member_Category__c', 'MOU_Participant__c', 'Member_Join_Date__c', 'Status__c', 'Website', 'InCommon_Participant__c', 'InCommon_Participation__c', 'iMIS_ID__c', 'Membership_Status__c']
FIELDS_SELECT_STR = FIELDS.join(', ')
MEMBER_TYPES = ['R&E Network Member', 'University Member', 'Industry Member', 'Affiliate Member']
MEMBER_TYPES_STR = MEMBER_TYPES.map{|v| "\'#{v}\'"}.join(', ')
module Sf
class Account
include Sf::Base

def initialize(account=nil)
@account = account
end
FIELDS = %w[Id Name Member_Type__c Member_Category__c MOU_Participant__c Member_Join_Date__c
Status__c Website InCommon_Participant__c InCommon_Participation__c iMIS_ID__c Membership_Status__c].freeze
FIELDS_SELECT_STR = FIELDS.join(', ')
MEMBER_TYPES = ['R&E Network Member', 'University Member', 'Industry Member', 'Affiliate Member'].freeze
MEMBER_TYPES_STR = MEMBER_TYPES.map { |v| "\'#{v}\'" }.join(', ')

def update(args={})
params = {Id: self.Id}
args.map {|k,v| params[k] = v}
end
def initialize(account = nil)
@account = account
end

def contacts
Sf::Contact.where({AccountId: self.Id, Status__c: 'Active'})
end
def update(args = {})
params = { Id: self.Id }
args.map { |k, v| params[k] = v }
end

def method_missing(method_name, *args, &block)
@account.send(method_name, *args, &block)
end
def contacts
Sf::Contact.where({ AccountId: self.Id, Status__c: 'Active' })
end

def respond_to_missing?(method_name, include_private = false)
@account.respond_to?(method_name, include_private) || super
end
def method_missing(method_name, *args, &block)
@account.send(method_name, *args, &block)
end

def inc_execs
Sf::Contact.inc_execs_for(self.Id)
end
def respond_to_missing?(method_name, include_private = false)
@account.respond_to?(method_name, include_private) || super
end

def inc_part_since_year
if self.InCommon_Participant__c
start_date = start_dates_by_subscription["InCommon Participation"]
start_date.split("-")[0] if start_date
def inc_execs
Sf::Contact.inc_execs_for(self.Id)
end
end

# Class Methods
def self.find(id)
new Sf.client.find("Account", id)
end
def inc_part_since_year
if self.InCommon_Participant__c
start_date = start_dates_by_subscription['InCommon Participation']
start_date.split('-')[0] if start_date
end
end

def self.find_by(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobject = Sf.client.query("select #{FIELDS_SELECT_STR} from Account where #{where}").first
if sobject.present?
new sobject
# Class Methods
def self.find(id)
new Sf.client.find('Account', id)
end
end

def self.intl_partners
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where MOU_Participant__c = true order by Name")
end
def self.find_by(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobject = Sf.client.query("select #{FIELDS_SELECT_STR} from Account where #{where}").first
new sobject if sobject.present?
end

def self.members
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where Membership_Status__c = true order by Name")
end
def self.intl_partners
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where MOU_Participant__c = true order by Name")
end

def self.all
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account order by Name")
end
def self.members
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where Membership_Status__c = true order by Name")
end

def self.all
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account order by Name")
end

def self.community_orgs
build_collection Sf.client.query(
"select #{FIELDS_SELECT_STR} from Account
def self.community_orgs
build_collection Sf.client.query(
"select #{FIELDS_SELECT_STR} from Account
where Name='Internet2' or InCommon_Participant__c = true
or Membership_Status__c = true
or MOU_Participant__c = true
order by Name"
)
end
)
end

def self.incommon_participants
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true order by Name")
end
def self.incommon_participants
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true order by Name")
end

def self.internet2
i2 = find_by({Name: "Internet2", Status__c: "Active"})
find i2.Id
end
def self.internet2
i2 = find_by({ Name: 'Internet2', Status__c: 'Active' })
find i2.Id
end

def self.member?(account_id)
members.map(&:Id).include?(account_id)
end
def self.member?(account_id)
members.map(&:Id).include?(account_id)
end

def self.inc_part?(account_id)
incommon_participants.map(&:Id).include?(account_id)
end
def self.inc_part?(account_id)
incommon_participants.map(&:Id).include?(account_id)
end

def self.intl_partner?(account_id)
intl_partners.map(&:Id).include?(account_id)
end
def self.intl_partner?(account_id)
intl_partners.map(&:Id).include?(account_id)
end

# Accounts with a closed won opportunity but not yet the "InCommon Control" check box is checked.
def self.inc_parts_to_be
acct_ids = Sf::Opportunity.inc_participations(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map{|v| "\'#{v}\'"}.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c != true and Id in (#{accts_str})")
# Accounts with a closed won opportunity but not yet the "InCommon Control" check box is checked.
def self.inc_parts_to_be
acct_ids = Sf::Opportunity.inc_participations(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map { |v| "\'#{v}\'" }.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c != true and Id in (#{accts_str})")
end
end
end

def self.inc_certs_to_be
acct_ids = Sf::Opportunity.cert_subscribers(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map{|v| "\'#{v}\'"}.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true and Id in (#{accts_str})")
def self.inc_certs_to_be
acct_ids = Sf::Opportunity.cert_subscribers(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map { |v| "\'#{v}\'" }.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true and Id in (#{accts_str})")
end
end
end

def self.active_inc_parts(service_name)
today = Date.today.strftime('%Y-%m-%d')
sobjects = Sf.client.query("select
def self.active_inc_parts(service_name)
today = Date.today.strftime('%Y-%m-%d')
sobjects = Sf.client.query("select
Supporting_Institution__r.Id,
Supporting_Institution__r.Name,
Supporting_Institution__r.InCommon_Website_Name__c,
Expand All @@ -127,11 +129,11 @@ def self.active_inc_parts(service_name)
and (Service_End_Date__c = null or Service_End_Date__c > #{today})
and (Service_Start_Date__c = null or Service_Start_Date__c < #{today})
and Do_Not_Publish__c <> true")
build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank?
end
build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank?
end

def self.cert_service_subscribers
sobjects = Sf.client.query("select
def self.cert_service_subscribers
sobjects = Sf.client.query("select
Supporting_Institution__r.Id,
Supporting_Institution__r.Name,
Supporting_Institution__r.InCommon_Website_Name__c,
Expand All @@ -141,21 +143,21 @@ def self.cert_service_subscribers
and Service_End_Date__c = null
and (Type_of_Support__c = 'Subscriber' or Type_of_Support__c = 'subscriber_parent')
and Do_Not_Publish__c <> true")
build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank?
end
build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank?
end

private
private

def subscriptions
# sorting by Service_Start_Date__c in case of multiple subscriptions of the same service
Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\' ORDER BY Service_Start_Date__c")
end
def subscriptions
# sorting by Service_Start_Date__c in case of multiple subscriptions of the same service
Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\' ORDER BY Service_Start_Date__c")
end

# The latest subscription is included only in case of the multiple subscriptions of the same service.
def start_dates_by_subscription
start_dates = {}
subscriptions.each {|s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c}
start_dates
# The latest subscription is included only in case of the multiple subscriptions of the same service.
def start_dates_by_subscription
start_dates = {}
subscriptions.each { |s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c }
start_dates
end
end

end
25 changes: 12 additions & 13 deletions lib/sf/base.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

module Sf
module Base
def self.included(base)
base.extend(ClassMathods)
def update(args={})
def update(args = {})
unless self.Id.blank?
params = {'Id' => self.Id}
args.map {|k,v| params[k] = v}
Sf.client.update!(self.sobject.attributes[:type], params)
params = { 'Id' => self.Id }
args.map { |k, v| params[k] = v }
Sf.client.update!(sobject.attributes[:type], params)
end
end
end
Expand All @@ -17,18 +19,18 @@ def build_collection(models)
end

def class_name
obj = self.new
#TODO: migrate it to use obj.sobject, refer Opportunity initialize
obj = new
# TODO: migrate it to use obj.sobject, refer Opportunity initialize
cname = obj.sobject[:sobject_type]
cname ||= obj.sobject
end

def find(id)
new Sf.client.find(self.class_name, id)
new Sf.client.find(class_name, id)
end

def find_by_name(name)
sobject = where({Name: name}).first
sobject = where({ Name: name }).first
find(sobject.Id) unless sobject.blank?
end

Expand All @@ -38,13 +40,10 @@ def find_by(args = {})
end

def where(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobjects = Sf.client.query("select Id, Name from #{self.class_name} where #{where}")
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobjects = Sf.client.query("select Id, Name from #{class_name} where #{where}")
build_collection sobjects unless sobjects.blank?
end

end

end

end
65 changes: 34 additions & 31 deletions lib/sf/contact_affiliation.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
class Sf::ContactAffiliation
include Sf::Base
API_NAME = 'Contact_Affiliation__c'
#FIELDS = [
# 'Account__c', 'Contact__c', 'Contact_Email__c', 'Contact_Name__c',
# 'End_Date__c', 'Primary__c', 'Program__c', 'Role__c', 'Service__c',
# 'Status__c', 'Title__c'
#]
FIELDS = [
'Account__c', 'Contact__c', 'Contact_Email__c', 'Contact_Name__c',
'Program__c', 'Role__c', 'Service__c',
'Status__c', 'Title__c'
]
FIELDS_SELECT_STR = FIELDS.join(', ')
# frozen_string_literal: true

def initialize(contact_affiliation = nil)
@contact_affiliation = contact_affiliation
end
module Sf
class ContactAffiliation
include Sf::Base
API_NAME = 'Contact_Affiliation__c'
# FIELDS = [
# 'Account__c', 'Contact__c', 'Contact_Email__c', 'Contact_Name__c',
# 'End_Date__c', 'Primary__c', 'Program__c', 'Role__c', 'Service__c',
# 'Status__c', 'Title__c'
# ]
FIELDS = %w[
Account__c Contact__c Contact_Email__c Contact_Name__c
Program__c Role__c Service__c
Status__c Title__c
].freeze
FIELDS_SELECT_STR = FIELDS.join(', ')

def account
new Sf::Account.find("Account", Account__c)
end
def initialize(contact_affiliation = nil)
@contact_affiliation = contact_affiliation
end

def method_missing(method_name, *args, &block)
@contact_affiliation.send(method_name, *args, &block)
end
def account
new Sf::Account.find('Account', Account__c)
end

def respond_to_missing?(method_name, include_private = false)
@contact_affiliation.respond_to?(method_name, include_private) || super
end
def method_missing(method_name, *args, &block)
@contact_affiliation.send(method_name, *args, &block)
end

def respond_to_missing?(method_name, include_private = false)
@contact_affiliation.respond_to?(method_name, include_private) || super
end

def self.where(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from #{API_NAME} where #{where}")
build_collection sobjects unless sobjects.blank?
def self.where(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from #{API_NAME} where #{where}")
build_collection sobjects unless sobjects.blank?
end
end

end
Loading

0 comments on commit dd60973

Please sign in to comment.