Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
926fe1e
Auto stash before merge of "upstream" and "upstream/master"
syphax-bouazzouni Feb 11, 2022
acbf289
Merge remote-tracking branch 'upstream/master' into upstream
syphax-bouazzouni May 13, 2022
398a80c
Merge remote-tracking branch 'upstream/master' into upstream
syphax-bouazzouni Aug 19, 2022
b68a8dc
auto lint mappings_controller et test_mappings
syphax-bouazzouni Aug 19, 2022
48816ea
move request_has_file? and ile_from_request to applicatio_helper
syphax-bouazzouni Aug 19, 2022
8d7203d
add mappings json file parser as a mapping helper
syphax-bouazzouni Aug 19, 2022
007dcc8
add the '/load' post endpoint to mappings namespace
syphax-bouazzouni Aug 19, 2022
061e9a8
extract commun_created_mappings_test method
syphax-bouazzouni Aug 19, 2022
eedaa3d
extract build_mappings_hash method in the test_mappings_controller
syphax-bouazzouni Aug 19, 2022
bbc40f1
use commun_created_mappings_test and build_mappings_hash
syphax-bouazzouni Aug 19, 2022
5cf87e1
add test_mappings_file_load in the test_mappings_controller.rb
syphax-bouazzouni Aug 19, 2022
0682e85
set OLD gem to 'pr/feature/add-rest-mapping-bulk-loader' to pass tests
syphax-bouazzouni Aug 19, 2022
fcc10e6
add mappings_helpers to find the creator user of a mapping
syphax-bouazzouni Sep 14, 2022
8adfb02
use LinkedData::Mappings.create_mapping
syphax-bouazzouni Sep 14, 2022
5f41bb5
update tests with the new mapping_hash structure
syphax-bouazzouni Sep 14, 2022
34f0c7e
update ontologies_linked_data brach to pass tests
syphax-bouazzouni Sep 15, 2022
22f185e
extract create_mapping_counts to the before_suite of mappings test
syphax-bouazzouni Sep 16, 2022
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ test/test_run.log
test/data/ontology_files/catalog-v001.xml

create_permissions.log

ontologies_api.iml
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ gem 'goo', github: 'ncbo/goo', branch: 'master'
gem 'ncbo_annotator', github: 'ncbo/ncbo_annotator', branch: 'master'
gem 'ncbo_cron', github: 'ncbo/ncbo_cron', branch: 'master'
gem 'ncbo_ontology_recommender', github: 'ncbo/ncbo_ontology_recommender', branch: 'master'
gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'master'
gem 'ontologies_linked_data', github: 'ontoportal-lirmm/ontologies_linked_data', branch: 'pr/refactor/centralize-mapping-creation'
gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'master'

group :development do
Expand Down
43 changes: 22 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ GIT
redis

GIT
remote: https://github.com/ncbo/ontologies_linked_data.git
revision: 8196bf34b45c75f8104bb76dfcba1db0f2c048e4
remote: https://github.com/ncbo/sparql-client.git
revision: fb4a89b420f8eb6dda5190a126b6c62e32c4c0c9
branch: master
specs:
sparql-client (1.0.1)
json_pure (>= 1.4)
net-http-persistent (= 2.9.4)
rdf (>= 1.0)

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 7868dd6bed68797086f5a9ac5e0faceb403c98a6
branch: pr/refactor/centralize-mapping-creation
specs:
ontologies_linked_data (0.0.1)
activesupport
Expand All @@ -71,16 +81,6 @@ GIT
rsolr
rubyzip

GIT
remote: https://github.com/ncbo/sparql-client.git
revision: fb4a89b420f8eb6dda5190a126b6c62e32c4c0c9
branch: master
specs:
sparql-client (1.0.1)
json_pure (>= 1.4)
net-http-persistent (= 2.9.4)
rdf (>= 1.0)

GIT
remote: https://github.com/palexander/rack-post-body-to-params.git
revision: 0fd30e710386d0cb8a3a6833d9549d7b655d5398
Expand All @@ -103,8 +103,8 @@ GEM
activesupport (3.2.22.5)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
airbrussh (1.4.1)
sshkit (>= 1.6.1, != 1.7.0)
backports (3.23.0)
Expand All @@ -131,7 +131,7 @@ GEM
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
faraday (1.10.1)
faraday (1.10.2)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
Expand Down Expand Up @@ -159,7 +159,7 @@ GEM
ffi (~> 1.0)
google-apis-analytics_v3 (0.10.0)
google-apis-core (>= 0.7, < 2.a)
google-apis-core (0.7.0)
google-apis-core (0.7.2)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
Expand Down Expand Up @@ -188,7 +188,7 @@ GEM
json-schema (2.8.1)
addressable (>= 2.4)
json_pure (2.6.2)
jwt (2.4.1)
jwt (2.5.0)
kgio (2.11.4)
libxml-ruby (3.2.3)
logger (1.5.1)
Expand All @@ -213,7 +213,7 @@ GEM
net-ssh (>= 2.6.5)
net-ssh (7.0.1)
netrc (0.11.0)
newrelic_rpm (8.9.0)
newrelic_rpm (8.10.1)
oj (2.18.5)
omni_logger (0.1.4)
logger
Expand All @@ -224,7 +224,7 @@ GEM
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.7)
public_suffix (5.0.0)
rack (1.6.13)
rack-accept (0.4.5)
rack (>= 0.4)
Expand All @@ -246,7 +246,7 @@ GEM
rdf (1.0.8)
addressable (>= 2.2)
redcarpet (3.5.1)
redis (4.7.1)
redis (4.8.0)
redis-activesupport (5.3.0)
activesupport (>= 3, < 8)
redis-store (>= 1.3, < 2)
Expand Down Expand Up @@ -301,7 +301,7 @@ GEM
rack-test
sinatra (~> 1.4.0)
tilt (>= 1.3, < 3)
sshkit (1.21.2)
sshkit (1.21.3)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
systemu (2.6.5)
Expand All @@ -325,6 +325,7 @@ GEM
webrick (1.7.0)

PLATFORMS
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
Expand Down
91 changes: 30 additions & 61 deletions controllers/mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MappingsController < ApplicationController
end

mappings = LinkedData::Mappings.mappings_ontology(submission,
0,0,
0, 0,
cls.id)
populate_mapping_classes(mappings.to_a)
reply mappings
Expand All @@ -21,15 +21,15 @@ class MappingsController < ApplicationController
get '/ontologies/:ontology/mappings' do
ontology = ontology_from_acronym(@params[:ontology])
if ontology.nil?
error(404, "Ontology not found")
error(404, "Ontology not found")
end
page, size = page_params
submission = ontology.latest_submission
if submission.nil?
error(404, "Submission not found for ontology " + ontology.acronym)
error(404, "Submission not found for ontology " + ontology.acronym)
end
mappings = LinkedData::Mappings.mappings_ontology(submission,
page,size,
page, size,
nil)
populate_mapping_classes(mappings)
reply mappings
Expand All @@ -55,8 +55,8 @@ class MappingsController < ApplicationController
if sub2.nil?
error(404, "Submission not found for ontology " + ontologies[1].id.to_s)
end
mappings = LinkedData::Mappings.mappings_ontologies(sub1,sub2,
page,size)
mappings = LinkedData::Mappings.mappings_ontologies(sub1, sub2,
page, size)
populate_mapping_classes(mappings)
reply mappings
end
Expand All @@ -70,7 +70,7 @@ class MappingsController < ApplicationController
else
mappings = LinkedData::Mappings.recent_rest_mappings(size + 15)
populate_mapping_classes(mappings)
reply mappings[0..size-1]
reply mappings[0..size - 1]
end
end

Expand All @@ -96,57 +96,26 @@ class MappingsController < ApplicationController

# Create a new mapping
post do
error(400, "Input does not contain classes") if !params[:classes]
if params[:classes].length > 2
error(400, "Input does not contain at least 2 terms")
begin
mapping = LinkedData::Mappings.create_mapping(mapping_hash: params, user_creator: find_user)
reply(201, mapping)
rescue StandardError => e
error(400, e.message)
end
error(400, "Input does not contain mapping relation") if !params[:relation]
error(400, "Input does not contain user creator ID") if !params[:creator]
classes = []
params[:classes].each do |class_id,ontology_id|
o = ontology_id
o = o.start_with?("http://") ? ontology_id :
ontology_uri_from_acronym(ontology_id)
o = LinkedData::Models::Ontology.find(RDF::URI.new(o))
.include(submissions:
[:submissionId, :submissionStatus]).first
if o.nil?
error(400, "Ontology with ID `#{ontology_id}` not found")
end
submission = o.latest_submission
if submission.nil?
error(400,
"Ontology with id #{ontology_id} does not have parsed valid submission")
end
submission.bring(ontology: [:acronym])
c = LinkedData::Models::Class.find(RDF::URI.new(class_id))
.in(submission)
.first
if c.nil?
error(400, "Class ID `#{id}` not found in `#{submission.id.to_s}`")
end
classes << c
end
user_id = params[:creator].start_with?("http://") ?
params[:creator].split("/")[-1] : params[:creator]
user_creator = LinkedData::Models::User.find(user_id)
.include(:username).first
if user_creator.nil?
error(400, "User with id `#{params[:creator]}` not found")
end
process = LinkedData::Models::MappingProcess.new(
:creator => user_creator, :name => "REST Mapping")
process.relation = RDF::URI.new(params[:relation])
process.date = DateTime.now
process_fields = [:source,:source_name, :comment]
process_fields.each do |att|
process.send("#{att}=",params[att]) if params[att]
end
process.save
mapping = LinkedData::Mappings.create_rest_mapping(classes,process)
reply(201, mapping)
end

post '/load' do
begin
mappings = parse_bulk_load_file
loaded_mappings, errors = LinkedData::Mappings.bulk_load_mappings(mappings, current_user, check_exist: true)
response = {}
response[:created] = loaded_mappings unless loaded_mappings.empty?
response[:errors] = errors unless errors.empty?
reply(201, response)
rescue ::JSON::ParserError => e
error(404, "File parsing error: #{e.message}")
end
end
# Delete a mapping
delete '/:mapping' do
mapping_id = RDF::URI.new(replace_url_prefix(params[:mapping]))
Expand All @@ -166,9 +135,9 @@ class MappingsController < ApplicationController
persistent_counts = {}
f = Goo::Filter.new(:pair_count) == false
LinkedData::Models::MappingCount.where.filter(f)
.include(:ontologies,:count)
.all
.each do |m|
.include(:ontologies, :count)
.all
.each do |m|
persistent_counts[m.ontologies.first] = m.count
end
reply persistent_counts
Expand All @@ -189,9 +158,9 @@ class MappingsController < ApplicationController
persistent_counts = {}
LinkedData::Models::MappingCount.where(pair_count: true)
.and(ontologies: ontology.acronym)
.include(:ontologies,:count)
.all
.each do |m|
.include(:ontologies, :count)
.all
.each do |m|
other = m.ontologies.first
if other == ontology.acronym
other = m.ontologies[1]
Expand Down
17 changes: 17 additions & 0 deletions helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,23 @@ def include_param_contains?(str)
return class_params_include || params_include
end


##
# Checks to see if the request has a file attached
def request_has_file?
@params.any? {|p,v| v.instance_of?(Hash) && v.key?(:tempfile) && v[:tempfile].instance_of?(Tempfile)}
end

##
# Looks for a file that was included as a multipart in a request
def file_from_request
@params.each do |param, value|
if value.instance_of?(Hash) && value.has_key?(:tempfile) && value[:tempfile].instance_of?(Tempfile)
return value[:filename], value[:tempfile]
end
end
return nil, nil
end
private

def naive_expiring_cache_write(key, object, timeout = 60)
Expand Down
26 changes: 26 additions & 0 deletions helpers/mappings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ def populate_mapping_classes(mappings)

mappings
end
##
# Parse the uploaded mappings file
def parse_bulk_load_file
filename, tmpfile = file_from_request
if tmpfile
if filename.nil?
error 400, "Failure to resolve mappings json filename from upload file."
end
Array(::JSON.parse(tmpfile.read,{:symbolize_names => true}))
end

end
def creator_id
params[:creator]&.start_with?("http://") ?
params[:creator]&.split("/")[-1] : params[:creator]
end

def find_user
user_id = creator_id
user_creator = LinkedData::Models::User.find(user_id)
.include(:username).first
if user_creator.nil?
raise StandardError, "User with id `#{params[:creator]}` not found"
end
user_creator
end
end
end
end
Expand Down
16 changes: 0 additions & 16 deletions helpers/ontology_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ def create_submission(ont)
ont_submission
end

##
# Checks to see if the request has a file attached
def request_has_file?
@params.any? {|p,v| v.instance_of?(Hash) && v.key?(:tempfile) && v[:tempfile].instance_of?(Tempfile)}
end

##
# Looks for a file that was included as a multipart in a request
def file_from_request
@params.each do |param, value|
if value.instance_of?(Hash) && value.has_key?(:tempfile) && value[:tempfile].instance_of?(Tempfile)
return value[:filename], value[:tempfile]
end
end
return nil, nil
end

##
# Add a file to the submission if a file exists in the params
Expand Down
Loading