forked from ontoportal/ontologies_api
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge to master: Release 2.3.2 - Submissions endpoint pagination and …
…fixes (#52) * add get submission all including all properties test * extract and use submission_include_params where we use submission.bring * use retrieve_submissions helper in the :acronym/submissions endpoint
- Loading branch information
1 parent
eb9103b
commit 1234096
Showing
11 changed files
with
329 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'sinatra/base' | ||
|
||
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 submission_attributes_all | ||
out = [LinkedData::Models::OntologySubmission.embed_values_hash] | ||
out << {:contact=>[:name, :email]} | ||
out << {:ontology=>[:acronym, :name, :administeredBy, :group, :viewingRestriction, :doNotUpdate, :flat, | ||
:hasDomain, :summaryOnly, :acl, :viewOf, :ontologyType]} | ||
|
||
out | ||
end | ||
|
||
def retrieve_submissions(options) | ||
status = (options[:status] || "RDF").to_s.upcase | ||
status = "RDF" if status.eql?("READY") | ||
ontology_acronym = options[:ontology] | ||
any = status.eql?("ANY") | ||
include_views = options[:also_include_views] || false | ||
includes, page, size, order_by, _ = settings_params(LinkedData::Models::OntologySubmission) | ||
includes << :submissionStatus unless includes.include?(:submissionStatus) | ||
|
||
submissions_query = LinkedData::Models::OntologySubmission | ||
submissions_query = submissions_query.where(ontology: [acronym: ontology_acronym]) if ontology_acronym | ||
|
||
if any | ||
submissions_query = submissions_query.where unless ontology_acronym | ||
else | ||
submissions_query = submissions_query.where({ submissionStatus: [code: status] }) | ||
end | ||
|
||
submissions_query = apply_submission_filters(submissions_query) | ||
submissions_query = submissions_query.filter(Goo::Filter.new(ontology: [:viewOf]).unbound) unless include_views | ||
submissions_query = submissions_query.filter(filter) if filter? | ||
|
||
|
||
submissions = submissions_query.include(submission_include_params) | ||
if page? | ||
submissions.page(page, size).all | ||
else | ||
submissions.to_a | ||
end | ||
end | ||
|
||
def include_ready?(options) | ||
options[:status] && options[:status].to_s.upcase.eql?("READY") | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
||
helpers Sinatra::Helpers::SubmissionHelper |
Oops, something went wrong.