Skip to content
Snippets Groups Projects
Commit 4a8383b2 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

wip

parent ea36da7e
No related branches found
No related tags found
No related merge requests found
Showing
with 243 additions and 63 deletions
app/assets/images/admin/research/hal-thumb.jpg

30.5 KiB

app/assets/images/admin/research/hal.jpg

325 KiB

class Admin::Research::Hal::ApplicationController < Admin::Research::ApplicationController
protected
def breadcrumb
super
add_breadcrumb Research::Hal.model_name.human, admin_research_hal_root_path
end
end
\ No newline at end of file
class Admin::Research::Hal::AuthorsController < Admin::Research::Hal::ApplicationController
before_action :load_author, except: :index
before_action :load_researcher, only: [:connect_researcher, :disconnect_researcher]
def index
@authors = Research::Hal::Author.ordered.page(params[:page])
breadcrumb
end
def show
breadcrumb
end
def connect_researcher
@author.connect_researcher @researcher
redirect_back(fallback_location: admin_research_researcher_path(@researcher))
end
def disconnect_researcher
@author.disconnect_researcher @researcher
redirect_back(fallback_location: admin_research_researcher_path(@researcher))
end
def destroy
@author.destroy
redirect_to admin_research_hal_authors_path
end
protected
def load_author
@author = Research::Hal::Author.find params[:id]
end
def load_researcher
@researcher = current_university.university_people.find params[:researcher_id]
end
def breadcrumb
super
add_breadcrumb Research::Hal::Author.model_name.human(count: 2),
admin_research_hal_authors_path
breadcrumb_for @author
end
end
class Admin::Research::Hal::DashboardController < Admin::Research::Hal::ApplicationController
def index
@namespace = Research::Hal
breadcrumb
render 'admin/dashboard/namespace'
end
end
class Admin::Research::Hal::PublicationsController < Admin::Research::ApplicationController
class Admin::Research::Hal::PublicationsController < Admin::Research::Hal::ApplicationController
before_action :load_publication, except: :index
def index
......
......@@ -15,7 +15,7 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationContr
def show
@papers = @researcher.research_journal_papers.ordered.page(params[:page])
@possible_hal_authors = @researcher.possible_hal_authors
@hal_authors_with_same_name = Research::Hal::Author.import_from_hal @researcher.to_s
@papers = @researcher.research_journal_papers.ordered.page(params[:page])
breadcrumb
add_breadcrumb @researcher
......@@ -45,7 +45,7 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationContr
def breadcrumb
super
add_breadcrumb t('research.researchers', count: 2), admin_research_researchers_path
add_breadcrumb University::Person::Researcher.model_name.human(count: 2), admin_research_researchers_path
end
end
......@@ -5,4 +5,17 @@ module Research::Hal
def self.table_name_prefix
'research_hal_'
end
def self.update_from_api!
Research::Hal::Author.find_each do |author|
author.import_research_hal_publications!
end
end
def self.parts
[
[Research::Hal::Publication, :admin_research_hal_publications_path],
[Research::Hal::Author, :admin_research_hal_authors_path],
]
end
end
......@@ -3,7 +3,7 @@
# Table name: research_hal_authors
#
# id :uuid not null, primary key
# doc_identifier :string
# docid :string indexed
# first_name :string
# form_identifier :string
# full_name :string
......@@ -12,6 +12,71 @@
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_research_hal_authors_on_docid (docid)
#
class Research::Hal::Author < ApplicationRecord
has_and_belongs_to_many :publications
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!
# Do not use the API if no researcher is concerned
return if researchers.none?
Research::Hal::Publication.import_from_hal_for_author(self)
end
def connect_researcher(researcher)
researchers << researcher
end
def disconnect_researcher(researcher)
researchers.delete researcher
end
def to_s
"#{full_name}"
end
end
......@@ -23,9 +23,12 @@ class Research::Hal::Publication < ApplicationRecord
include WithGit
include WithSlug
DOI_PREFIX = 'http://dx.doi.org/'.freeze
has_and_belongs_to_many :researchers,
class_name: 'University::Person',
foreign_key: 'university_person_id',
association_foreign_key: 'research_hal_publication_id'
has_and_belongs_to_many :publications
DOI_PREFIX = 'http://dx.doi.org/'.freeze
before_destroy { research_people.clear }
......@@ -33,9 +36,27 @@ class Research::Hal::Publication < ApplicationRecord
scope :ordered, -> { order(publication_date: :desc)}
def self.import_from_hal_for_author(author)
fields = [
'docid',
'title_s',
'citationRef_s',
'uri_s',
'doiId_s',
'publicationDate_tdate',
'linkExtUrl_s',
# '*',
]
response = HalOpenscience::Document.search "authIdForm_i:#{author.form_identifier}", fields: fields, limit: 1000
response.results.each do |doc|
publication = Research::Hal::Publication.create_from doc
author.publications << publication unless publication.in?(author.publications)
end
end
def self.create_from(doc)
publication = where(docid: doc.docid).first_or_create
puts "pub-- #{where(docid: doc.docid).count}"
puts "HAL sync publication #{doc.docid}"
publication.title = Osuny::Sanitizer.sanitize doc.title_s.first, 'string'
publication.ref = doc.attributes['citationRef_s']
publication.hal_url = doc.attributes['uri_s']
......@@ -46,13 +67,6 @@ class Research::Hal::Publication < ApplicationRecord
publication
end
def self.update_from_hal
University::Person::Researcher.with_hal_identifier.find_each do |researcher|
# puts "Loading publications for #{researcher} (#{researcher.university})"
researcher.import_research_hal_publications!
end
end
def template_static
"admin/research/publications/static"
end
......
......@@ -2,17 +2,26 @@ module University::Person::WithResearch
extend ActiveSupport::Concern
included do
has_and_belongs_to_many :research_hal_authors,
class_name: 'Research::Hal::Author',
foreign_key: 'research_hal_author_id',
association_foreign_key: 'university_person_id'
alias :hal_authors :research_hal_authors
has_and_belongs_to_many :research_hal_publications,
class_name: 'Research::Hal::Publication',
foreign_key: 'research_publication_id',
association_foreign_key: 'university_person_id'
alias :publications :research_hal_publications
alias :hal_publications :research_hal_publications
alias :publications :research_hal_publications
scope :with_hal_identifier, -> { where.not(hal_form_identifier: [nil,'']) }
end
def import_research_hal_publications!
hal_authors.each do |author|
author.import_research_hal_publications!
end
response = HalOpenscience::Document.search "authIdForm_i:#{hal_form_identifier}",
fields: ["*"],
limit: 1000
......@@ -23,8 +32,4 @@ module University::Person::WithResearch
end
handle_asynchronously :import_research_hal_publications!
def possible_hal_authors
HalOpenscience::Author.search(to_s, fields: ["*"]).results
end
end
<div class="table-responsive">
<table class="<%= table_classes %>">
<thead>
<tr>
<th><%= Research::Hal::Author.human_attribute_name('full_name') %></th>
<th><%= Research::Hal::Publication.human_attribute_name('docid') %></th>
<th><%= Research::Hal::Publication.human_attribute_name('publications') %></th>
<th><%= Research::Hal::Publication.human_attribute_name('researchers') %></th>
</tr>
</thead>
<tbody>
<% authors.each do |author| %>
<tr>
<td><%= link_to author, [:admin, author] %></td>
<td><%= author.docid %></td>
<td><%= author.publications.count %></td>
<td><%= author.researchers.count %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
\ No newline at end of file
<% content_for :title, Research::Hal::Author.model_name.human(count: 2) %>
<% content_for :title_right, "#{ @authors.total_count }" %>
<%= render 'admin/research/hal/authors/list', authors: @authors %>
<%= paginate @authors, theme: 'bootstrap-5' %>
<% content_for :title, @author %>
<% content_for :action_bar_left do %>
<%= destroy_link @author %>
<% end %>
......@@ -4,7 +4,7 @@
<tr>
<th><%= Research::Hal::Publication.human_attribute_name('title') %></th>
<th><%= Research::Hal::Publication.human_attribute_name('publication_date') %></th>
<th><%= t('research.researchers', count: 2) %></th>
<th><%= University::Person::Researcher.model_name.human(count: 2) %></th>
</tr>
</thead>
<tbody>
......
......@@ -23,14 +23,14 @@
</div>
</div>
<div class="col-lg-4">
<% @publication.research_people.each do |person| %>
<% next if person.university != current_university %>
<% @publication.researchers.each do |researcher| %>
<% next if researcher.university != current_university %>
<article class="mb-4 d-flex align-items-center position-relative">
<div style="width: 80px">
<%= kamifusen_tag person.best_picture, width: 80, class: 'img-circle' if person.best_picture.attached? %>
<%= kamifusen_tag researcher.best_picture, width: 80, class: 'img-circle' if researcher.best_picture.attached? %>
</div>
<div class="ms-3">
<%= link_to person, admin_research_researcher_path(person), class: 'stretched-link' %>
<%= link_to researcher, admin_research_researcher_path(researcher), class: 'stretched-link' %>
</div>
</article>
<% end %>
......
<% content_for :title, t('research.researchers', count: 2) %>
<% content_for :title, University::Person::Researcher.model_name.human(count: 2) %>
<%= render 'filters', current_path: admin_research_researchers_path, filters: @filters if @filters.any? %>
......@@ -33,9 +33,4 @@
</tbody>
</table>
</div>
<%= paginate @researchers, theme: 'bootstrap-5' %>
<% content_for :action_bar_right do %>
<%= link_to t('research.manage_researchers'), admin_university_people_path, class: button_classes if can?(:read, University::Person) %>
<% end %>
......@@ -9,30 +9,30 @@
<% end %>
<% end %>
<%= osuny_panel Research::Hal::Author.model_name.human(count: 2), action: @researcher.hal_publications.count do %>
<%= osuny_panel Research::Hal::Author.model_name.human(count: 2) do %>
<p><%= t 'research.hal.select_identifier' %><p>
<div class="table-responsive">
<table class="table">
<tbody>
<% @possible_hal_authors.each do |author| %>
<%
path = admin_research_researcher_path @researcher,
hal_doc_identifier: author.docid,
hal_form_identifier: author.attributes['form_i'],
hal_person_identifier: author.attributes['person_i']
%>
<% @hal_authors_with_same_name.each do |author| %>
<tr>
<td width="300">
Identifiant HAL : <%= author.docid %><br>
<small><%= author.fullName_s %></small>
<%= Research::Hal::Author.human_attribute_name('docid') %> : <%= author.docid %><br>
<small><%= author.full_name %></small>
</td>
<td class="ps-3" width="200"><%= link_to 'Choisir cet identifiant', path, method: :put, class: 'btn btn-primary btn-sm' %><td>
<td class="ps-3" width="200">
<% path = researcher_admin_research_hal_author_path author, researcher_id: @researcher %>
<% if author.in? @researcher.hal_authors %>
<%= link_to 'Déconnecter', path, method: :delete, class: button_classes_danger %>
<% else %>
<%= link_to 'Connecter', path, method: :post, class: button_classes %>
<% end %>
<td>
<td class="ps-3">
<% docs = HalOpenscience::Document.search "authIdFormPerson_s:#{author.docid}", fields: ["*"], limit: 5 %>
<ul class="list-unstyled small">
<% docs.results.each do |doc| %>
<li class="mb-2"><%= sanitize doc.citationFull_s %></li>
<% end unless docs.nil? %>
<% author.sample_documents.each do |doc| %>
<li class="mb-2"><%= sanitize doc %></li>
<% end %>
</ul>
</td>
</tr>
......@@ -42,7 +42,7 @@
</div>
<% end %>
<%= osuny_panel Research::Hal::Publication.model_name.human do %>
<%= osuny_panel Research::Hal::Publication.model_name.human(count: 2) do %>
<p><%= "#{@researcher.hal_publications.count} #{Research::Hal::Publication.model_name.human(count: @researcher.hal_publications.count).downcase}" %>
<div class="table-responsive">
<%= render 'admin/research/hal/publications/list', publications: @researcher.hal_publications.ordered %>
......
......@@ -9,11 +9,11 @@ en:
one: Researcher
other: Researchers
research/hal/author:
one: Author
other: Authors
one: HAL author
other: HAL authors
research/hal/publication:
one: Publication
other: Publications
one: HAL publication
other: HAL publications
research/journal:
one: Journal
other: Journals
......@@ -37,6 +37,7 @@ en:
other: Theses
attributes:
research/hal/author:
docid: HAL identifier
first_name: First name
last_name: Last name
full_name: Full name
......@@ -102,10 +103,6 @@ en:
hal:
title: HAL
select_identifier: Select all the HAL authors that correspond to this researcher. Use the publications to be sure it's the same person.
manage_researchers: Manage researchers
researchers:
one: Researcher
other: Researchers
simple_form:
hints:
research_journal_volume:
......
......@@ -9,11 +9,11 @@ fr:
one: Chercheur·e
other: Chercheur·e·s
research/hal/author:
one: Auteur·e
other: Auteur·e·s
one: Auteur·e HAL
other: Auteur·e·s HAL
research/hal/publication:
one: Publication
other: Publications
one: Publication HAL
other: Publications HAL
research/journal:
one: Revue scientifique
other: Revues scientifiques
......@@ -37,6 +37,7 @@ fr:
other: Thèses
attributes:
research/hal/author:
docid: Identifiant HAL
first_name: Prénom
last_name: Nom
full_name: Nom complet
......@@ -101,10 +102,6 @@ fr:
source: Serge Haroche, Prix Nobel de physique 2012
hal:
select_identifier: Choisissez tou·te·s les auteur·e·s HAL correspondant à cette personne. Appuyez-vous sur les publications pour vérifier qu'il s'agit de la bonne personne.
manage_researchers: Gérer les chercheur·e·s
researchers:
one: Chercheur·e
other: Chercheur·e·s
simple_form:
hints:
research_journal_volume:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment