Skip to content

Commit

Permalink
Merge branch 'master' into fix/show-multiple-languages
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni authored Jul 6, 2024
2 parents f0ce035 + 6ca322e commit 52f9f86
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 27 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gem 'rest-client'
gem 'rsolr', '~> 1.0'
gem 'rubyzip', '~> 1.0'
gem 'thin'
gem "oauth2", "~> 2.0"
gem 'request_store'
gem 'jwt'
gem 'json-ld', '~> 3.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ def is_person(inst, attr)
enforce_agent_type(persons, 'person', attr)
end

def is_person(inst, attr)
inst.bring(attr) if inst.bring?(attr)
persons = inst.send(attr)

Array(persons).each do |person|
person.bring(:agentType) if person.bring?(:agentType)
unless person.agentType&.eql?('person')
return [:persons, "`#{attr}` must contain only agents of type Person"]
end
end

[]
end

def lexvo_language(inst, attr)
values = Array(attr_value(inst, attr))

Expand Down
59 changes: 59 additions & 0 deletions lib/ontologies_linked_data/models/identifier_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require "ontologies_linked_data/models/users/user"
require "ontologies_linked_data/models/ontology_submission"

module LinkedData
module Models

class IdentifierRequestType
DOI_CREATE = "DOI_CREATE"
DOI_UPDATE = "DOI_UPDATE"
end

class IdentifierRequestStatus
PENDING = "PENDING"
SATISFIED = "SATISFIED"
CANCELED = "CANCELED"
REJECTED = "REJECTED"
ERROR = "ERROR"
end

class IdentifierRequest < LinkedData::Models::Base
# ECOPORTAL_LOGGER.debug("\n\n\nONTOLOGIES_LINKED_DATA: identifier_request.rb")
model :identifier_request, :name_with => :requestId

attribute :requestId, enforce: [:unique, :existence]
attribute :status, enforce: [:existence] #[PENDING, SATISFIED, CANCELED, REJECTED, ERROR]
attribute :requestType, enforce: [:existence] #[DOI_CREATE, DOI_UPDATE]
attribute :requestedBy, enforce: [:existence, :user]
attribute :requestDate, enforce: [:existence, :date_time]
attribute :processedBy, enforce: [:user]
attribute :processingDate, enforce: [:date_time]
attribute :message
attribute :submission, enforce: [:ontology_submission]
link_to LinkedData::Hypermedia::Link.new("requestedBy", lambda {|r| "identifier_requests/#{r.requestId}/requestedBy"}, LinkedData::Models::User.uri_type),
LinkedData::Hypermedia::Link.new("processedBy", lambda {|r| "identifier_requests/#{r.requestId}/processedBy"}, LinkedData::Models::User.uri_type),
LinkedData::Hypermedia::Link.new("submission", lambda {|r| "identifier_requests/#{r.requestId}/submission"}, LinkedData::Models::OntologySubmission.uri_type)

# Access control
#read_restriction_based_on lambda {|req| req.submission.ontology}
#access_control_load submission: [ontology: [:administeredBy, :acl, :viewingRestriction]]
#write_access submission: [ontology: [:administeredBy]]
#access_control_load submission: [:access_control_load_attrs]

embed :submission, :requestedBy, :processedBy
embed_values submission: LinkedData::Models::OntologySubmission.goo_attrs_to_load + [ontology: [:acronym,:viewingRestriction]],
requestedBy: [:username, :email],
processedBy: [:username, :email]

def self.identifierRequest_id_generator()
millis = Time.now.strftime('%s%3N')
return millis
end

end




end
end
6 changes: 4 additions & 2 deletions lib/ontologies_linked_data/models/ontology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'ontologies_linked_data/models/skos/collection'
require 'ontologies_linked_data/models/skos/skosxl'
require 'ontologies_linked_data/models/notes/note'
require 'ontologies_linked_data/models/identifier_request'
require 'ontologies_linked_data/purl/purl_client'

module LinkedData
Expand Down Expand Up @@ -51,7 +52,7 @@ class OntologyAnalyticsError < StandardError; end

attribute :acl, enforce: [:list, :user]

attribute :viewOf, enforce: [:ontology], onUpdate: :update_submissions_has_part
attribute :viewOf, enforce: [:ontology]
attribute :views, :inverse => { on: :ontology, attribute: :viewOf }
attribute :ontologyType, enforce: [:ontology_type], default: lambda { |record| LinkedData::Models::OntologyType.find("ONTOLOGY").include(:code).first }

Expand All @@ -77,7 +78,8 @@ class OntologyAnalyticsError < StandardError; end
LinkedData::Hypermedia::Link.new("download", lambda {|s| "ontologies/#{s.acronym}/download"}, self.type_uri),
LinkedData::Hypermedia::Link.new("views", lambda {|s| "ontologies/#{s.acronym}/views"}, self.type_uri),
LinkedData::Hypermedia::Link.new("analytics", lambda {|s| "ontologies/#{s.acronym}/analytics"}, "#{Goo.namespaces[:metadata].to_s}Analytics"),
LinkedData::Hypermedia::Link.new("ui", lambda {|s| "http://#{LinkedData.settings.ui_host}/ontologies/#{s.acronym}"}, self.uri_type)
LinkedData::Hypermedia::Link.new("ui", lambda {|s| "http://#{LinkedData.settings.ui_host}/ontologies/#{s.acronym}"}, self.uri_type),
LinkedData::Hypermedia::Link.new("identifier_requests", lambda {|s| "ontologies/#{s.acronym}/identifier_requests"}, LinkedData::Models::IdentifierRequest.uri_type)

# Access control
read_restriction lambda {|o| !o.viewingRestriction.eql?("public") }
Expand Down
6 changes: 4 additions & 2 deletions lib/ontologies_linked_data/models/ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ class OntologySubmission < LinkedData::Models::Base
# Metrics metadata
attribute :metrics, type: :metrics


# Configuration metadata

# Internal values for parsing - not definitive
attribute :submissionStatus, type: %i[submission_status list], default: ->(record) { [LinkedData::Models::SubmissionStatus.find("UPLOADED").first] }
attribute :missingImports, type: :list

# Link to ontology
attribute :identifierRequests, inverse: {on: :identifier_request, attribute: :submission}
attribute :ontology, type: :ontology, enforce: [:existence]

def self.agents_attrs
Expand Down Expand Up @@ -201,8 +203,8 @@ def self.embed_values_hash

# Links
links_load :submissionId, ontology: [:acronym]
link_to LinkedData::Hypermedia::Link.new("metrics", ->(s) { "#{self.ontology_link(s)}/submissions/#{s.submissionId}/metrics" }, self.type_uri)
LinkedData::Hypermedia::Link.new("download", ->(s) { "#{self.ontology_link(s)}/submissions/#{s.submissionId}/download" }, self.type_uri)
link_to LinkedData::Hypermedia::Link.new("metrics", ->(s) { "#{self.ontology_link(s)}/submissions/#{s.id.split('/').last}/metrics" }, self.type_uri)
LinkedData::Hypermedia::Link.new("download", ->(s) { "#{self.ontology_link(s)}/submissions/#{s.id.split('/').last}/download" }, self.type_uri)

# HTTP Cache settings
cache_timeout 3600
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Models
module Users
module OAuthAuthentication

def self.included base
def self.included(base)
base.extend ClassMethods
end

Expand Down
1 change: 1 addition & 0 deletions lib/ontologies_linked_data/models/users/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'bcrypt'
require 'securerandom'
require 'ontologies_linked_data/models/users/authentication'
require 'ontologies_linked_data/models/users/oauth_authentication'
require 'ontologies_linked_data/models/users/role'
require 'ontologies_linked_data/models/users/subscription'

Expand Down
11 changes: 11 additions & 0 deletions lib/ontologies_linked_data/security/authorization.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'set'
require 'jwt'

module LinkedData
module Security
Expand Down Expand Up @@ -96,6 +97,16 @@ def find_apikey(env, params)
cookie_apikey(env)
end

def find_access_token(env, params)
access_token = nil
header_auth = env["HTTP_AUTHORIZATION"] || env["Authorization"]
if header_auth && header_auth.downcase().start_with?("bearer ")
access_token = header_auth.split()[1]
end
access_token
end


def authorized?(apikey, env)
return false if apikey.nil?

Expand Down
10 changes: 1 addition & 9 deletions lib/ontologies_linked_data/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def self.response(options = {})
end

def self.serialize(type, obj, params, request)

lang = self.get_language(params)

lang = params['lang'] || Goo.main_languages.first
only = params['display'] || []
only = only.split(',') unless only.is_a?(Array)
all = only[0] == 'all'
Expand All @@ -108,11 +106,5 @@ def self.print_stacktrace?
end
end

def self.get_language(params)
lang = params['lang'] || params['language'] || Goo.main_languages&.first.to_s || 'en'
lang = lang.split(',').map {|l| l.downcase.to_sym}
return lang.length == 1 ? lang.first : lang
end

end
end
2 changes: 1 addition & 1 deletion lib/ontologies_linked_data/serializers/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def self.get_languages(submission, user_languages)
def self.get_submission_languages(submission_natural_language = [])
submission_natural_language = submission_natural_language.values.flatten if submission_natural_language.is_a?(Hash)
submission_natural_language.map { |natural_language| natural_language.to_s['iso639'] && natural_language.to_s.split('/').last[0..1].to_sym }.compact
end
end

def self.type(current_cls, hashed_obj)
if current_cls.respond_to?(:type_uri)
Expand Down
1 change: 1 addition & 0 deletions rakelib/docker_based_test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace :test do
ENV["GOO_PORT"]="9000"
ENV["COMPOSE_PROFILES"]='fs'
Rake::Task["test:docker:up"].invoke

Rake::Task["test"].invoke
Rake::Task["test:docker:down"].invoke
end
Expand Down
19 changes: 8 additions & 11 deletions test/models/test_class_portal_lang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def self.before_suite

def self.after_suite
Goo.main_languages = @@old_main_languages
RequestStore.store[:requested_lang] = nil
end

def self.parse
Expand All @@ -20,7 +19,7 @@ def self.parse
end

def test_map_attribute_found
cls = parse_and_get_class lang: [:FR]
cls = parse_and_get_class lang: ['fr']
cls.bring :unmapped
LinkedData::Models::Class.map_attributes(cls)
assert_equal ['entité matérielle detaillée'], cls.label
Expand All @@ -29,7 +28,7 @@ def test_map_attribute_found
end

def test_map_attribute_not_found
cls = parse_and_get_class lang: [:ES]
cls = parse_and_get_class lang: ['es']
cls.bring :unmapped
LinkedData::Models::Class.map_attributes(cls)
assert_empty cls.label
Expand All @@ -38,7 +37,7 @@ def test_map_attribute_not_found
end

def test_map_attribute_secondary_lang
cls = parse_and_get_class lang: %i[ES FR]
cls = parse_and_get_class lang: %w[es fr]
cls.bring :unmapped
LinkedData::Models::Class.map_attributes(cls)
assert_empty cls.label
Expand All @@ -55,7 +54,7 @@ def test_label_main_lang_fr_found
end

def test_label_main_lang_not_found
cls = parse_and_get_class lang: [:ES]
cls = parse_and_get_class lang: ['es']

assert_empty cls.label
assert_equal 'skos prefLabel rien', cls.prefLabel
Expand All @@ -73,7 +72,7 @@ def test_label_secondary_lang
end

def test_label_main_lang_en_found
cls = parse_and_get_class lang: [:EN]
cls = parse_and_get_class lang: ['en']
assert_equal 'material detailed entity', cls.label.first
assert_includes ['skos prefLabel en', 'skos prefLabel rien'], cls.prefLabel # TODO fix in Goo to show en in priority
assert_equal ['entity eng', 'entite rien'].sort, cls.synonym.sort
Expand All @@ -83,18 +82,16 @@ def test_label_main_lang_en_found
private

def parse_and_get_class(lang:, klass: 'http://lirmm.fr/2015/resource/AGROOE_c_03')
portal_lang_set portal_languages: lang
lang_set lang

cls = get_class(klass,'AGROOE')
assert !cls.nil?
cls.bring_remaining
cls
end


def portal_lang_set(portal_languages: nil)
Goo.main_languages = portal_languages if portal_languages
RequestStore.store[:requested_lang] = nil
def lang_set(lang)
Goo.main_languages = lang
end


Expand Down
2 changes: 1 addition & 1 deletion test/models/test_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_search_ontology_data
.first[:c]
.to_i

assert_equal count, response['response']['numFound']
assert_includes [count, count+1], response['response']['numFound']

response = conn.search('*', fq: ' resource_id:"http://opendata.inrae.fr/thesaurusINRAE/c_10065"')

Expand Down

0 comments on commit 52f9f86

Please sign in to comment.