Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Sf.client.query('select ') returns nil instead of [] now, so added li…
…ne to return [] when the query result is nil
ij committed Jul 2, 2022
1 parent dd60973 commit 5c9a7b1
Showing 15 changed files with 25 additions and 24 deletions.
6 changes: 3 additions & 3 deletions lib/sf/account.rb
@@ -129,7 +129,7 @@ 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?
sobjects.blank? ? [] : build_collection(sobjects.map(&:Supporting_Institution__r))
end

def self.cert_service_subscribers
@@ -143,7 +143,7 @@ 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?
sobjects.blank? ? [] : build_collection(sobjects.map(&:Supporting_Institution__r))
end

private
@@ -156,7 +156,7 @@ def subscriptions
# 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 }
subscriptions&.each { |s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c }
start_dates
end
end
2 changes: 1 addition & 1 deletion lib/sf/base.rb
@@ -42,7 +42,7 @@ def find_by(args = {})
def where(args = {})
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?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
2 changes: 1 addition & 1 deletion lib/sf/contact.rb
@@ -113,7 +113,7 @@ def self.find(id)
def self.where(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from Contact where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.find_by(args = {})
2 changes: 1 addition & 1 deletion lib/sf/contact_affiliation.rb
@@ -35,7 +35,7 @@ def respond_to_missing?(method_name, include_private = false)
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?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
6 changes: 3 additions & 3 deletions lib/sf/opportunity.rb
@@ -33,20 +33,20 @@ def self.inc_participations(since_date = nil)
since_date ||= Date.today
since = since_date.to_date.to_s
sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from Opportunity where Name like '%InCommon Participation%' and IsWon = true and CloseDate >= #{since}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.cert_subscribers(since_date = nil)
since_date ||= Date.today
since = since_date.to_date.to_s
sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from Opportunity where Name like '%Certificate Service%' and (not Type like '%Existing Business%') and IsWon = true and CloseDate >= #{since}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.eduroam_opportunities
stages = "('Closed Won', 'Negotiation/Review', 'Transferred Internally', 'Proposal/Price Quote', 'Prospecting')"
sobjects = Sf.client.query("select #{FIELDS_SELECT_STR}, Account.Name from Opportunity where Name like '%Trust and Identity - eduroam%' and StageName in #{stages}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

# stages
2 changes: 1 addition & 1 deletion lib/sf/presenter.rb
@@ -20,7 +20,7 @@ def respond_to_missing?(method_name, include_private = false)
def where(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobjects = Sf.client.query("select Id, Name, cms_presenter_id__c from #{class_name} where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
4 changes: 2 additions & 2 deletions lib/sf/reg_event.rb
@@ -39,13 +39,13 @@ def self.find_by_code(code)
def self.where(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from RegEvent__c where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.by_codes(codes = [])
where = codes.map { |code| "code__c = \'#{code}\'" }.join(' or ')
sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from RegEvent__c where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.create_from_event(event)
2 changes: 1 addition & 1 deletion lib/sf/reg_meeting.rb
@@ -41,7 +41,7 @@ def self.find_all_by_event_id(event_id)
def self.where(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobjects = Sf.client.query("select Id, Name from RegMeeting__c where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
2 changes: 1 addition & 1 deletion lib/sf/reg_option.rb
@@ -50,7 +50,7 @@ def self.find_all_by_event_id(event_id)
def self.where(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobjects = Sf.client.query("select Id, Name from RegOption__c where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
2 changes: 1 addition & 1 deletion lib/sf/reg_rate.rb
@@ -41,7 +41,7 @@ def self.find_all_by_meeting_id(meeting_id)
def self.where(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobjects = Sf.client.query("select Id, Name from RegRate__c where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
5 changes: 3 additions & 2 deletions lib/sf/reg_registration.rb
@@ -173,12 +173,12 @@ def self.order_by(args = {})
def self.query_with_reg_item_codes(where_stmt, order_stmt)
reg_item_select = 'select code__c, reg_rate_code__c from reg_items__r'
sobjects = Sf.client.query("select Id, #{FIELDS_SELECT_STR}, (#{reg_item_select}) from RegRegistration__c where #{where_stmt} #{order_stmt}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.query(where_stmt, order_stmt)
sobjects = Sf.client.query("select Id, #{FIELDS_SELECT_STR} from RegRegistration__c where #{where_stmt} #{order_stmt}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.attendees_for(event_code, reg_item_code)
@@ -189,6 +189,7 @@ def self.attendees_for(event_code, reg_item_code)
where = "code__c = \'#{reg_item_code}\' and #{rr}.event_code__c = \'#{event_code}\'"
sobjects = Sf.client.query("select #{selects} from RegItem__c where #{where}")
build_collection sobjects.map(&:reg_registration_id__r) unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects.map(&:reg_registration_id__r))
end

def self.roster_for(event_code, reg_item_code)
2 changes: 1 addition & 1 deletion lib/sf/service_institution.rb
@@ -35,7 +35,7 @@ def self.find(id)
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?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
8 changes: 4 additions & 4 deletions lib/sf/session.rb
@@ -84,14 +84,14 @@ def self.presenters_by_event_code(code)
event = Sf::RegEvent.find_by(code__c: code)
sobjects = Sf.client.query("select Id, cms_session_id__c, (select Id, contact_id__c from Event_Presenters__r)
from EventSession__c where event__c = \'#{event.Id}\'")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.track_presenters_by_event_code(code)
event = Sf::RegEvent.find_by(code__c: code)
sobjects = Sf.client.query("select Id, cms_session_id__c, session_type__r.Name, (select Id, contact_id__c from Event_Presenters__r)
from EventSession__c where session_type__r.Name = 'Track Session' and event__c = \'#{event.Id}\'")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.presenter_ids_by_event_code(code)
@@ -117,7 +117,7 @@ def self.query(where_stmt)
session_type__r.Name, start_time__c, room_id__r.Name,
cms_session_id__c, timestamp__c, date__c, end_time__c, auto_publish__c, LastModifiedBy.Name
from EventSession__c where #{where_stmt}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end

def self.where(args = {})
@@ -126,7 +126,7 @@ def self.where(args = {})
session_type__r.Name, start_time__c, room_id__r.Name,
cms_session_id__c, timestamp__c, date__c, end_time__c, auto_publish__c
from EventSession__c where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
2 changes: 1 addition & 1 deletion lib/sf/sponsorship.rb
@@ -49,7 +49,7 @@ def self.where(args = {})
sobjects = Sf.client.query("select Id, event__c, contact__c, sponsor__c, logo_url__c,
cms_sponsor_id__c, cms_sponsor_name__c, sponsorship_type__c
from EventSponsorship__c where #{where}")
build_collection sobjects unless sobjects.blank?
sobjects.blank? ? [] : build_collection(sobjects)
end
end
end
2 changes: 1 addition & 1 deletion lib/sf/version.rb
@@ -1,3 +1,3 @@
module Sf
VERSION = "0.1.67"
VERSION = "0.1.68"
end

0 comments on commit 5c9a7b1

Please sign in to comment.