diff --git a/Gemfile.lock b/Gemfile.lock index 7fa0b52e..98aaab92 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,40 +1,3 @@ -GIT - remote: https://github.com/lifewatch-eric/ncbo_cron.git - revision: 2ff764e536e049220208e3cd6c0ee9f03366df17 - branch: master - specs: - ncbo_cron (0.0.1) - dante - goo - google-analytics-data - google-apis-analytics_v3 - mlanett-redis-lock - multi_json - ncbo_annotator - ontologies_linked_data - redis - rufus-scheduler (~> 2.0.24) - -GIT - remote: https://github.com/lifewatch-eric/ontologies_linked_data.git - revision: 17edfcb470848152dec8939fc6f68f5ed00f83db - branch: master - specs: - ontologies_linked_data (0.0.1) - activesupport - bcrypt - goo - json - libxml-ruby - multi_json - oj - omni_logger - pony - rack - rack-test - rsolr - rubyzip - GIT remote: https://github.com/ncbo/ncbo_ontology_recommender.git revision: 013abea4af3b10910ec661dbb358a4b6cae198a4 @@ -48,7 +11,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: b2a635fb1e8206e6e3010be4dbe033b47eb58481 + revision: a95245b8c964431505ca6315907440996c59a00d branch: development specs: goo (0.0.2) @@ -77,7 +40,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git - revision: 6bb53a13f514a60513afe25e37c5c69475140452 + revision: fabd04ef4fa37989d526fc6a7aa1e98830008dae branch: master specs: ncbo_cron (0.0.1) @@ -94,7 +57,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: a5b56a68e6dc8ecfc9db708d44350342dac38ce6 + revision: 4cd56da111c2037bf0b606574e6b325bfa74a2f1 branch: development specs: ontologies_linked_data (0.0.1) @@ -154,7 +117,7 @@ GEM bcrypt_pbkdf (1.1.1-x86_64-darwin) bigdecimal (1.4.2) builder (3.3.0) - capistrano (3.19.0) + capistrano (3.19.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -293,7 +256,7 @@ GEM method_source (1.1.0) mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2024.0604) + mime-types-data (3.2024.0702) mini_mime (1.1.5) minitest (4.7.5) minitest-stub_any_instance (1.0.3) @@ -431,7 +394,7 @@ GEM strscan (3.1.0) systemu (2.6.5) temple (0.10.3) - tilt (2.3.0) + tilt (2.4.0) timeout (0.4.1) trailblazer-option (0.1.2) tzinfo (2.0.6) diff --git a/controllers/ontologies_controller.rb b/controllers/ontologies_controller.rb index d868e4cb..493c9bd0 100644 --- a/controllers/ontologies_controller.rb +++ b/controllers/ontologies_controller.rb @@ -99,13 +99,13 @@ class OntologiesController < ApplicationController ## # Create an ontology post do - create_ontology + create_ontology_with_params end ## # Create an ontology with constructed URL put '/:acronym' do - create_ontology + create_ontology_with_params end ## @@ -185,45 +185,13 @@ def find_latest_submission latest end - def create_ontology - params ||= @params - - # acronym must be well formed - params['acronym'] = params['acronym'].upcase # coerce new ontologies to upper case - - # ontology acronym must be unique - ont = Ontology.find(params['acronym']).first - if ont.nil? - ont = instance_from_params(Ontology, params) - else - error_msg = <<-ERR - Ontology already exists, see #{ont.id} - To add a new submission, POST to: /ontologies/#{params['acronym']}/submission. - To modify the resource, use PATCH. - ERR - error 409, error_msg - end - - # ontology name must be unique - ont_names = Ontology.where.include(:name).to_a.map { |o| o.name } - if ont_names.include?(ont.name) - error 409, "Ontology name is already in use by another ontology." - end - + def create_ontology_with_params + ont = create_ontology if ont.valid? - ont.save - # Send an email to the administrator to warn him about the newly created ontology - begin - if !LinkedData.settings.admin_emails.nil? && !LinkedData.settings.admin_emails.empty? - LinkedData::Utils::Notifications.new_ontology(ont) - end - rescue Exception => e - end + reply 201, ont else error 422, ont.errors end - - reply 201, ont end end diff --git a/controllers/ontology_submissions_controller.rb b/controllers/ontology_submissions_controller.rb index 3b81d7f0..5b72cce2 100644 --- a/controllers/ontology_submissions_controller.rb +++ b/controllers/ontology_submissions_controller.rb @@ -43,7 +43,16 @@ class OntologySubmissionsController < ApplicationController # Create a new submission for an existing ontology post do ont = Ontology.find(params["acronym"]).include(Ontology.attributes).first - error 422, "You must provide a valid `acronym` to create a new submission" if ont.nil? + params["name"] ||= params["titles"]&.first&.dig('title') + + if params["name"] && params["acronym"] && ont.nil? + params["hasOntologyLanguage"] = "SKOS" + params["administeredBy"] = [ current_user.username ] + ont = create_ontology + elsif ont.nil? + error 422, "You must provide a valid `acronym` to create a new submission" + end + reply 201, create_submission(ont) end diff --git a/helpers/ontology_helper.rb b/helpers/ontology_helper.rb index cea3de77..681ac7c7 100644 --- a/helpers/ontology_helper.rb +++ b/helpers/ontology_helper.rb @@ -7,6 +7,44 @@ module Helpers module OntologyHelper include Sinatra::Concerns::EcoPortalMetadataExporter + def create_ontology + params ||= @params + + # acronym must be well formed + params['acronym'] = params['acronym'].upcase # coerce new ontologies to upper case + + # ontology acronym must be unique + ont = Ontology.find(params['acronym']).first + if ont.nil? + ont = instance_from_params(Ontology, params) + else + error_msg = <<-ERR + Ontology already exists, see #{ont.id} + To add a new submission, POST to: /ontologies/#{params['acronym']}/submission. + To modify the resource, use PATCH. + ERR + error 409, error_msg + end + + # ontology name must be unique + ont_names = Ontology.where.include(:name).to_a.map { |o| o.name } + if ont_names.include?(ont.name) + error 409, "Ontology name is already in use by another ontology." + end + + if ont.valid? + ont.save + # Send an email to the administrator to warn him about the newly created ontology + begin + if !LinkedData.settings.admin_emails.nil? && !LinkedData.settings.admin_emails.empty? + LinkedData::Utils::Notifications.new_ontology(ont) + end + rescue Exception => e + end + end + ont + end + ## # Create a new OntologySubmission object based on the request data def create_submission(ont) diff --git a/test/controllers/test_ontology_submissions_controller.rb b/test/controllers/test_ontology_submissions_controller.rb index 6a2489d3..7362e5f5 100644 --- a/test/controllers/test_ontology_submissions_controller.rb +++ b/test/controllers/test_ontology_submissions_controller.rb @@ -271,10 +271,16 @@ def test_upload_eco_portal_metadata 2.times.each do |i| header 'Authorization', "apikey token=#{user.apikey}" - post "/ontologies/#{@@acronym}/submissions", example_of_input, "CONTENT_TYPE" => "application/json" + post "/ontologies/SYPHAX_TEST_VOC/submissions", example_of_input, "CONTENT_TYPE" => "application/json" assert_equal 201, last_response.status - ont = Ontology.find(@@acronym).first + ont = Ontology.find('SYPHAX_TEST_VOC').first + + refute_nil ont + + ont.bring_remaining + + assert_equal ont.name, example_of_input["titles"].first["title"] subs = ont.bring(:submissions).submissions