Skip to content

Commit

Permalink
Merge pull request #153 from ncbo/develop
Browse files Browse the repository at this point in the history
Merge develop to master, release v5.30.0
  • Loading branch information
alexskr authored May 3, 2024
2 parents f01386f + 33583fd commit 3a3f926
Show file tree
Hide file tree
Showing 18 changed files with 1,221 additions and 874 deletions.
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

0 comments on commit 3a3f926

Please sign in to comment.