Skip to content

Commit

Permalink
added events to graphql api. #346
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 12, 2019
1 parent 0c1fdc0 commit 98a1f64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions app/graphql/types/event_data_edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,34 @@ class EventDataEdge < GraphQL::Relay::Edge

def event_data
@event_data ||= begin
Event.query(nil, subj_id: self.node.id, obj_id: self.parent.id).results.first.to_h
return nil unless self.node.present?
Event.query(nil, subj_id: doi_from_node(self.node), obj_id: self.parent.id).results.first.to_h.fetch("_source", nil)
end
end

def source_id
self.node.id
self.node.identifier if self.node.present?
end

def target_id
self.parent.id
end

def source
event_data.source_id.underscore.camelcase(:lower)
event_data.source_id if event_data.present?
end

# We are switching subj and obj, and thus need to change direction of relation type
def relation_type
rt = event_data.relation_type_id.underscore.camelcase(:lower)
RELATION_TYPES.fetch(rt, rt)
event_data.relation_type_id.underscore.camelcase(:lower) if event_data.present?
end

def total
event_data.total
event_data.total if event_data.present?
end

def doi_from_node(node)
return nil unless node.present?

"https://doi.org/#{node.uid.downcase}"
end
end
4 changes: 2 additions & 2 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def query(query, options={})
must << { terms: { "client.certificate" => options[:certificate].split(",") }} if options[:certificate].present?
must_not << { terms: { provider_id: ["crossref", "medra", "op"] }} if options[:exclude_registration_agencies]
elsif self.name == "Event"
must << { term: { subj_id: options[:subj_id] }} if options[:subj_id].present?
must << { term: { obj_id: options[:obj_id] }} if options[:obj_id].present?
must << { term: { subj_id: URI.decode(options[:subj_id]) }} if options[:subj_id].present?
must << { term: { obj_id: URI.decode(options[:obj_id]) }} if options[:obj_id].present?
must << { term: { citation_type: options[:citation_type] }} if options[:citation_type].present?
must << { term: { year_month: options[:year_month] }} if options[:year_month].present?
must << { range: { "subj.datePublished" => { gte: "#{options[:publication_year].split("-").min}||/y", lte: "#{options[:publication_year].split("-").max}||/y", format: "yyyy" }}} if options[:publication_year].present?
Expand Down

0 comments on commit 98a1f64

Please sign in to comment.