From 9ca250049c6615d8f94c3fb406e8d3753dea814a Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Mon, 20 May 2024 20:26:12 +0200 Subject: [PATCH] make the api use submission naturalLanguage to choose the default language to display --- Gemfile | 2 +- Gemfile.lock | 52 ++++++++++++--------- helpers/application_helper.rb | 19 ++++++++ test/controllers/test_classes_controller.rb | 26 ++++++++++- test/data/ontology_files/BRO_v3.2.owl | 2 +- 5 files changed, 75 insertions(+), 26 deletions(-) diff --git a/Gemfile b/Gemfile index d25c7660..f2ecfca5 100644 --- a/Gemfile +++ b/Gemfile @@ -46,7 +46,7 @@ gem 'ncbo_annotator', git: 'https://github.com/ncbo/ncbo_annotator.git', branch: gem 'ncbo_cron', git: 'https://github.com/ncbo/ncbo_cron.git', branch: 'master' gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master' gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'master' -gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'pr/sync-agroportal-bioportal' +gem 'goo', github: 'ncbo/goo', branch: 'develop' gem 'ontologies_linked_data', github: 'ontoportal-lirmm/ontologies_linked_data', branch: 'pr/sync-agroportal-ncbo' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 488c23ca..95b07be8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,19 @@ +GIT + remote: https://github.com/ncbo/goo.git + revision: 70007faf43d0d96292809f89f15a27a757ccaa25 + branch: develop + specs: + goo (0.0.2) + addressable (~> 2.8) + pry + rdf (= 1.0.8) + redis + request_store + rest-client + rsolr + sparql-client + uuid + GIT remote: https://github.com/ncbo/ncbo_annotator.git revision: 63c986880aa88c9384043e6611a682434a14aba7 @@ -11,11 +27,13 @@ GIT GIT remote: https://github.com/ncbo/ncbo_cron.git - revision: f239b34230131cd7cfb9eec5b34068ba990b698b + revision: 67810ddd2e14876d789c63c427b08af6919f661e branch: master specs: ncbo_cron (0.0.1) dante + faraday (~> 2) + faraday-follow_redirects (~> 0) goo google-analytics-data mlanett-redis-lock @@ -46,25 +64,9 @@ GIT net-http-persistent (= 2.9.4) rdf (>= 1.0) -GIT - remote: https://github.com/ontoportal-lirmm/goo.git - revision: f2751fe9324e48a0a5c2a8b15580ab879fc53a2b - branch: pr/sync-agroportal-bioportal - specs: - goo (0.0.2) - addressable (~> 2.8) - pry - rdf (= 1.0.8) - redis - request_store - rest-client - rsolr - sparql-client - uuid - GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: fc48343ad7a3f1867821c173be900cf16506b4b7 + revision: 7c5184fc7d3b25b5c9dd54c25f5ea2b1c4951318 branch: pr/sync-agroportal-ncbo specs: ontologies_linked_data (0.0.1) @@ -143,6 +145,8 @@ GEM base64 faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) + faraday-follow_redirects (0.3.0) + faraday (>= 1, < 3) faraday-net_http (3.0.2) faraday-retry (2.2.1) faraday (~> 2.0) @@ -223,7 +227,7 @@ GEM method_source (1.1.0) mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2024.0305) + mime-types-data (3.2024.0507) mini_mime (1.1.5) minitest (4.7.5) minitest-stub_any_instance (1.0.3) @@ -232,7 +236,7 @@ GEM multi_json (1.15.0) mutex_m (0.2.0) net-http-persistent (2.9.4) - net-imap (0.4.10) + net-imap (0.4.11) date net-protocol net-pop (0.1.2) @@ -295,7 +299,7 @@ GEM redis-store (>= 1.6, < 2) redis-store (1.10.0) redis (>= 4, < 6) - regexp_parser (2.9.0) + regexp_parser (2.9.2) request_store (1.7.0) rack (>= 1.4) rest-client (2.1.0) @@ -303,11 +307,12 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rexml (3.2.6) + rexml (3.2.8) + strscan (>= 3.0.9) rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) - rubocop (1.63.4) + rubocop (1.63.5) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -359,6 +364,7 @@ GEM net-scp (>= 1.1.2) net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) + strscan (3.1.0) systemu (2.6.5) temple (0.10.3) tilt (2.3.0) diff --git a/helpers/application_helper.rb b/helpers/application_helper.rb index 251f90f0..916c24c9 100644 --- a/helpers/application_helper.rb +++ b/helpers/application_helper.rb @@ -409,6 +409,9 @@ def get_ontology_and_submission error 404, "Ontology #{@params["acronym"]} does not have any submissions" end end + + save_submission_language(submission) + return ont, submission end @@ -438,6 +441,22 @@ def naive_expiring_cache_read(key) return object[:object] end + + def save_submission_language(submission, language_property = :naturalLanguage) + request_lang = RequestStore.store[:requested_lang] + + return if submission.nil? || !request_lang.blank? + + submission.bring(language_property) if submission.bring?(language_property) + collection_natural_language = submission.send(language_property) rescue nil + return [] if collection_natural_language.blank? + + collection_natural_language = collection_natural_language.values.flatten if collection_natural_language.is_a?(Hash) + submissions_language = collection_natural_language.map { |natural_language| natural_language.to_s.split('/').last[0..1] }.compact.first + + RequestStore.store[:requested_lang] = submissions_language if submissions_language + end + end end end diff --git a/test/controllers/test_classes_controller.rb b/test/controllers/test_classes_controller.rb index 42ccf29b..e43d9e0a 100644 --- a/test/controllers/test_classes_controller.rb +++ b/test/controllers/test_classes_controller.rb @@ -8,7 +8,8 @@ def self.before_suite submissions_to_process: [1, 2], process_submission: true, random_submission_count: false, - process_options: {process_rdf: true, extract_metadata: false} + process_options: {process_rdf: true, extract_metadata: false}, + file_path: "./test/data/ontology_files/BRO_v3.2.owl", } return LinkedData::SampleData::Ontology.create_ontologies_and_submissions(options) end @@ -531,4 +532,27 @@ def test_class_page_with_metric_count assert page_response["collection"].length == 0 end + def test_default_multilingual + ont = Ontology.find("TEST-ONT-0").include(:acronym).first + sub = ont.latest_submission + sub.bring_remaining + + get "/ontologies/#{ont.acronym}/classes/#{CGI.escape('http://bioontology.org/ontologies/Activity.owl#Biospecimen_Management')}" + assert last_response.ok? + page_response = MultiJson.load(last_response.body) + + # does not contain a value in english show the generated one + assert_equal 'Biospecimen_Management', page_response["prefLabel"] + + + sub.naturalLanguage = ['fr'] + sub.save + + get "/ontologies/#{ont.acronym}/classes/#{CGI.escape('http://bioontology.org/ontologies/Activity.owl#Biospecimen_Management')}" + assert last_response.ok? + page_response = MultiJson.load(last_response.body) + + # show french value as specified in submission naturalLanguage + assert_equal 'Biospecimen Management', page_response["prefLabel"] + end end diff --git a/test/data/ontology_files/BRO_v3.2.owl b/test/data/ontology_files/BRO_v3.2.owl index b2aeccf5..7417f79c 100644 --- a/test/data/ontology_files/BRO_v3.2.owl +++ b/test/data/ontology_files/BRO_v3.2.owl @@ -645,7 +645,7 @@ Activity related to the creation, use, or maintenance of a biorepository (http://en.wikipedia.org/wiki/Biorepository) - Biospecimen Management + Biospecimen Management