Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop to master, release v5.30.0 #153

Merged
merged 45 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
13ad0fc
auto lint changes
syphax-bouazzouni Jul 14, 2022
fac2795
remove duplicated method
syphax-bouazzouni Jul 14, 2022
8e52ba8
add the new function expand_equivalent_predicates_filter
syphax-bouazzouni Jul 14, 2022
f18548a
update get_includes to select :id, :attributeProperty, :attributeObject
syphax-bouazzouni Jul 14, 2022
320a7ed
use the new get_includes
syphax-bouazzouni Jul 14, 2022
1e3c164
update the query builder to add the ?attributeProperty filters
syphax-bouazzouni Jul 14, 2022
8a94793
update solutions_mapper to use the new pattern (?s,?p,?v,?inverse_v))
syphax-bouazzouni Jul 14, 2022
2022222
update expand_equivalent_predicates
syphax-bouazzouni Jul 19, 2022
7745e1f
update get_predicate_map to predicate_map
syphax-bouazzouni Jul 19, 2022
d085508
update get_includes
syphax-bouazzouni Jul 19, 2022
95a3fea
update get_binding_as
syphax-bouazzouni Jul 19, 2022
72c6717
update get_models_by_id_hash
syphax-bouazzouni Jul 19, 2022
076420c
remove unused functions in the loader (an omission)
syphax-bouazzouni Jul 19, 2022
2f8196e
update get_embed_includes
syphax-bouazzouni Jul 19, 2022
e312656
add to the module loader `class << self to specify private functions
syphax-bouazzouni Jul 19, 2022
b222270
add properties_to_include to save the properties to include in the query
syphax-bouazzouni Jul 19, 2022
149a2e8
use the new get_includes, predicate_map and get_bnode_extraction
syphax-bouazzouni Jul 19, 2022
5ea4f09
use the new expand_equivalent_predicates
syphax-bouazzouni Jul 19, 2022
8028017
add in the query builder initialize instance variables
syphax-bouazzouni Jul 19, 2022
cf1d9ea
update the build_select_query
syphax-bouazzouni Jul 19, 2022
a9161b4
add to the solution mapper initialize some instance variable
syphax-bouazzouni Jul 19, 2022
f4dc339
update map_each_solutions
syphax-bouazzouni Jul 19, 2022
6cf7320
update order by query to use unions so that it can be optional
syphax-bouazzouni Nov 23, 2022
dce68a7
use optional statements for order by instead of UNION
syphax-bouazzouni Nov 29, 2022
352f3ca
fix embed ready only models
syphax-bouazzouni Dec 17, 2022
3162ee8
fix requests with multiple filters
syphax-bouazzouni Jan 19, 2023
1b26d2b
use ontoportal-lirmm sparql client version to pass tests
syphax-bouazzouni Jan 19, 2023
87e991b
fix healthcheck for AG
alexskr Mar 15, 2024
1a6c63e
manually merged PR #124
mdorf Apr 16, 2024
c7ee4a6
Merge branch 'ontoportal-lirmm-pr/feature/optimize-sparql-query-build…
mdorf Apr 16, 2024
7215f49
add request store dependency to save globally the language per request
syphax-bouazzouni Apr 17, 2024
d6e8c33
and languages settings dsl
syphax-bouazzouni Apr 17, 2024
163a3de
create a module in sparql mixins to handle languages filters logic
syphax-bouazzouni Apr 17, 2024
43c8459
refactor query_builder to extract internal_variables as instance vari…
syphax-bouazzouni Apr 17, 2024
0dc978a
add complex oder_by for embed attributes and fix empty pagination
syphax-bouazzouni Apr 17, 2024
e72d643
add multilingual support tests
syphax-bouazzouni Apr 17, 2024
a3d50fb
update the lang filter module to include not tagged values if multipl…
syphax-bouazzouni Apr 17, 2024
f34f2b0
make map_attributes support multilingual
syphax-bouazzouni Apr 17, 2024
27fbe7d
unskip test_embed_struct
syphax-bouazzouni Apr 17, 2024
eba6251
add ruby-version file
syphax-bouazzouni Apr 17, 2024
fb04e78
fix multilingual support for AG backend
syphax-bouazzouni Apr 17, 2024
9fb8163
Merge branch 'ontoportal-lirmm-pr/sync-agroportal-bioportal' into dev…
mdorf Apr 24, 2024
563a47f
Gemfile.lock update after merging #150
mdorf Apr 24, 2024
5d911f5
Gemfile.lock update
mdorf Apr 24, 2024
33583fd
Gemfile.lock update
mdorf Apr 24, 2024
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
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.8
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ gem "activesupport"
gem "cube-ruby", require: "cube"
gem "rake"
gem "uuid"
gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'develop'


group :test do
gem "minitest", '< 5.0'
Expand All @@ -21,4 +23,3 @@ group :profiling do
gem "thin"
end

gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'develop'
26 changes: 15 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ncbo/sparql-client.git
revision: 55e7dbf858eb571c767bc67868f9af61663859cb
revision: 1657f0dd69fd4b522d3549a6848670175f5e98cc
branch: develop
specs:
sparql-client (1.0.1)
Expand All @@ -16,6 +16,7 @@ PATH
pry
rdf (= 1.0.8)
redis
request_store
rest-client
rsolr
sparql-client
Expand Down Expand Up @@ -52,10 +53,10 @@ GEM
domain_name (~> 0.5)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json_pure (2.7.1)
json_pure (2.7.2)
macaddr (1.7.2)
systemu (~> 2.6.5)
method_source (1.0.0)
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0305)
Expand All @@ -68,29 +69,31 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.4)
rack (2.2.8.1)
public_suffix (5.0.5)
rack (2.2.9)
rack-accept (0.4.5)
rack (>= 0.4)
rack-post-body-to-params (0.1.8)
activesupport (>= 2.3)
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
rake (13.1.0)
rake (13.2.1)
rdf (1.0.8)
addressable (>= 2.2)
redis (5.1.0)
redis-client (>= 0.17.0)
redis-client (0.21.0)
redis (5.2.0)
redis-client (>= 0.22.0)
redis-client (0.22.1)
connection_pool
request_store (1.6.0)
rack (>= 1.4)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.6)
rsolr (2.5.0)
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
ruby2_keywords (0.0.5)
Expand Down Expand Up @@ -120,7 +123,8 @@ GEM
macaddr (~> 1.0)

PLATFORMS
ruby
x86_64-darwin-21
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ services:
; agtool users grant anonymous root:ontoportal_test:rw
; tail -f /agraph/data/agraph.log"
healthcheck:
test: ["CMD-SHELL", "curl -m 1 -sf http://127.0.0.1:10035/repositories/ontoportal_test/status | grep -iqE '(^running|^lingering)' || exit 1"]
start_period: 60s
test: ["CMD-SHELL", "agtool storage-report ontoportal_test || exit 1"]
start_period: 30s
interval: 10s
timeout: 5s
retries: 5
timeout: 10s
retries: 10
profiles:
- ag

Expand Down
1 change: 1 addition & 0 deletions goo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Gem::Specification.new do |s|
s.add_dependency("rsolr")
s.add_dependency("sparql-client")
s.add_dependency("uuid")
s.add_dependency("request_store")
end
28 changes: 27 additions & 1 deletion lib/goo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ module Goo

@@resource_options = Set.new([:persistent]).freeze

# Define the languages from which the properties values will be taken
# It choose the first language that match otherwise return all the values
@@main_languages = %w[en]
@@requested_language = nil

@@configure_flag = false
@@sparql_backends = {}
@@model_by_name = {}
Expand All @@ -47,6 +52,27 @@ module Goo

@@slice_loading_size = 500


def self.main_languages
@@main_languages
end
def self.main_languages=(lang)
@@main_languages = lang
end

def self.requested_language
@@requested_language
end

def self.requested_language=(lang)
@@requested_language = lang
end

def self.language_includes(lang)
lang_str = lang.to_s
main_languages.index { |l| lang_str.downcase.eql?(l) || lang_str.upcase.eql?(l)}
end

def self.add_namespace(shortcut, namespace,default=false)
if !(namespace.instance_of? RDF::Vocabulary)
raise ArgumentError, "Namespace must be a RDF::Vocabulary object"
Expand Down Expand Up @@ -84,7 +110,7 @@ def self.add_sparql_backend(name, *opts)
@@sparql_backends[name][:backend_name] = opts[:backend_name]
@@sparql_backends.freeze
end

def self.use_cache=(value)
@@use_cache = value
set_sparql_cache
Expand Down
71 changes: 38 additions & 33 deletions lib/goo/base/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Resource
attr_reader :modified_attributes
attr_reader :errors
attr_reader :aggregates
attr_reader :unmapped
attr_writer :unmapped

attr_reader :id

Expand Down Expand Up @@ -123,7 +123,12 @@ def missing_load_attributes

def unmapped_set(attribute,value)
@unmapped ||= {}
(@unmapped[attribute] ||= Set.new) << value
@unmapped[attribute] ||= Set.new
@unmapped[attribute].merge(Array(value)) unless value.nil?
end

def unmapped_get(attribute)
@unmapped[attribute]
end

def unmmaped_to_array
Expand All @@ -134,6 +139,12 @@ def unmmaped_to_array
@unmapped = cpy
end

def unmapped(*args)
@unmapped&.transform_values do |language_values|
self.class.not_show_all_languages?(language_values, args) ? language_values.values.flatten: language_values
end
end

def delete(*args)
if self.kind_of?(Goo::Base::Enum)
unless args[0] && args[0][:init_enum]
Expand Down Expand Up @@ -211,13 +222,13 @@ def graph
return col ? col.id : nil
end

def self.map_attributes(inst,equivalent_predicates=nil)
def self.map_attributes(inst,equivalent_predicates=nil, include_languages: false)
if (inst.kind_of?(Goo::Base::Resource) && inst.unmapped.nil?) ||
(!inst.respond_to?(:unmapped) && inst[:unmapped].nil?)
(!inst.respond_to?(:unmapped) && inst[:unmapped].nil?)
raise ArgumentError, "Resource.map_attributes only works for :unmapped instances"
end
klass = inst.respond_to?(:klass) ? inst[:klass] : inst.class
unmapped = inst.respond_to?(:klass) ? inst[:unmapped] : inst.unmapped
unmapped = inst.respond_to?(:klass) ? inst[:unmapped] : inst.unmapped(include_languages: include_languages)
list_attrs = klass.attributes(:list)
unmapped_string_keys = Hash.new
unmapped.each do |k,v|
Expand All @@ -228,36 +239,38 @@ def self.map_attributes(inst,equivalent_predicates=nil)
next unless inst.respond_to?(attr)
attr_uri = klass.attribute_uri(attr,inst.collection).to_s
if unmapped_string_keys.include?(attr_uri.to_s) ||
(equivalent_predicates && equivalent_predicates.include?(attr_uri))
object = nil
(equivalent_predicates && equivalent_predicates.include?(attr_uri))
if !unmapped_string_keys.include?(attr_uri)
equivalent_predicates[attr_uri].each do |eq_attr|
if object.nil? and !unmapped_string_keys[eq_attr].nil?
object = unmapped_string_keys[eq_attr].dup
else
if object.is_a?Array
if !unmapped_string_keys[eq_attr].nil?
object.concat(unmapped_string_keys[eq_attr])
end
end
object = Array(equivalent_predicates[attr_uri].map { |eq_attr| unmapped_string_keys[eq_attr] }).flatten.compact
if include_languages && [RDF::URI, Hash].all?{|c| object.map(&:class).include?(c)}
object = object.reduce({}) do |all, new_v|
new_v = { none: [new_v] } if new_v.is_a?(RDF::URI)
all.merge(new_v) {|_, a, b| a + b }
end
elsif include_languages
object = object.first
end

if object.nil?
inst.send("#{attr}=",
list_attrs.include?(attr) ? [] : nil, on_load: true)
inst.send("#{attr}=", list_attrs.include?(attr) ? [] : nil, on_load: true)
next
end
else
object = unmapped_string_keys[attr_uri]
end
object = object.map { |o| o.is_a?(RDF::URI) ? o : o.object }

if object.is_a?(Hash)
object = object.transform_values{|values| Array(values).map{|o|o.is_a?(RDF::URI) ? o : o.object}}
else
object = object.map {|o| o.is_a?(RDF::URI) ? o : o.object}
end

if klass.range(attr)
object = object.map { |o|
o.is_a?(RDF::URI) ? klass.range_object(attr,o) : o }
end
unless list_attrs.include?(attr)
object = object.first
end

object = object.first unless list_attrs.include?(attr) || include_languages
if inst.respond_to?(:klass)
inst[attr] = object
else
Expand All @@ -266,16 +279,12 @@ def self.map_attributes(inst,equivalent_predicates=nil)
else
inst.send("#{attr}=",
list_attrs.include?(attr) ? [] : nil, on_load: true)
if inst.id.to_s == "http://purl.obolibrary.org/obo/IAO_0000415"
if attr == :definition
# binding.pry
end
end
end

end
end


def collection
opts = self.class.collection_opts
if opts.instance_of?(Symbol)
Expand Down Expand Up @@ -414,12 +423,8 @@ def self.range_object(attr,id)
end

def self.find(id, *options)
if !id.instance_of?(RDF::URI) && self.name_with == :id
id = RDF::URI.new(id)
end
unless id.instance_of?(RDF::URI)
id = id_from_unique_attribute(name_with(),id)
end
id = RDF::URI.new(id) if !id.instance_of?(RDF::URI) && self.name_with == :id
id = id_from_unique_attribute(name_with(),id) unless id.instance_of?(RDF::URI)
if self.inmutable? && self.inm_instances && self.inm_instances[id]
w = Goo::Base::Where.new(self)
w.instance_variable_set("@result", [self.inm_instances[id]])
Expand Down
23 changes: 21 additions & 2 deletions lib/goo/base/settings/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,29 @@ def shape_attribute(attr)
self.instance_variable_set("@#{attr}",value)
end
define_method("#{attr}") do |*args|
attr_value = self.instance_variable_get("@#{attr}")

if self.class.not_show_all_languages?(attr_value, args)
is_array = attr_value.values.first.is_a?(Array)
attr_value = attr_value.values.flatten
attr_value = attr_value.first unless is_array
end


if self.class.handler?(attr)
if @loaded_attributes.include?(attr)
return self.instance_variable_get("@#{attr}")
return attr_value
end
value = self.send("#{self.class.handler(attr)}")
self.instance_variable_set("@#{attr}",value)
@loaded_attributes << attr
return value
end

if (not @persistent) or @loaded_attributes.include?(attr)
return self.instance_variable_get("@#{attr}")
return attr_value
else
# TODO: bug here when no labels from one of the main_lang available... (when it is called by ontologies_linked_data ontologies_submission)
raise Goo::Base::AttributeNotLoaded, "Attribute `#{attr}` is not loaded for #{self.id}. Loaded attributes: #{@loaded_attributes.inspect}."
end
end
Expand Down Expand Up @@ -372,6 +383,14 @@ def read_only(attributes)
instance
end

def show_all_languages?(args)
args.first.is_a?(Hash) && args.first.keys.include?(:include_languages) && args.first[:include_languages]
end

def not_show_all_languages?(values, args)
values.is_a?(Hash) && !show_all_languages?(args)
end

end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/goo/base/where.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def process_query_intl(count=false)

options_load[:ids] = ids if ids
models_by_id = {}
if @page_i && (options_load[:models].length > 0)
options_load.delete(:filters)
options_load.delete(:order_by)
end

if (@page_i && options_load[:models].length > 0) ||
(!@page_i && (@count.nil? || @count > 0))
models_by_id = Goo::SPARQL::Queries.model_load(options_load)
Expand Down
Loading