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 branch 'features/add-submission-ontology-metadata-endpoint'
- Loading branch information
Showing
2 changed files
with
98 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,16 @@ | ||
class SubmissionMetadataController < ApplicationController | ||
|
||
namespace "/submission_metadata" do | ||
|
||
## | ||
# Display all metadata for submissions | ||
get do | ||
all_attr = [] | ||
|
||
LinkedData::Models::OntologySubmission.attributes(:all).each do |attr| | ||
|
||
if LinkedData.settings.id_url_prefix.nil? || LinkedData.settings.id_url_prefix.empty? | ||
id_url_prefix = "http://data.bioontology.org/" | ||
else | ||
id_url_prefix = LinkedData.settings.id_url_prefix | ||
end | ||
|
||
attr_settings = {} | ||
attr_settings[:@id] = "#{id_url_prefix}submission_metadata/#{attr.to_s}" | ||
attr_settings[:@type] = "#{id_url_prefix}metadata/SubmissionMetadata" | ||
attr_settings[:attribute] = attr.to_s | ||
|
||
# Get metadata namespace | ||
if LinkedData::Models::OntologySubmission.attribute_settings(attr)[:namespace].nil? | ||
attr_settings[:namespace] = nil | ||
else | ||
attr_settings[:namespace] = LinkedData::Models::OntologySubmission.attribute_settings(attr)[:namespace].to_s | ||
end | ||
|
||
# Get metadata label if one | ||
if LinkedData::Models::OntologySubmission.attribute_settings(attr)[:label].nil? | ||
attr_settings[:label] = nil | ||
else | ||
attr_settings[:label] = LinkedData::Models::OntologySubmission.attribute_settings(attr)[:label] | ||
end | ||
|
||
# Get if it is an extracted metadata | ||
if LinkedData::Models::OntologySubmission.attribute_settings(attr)[:extractedMetadata] | ||
attr_settings[:extracted] = true | ||
else | ||
attr_settings[:extracted] = false | ||
end | ||
|
||
# Get mappings of the metadata | ||
if LinkedData::Models::OntologySubmission.attribute_settings(attr)[:metadataMappings].nil? | ||
attr_settings[:metadataMappings] = nil | ||
else | ||
attr_settings[:metadataMappings] = LinkedData::Models::OntologySubmission.attribute_settings(attr)[:metadataMappings] | ||
end | ||
|
||
# Get enforced from the metadata | ||
if LinkedData::Models::OntologySubmission.attribute_settings(attr)[:enforce].nil? | ||
attr_settings[:enforce] = [] | ||
else | ||
attr_settings[:enforce] = [] | ||
LinkedData::Models::OntologySubmission.attribute_settings(attr)[:enforce].each do |enforced| | ||
attr_settings[:enforce] << enforced.to_s | ||
end | ||
end | ||
|
||
# Get enforcedValues from the metadata | ||
attr_settings[:enforcedValues] = LinkedData::Models::OntologySubmission.attribute_settings(attr)[:enforcedValues] | ||
|
||
# Get display from the metadata | ||
if LinkedData::Models::OntologySubmission.attribute_settings(attr)[:display].nil? | ||
attr_settings[:display] = "no" | ||
else | ||
attr_settings[:display] = LinkedData::Models::OntologySubmission.attribute_settings(attr)[:display] | ||
end | ||
|
||
if !LinkedData::Models::OntologySubmission.attribute_settings(attr)[:helpText].nil? | ||
attr_settings[:helpText] = LinkedData::Models::OntologySubmission.attribute_settings(attr)[:helpText] | ||
end | ||
|
||
attr_settings[:@context] = { | ||
"@vocab" => "#{id_url_prefix}metadata/" | ||
} | ||
|
||
all_attr << attr_settings | ||
end | ||
## | ||
# Display all metadata for submissions | ||
get "/submission_metadata" do | ||
reply klass_metadata(LinkedData::Models::OntologySubmission, "submission_metadata") | ||
end | ||
|
||
reply all_attr | ||
end | ||
|
||
## | ||
# Display all metadata for ontologies | ||
get "/ontology_metadata" do | ||
reply klass_metadata(LinkedData::Models::Ontology, "ontology_metadata") | ||
end | ||
|
||
end |
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,89 @@ | ||
require 'sinatra/base' | ||
require 'date' | ||
|
||
module Sinatra | ||
module Helpers | ||
module MetadataHelper | ||
|
||
def klass_metadata(klass, type) | ||
all_attr = [] | ||
klass.attributes(:all).each do |attr| | ||
|
||
if LinkedData.settings.id_url_prefix.nil? || LinkedData.settings.id_url_prefix.empty? | ||
id_url_prefix = "http://data.bioontology.org/" | ||
else | ||
id_url_prefix = LinkedData.settings.id_url_prefix | ||
end | ||
|
||
attr_settings = {} | ||
attr_settings[:@id] = "#{id_url_prefix}#{type}/#{attr.to_s}" | ||
attr_settings[:@type] = "#{id_url_prefix}metadata/#{type.camelize}" | ||
attr_settings[:attribute] = attr.to_s | ||
|
||
# Get metadata namespace | ||
if klass.attribute_settings(attr)[:namespace].nil? | ||
attr_settings[:namespace] = nil | ||
else | ||
attr_settings[:namespace] = klass.attribute_settings(attr)[:namespace].to_s | ||
end | ||
|
||
# Get metadata label if one | ||
if klass.attribute_settings(attr)[:label].nil? | ||
attr_settings[:label] = nil | ||
else | ||
attr_settings[:label] = klass.attribute_settings(attr)[:label] | ||
end | ||
|
||
# Get if it is an extracted metadata | ||
if klass.attribute_settings(attr)[:extractedMetadata] | ||
attr_settings[:extracted] = true | ||
else | ||
attr_settings[:extracted] = false | ||
end | ||
|
||
# Get mappings of the metadata | ||
if klass.attribute_settings(attr)[:metadataMappings].nil? | ||
attr_settings[:metadataMappings] = nil | ||
else | ||
attr_settings[:metadataMappings] = klass.attribute_settings(attr)[:metadataMappings] | ||
end | ||
|
||
# Get enforced from the metadata | ||
if klass.attribute_settings(attr)[:enforce].nil? | ||
attr_settings[:enforce] = [] | ||
else | ||
attr_settings[:enforce] = [] | ||
klass.attribute_settings(attr)[:enforce].each do |enforced| | ||
next if enforced.is_a? Proc | ||
attr_settings[:enforce] << enforced.to_s | ||
end | ||
end | ||
|
||
# Get enforcedValues from the metadata | ||
attr_settings[:enforcedValues] = klass.attribute_settings(attr)[:enforcedValues] | ||
|
||
# Get display from the metadata | ||
if klass.attribute_settings(attr)[:display].nil? | ||
attr_settings[:display] = "no" | ||
else | ||
attr_settings[:display] = klass.attribute_settings(attr)[:display] | ||
end | ||
|
||
if !klass.attribute_settings(attr)[:helpText].nil? | ||
attr_settings[:helpText] = klass.attribute_settings(attr)[:helpText] | ||
end | ||
|
||
attr_settings[:@context] = { | ||
"@vocab" => "#{id_url_prefix}metadata/" | ||
} | ||
|
||
all_attr << attr_settings | ||
end | ||
all_attr | ||
end | ||
end | ||
end | ||
end | ||
|
||
helpers Sinatra::Helpers::MetadataHelper | ||
|