diff --git a/app/controllers/admin/research/researchers_controller.rb b/app/controllers/admin/research/researchers_controller.rb index 0c351151827d636dd7767401390188f9701746b0..81c0ad21868b26b2fefacc2519c59fee73a4afee 100644 --- a/app/controllers/admin/research/researchers_controller.rb +++ b/app/controllers/admin/research/researchers_controller.rb @@ -21,6 +21,11 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationContr add_breadcrumb @researcher end + def sync_with_hal + @researcher.import_research_hal_publications! + redirect_to admin_research_researcher_path(@researcher) + end + def update [ :hal_doc_identifier, @@ -29,7 +34,6 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationContr ].each do |key| @researcher.update_column key, params[key] if params.has_key?(key) end - @researcher.import_research_hal_publications! redirect_to admin_research_researcher_path(@researcher) end diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb index 1a4615b3d6c6865f180dd318b43f9c1268235907..0dc31636314ab864924471003317609996665e7c 100644 --- a/app/models/communication/extranet.rb +++ b/app/models/communication/extranet.rb @@ -2,35 +2,34 @@ # # Table name: communication_extranets # -# id :uuid not null, primary key -# about_type :string indexed => [about_id] -# allow_experiences_modification :boolean default(TRUE) -# color :string -# cookies_policy :text -# css :text -# feature_alumni :boolean default(FALSE) -# feature_contacts :boolean default(FALSE) -# feature_jobs :boolean default(FALSE) -# feature_library :boolean default(FALSE) -# feature_posts :boolean default(FALSE) -# has_sso :boolean default(FALSE) -# home_sentence :text -# host :string -# name :string -# privacy_policy :text -# registration_contact :string -# sass :text -# sso_button_label :string -# sso_cert :text -# sso_mapping :jsonb -# sso_name_identifier_format :string -# sso_provider :integer default("saml") -# sso_target_url :string -# terms :text -# created_at :datetime not null -# updated_at :datetime not null -# about_id :uuid indexed => [about_type] -# university_id :uuid not null, indexed +# id :uuid not null, primary key +# about_type :string indexed => [about_id] +# color :string +# cookies_policy :text +# css :text +# feature_alumni :boolean default(FALSE) +# feature_contacts :boolean default(FALSE) +# feature_jobs :boolean default(FALSE) +# feature_library :boolean default(FALSE) +# feature_posts :boolean default(FALSE) +# has_sso :boolean default(FALSE) +# home_sentence :text +# host :string +# name :string +# privacy_policy :text +# registration_contact :string +# sass :text +# sso_button_label :string +# sso_cert :text +# sso_mapping :jsonb +# sso_name_identifier_format :string +# sso_provider :integer default("saml") +# sso_target_url :string +# terms :text +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed => [about_type] +# university_id :uuid not null, indexed # # Indexes # diff --git a/app/models/research/hal/publication.rb b/app/models/research/hal/publication.rb index cea8d0f8b284045e4abdc8df562e93ded4d3fbb0..31926194320a3f63b67371bd4fde122ff2450902 100644 --- a/app/models/research/hal/publication.rb +++ b/app/models/research/hal/publication.rb @@ -4,6 +4,8 @@ # # id :uuid not null, primary key # abstract :text +# authors_citeproc :json +# authors_list :text # citation_full :text # data :jsonb # docid :string indexed @@ -45,6 +47,7 @@ class Research::Hal::Publication < ApplicationRecord scope :ordered, -> { order(publication_date: :desc)} + # https://api.archives-ouvertes.fr/search/?q=03713859&fl=* def self.import_from_hal_for_author(author) fields = [ 'docid', @@ -58,6 +61,9 @@ class Research::Hal::Publication < ApplicationRecord 'abstract_s', 'openAccess_bool', 'journalTitle_s', + 'authFullName_s', + 'authLastName_s', + 'authFirstName_s', 'files_s' # '*', ] @@ -84,6 +90,14 @@ class Research::Hal::Publication < ApplicationRecord publication.open_access = doc.attributes['openAccess_bool'] publication.journal_title = doc.attributes['journalTitle_s'] publication.file = doc.attributes['files_s']&.first + publication.authors_list = doc.attributes['authFullName_s'].join(', ') + publication.authors_citeproc = [] + doc.attributes['authLastName_s'].each_with_index do |last_name, index| + publication.authors_citeproc << { + "family" => last_name, + "given" => doc.attributes['authFirstName_s'][index] + } + end publication.save publication end @@ -113,9 +127,7 @@ class Research::Hal::Publication < ApplicationRecord def to_citeproc(website: nil) { "title" => title, - "author" => authors.map { |author| - { "family" => author.last_name, "given" => author.first_name } - }, + "author" => authors_citeproc, "URL" => hal_url, "container-title" => journal_title, "pdf" => file, diff --git a/app/views/admin/research/hal/publications/show.html.erb b/app/views/admin/research/hal/publications/show.html.erb index da9578ae684431b314a4035dec57694c8afee425..4f0a02251bae44db524964b7b9fa041462674f3f 100644 --- a/app/views/admin/research/hal/publications/show.html.erb +++ b/app/views/admin/research/hal/publications/show.html.erb @@ -31,6 +31,9 @@ </div> </div> <div class="col-lg-4"> + <%= osuny_panel Research::Hal::Publication.human_attribute_name('authors_list') do %> + <p><%= @publication.authors_list %></p> + <% end %> <%= osuny_panel University::Person::Researcher.model_name.human(count: 2) do %> <% @publication.researchers.in_university(current_university).each do |researcher| %> <%= render 'admin/university/people/researchers/researcher', researcher: researcher %> diff --git a/app/views/admin/research/hal/publications/static.html.erb b/app/views/admin/research/hal/publications/static.html.erb index 66151c7350cd2f00092ef9ba2426b13aefbe64ea..a7b013268f0be97850031870d30c1e9ebecbb1d1 100644 --- a/app/views/admin/research/hal/publications/static.html.erb +++ b/app/views/admin/research/hal/publications/static.html.erb @@ -9,7 +9,7 @@ abstract: >- citation_full: >- <%= prepare_html_for_static @about.citation_full, @website.university %> authors: >- - <%= @about.authors.ordered.join(', ') %> + <%= @about.authors_list %> ref: >- <%= sanitize @about.ref %> links: @@ -35,4 +35,4 @@ citations: - label: "ISO 690" content: >- <%= prepare_html_for_static @about.citation_iso690, @website.university %> ---- +--- \ No newline at end of file diff --git a/app/views/admin/research/researchers/show.html.erb b/app/views/admin/research/researchers/show.html.erb index 9db21e29134fa28fcab6785e392c5b0f6e6f294f..d1f930ea00068f34008a080e9e4753ae6085d25a 100644 --- a/app/views/admin/research/researchers/show.html.erb +++ b/app/views/admin/research/researchers/show.html.erb @@ -55,5 +55,9 @@ <% end %> <% content_for :action_bar_right do %> + <%= link_to t('research.hal.sync'), + sync_with_hal_admin_research_researcher_path(@researcher), + method: :post, + class: button_classes %> <%= edit_link @researcher %> <% end %> diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml index c068e02aba768dc16f1d0a21f0bfc8f738814f1a..bd114710f352cd54406fc1779941860ba7ed47d0 100644 --- a/config/locales/research/en.yml +++ b/config/locales/research/en.yml @@ -9,8 +9,8 @@ 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 @@ -42,6 +42,7 @@ en: full_name: Full name last_name: Last name research/hal/publication: + authors_list: Authors list docid: Identifier doi_url: URL DOI publication_date: Publication date @@ -124,6 +125,7 @@ en: description: Publications scientifiques importées automatiquement de 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. + sync: Synchronize HAL publications simple_form: hints: research_journal_paper: diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml index edac0dead62d80aae449ce17dd3b993c360e0660..915c14779b6bc92b2ed25f0863bba98e26978a67 100644 --- a/config/locales/research/fr.yml +++ b/config/locales/research/fr.yml @@ -9,8 +9,8 @@ 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 @@ -42,6 +42,7 @@ fr: full_name: Nom complet last_name: Nom research/hal/publication: + authors_list: Liste des auteur·e·s docid: Identifiant doi_url: URL DOI publication_date: Date de publication @@ -123,6 +124,7 @@ fr: publication: description: Publications scientifiques importées automatiquement de 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. + sync: Synchroniser les publications HAL simple_form: hints: research_journal_paper: diff --git a/config/routes/admin/research.rb b/config/routes/admin/research.rb index 832236f03da3a50a8a132c02dea5f618492f0b9a..329a657052c1ca6fa5339608281f91679346030d 100644 --- a/config/routes/admin/research.rb +++ b/config/routes/admin/research.rb @@ -1,5 +1,9 @@ namespace :research do - resources :researchers, only: [:index, :show, :update] + resources :researchers, only: [:index, :show, :update] do + member do + post 'sync-with-hal' => 'researchers#sync_with_hal', as: :sync_with_hal + end + end namespace :hal do resources :authors, only: [:index, :show, :destroy] do member do diff --git a/db/migrate/20230711071413_add_authors_list_to_research_hal_publications.rb b/db/migrate/20230711071413_add_authors_list_to_research_hal_publications.rb new file mode 100644 index 0000000000000000000000000000000000000000..caa1cb25c5771b4f05409630d56a367072d0e364 --- /dev/null +++ b/db/migrate/20230711071413_add_authors_list_to_research_hal_publications.rb @@ -0,0 +1,5 @@ +class AddAuthorsListToResearchHalPublications < ActiveRecord::Migration[7.0] + def change + add_column :research_hal_publications, :authors_list, :text + end +end diff --git a/db/migrate/20230711073707_add_authors_citeproc_to_research_hal_publications.rb b/db/migrate/20230711073707_add_authors_citeproc_to_research_hal_publications.rb new file mode 100644 index 0000000000000000000000000000000000000000..ed3c28160698aabb6ef845c3d60619e8d3ce15cb --- /dev/null +++ b/db/migrate/20230711073707_add_authors_citeproc_to_research_hal_publications.rb @@ -0,0 +1,5 @@ +class AddAuthorsCiteprocToResearchHalPublications < ActiveRecord::Migration[7.0] + def change + add_column :research_hal_publications, :authors_citeproc, :json + end +end diff --git a/db/schema.rb b/db/schema.rb index fa52bb2e18d59a435196d29a5ff37709181ce345..8d846ab196a019d264f4f88bf32f1f4b5af3465a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_07_05_103400) do +ActiveRecord::Schema[7.0].define(version: 2023_07_11_073707) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -105,8 +105,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_05_103400) do t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "communication_website_id" t.uuid "heading_id" + t.uuid "communication_website_id" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" t.index ["heading_id"], name: "index_communication_blocks_on_heading_id" @@ -223,7 +223,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_05_103400) do t.text "home_sentence" t.text "sass" t.text "css" - t.boolean "allow_experiences_modification", default: true t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about" t.index ["university_id"], name: "index_communication_extranets_on_university_id" end @@ -462,7 +461,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_05_103400) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false @@ -744,6 +743,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_05_103400) do t.text "abstract" t.string "journal_title" t.text "file" + t.text "authors_list" + t.json "authors_citeproc" t.index ["docid"], name: "index_research_hal_publications_on_docid" end diff --git a/test/fixtures/communication/extranets.yml b/test/fixtures/communication/extranets.yml index 5b00f559b78ac19b9a3871e2736923e92e325c4b..c4a72564511a4905256b44eff1b90d9ad95d76db 100644 --- a/test/fixtures/communication/extranets.yml +++ b/test/fixtures/communication/extranets.yml @@ -2,35 +2,34 @@ # # Table name: communication_extranets # -# id :uuid not null, primary key -# about_type :string indexed => [about_id] -# allow_experiences_modification :boolean default(TRUE) -# color :string -# cookies_policy :text -# css :text -# feature_alumni :boolean default(FALSE) -# feature_contacts :boolean default(FALSE) -# feature_jobs :boolean default(FALSE) -# feature_library :boolean default(FALSE) -# feature_posts :boolean default(FALSE) -# has_sso :boolean default(FALSE) -# home_sentence :text -# host :string -# name :string -# privacy_policy :text -# registration_contact :string -# sass :text -# sso_button_label :string -# sso_cert :text -# sso_mapping :jsonb -# sso_name_identifier_format :string -# sso_provider :integer default("saml") -# sso_target_url :string -# terms :text -# created_at :datetime not null -# updated_at :datetime not null -# about_id :uuid indexed => [about_type] -# university_id :uuid not null, indexed +# id :uuid not null, primary key +# about_type :string indexed => [about_id] +# color :string +# cookies_policy :text +# css :text +# feature_alumni :boolean default(FALSE) +# feature_contacts :boolean default(FALSE) +# feature_jobs :boolean default(FALSE) +# feature_library :boolean default(FALSE) +# feature_posts :boolean default(FALSE) +# has_sso :boolean default(FALSE) +# home_sentence :text +# host :string +# name :string +# privacy_policy :text +# registration_contact :string +# sass :text +# sso_button_label :string +# sso_cert :text +# sso_mapping :jsonb +# sso_name_identifier_format :string +# sso_provider :integer default("saml") +# sso_target_url :string +# terms :text +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed => [about_type] +# university_id :uuid not null, indexed # # Indexes # diff --git a/test/fixtures/research/hal/publications.yml b/test/fixtures/research/hal/publications.yml index e94b3c2eadf87e2a671f983703cc5bfa786f3591..b8477b21cb1b967e057ecc43db026a84ba84c59e 100644 --- a/test/fixtures/research/hal/publications.yml +++ b/test/fixtures/research/hal/publications.yml @@ -4,6 +4,8 @@ # # id :uuid not null, primary key # abstract :text +# authors_citeproc :json +# authors_list :text # citation_full :text # data :jsonb # docid :string indexed