Skip to content

Commit

Permalink
extract and use submission_include_params where we use submission.bring
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Sep 15, 2023
1 parent 13c9145 commit 62c7b0e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AdminController < ApplicationController
latest = ont.latest_submission(status: :any)
error 404, "Ontology #{params["acronym"]} contains no submissions" if latest.nil?
check_last_modified(latest)
latest.bring(*OntologySubmission.goo_attrs_to_load(includes_param))
latest.bring(*submission_include_params)
NcboCron::Models::OntologySubmissionParser.new.queue_submission(latest, actions)
halt 204
end
Expand All @@ -84,7 +84,7 @@ class AdminController < ApplicationController
latest = ont.latest_submission(status: :any)
end
check_last_modified(latest) if latest
latest.bring(*OntologySubmission.goo_attrs_to_load(includes_param)) if latest
latest.bring(*submission_include_params) if latest
reply(latest || {})
end

Expand Down
23 changes: 5 additions & 18 deletions controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,12 @@ class OntologiesController < ApplicationController
else
latest = ont.latest_submission(status: :any)
end
check_last_modified(latest) if latest
# When asking to display all metadata, we are using bring_remaining which is more performant than including all metadata (remove this when the query to get metadata will be fixed)

if latest
if includes_param.first == :all
# Bring what we need to display all attr of the submission
latest.bring_remaining
latest.bring({:contact=>[:name, :email],
:ontology=>[:acronym, :name, :administeredBy, :group, :viewingRestriction, :doNotUpdate, :flat,
:hasDomain, :summaryOnly, :acl, :viewOf, :ontologyType],
:submissionStatus=>[:code], :hasOntologyLanguage=>[:acronym], :metrics =>[:classes, :individuals, :properties]})
else
includes = OntologySubmission.goo_attrs_to_load(includes_param)

includes << {:contact=>[:name, :email]} if includes.find{|v| v.is_a?(Hash) && v.keys.first.eql?(:contact)}

latest.bring(*includes)
end
check_last_modified(latest)
latest.bring(*submission_include_params)
end
#remove the whole previous if block and replace by it: latest.bring(*OntologySubmission.goo_attrs_to_load(includes_param)) if latest

reply(latest || {})
end

Expand All @@ -66,7 +53,7 @@ class OntologiesController < ApplicationController
patch '/:acronym/latest_submission' do
ont = Ontology.find(params["acronym"]).first
error 422, "You must provide an existing `acronym` to patch" if ont.nil?

submission = ont.latest_submission(status: :any)

submission.bring(*OntologySubmission.attributes)
Expand Down
2 changes: 1 addition & 1 deletion controllers/ontology_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class OntologySubmissionsController < ApplicationController
ont.bring(:submissions)
ont_submission = ont.submission(params["ontology_submission_id"])
error 404, "`submissionId` not found" if ont_submission.nil?
ont_submission.bring(*OntologySubmission.goo_attrs_to_load(includes_param))
ont_submission.bring(*submission_include_params)
reply ont_submission
end

Expand Down
12 changes: 12 additions & 0 deletions helpers/submission_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
module Sinatra
module Helpers
module SubmissionHelper
def submission_include_params
# When asking to display all metadata, we are using bring_remaining on each submission. Slower but best way to retrieve all attrs
includes = OntologySubmission.goo_attrs_to_load(includes_param)
if includes.find{|v| v.is_a?(Hash) && v.keys.include?(:ontology)}
includes << {:ontology=>[:administeredBy, :acronym, :name, :viewingRestriction, :group, :hasDomain,:notes, :reviews, :projects,:acl, :viewOf]}
end

if includes.find{|v| v.is_a?(Hash) && v.keys.include?(:contact)}
includes << {:contact=>[:name, :email]}
end
includes
end

def retrieve_submissions(options)
status = (options[:status] || "RDF").to_s.upcase
Expand Down

0 comments on commit 62c7b0e

Please sign in to comment.