From 205d9b7a9a778d3d5eefa4a20a4f94b931dfecec Mon Sep 17 00:00:00 2001 From: Syphax Date: Wed, 30 Oct 2024 11:59:32 +0100 Subject: [PATCH 1/6] fix: docker-compose app volume --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2a08a35e..564fc8d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,7 +49,7 @@ services: - "9393:9393" volumes: # bundle volume for hosting gems installed by bundle; it speeds up gem install in local development - - .:/srv/ontoportal/ontologies_api + - app_api:/srv/ontoportal/ontologies_api - repository:/srv/ontoportal/data/repository ncbo_cron: @@ -199,4 +199,3 @@ volumes: mgrep: logs: history: - From 8366d47851d3e45717b72f3a6bfec137d16b76fb Mon Sep 17 00:00:00 2001 From: Syphax Date: Tue, 5 Nov 2024 04:15:42 +0100 Subject: [PATCH 2/6] fix ncbo_ontology_recommender version --- Gemfile | 2 +- Gemfile.lock | 40 ++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index c4efa29f..5082ef4e 100644 --- a/Gemfile +++ b/Gemfile @@ -48,7 +48,7 @@ gem 'redcarpet' # NCBO gems (can be from a local dev path or from rubygems/git) gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.git', branch: 'development' gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'master' -gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master' +gem 'ncbo_ontology_recommender', git: 'https://github.com/ontoportal-lirmm/ncbo_ontology_recommender.git', branch: 'development' gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development' gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'development' diff --git a/Gemfile.lock b/Gemfile.lock index 62396ce6..e2a97501 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,14 +1,3 @@ -GIT - remote: https://github.com/ncbo/ncbo_ontology_recommender.git - revision: 9dbd4f179e42c52095129d353a5ac584e9bd47f3 - branch: master - specs: - ncbo_ontology_recommender (0.0.1) - goo - ncbo_annotator - ontologies_linked_data - redis - GIT remote: https://github.com/ontoportal-lirmm/goo.git revision: f8ac7b00e8d8b46d1eea04de014175525c1cdd83 @@ -40,7 +29,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git - revision: bed0ff08408ad1241db3513992ad025a253eeef0 + revision: 37a9573c11978869a867050f8ec75e048c8b9b2b branch: master specs: ncbo_cron (0.0.1) @@ -55,6 +44,17 @@ GIT redis rufus-scheduler (~> 2.0.24) +GIT + remote: https://github.com/ontoportal-lirmm/ncbo_ontology_recommender.git + revision: a0e36c89e6e2f8502cac288df2992625649dad7a + branch: development + specs: + ncbo_ontology_recommender (0.0.1) + goo + ncbo_annotator + ontologies_linked_data + redis + GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git revision: 312ef426eeaa461e88fa23124ea5fd531f4276ba @@ -138,7 +138,7 @@ GEM rexml cube-ruby (0.0.3) dante (0.2.0) - date (3.3.4) + date (3.4.0) declarative (0.0.20) docile (1.4.1) domain_name (0.6.20240107) @@ -211,7 +211,7 @@ GEM httpclient (2.8.3) i18n (1.14.6) concurrent-ruby (~> 1.0) - json (2.7.5) + json (2.7.6) json-ld (3.0.2) multi_json (~> 1.12) rdf (>= 2.2.8, < 4.0) @@ -262,8 +262,8 @@ GEM net-protocol net-ssh (7.3.0) netrc (0.11.0) - newrelic_rpm (9.14.0) - oj (3.16.6) + newrelic_rpm (9.15.0) + oj (3.16.7) bigdecimal (>= 3.0) ostruct (>= 0.2) omni_logger (0.1.4) @@ -272,7 +272,7 @@ GEM ostruct (0.6.0) parallel (1.26.3) parseconfig (1.1.2) - parser (3.3.5.0) + parser (3.3.5.1) ast (~> 2.4.1) racc pony (1.13.1) @@ -343,7 +343,7 @@ GEM rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) - rubocop (1.67.0) + rubocop (1.68.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -353,7 +353,7 @@ GEM rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.33.0) + rubocop-ast (1.34.0) parser (>= 3.3.1.0) ruby-progressbar (1.13.0) ruby-xxHash (0.4.0.2) @@ -416,7 +416,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.8.2) + webrick (1.9.0) PLATFORMS x86_64-linux From 77f25a9bdb28c69629710c692c07a339022ac87e Mon Sep 17 00:00:00 2001 From: Syphax Date: Sat, 11 Jan 2025 17:05:49 +0100 Subject: [PATCH 3/6] add admin graphs controller to list triple store graphs and delete them --- .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 78 +++++++++++++------------- controllers/admin_graphs_controller.rb | 30 ++++++++++ mise.toml | 2 + 5 files changed, 74 insertions(+), 40 deletions(-) create mode 100644 controllers/admin_graphs_controller.rb create mode 100644 mise.toml diff --git a/.ruby-version b/.ruby-version index 818bd47a..a603bb50 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.6 +2.7.5 diff --git a/Gemfile b/Gemfile index 5082ef4e..e4705588 100644 --- a/Gemfile +++ b/Gemfile @@ -47,7 +47,7 @@ gem 'redcarpet' # NCBO gems (can be from a local dev path or from rubygems/git) gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.git', branch: 'development' -gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'master' +gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'feature/create-script-to-count-graphs' gem 'ncbo_ontology_recommender', git: 'https://github.com/ontoportal-lirmm/ncbo_ontology_recommender.git', branch: 'development' gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development' diff --git a/Gemfile.lock b/Gemfile.lock index e2a97501..7917fbed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,8 +29,8 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git - revision: 37a9573c11978869a867050f8ec75e048c8b9b2b - branch: master + revision: d5ca3d6a826bdcf70707af87207943e8b531ae1d + branch: feature/create-script-to-count-graphs specs: ncbo_cron (0.0.1) dante @@ -57,7 +57,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: 312ef426eeaa461e88fa23124ea5fd531f4276ba + revision: d84e379b6ce6cd0e8c4672e5056279b3cc643827 branch: development specs: ontologies_linked_data (0.0.1) @@ -117,9 +117,9 @@ GEM base64 (0.2.0) bcrypt (3.1.20) bcrypt_pbkdf (1.1.1) - bigdecimal (3.1.8) + bigdecimal (3.1.9) builder (3.3.0) - capistrano (3.19.1) + capistrano (3.19.2) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -133,12 +133,12 @@ GEM sshkit (~> 1.3) coderay (1.1.3) concurrent-ruby (1.3.4) - connection_pool (2.4.1) + connection_pool (2.5.0) crack (0.4.5) rexml cube-ruby (0.0.3) dante (0.2.0) - date (3.4.0) + date (3.4.1) declarative (0.0.20) docile (1.4.1) domain_name (0.6.20240107) @@ -164,7 +164,7 @@ GEM google-analytics-data (0.6.1) google-analytics-data-v1beta (>= 0.11, < 2.a) google-cloud-core (~> 1.6) - google-analytics-data-v1beta (0.13.1) + google-analytics-data-v1beta (0.14.0) gapic-common (>= 0.21.1, < 2.a) google-cloud-errors (~> 1.0) google-apis-analytics_v3 (0.16.0) @@ -188,7 +188,7 @@ GEM google-protobuf (>= 3.18, < 5.a) googleapis-common-protos-types (~> 1.7) grpc (~> 1.41) - googleapis-common-protos-types (1.16.0) + googleapis-common-protos-types (1.17.0) google-protobuf (>= 3.18, < 5.a) googleauth (1.11.2) faraday (>= 1.0, < 3.a) @@ -203,27 +203,27 @@ GEM haml (5.2.2) temple (>= 0.8.0) tilt - hashdiff (1.1.1) + hashdiff (1.1.2) htmlentities (4.3.4) http-accept (1.7.0) - http-cookie (1.0.7) + http-cookie (1.0.8) domain_name (~> 0.5) httpclient (2.8.3) i18n (1.14.6) concurrent-ruby (~> 1.0) - json (2.7.6) + json (2.9.1) json-ld (3.0.2) multi_json (~> 1.12) rdf (>= 2.2.8, < 4.0) json-schema (2.8.1) addressable (>= 2.4) - jwt (2.9.3) + jwt (2.10.1) base64 kgio (2.11.4) language_server-protocol (3.17.0.3) libxml-ruby (5.0.3) link_header (0.0.8) - logger (1.6.1) + logger (1.6.5) macaddr (1.7.2) systemu (~> 2.6.5) mail (2.8.1) @@ -235,19 +235,19 @@ GEM mime-types (3.6.0) logger mime-types-data (~> 3.2015) - mime-types-data (3.2024.1001) + mime-types-data (3.2025.0107) mini_mime (1.1.5) - minitest (5.25.1) + minitest (5.25.4) minitest-hooks (1.5.2) minitest (> 5.3) minitest-stub_any_instance (1.0.3) mlanett-redis-lock (0.2.7) redis multi_json (1.15.0) - mutex_m (0.2.0) - net-http-persistent (4.0.4) + mutex_m (0.3.0) + net-http-persistent (4.0.5) connection_pool (~> 2.2) - net-imap (0.4.17) + net-imap (0.4.18) date net-protocol net-pop (0.1.2) @@ -262,22 +262,22 @@ GEM net-protocol net-ssh (7.3.0) netrc (0.11.0) - newrelic_rpm (9.15.0) - oj (3.16.7) + newrelic_rpm (9.16.1) + oj (3.16.9) bigdecimal (>= 3.0) ostruct (>= 0.2) omni_logger (0.1.4) logger os (1.1.4) - ostruct (0.6.0) + ostruct (0.6.1) parallel (1.26.3) parseconfig (1.1.2) - parser (3.3.5.1) + parser (3.3.6.0) ast (~> 2.4.1) racc pony (1.13.1) mail (>= 2.0) - pry (0.14.2) + pry (0.15.2) coderay (~> 1.1) method_source (~> 1.0) public_suffix (5.1.1) @@ -295,7 +295,7 @@ GEM rack (>= 1.2.0) rack-protection (1.5.5) rack - rack-test (2.1.0) + rack-test (2.2.0) rack (>= 1.3) rack-timeout (0.7.0) rainbow (3.1.1) @@ -319,14 +319,14 @@ GEM redcarpet (3.6.0) redis (5.3.0) redis-client (>= 0.22.0) - redis-client (0.22.2) + redis-client (0.23.0) connection_pool redis-rack-cache (2.2.1) rack-cache (>= 1.10, < 2) redis-store (>= 1.6, < 2) redis-store (1.11.0) redis (>= 4, < 6) - regexp_parser (2.9.2) + regexp_parser (2.10.0) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) @@ -339,26 +339,26 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retriable (3.1.2) - rexml (3.3.9) + rexml (3.4.0) rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) - rubocop (1.68.0) + rubocop (1.70.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 2.4, < 3.0) - rubocop-ast (>= 1.32.2, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.36.2, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.34.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.37.0) parser (>= 3.3.1.0) ruby-progressbar (1.13.0) ruby-xxHash (0.4.0.2) ruby2_keywords (0.0.5) - rubyzip (2.3.2) + rubyzip (2.4.1) rufus-scheduler (2.0.24) tzinfo (>= 0.3.22) signet (0.19.0) @@ -397,13 +397,15 @@ GEM systemu (2.6.5) temple (0.10.3) thread_safe (0.3.6) - tilt (2.4.0) - timeout (0.4.1) + tilt (2.5.0) + timeout (0.4.3) trailblazer-option (0.1.2) tzinfo (1.2.11) thread_safe (~> 0.1) uber (0.1.0) - unicode-display_width (2.6.0) + unicode-display_width (3.1.3) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) unicorn (6.1.0) kgio (~> 2.6) raindrops (~> 0.7) @@ -416,7 +418,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.9.0) + webrick (1.9.1) PLATFORMS x86_64-linux diff --git a/controllers/admin_graphs_controller.rb b/controllers/admin_graphs_controller.rb new file mode 100644 index 00000000..8d54201c --- /dev/null +++ b/controllers/admin_graphs_controller.rb @@ -0,0 +1,30 @@ +require 'ncbo_cron/graphs_counts' +class AdminGraphsController < ApplicationController + + namespace '/admin' do + before do + if LinkedData.settings.enable_security && (!env['REMOTE_USER'] || !env['REMOTE_USER'].admin?) + error 403, 'Access denied' + end + end + + get '/graphs' do + file_path = NcboCron.settings.graph_counts_report_path + output = NcboCron::GraphsCounts.new.read_graph_counts(file_path) + reply output + end + + post '/graphs' do + file_path = NcboCron.settings.graph_counts_report_path + NcboCron::GraphsCounts.new.run(Logger.new($stdout), file_path) + reply({ message: 'Graph counts generated', status: 200 }) + end + + delete '/graphs' do + url = params['url'] + error 400, 'You must provide a valid URL for the graph to delete' if url.blank? + Goo.sparql_data_client.delete_graph(url) + reply({ message: "Graph #{url} deleted", status: 200 }) + end + end +end diff --git a/mise.toml b/mise.toml new file mode 100644 index 00000000..83aa57a8 --- /dev/null +++ b/mise.toml @@ -0,0 +1,2 @@ +[tools] +ruby = "2.7.8" From d1c523f028f250f83dd880de731737b0ed88afe1 Mon Sep 17 00:00:00 2001 From: Syphax Date: Tue, 14 Jan 2025 14:02:52 +0100 Subject: [PATCH 4/6] update gemfile --- Gemfile | 2 +- Gemfile.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index e4705588..bf0d2af8 100644 --- a/Gemfile +++ b/Gemfile @@ -47,7 +47,7 @@ gem 'redcarpet' # NCBO gems (can be from a local dev path or from rubygems/git) gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.git', branch: 'development' -gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'feature/create-script-to-count-graphs' +gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'development' gem 'ncbo_ontology_recommender', git: 'https://github.com/ontoportal-lirmm/ncbo_ontology_recommender.git', branch: 'development' gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development' diff --git a/Gemfile.lock b/Gemfile.lock index 7917fbed..390401fb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,8 +29,8 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git - revision: d5ca3d6a826bdcf70707af87207943e8b531ae1d - branch: feature/create-script-to-count-graphs + revision: 70de4d7a3f625e41b263015fdd11f54adea0545d + branch: development specs: ncbo_cron (0.0.1) dante @@ -319,7 +319,7 @@ GEM redcarpet (3.6.0) redis (5.3.0) redis-client (>= 0.22.0) - redis-client (0.23.0) + redis-client (0.23.1) connection_pool redis-rack-cache (2.2.1) rack-cache (>= 1.10, < 2) @@ -397,13 +397,13 @@ GEM systemu (2.6.5) temple (0.10.3) thread_safe (0.3.6) - tilt (2.5.0) + tilt (2.6.0) timeout (0.4.3) trailblazer-option (0.1.2) tzinfo (1.2.11) thread_safe (~> 0.1) uber (0.1.0) - unicode-display_width (3.1.3) + unicode-display_width (3.1.4) unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) unicorn (6.1.0) From 05115d7075aab432c9fc699da4ac58df57cd6905 Mon Sep 17 00:00:00 2001 From: Syphax Date: Tue, 14 Jan 2025 14:08:31 +0100 Subject: [PATCH 5/6] extract graph count path in a constant --- controllers/admin_graphs_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/controllers/admin_graphs_controller.rb b/controllers/admin_graphs_controller.rb index 8d54201c..3661f6c6 100644 --- a/controllers/admin_graphs_controller.rb +++ b/controllers/admin_graphs_controller.rb @@ -2,6 +2,7 @@ class AdminGraphsController < ApplicationController namespace '/admin' do + GRAPH_COUNT_REPORT_PATH = NcboCron.settings.graphs_counts_report_path before do if LinkedData.settings.enable_security && (!env['REMOTE_USER'] || !env['REMOTE_USER'].admin?) error 403, 'Access denied' @@ -9,14 +10,12 @@ class AdminGraphsController < ApplicationController end get '/graphs' do - file_path = NcboCron.settings.graph_counts_report_path - output = NcboCron::GraphsCounts.new.read_graph_counts(file_path) + output = NcboCron::GraphsCounts.new(nil, GRAPH_COUNT_REPORT_PATH).read_graph_counts reply output end post '/graphs' do - file_path = NcboCron.settings.graph_counts_report_path - NcboCron::GraphsCounts.new.run(Logger.new($stdout), file_path) + NcboCron::GraphsCounts.new(nil, GRAPH_COUNT_REPORT_PATH).run reply({ message: 'Graph counts generated', status: 200 }) end From a3fb4fba957296117ef8982e713348462086be32 Mon Sep 17 00:00:00 2001 From: Syphax Date: Thu, 23 Jan 2025 20:41:28 +0100 Subject: [PATCH 6/6] add graphs admin action unit tests --- Gemfile.lock | 24 ++++----- config/environments/test.rb | 1 + controllers/admin_graphs_controller.rb | 7 ++- .../test_graphs_admin_controller.rb | 53 +++++++++++++++++++ 4 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 test/controllers/test_graphs_admin_controller.rb diff --git a/Gemfile.lock b/Gemfile.lock index 390401fb..beed6b2d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: f8ac7b00e8d8b46d1eea04de014175525c1cdd83 + revision: 27300f28ca6c656c7e78af65013d88b792a6312f branch: development specs: goo (0.0.2) @@ -29,7 +29,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git - revision: 70de4d7a3f625e41b263015fdd11f54adea0545d + revision: dd736917974f13ac7558e0d2a61a84030d82acaa branch: development specs: ncbo_cron (0.0.1) @@ -57,7 +57,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: d84e379b6ce6cd0e8c4672e5056279b3cc643827 + revision: 6cb18910e322645e3cc3490951d10f19468da52f branch: development specs: ontologies_linked_data (0.0.1) @@ -77,7 +77,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/sparql-client.git - revision: 59251e59346c9a69a67c88552ba55a1244eec602 + revision: 4364d34e9e4c411f1dd0ea706bf052465bf0b467 branch: development specs: sparql-client (3.2.2) @@ -132,7 +132,7 @@ GEM capistrano (~> 3.1) sshkit (~> 1.3) coderay (1.1.3) - concurrent-ruby (1.3.4) + concurrent-ruby (1.3.5) connection_pool (2.5.0) crack (0.4.5) rexml @@ -169,7 +169,7 @@ GEM google-cloud-errors (~> 1.0) google-apis-analytics_v3 (0.16.0) google-apis-core (>= 0.15.0, < 2.a) - google-apis-core (0.15.1) + google-apis-core (0.16.0) addressable (~> 2.5, >= 2.5.1) googleauth (~> 1.9) httpclient (>= 2.8.3, < 3.a) @@ -188,7 +188,7 @@ GEM google-protobuf (>= 3.18, < 5.a) googleapis-common-protos-types (~> 1.7) grpc (~> 1.41) - googleapis-common-protos-types (1.17.0) + googleapis-common-protos-types (1.18.0) google-protobuf (>= 3.18, < 5.a) googleauth (1.11.2) faraday (>= 1.0, < 3.a) @@ -209,7 +209,7 @@ GEM http-cookie (1.0.8) domain_name (~> 0.5) httpclient (2.8.3) - i18n (1.14.6) + i18n (1.14.7) concurrent-ruby (~> 1.0) json (2.9.1) json-ld (3.0.2) @@ -254,7 +254,7 @@ GEM net-protocol net-protocol (0.2.2) timeout - net-scp (4.0.0) + net-scp (4.1.0) net-ssh (>= 2.6.5, < 8.0.0) net-sftp (4.0.0) net-ssh (>= 5.0.0, < 8.0.0) @@ -272,7 +272,7 @@ GEM ostruct (0.6.1) parallel (1.26.3) parseconfig (1.1.2) - parser (3.3.6.0) + parser (3.3.7.0) ast (~> 2.4.1) racc pony (1.13.1) @@ -319,7 +319,7 @@ GEM redcarpet (3.6.0) redis (5.3.0) redis-client (>= 0.22.0) - redis-client (0.23.1) + redis-client (0.23.2) connection_pool redis-rack-cache (2.2.1) rack-cache (>= 1.10, < 2) @@ -343,7 +343,7 @@ GEM rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) - rubocop (1.70.0) + rubocop (1.71.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) diff --git a/config/environments/test.rb b/config/environments/test.rb index 2cef531a..ac9c104e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -102,5 +102,6 @@ NcboCron.config do |config| config.redis_host = REDIS_PERSISTENT_HOST.to_s config.redis_port = REDIS_PORT.to_i + config.graphs_counts_report_path = './test/ontologies_report.json' # config.ontology_report_path = REPORT_PATH end diff --git a/controllers/admin_graphs_controller.rb b/controllers/admin_graphs_controller.rb index 3661f6c6..89f17263 100644 --- a/controllers/admin_graphs_controller.rb +++ b/controllers/admin_graphs_controller.rb @@ -15,7 +15,7 @@ class AdminGraphsController < ApplicationController end post '/graphs' do - NcboCron::GraphsCounts.new(nil, GRAPH_COUNT_REPORT_PATH).run + generate_graphs_counts reply({ message: 'Graph counts generated', status: 200 }) end @@ -23,7 +23,12 @@ class AdminGraphsController < ApplicationController url = params['url'] error 400, 'You must provide a valid URL for the graph to delete' if url.blank? Goo.sparql_data_client.delete_graph(url) + generate_graphs_counts reply({ message: "Graph #{url} deleted", status: 200 }) end + + def generate_graphs_counts + NcboCron::GraphsCounts.new(nil, GRAPH_COUNT_REPORT_PATH).run + end end end diff --git a/test/controllers/test_graphs_admin_controller.rb b/test/controllers/test_graphs_admin_controller.rb new file mode 100644 index 00000000..e161aad3 --- /dev/null +++ b/test/controllers/test_graphs_admin_controller.rb @@ -0,0 +1,53 @@ +require_relative '../test_case' + +class TestGraphAdminController < TestCase + def setup + ontologies = LinkedData::Models::Ontology.all + if ontologies.empty? + LinkedData::SampleData::Ontology.delete_ontologies_and_submissions + @@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies(process_submission: false) + end + file_path = AdminGraphsController::GRAPH_COUNT_REPORT_PATH + File.delete(file_path) if File.exist?(file_path) + end + + def test_initial_graphs_admin_actions + get '/admin/graphs' + assert last_response.ok? + response = MultiJson.load(last_response.body) + assert_empty response + end + + def test_graph_creation_and_retrieval + post '/admin/graphs' + + get '/admin/graphs' + assert last_response.ok? + response = MultiJson.load(last_response.body) + refute_empty response + + response.each do |graph, count| + assert graph.is_a?(String) + assert count.is_a?(Array) + assert count[0].is_a?(Integer) + assert count[1].is_a?(TrueClass) || count[1].is_a?(FalseClass) + end + end + + def test_graph_deletion + post '/admin/graphs' + + get '/admin/graphs' + response = MultiJson.load(last_response.body) + refute_empty response + + graph = 'http://data.bioontology.org/metadata/OntologySubmission' + + delete '/admin/graphs', url: graph + + get '/admin/graphs' + assert last_response.ok? + response = MultiJson.load(last_response.body) + assert_nil response[graph] + end +end