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

Ontoportal align: Ecoportal ontoportal reset #1

Merged
merged 74 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
44dca35
Now avoid to refresh cache for all submissions. When editing or savin…
vemonet Jun 8, 2017
89154ff
now we can avoid cache refresh when using the .save method also
vemonet Jun 8, 2017
5bbba06
Fixed bug in user.rb to match update in ontologies API
twktheainur Oct 2, 2017
97cf8f6
Merge branch 'master' of https://github.com/ncbo/ontologies_api_ruby_…
Apr 7, 2020
90124b7
Merge branch 'master' of https://github.com/ncbo/ontologies_api_ruby_…
Apr 24, 2020
4d65287
Merge branch 'virtual-appliance-3.0-merge' of https://github.com/sifr…
Apr 24, 2020
06f7596
Gemfile.lock update
jlamarque34 Jun 16, 2020
88f2138
.gitignore update (added .bundle/)
Jun 18, 2020
c6d610f
[ontoportal-bot] Gemfile.lock update
ontoportal-bot-lirmm Jul 10, 2020
9833ae9
[ontoportal-bot] Gemfile.lock update
ontoportal-bot-lirmm Jul 16, 2020
0975c15
Merge branch 'master' of https://github.com/ncbo/ontologies_api_ruby_…
Aug 18, 2020
fae8ec2
[ontoportal-bot] Gemfile.lock update
ontoportal-bot-lirmm Aug 25, 2020
04cb912
Merge branch 'virtual-appliance-3.0-merge'
Sep 10, 2020
036d7ef
[ontoportal-bot] Gemfile.lock update
ontoportal-bot-lirmm Sep 10, 2020
72f8020
[ontoportal-bot] Gemfile.lock update
ontoportal-bot-lirmm Oct 30, 2020
89f169b
[ontoportal-bot] Merge branch 'master' of https://github.com/ncbo/ont…
ontoportal-bot-lirmm Jun 28, 2021
53b6dd3
[ontoportal-bot] Merge branch 'master' of https://github.com/ncbo/ont…
ontoportal-bot-lirmm Dec 6, 2021
ee2fa6a
update gem versions
syphax-bouazzouni Jan 4, 2022
3e9e1fa
set a fixed version to faraday
syphax-bouazzouni Jan 4, 2022
19ae5f7
merge fix-faraday-version in master branch
syphax-bouazzouni Jan 4, 2022
aa3e8ec
merge to upstream v2.1.0
syphax-bouazzouni May 16, 2022
101c2bb
inverse the invalidate_cache all condition and extract it in a function
syphax-bouazzouni May 22, 2022
495725a
Merge branch 'pl/feature-add-option-disable-invalidate-cache-for-all'
syphax-bouazzouni May 22, 2022
46c1269
Merge branch 'upstream' into pl/feature-add-option-disable-invalidate…
syphax-bouazzouni May 22, 2022
ec7dd19
unpin activesupport version
syphax-bouazzouni May 26, 2022
e4c61d0
Merge branch 'pr/unpin-activesupport-version' into development
syphax-bouazzouni May 26, 2022
e6d6587
return the response for path, batch and delete methods
syphax-bouazzouni Sep 5, 2022
d468ce0
replace Exception with StandardError
syphax-bouazzouni Sep 5, 2022
94463b6
remove useless return keyword
syphax-bouazzouni Sep 5, 2022
d98fb94
RuboCop auto lint
syphax-bouazzouni Sep 5, 2022
28af31f
Merge branch 'pr/fix/return-delete-response' into development
syphax-bouazzouni Sep 5, 2022
7747252
Merge branch 'pr/fix/return-delete-response'
syphax-bouazzouni Sep 5, 2022
a7d447f
add bundle linux platform
syphax-bouazzouni Sep 6, 2022
dce189f
Merge branch 'pr/fix/return-delete-response' into development
syphax-bouazzouni Oct 13, 2022
9059eab
Merge branch 'development'
syphax-bouazzouni Oct 13, 2022
063383c
append value to the url if nowhere to replace
syphax-bouazzouni Nov 15, 2022
d9b6b5c
Merge branch 'pr/feature/add-link-explorer-by-id' into development
syphax-bouazzouni Nov 15, 2022
dcd41e1
Merge branch 'pr/feature/add-link-explorer-by-id'
syphax-bouazzouni Nov 15, 2022
87e2845
Add skos collection, schemes and skos label models
syphax-bouazzouni Nov 15, 2022
839018c
Merge branch 'feature/add-skos-models' into development
syphax-bouazzouni Nov 15, 2022
5a0d380
set fail-fast to false in order to run all jobs regardless if one fails
alexskr Nov 16, 2022
a52f30b
Add extra check to detect empty value of UI_APIKEY env var
alexskr Nov 16, 2022
f6231ac
use pull_request_target instead of pull_request
alexskr Nov 17, 2022
e9b2ee8
add media_types to get media_type as Array
syphax-bouazzouni Nov 18, 2022
e12e769
get the map classes using media_types and no more media_type
syphax-bouazzouni Nov 18, 2022
c320f44
add skos:Concept media type for Class model
syphax-bouazzouni Nov 18, 2022
9a93fbb
Merge branch 'pr/feautre/add-multiple-media-types-models' into develo…
syphax-bouazzouni Nov 18, 2022
a427126
Merge branch 'pr/feautre/add-multiple-media-types-models'
syphax-bouazzouni Nov 18, 2022
21cdfe2
update actions/checkout version
alexskr Nov 23, 2022
05d05c0
Merge branch 'pl/feature-add-option-disable-invalidate-cache-for-all'…
jvendetti Dec 13, 2022
2f39aff
Merge branch 'ontoportal-lirmm-pl/feature-add-option-disable-invalida…
jvendetti Dec 13, 2022
7132f1e
Merge pull request #13 from ontoportal-lirmm/pr/fix/return-delete-res…
jvendetti Dec 13, 2022
b82e72a
add inScheme and memberOf to class.rb model
syphax-bouazzouni Dec 13, 2022
336c3a5
add :inScheme, :memberOf to @attrs_always_present of class model
syphax-bouazzouni Dec 13, 2022
4bcfad5
Merge branch 'feature/add-skos-models' into development
syphax-bouazzouni Dec 13, 2022
ac80768
Bump activesupport from 6.0.4.1 to 6.1.5.1
jvendetti Dec 14, 2022
ca18863
Update gem.version
jvendetti Dec 14, 2022
d8577e3
Merge remote-tracking branch 'upstream/master' into upstream
syphax-bouazzouni Dec 18, 2022
f26f4f4
Merge branch 'upstream v2.2.0' into development
syphax-bouazzouni Dec 18, 2022
a2245a9
Merge branch 'master' into development
syphax-bouazzouni Dec 18, 2022
fe929a4
Merge pull request #7 from ontoportal-lirmm/development
syphax-bouazzouni Dec 18, 2022
0c8cd2b
replace URI.escape with CGI.escape
syphax-bouazzouni Dec 24, 2022
695168f
enable read/write feature to Group and Category models
syphax-bouazzouni Apr 15, 2023
89c6d98
add identifier_request model
syphax-bouazzouni Apr 15, 2023
e932948
add the possibility to use bearer_token for authentification
syphax-bouazzouni Apr 15, 2023
7b298ff
Merge pull request #9 from ontoportal-lirmm/development
syphax-bouazzouni May 4, 2023
ca20880
Merge pull request #10 from ontoportal-lirmm/feature/ecoportal/groups…
syphax-bouazzouni May 8, 2023
fc70caa
enable read/write feature to Group and Category models
syphax-bouazzouni Apr 15, 2023
749e9fe
Merge pull request #2 from ontoportal-lirmm/feature/ecoportal/groups-…
syphax-bouazzouni May 14, 2023
24dc6bb
Merge branch 'master' into ecoportal-ontoportal-reset
syphax-bouazzouni May 14, 2023
1a0caae
Merge pull request #4 from lifewatch-eric/feature/ecoportal/doi-creation
syphax-bouazzouni May 14, 2023
18d1900
add agent model
syphax-bouazzouni Jun 15, 2023
8fc3c77
Merge pull request #6 from ontoportal-lirmm/feature/add-agent-model
syphax-bouazzouni Jul 9, 2023
90bb0bc
Merge pull request #3 from lifewatch-eric/feature/ecoportal/improve-a…
syphax-bouazzouni Sep 12, 2023
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: 4 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ name: Ruby

on:
push:
pull_request:
pull_request_target:
types: [opened, reopened]

jobs:
test:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby-version: ['2.7', '3.0']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.bundle/

*.gem
.DS_Store
config/config.rb
Expand Down
48 changes: 22 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PATH
remote: .
specs:
ontologies_api_client (2.0.3)
activesupport (= 6.0.4.1)
ontologies_api_client (2.2.0)
activesupport
excon
faraday
faraday-excon (~> 2.0.0)
Expand All @@ -15,50 +15,46 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.4.1)
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
coderay (1.1.3)
concurrent-ruby (1.1.9)
excon (0.91.0)
concurrent-ruby (1.1.10)
excon (0.95.0)
faraday (2.0.1)
faraday-net_http (~> 2.0)
ruby2_keywords (>= 0.0.4)
faraday-excon (2.0.0)
excon (>= 0.27.4)
faraday (~> 2.0.0.alpha.pre.2)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (2.0.1)
i18n (1.10.0)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (2.1.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
lz4-ruby (0.3.3)
method_source (1.0.0)
minitest (5.15.0)
minitest (5.16.3)
multi_json (1.15.0)
multipart-post (2.1.1)
oj (3.13.11)
power_assert (2.0.1)
multipart-post (2.2.3)
oj (3.13.23)
power_assert (2.0.2)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rake (13.0.6)
ruby2_keywords (0.0.5)
spawnling (2.1.5)
test-unit (3.5.3)
test-unit (3.5.7)
power_assert
thread_safe (0.3.6)
tzinfo (1.2.10)
thread_safe (~> 0.1)
zeitwerk (2.5.4)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)

PLATFORMS
ruby
x86_64-darwin-16
x86_64-darwin-17
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
ontologies_api_client!
Expand All @@ -67,4 +63,4 @@ DEPENDENCIES
test-unit

BUNDLED WITH
2.1.4
2.3.23
3 changes: 2 additions & 1 deletion config/config.test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# config.rb is required for testing
# unit test makes calls to bioportal api so it needs a valid API key which can
# be set via ENV variable UT_APIKEY
abort('env variable UT_APIKEY is not set. Canceling tests...') unless ENV.include?('UT_APIKEY')
abort('UT_APIKEY env variable is not set. Canceling tests') unless ENV.include?('UT_APIKEY')
abort('UT_APIKEY env variable is set to an empty value. Canceling tests') unless ENV['UT_APIKEY'].size > 5

LinkedData::Client.config do |config|
config.rest_url = 'https://data.bioontology.org'
Expand Down
17 changes: 14 additions & 3 deletions lib/ontologies_api_client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ class Base
attr_accessor :context, :links

class << self
attr_accessor :media_type, :act_as_media_type, :include_attrs, :include_attrs_full, :attrs_always_present
attr_accessor :act_as_media_type, :include_attrs, :include_attrs_full, :attrs_always_present
def media_types
Array(@media_type)
end

def media_type
media_types.first
end

end

##
Expand All @@ -31,8 +39,11 @@ def self.map_classes
map = {}
classes = LinkedData::Client::Models.constants.map {|c| LinkedData::Client::Models.const_get(c)}
classes.each do |media_type_cls|
next if map[media_type_cls] || !media_type_cls.respond_to?(:media_type) || !media_type_cls.ancestors.include?(LinkedData::Client::Base)
map[media_type_cls.media_type] = media_type_cls
next if map[media_type_cls] || !media_type_cls.respond_to?(:media_types) || !media_type_cls.ancestors.include?(LinkedData::Client::Base)
media_type_cls.media_types.each do |type|
next if map[type]
map[type] = media_type_cls
end
media_type_cls.act_as_media_type.each {|mt| map[mt] = media_type_cls} if media_type_cls.act_as_media_type
end
return map
Expand Down
58 changes: 33 additions & 25 deletions lib/ontologies_api_client/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def members
def length
@table.keys.length
end

alias :size :length

def to_a
Expand All @@ -37,7 +38,9 @@ def values_at(*selectors)
module LinkedData
module Client
module HTTP
class Link < String; attr_accessor :media_type; end
class Link < String
attr_accessor :media_type;
end

def self.conn
unless LinkedData::Client.connection_configured?
Expand All @@ -53,7 +56,7 @@ def self.conn
def self.get(path, params = {}, options = {})
headers = options[:headers] || {}
raw = options[:raw] || false # return the unparsed body of the request
params = params.delete_if {|k,v| v == nil || v.to_s.empty?}
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

Expand Down Expand Up @@ -85,7 +88,7 @@ def self.get(path, params = {}, options = {})
else
obj = recursive_struct(load_json(response.body))
end
rescue Exception => e
rescue StandardError => e
puts "Problem getting #{path}" if $DEBUG
raise e
end
Expand All @@ -96,30 +99,26 @@ def self.get_batch(paths, params = {})
responses = []
if conn.in_parallel?
conn.in_parallel do
paths.each {|p| responses << conn.get(p, params) }
paths.each { |p| responses << conn.get(p, params) }
end
else
responses = threaded_request(paths, params)
end
return responses
responses
end

def self.post(path, obj, options = {})
begin
file, file_attribute = params_file_handler(obj)
response = conn.post do |req|
req.url path
custom_req(obj, file, file_attribute, req)
end
raise Exception, response.body if response.status >= 500
if options[:raw] || false # return the unparsed body of the request
return response.body
else
return recursive_struct(load_json(response.body))
end
rescue => e
LOGGER.debug "\n\n\nRUBY API - LinkedData::Client::HTTP ->post: - ECCEZIONE: #{e.message}\n#{e.backtrace.join("\n")}"
raise e
file, file_attribute = params_file_handler(obj)
response = conn.post do |req|
req.url path
custom_req(obj, file, file_attribute, req)
end
raise StandardError, response.body if response.status >= 500

if options[:raw] || false # return the unparsed body of the request
response.body
else
recursive_struct(load_json(response.body))
end

end
Expand All @@ -130,7 +129,8 @@ def self.put(path, obj)
req.url path
custom_req(obj, file, file_attribute, req)
end
raise Exception, response.body if response.status >= 500
raise StandardError, response.body if response.status >= 500

recursive_struct(load_json(response.body))
end

Expand All @@ -140,13 +140,17 @@ def self.patch(path, obj)
req.url path
custom_req(obj, file, file_attribute, req)
end
raise Exception, response.body if response.status >= 500
raise StandardError, response.body if response.status >= 500

response
end

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

response
end

def self.object_from_json(json)
Expand Down Expand Up @@ -178,9 +182,11 @@ def self.custom_req(obj, file, file_attribute, req)

def self.params_file_handler(params)
return if params.nil?

file, return_attribute = nil, nil
params.dup.each do |attribute, value|
next unless value.is_a?(File) || value.is_a?(Tempfile) || value.is_a?(ActionDispatch::Http::UploadedFile)

filename = value.original_filename
file = Faraday::UploadIO.new(value.path, "text/plain", filename)
return_attribute = attribute
Expand Down Expand Up @@ -211,7 +217,7 @@ def self.recursive_struct(json_obj)
context = json_obj.delete("@context") # strip context

# Create a struct with the left-over attributes to store data
attributes = json_obj.keys.map {|k| k.to_sym}
attributes = json_obj.keys.map { |k| k.to_sym }
attributes_always_present = value_cls.attrs_always_present || [] rescue []
attributes = (attributes + attributes_always_present).uniq

Expand Down Expand Up @@ -241,7 +247,7 @@ def self.recursive_struct(json_obj)
end
else
# Get the struct class
recursive_obj_hash = {links: nil, context: nil}
recursive_obj_hash = { links: nil, context: nil }
json_obj.each do |key, value|
recursive_obj_hash[key] = recursive_struct(value)
end
Expand All @@ -268,6 +274,7 @@ def self.prep_links(obj)

context = links.delete("@context")
return if context.nil?

links.keys.each do |link_type|
link = Link.new(links[link_type])
link.media_type = context[link_type]
Expand All @@ -278,6 +285,7 @@ def self.prep_links(obj)

def self.load_json(json)
return if json.nil? || json.empty?

begin
MultiJson.load(json)
rescue Exception => e
Expand Down
10 changes: 8 additions & 2 deletions lib/ontologies_api_client/link_explorer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ def replace_template_elements(url, values = [])
return url if values.nil? || values.empty?
values = values.dup
values = [values] unless values.is_a?(Array)
return url.gsub(/(\{.*?\})/) do
URI.escape(values.shift, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
escaped_value = CGI.escape(values.shift)
if url.match(/(\{.*?\})/)
url.gsub(/(\{.*?\})/) do
escaped_value
end
else
url + '/' + escaped_value
end

end

def linkable_attributes
Expand Down
14 changes: 14 additions & 0 deletions lib/ontologies_api_client/models/agent.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 Agent < LinkedData::Client::Base
include LinkedData::Client::Collection
include LinkedData::Client::ReadWrite

@media_type = "http://xmlns.com/foaf/0.1/Agent"
end
end
end
end
15 changes: 7 additions & 8 deletions lib/ontologies_api_client/models/class.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
require "uri"
require "cgi"
require_relative "../base"

module LinkedData
module Client
module Models
class Class < LinkedData::Client::Base
HTTP = LinkedData::Client::HTTP
@media_type = "http://www.w3.org/2002/07/owl#Class"
@include_attrs = "prefLabel,definition,synonym,obsolete,hasChildren"
@include_attrs_full = "prefLabel,definition,synonym,obsolete,properties,hasChildren,children"
@attrs_always_present = :prefLabel, :definition, :synonym, :obsolete, :properties, :hasChildren, :children

@media_type = %w[http://www.w3.org/2002/07/owl#Class http://www.w3.org/2004/02/skos/core#Concept]
@include_attrs = "prefLabel,definition,synonym,obsolete,hasChildren,inScheme,memberOf"
@include_attrs_full = "prefLabel,definition,synonym,obsolete,properties,hasChildren,childre,inScheme,memberOf"
@attrs_always_present = :prefLabel, :definition, :synonym, :obsolete, :properties, :hasChildren, :children, :inScheme, :memberOf
alias :fullId :id

# triple store predicate is <http://www.w3.org/2002/07/owl#deprecated>
Expand Down Expand Up @@ -48,7 +47,7 @@ def purl
return "" if self.links.nil?
return self.id if self.id.include?("purl.")
ont = self.explore.ontology
"#{LinkedData::Client.settings.purl_prefix}/#{ont.acronym}?conceptid=#{URI.escape(self.id, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"
"#{LinkedData::Client.settings.purl_prefix}/#{ont.acronym}?conceptid=#{CGI.escape(self.id)}"
end

def ontology
Expand All @@ -57,7 +56,7 @@ def ontology

def self.find(id, ontology, params = {})
ontology = HTTP.get(ontology, params)
ontology.explore.class(URI.escape(id, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")))
ontology.explore.class(CGI.escape(id))
end

def self.search(*args)
Expand Down
12 changes: 12 additions & 0 deletions lib/ontologies_api_client/models/collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require_relative "../base"

module LinkedData
module Client
module Models
class Collection < LinkedData::Client::Base
include LinkedData::Client::Collection
@media_type = "http://www.w3.org/2004/02/skos/core#Collection"
end
end
end
end
Loading