Skip to content

Commit

Permalink
Merge branch 'master' into ecoportal-ontoportal-reset
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed May 27, 2024
2 parents 90bb0bc + ff69534 commit 951e95c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ GEM

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

DEPENDENCIES
Expand All @@ -63,4 +64,4 @@ DEPENDENCIES
test-unit

BUNDLED WITH
2.3.23
2.4.21
10 changes: 5 additions & 5 deletions lib/ontologies_api_client/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def method_missing(meth, *args, &block)
##
# Get all top-level links for the API
def top_level_links
HTTP.get(LinkedData::Client.settings.rest_url)
@top_level_links||= HTTP.get(LinkedData::Client.settings.rest_url)
end

##
Expand Down Expand Up @@ -75,16 +75,16 @@ def where(params = {}, &block)

##
# Find a resource by id
# @deprecated replace with "get"
def find(id, params = {})
found = where do |obj|
obj.id.eql?(id)
end
found.first
[get(id, params)]
end

##
# Get a resource by id (this will retrieve it from the REST service)
def get(id, params = {})
path = collection_path
id = "#{path}/#{id}" unless id.include?(path)
HTTP.get(id, params)
end

Expand Down
28 changes: 14 additions & 14 deletions lib/ontologies_api_client/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'multi_json'
require 'digest'
require 'ostruct'

require 'benchmark'
##
# This monkeypatch makes OpenStruct act like Struct objects
class OpenStruct
Expand Down Expand Up @@ -58,20 +58,20 @@ def self.get(path, params = {}, options = {})
raw = options[:raw] || false # return the unparsed body of the request
params = params.delete_if { |k, v| v == nil || v.to_s.empty? }
params[:ncbo_cache_buster] = Time.now.to_f if raw # raw requests don't get cached to ensure body is available
invalidate_cache = params.delete(:invalidate_cache) || false

invalidate_cache = params.delete(:invalidate_cache) || $API_CLIENT_INVALIDATE_CACHE || false
begin
puts "Getting: #{path} with #{params}" if $DEBUG

# LOGGER.debug("\n\n RUBY API - LinkedData::Client::HTTP ->Get: #{path} with:\n > params:#{params.inspect}\n > options:#{options.inspect} ")
begin
response = conn.get do |req|
req.url path
req.params = params.dup
req.options[:timeout] = 60
req.headers.merge(headers)
req.headers[:invalidate_cache] = invalidate_cache
response = nil
time = Benchmark.realtime do
response = conn.get do |req|
req.url path
req.params = params.dup
req.options[:timeout] = 60
req.headers.merge(headers)
req.headers[:invalidate_cache] = invalidate_cache
end
end
puts "Getting: #{path} with #{params} (#{time}s)" if $DEBUG_API_CLIENT
rescue Exception => e
params = Faraday::Utils.build_query(params)
path << "?" unless params.empty? || path.include?("?")
Expand All @@ -89,7 +89,7 @@ def self.get(path, params = {}, options = {})
obj = recursive_struct(load_json(response.body))
end
rescue StandardError => e
puts "Problem getting #{path}" if $DEBUG
puts "Problem getting #{path}" if $DEBUG_API_CLIENT
raise e
end
obj
Expand Down Expand Up @@ -146,7 +146,7 @@ def self.patch(path, obj)
end

def self.delete(id)
puts "Deleting #{id}" if $DEBUG
puts "Deleting #{id}" if $DEBUG_API_CLIENT
response = conn.delete id
raise StandardError, response.body if response.status >= 500

Expand Down
4 changes: 2 additions & 2 deletions lib/ontologies_api_client/models/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class Class < LinkedData::Client::Base

# triple store predicate is <http://www.w3.org/2002/07/owl#deprecated>
def obsolete?
self.obsolete
self.obsolete && self.obsolete.to_s.eql?("true")
end

def prefLabel(options = {})
if options[:use_html]
if self.obsolete
if obsolete?
return "<span class='obsolete_class' title='obsolete class'>#{@prefLabel}</span>"
else
return "<span class='prefLabel'>#{@prefLabel}</span>"
Expand Down
14 changes: 14 additions & 0 deletions lib/ontologies_api_client/models/identifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative "../base"

module LinkedData
module Client
module Models
class Identifier < LinkedData::Client::Base
include LinkedData::Client::Collection
include LinkedData::Client::ReadWrite

@media_type = "http://www.w3.org/ns/adms#Identifier"
end
end
end
end
9 changes: 4 additions & 5 deletions lib/ontologies_api_client/models/ontology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ def admin?(user)
return administeredBy.any? {|u| u == user.id}
end

def invalidate_cache(cache_refresh_all = true)
self.class.all(invalidate_cache: true, include_views: true)
super(cache_refresh_all)
end

# ACL with administrators
def full_acl
Expand Down Expand Up @@ -108,7 +104,7 @@ def self.find_by(attrs, *args)
# Override to search for views as well by default
# Views get hidden on the REST service unless the `include_views`
# parameter is set to `true`
def find(id, params = {})
def self.find(id, params = {})
params[:include_views] = params[:include_views] || true
super(id, params)
end
Expand All @@ -119,6 +115,9 @@ def self.include_params
"acronym,administeredBy,group,hasDomain,name,notes,projects,reviews,summaryOnly,viewingRestriction"
end

def self.find_by_acronym(acronym, params = {})
[find(acronym, params)]
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ontologies_api_client/read_write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def invalidate_cache(cache_refresh_all = true)
HTTP.get(self.id, invalidate_cache: true) if self.id
session = Thread.current[:session]
session[:last_updated] = Time.now.to_f if session
refresh_cache
# refresh_cache
end

def refresh_cache
Expand Down

0 comments on commit 951e95c

Please sign in to comment.