Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ GIT

GIT
remote: https://github.com/ncbo/ontologies_linked_data.git
revision: 1a7e1972e8f9a9fd32e09fa7ccb6d2b4228be447
revision: d55bddd1a06eeec7353525b7d7ceba095cc756a1
branch: develop
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -367,7 +367,7 @@ GEM
rubocop-ast (>= 1.45.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.45.1)
rubocop-ast (1.46.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
ruby-progressbar (1.13.0)
Expand All @@ -387,7 +387,7 @@ GEM
simplecov-cobertura (3.0.0)
rexml
simplecov (~> 0.19)
simplecov-html (0.13.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
sinatra (1.4.8)
rack (~> 1.5)
Expand Down
119 changes: 64 additions & 55 deletions controllers/classes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ class ClassesController < ApplicationController
ont, submission = get_ontology_and_submission
cls_count = submission.class_count(LOGGER)
error 403, "Unable to display classes due to missing metrics for #{submission.id.to_s}. Please contact the administrator." if cls_count < 0

attributes, page, size, order_by_hash, bring_unmapped_needed = settings_params(LinkedData::Models::Class)
check_last_modified_segment(LinkedData::Models::Class, [ont.acronym])
page, size = page_params
ld = LinkedData::Models::Class.goo_attrs_to_load(includes_param)
unmapped = ld.delete(:properties)
page_data = LinkedData::Models::Class.in(submission).include(ld).page(page,size).page_count_set(cls_count).all

if unmapped && page_data.length > 0
LinkedData::Models::Class.in(submission).models(page_data).include(:unmapped).all
index = LinkedData::Models::Class.in(submission)
if order_by_hash
index = index.order_by(order_by_hash)
cls_count = nil
# Add index here when, indexing fixed
# index_name = 'classes_sort_by_date'
# index = index.index_as(index_name)
# index = index.with_index(index_name)
end

page_data = index
page_data = page_data.include(attributes).page(page, size).page_count_set(cls_count).all
reply page_data
end

Expand All @@ -28,7 +35,8 @@ class ClassesController < ApplicationController
load_attrs = LinkedData::Models::Class.goo_attrs_to_load(includes_param)
unmapped = load_attrs.delete(:properties)
page, size = page_params
roots = submission.roots(load_attrs, page, size)

roots = submission.roots(load_attrs, page, size, concept_schemes: concept_schemes, concept_collections: concept_collections)

if unmapped && roots.length > 0
LinkedData::Models::Class.in(submission).models(roots).include(:unmapped).all
Expand All @@ -44,13 +52,16 @@ class ClassesController < ApplicationController
check_last_modified_segment(LinkedData::Models::Class, [ont.acronym])
load_attrs = LinkedData::Models::Class.goo_attrs_to_load(includes_param)
unmapped = load_attrs.delete(:properties)
sort = params["sort"].eql?('true') || params["sort"].eql?('1') # default = false
roots = nil
load_attrs += LinkedData::Models::Class.concept_is_in_attributes if submission.skos?

request_display(load_attrs.join(','))

sort = params["sort"].eql?('true') || params["sort"].eql?('1') # default = false

if sort
roots = submission.roots_sorted(load_attrs)
roots = submission.roots_sorted(load_attrs, concept_schemes: concept_schemes, concept_collections: concept_collections)
else
roots = submission.roots(load_attrs)
roots = submission.roots(load_attrs, concept_schemes: concept_schemes, concept_collections: concept_collections)
end

if unmapped && roots.length > 0
Expand All @@ -66,25 +77,28 @@ class ClassesController < ApplicationController
ld = LinkedData::Models::Class.goo_attrs_to_load(includes_param)

load_children = ld.delete :children
if !load_children
unless load_children
load_children = ld.select { |x| x.instance_of?(Hash) && x.include?(:children) }
if load_children
ld = ld.select { |x| !(x.instance_of?(Hash) && x.include?(:children)) }
end
end

unmapped = ld.delete(:properties) ||
(includes_param && includes_param.include?(:all))
(includes_param && includes_param.include?(:all))

ld << :memberOf if includes_param.include?(:all)

cls = get_class(submission, ld)
if unmapped
LinkedData::Models::Class.in(submission)
.models([cls]).include(:unmapped).all
.models([cls]).include(:unmapped).all
end
if includes_param.include?(:hasChildren)
cls.load_has_children
end
if !load_children.nil? and load_children.length >0
LinkedData::Models::Class.partially_load_children([cls],500,cls.submission)
if !load_children.nil? and load_children.length > 0
LinkedData::Models::Class.partially_load_children([cls], 500, cls.submission)
if includes_param.include?(:hasChildren)
cls.children.each do |c|
c.load_has_children
Expand All @@ -104,35 +118,27 @@ class ClassesController < ApplicationController
reply cls.paths_to_root
end

# Get a tree view
# Get a tree view (returns the tree from the roots classes to the specified class)
get '/:cls/tree' do
params ||= @params
includes_param_check
sort = params["sort"].eql?('true') || params["sort"].eql?('1') # default = false
sort = params["sort"].eql?('true') || params["sort"].eql?('1') # default = false
# We override include values other than the following, user-provided include ignored
display_attrs = "prefLabel,hasChildren,children,obsolete,subClassOf"
params["display"] = display_attrs
params["serialize_nested"] = true # Override safety check and cause children to serialize

# Make sure Rack gets updated
req = Rack::Request.new(env)
req.update_param("display", display_attrs)
req.update_param("serialize_nested", true)

ont, submission = get_ontology_and_submission
check_last_modified_segment(LinkedData::Models::Class, [ont.acronym])
cls = get_class(submission)
root_tree = nil
roots = nil

display_attrs = [:prefLabel, :hasChildren, :children, :obsolete, :subClassOf]
display_attrs += LinkedData::Models::Class.concept_is_in_attributes if submission.skos?
request_display(display_attrs.join(','))
extra_include = [:hasChildren, :isInActiveScheme, :isInActiveCollection]
if sort
root_tree = cls.tree_sorted
#add the other roots to the response
roots = submission.roots_sorted(extra_include=[:hasChildren])
roots = submission.roots_sorted(extra_include, concept_schemes: concept_schemes, concept_collections: concept_collections)
root_tree = cls.tree_sorted(concept_schemes: concept_schemes, concept_collections: concept_collections, roots: roots)
# add the other roots to the response
else
root_tree = cls.tree
#add the other roots to the response
roots = submission.roots(extra_include=[:hasChildren])
roots = submission.roots(extra_include, concept_schemes: concept_schemes, concept_collections: concept_collections)
root_tree = cls.tree(concept_schemes: concept_schemes, concept_collections: concept_collections, roots: roots)
# add the other roots to the response
end

# if this path' root does not get returned by the submission.roots call, manually add it
Expand All @@ -143,7 +149,7 @@ class ClassesController < ApplicationController
if r.id == root_tree.id
roots[i] = root_tree
else
roots[i].instance_variable_set("@children",[])
roots[i].instance_variable_set("@children", [])
roots[i].loaded_attributes << :children
end
end
Expand All @@ -159,7 +165,7 @@ class ClassesController < ApplicationController
error 404 if cls.nil?
ancestors = cls.ancestors
LinkedData::Models::Class.in(submission).models(ancestors)
.include(:prefLabel,:synonym,:definition).all
.include(:prefLabel, :synonym, :definition).all
reply ancestors
end

Expand All @@ -169,13 +175,13 @@ class ClassesController < ApplicationController
ont, submission = get_ontology_and_submission
check_last_modified_segment(LinkedData::Models::Class, [ont.acronym])
page, size = page_params
cls = get_class(submission,load_attrs=[])
cls = get_class(submission, load_attrs = [])
error 404 if cls.nil?
ld = LinkedData::Models::Class.goo_attrs_to_load(includes_param)
unmapped = ld.delete(:properties)
page_data = cls.retrieve_descendants(page,size)
page_data = cls.retrieve_descendants(page, size)
LinkedData::Models::Class.in(submission).models(page_data)
.include(:prefLabel,:synonym,:definition).all
.include(:prefLabel, :synonym, :definition).all
if unmapped
LinkedData::Models::Class.in(submission).models(page_data).include(:unmapped).all
end
Expand All @@ -192,20 +198,12 @@ class ClassesController < ApplicationController
cls = get_class(submission)
error 404 if cls.nil?
ld = LinkedData::Models::Class.goo_attrs_to_load(includes_param)
unmapped = ld.delete(:properties)
aggregates = LinkedData::Models::Class.goo_aggregates_to_load(ld)
page_data_query = LinkedData::Models::Class.where(parents: cls).in(submission).include(ld)
page_data_query.aggregate(*aggregates) unless aggregates.empty?
page_data = page_data_query.page(page,size).all
if unmapped
LinkedData::Models::Class.in(submission).models(page_data).include(:unmapped).all
end
page_data.delete_if { |x| x.id.to_s == cls.id.to_s }
if ld.include?(:hasChildren)
page_data.each do |c|
c.load_has_children
end
end
ld += LinkedData::Models::Class.concept_is_in_attributes if submission.skos?
request_display(ld.join(','))

page_data = submission.children(cls, includes_param: includes_param, concept_schemes: concept_schemes,
concept_collections: concept_collections, page: page, size: size)

reply page_data
end

Expand Down Expand Up @@ -236,6 +234,7 @@ class ClassesController < ApplicationController
end

private

def includes_param_check
if includes_param
if includes_param.include?(:all)
Expand All @@ -248,5 +247,15 @@ def includes_param_check
end
end

def request_display(attrs)

params["display"] = attrs
params["serialize_nested"] = true # Override safety check and cause children to serialize

# Make sure Rack gets updated
req = Rack::Request.new(env)
req.update_param("display", attrs)
req.update_param("serialize_nested", true)
end
end
end
43 changes: 43 additions & 0 deletions controllers/collections_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class CollectionsController < ApplicationController

namespace "/ontologies/:ontology/collections" do
get do
submission, attributes, bring_unmapped_needed = collections_setting_params
attributes = attributes.delete_if {|x| x.is_a?(Hash)} # remove :member
page_data = LinkedData::Models::SKOS::Collection.where
.in(submission)
.include(attributes)


page_data = page_data.all
if bring_unmapped_needed
LinkedData::Models::SKOS::Collection.in(submission).models(page_data).include(:unmapped).all
end

reply page_data
end
namespace "/:collection" do
get do
submission, attributes, bring_unmapped_needed = collections_setting_params
collection_uri = get_collection_uri(params)

data = LinkedData::Models::SKOS::Collection.find(collection_uri).in(submission).include(attributes).first
if data && bring_unmapped_needed
LinkedData::Models::SKOS::Collection.in(submission).models([data]).include(:unmapped).all
end
reply data
end

get '/members' do
ont, submission = get_ontology_and_submission
attributes, page, size, filter_by_label, order_by, bring_unmapped_needed = settings_params(LinkedData::Models::Class)
collection_uri = get_collection_uri(params)
data = LinkedData::Models::Class.where(memberOf: collection_uri).in(submission).include(attributes).page(page,size).all
reply data
end
end
end


end

53 changes: 47 additions & 6 deletions controllers/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,65 @@ class InstancesController < ApplicationController

# Display individuals for a class
get '/ontologies/:ontology/classes/:cls/instances' do

ont, sub = get_ontology_and_submission
check_last_modified_segment(LinkedData::Models::Class, [ont.acronym])
check_last_modified_segment(LinkedData::Models::Instance, [ont.acronym])
cls = get_class(sub)
error 404 if cls.nil?
reply LinkedData::InstanceLoader.get_instances_by_class(sub.id, cls.id)
filter_by_label = label_regex_filter
attributes, page, size, order_by, bring_unmapped_needed = settings_params(LinkedData::Models::Instance)



page_data = LinkedData::Models::Instance.where(filter_classes_by(cls.id))
.in(sub)
.include(attributes)

page_data.filter(filter_by_label) unless filter_by_label.nil?
page_data.order_by(order_by) unless order_by.nil?
page_data = page_data.page(page,size).all

bring_unmapped_to page_data , sub, LinkedData::Models::Instance if bring_unmapped_needed

reply page_data
end

namespace "/ontologies/:ontology/instances" do

# Display individuals for an ontology
get do
ont, sub = get_ontology_and_submission
check_last_modified_segment(LinkedData::Models::Instance, [ont.acronym])
page, size = page_params
reply LinkedData::InstanceLoader.get_instances_by_ontology(sub.id, page, size)
filter_by_label = label_regex_filter
attributes, page, size, order_by, bring_unmapped_needed = settings_params(LinkedData::Models::Instance)


page_data = LinkedData::Models::Instance.where
.in(sub)
.include(attributes)

page_data.filter(filter_by_label) unless filter_by_label.nil?
page_data.order_by(order_by) unless order_by.nil?
page_data = page_data.page(page,size).all

bring_unmapped_to page_data , sub, LinkedData::Models::Instance if bring_unmapped_needed

reply page_data
end

get '/:inst' do
ont, sub = get_ontology_and_submission
check_last_modified_segment(LinkedData::Models::Instance, [ont.acronym])

attributes, page, size, order_by, bring_unmapped_needed = settings_params(LinkedData::Models::Instance)

page_data = LinkedData::Models::Instance.find(@params["inst"]).include(attributes).in(sub).first

bring_unmapped_to [page_data] , sub, LinkedData::Models::Instance if bring_unmapped_needed

reply page_data
end
end
end


end

Loading