Newer
Older
# == Schema Information
#
# Table name: research_hal_authors
#
# id :uuid not null, primary key
# first_name :string
# form_identifier :string
# full_name :string
# last_name :string
# person_identifier :string
# created_at :datetime not null
# updated_at :datetime not null
#
Sébastien Gaya
committed
include Sanitizable
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
has_and_belongs_to_many :publications,
foreign_key: 'research_hal_publication_id',
association_foreign_key: 'research_hal_author_id'
has_and_belongs_to_many :university_person_researchers,
class_name: 'University::Person',
foreign_key: 'university_person_id',
association_foreign_key: 'research_hal_author_id'
alias :researchers :university_person_researchers
scope :ordered, -> { order(:last_name, :first_name, :docid)}
def self.import_from_hal(full_name)
authors = []
fields = [
'docid',
'form_i',
'person_i',
'firstName_s',
'lastName_s',
'fullName_s'
]
HalOpenscience::Author.search(full_name, fields: fields).results.each do |doc|
authors << create_from(doc)
end
authors
end
def self.create_from(doc)
author = where(docid: doc.docid).first_or_create
author.form_identifier = doc.form_i
author.person_identifier = doc&.person_i if doc.attributes.has_key?(:person_i)
author.first_name = doc.firstName_s
author.last_name = doc.lastName_s
author.full_name = doc.fullName_s
author.save
author
end
# Direct import from HAL, does not return persisted publications
def sample_documents
HalOpenscience::Document.search("authIdFormPerson_s:#{docid}", fields: ['citationFull_s'], limit: 5)
.results
.collect(&:citationFull_s)
end
def import_research_hal_publications!
publications.clear
# Do not overuse the API if no researcher is concerned
Research::Hal::Publication.import_from_hal_for_author(self).each do |publication|
publications << publication
end
publications
end
def connect_researcher(researcher)
researchers << researcher
Sébastien Gaya
committed