Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Aug 1, 2024
2 parents 4144ed9 + fc11608 commit 5d40e76
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 132 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem 'sinatra-contrib', '~> 1.0'
gem 'request_store'
gem 'parallel'
gem 'json-ld'
gem 'google-apis-core', '0.15.0'


# Rack middleware
Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: c4dbcc14a3eb75343e597679ea4532ba53785b8f
revision: ca79d5a84a3b6e961118b7e1062f082e7f7b99fc
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -114,6 +114,7 @@ GEM
base64 (0.2.0)
bcrypt (3.1.20)
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-x86_64-darwin)
bigdecimal (1.4.2)
builder (3.3.0)
capistrano (3.19.1)
Expand Down Expand Up @@ -197,7 +198,7 @@ GEM
google-cloud-env (2.1.1)
faraday (>= 1.0, < 3.a)
google-cloud-errors (1.4.0)
google-protobuf (3.25.3-x86_64-linux)
google-protobuf (3.25.4)
googleapis-common-protos (1.6.0)
google-protobuf (>= 3.18, < 5.a)
googleapis-common-protos-types (~> 1.7)
Expand All @@ -211,13 +212,10 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
grpc (1.65.1)
grpc (1.65.2-x86_64-darwin)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.65.1-x86_64-darwin)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.65.1-x86_64-linux)
grpc (1.65.2-x86_64-linux)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
haml (5.2.2)
Expand Down Expand Up @@ -346,7 +344,7 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.3.2)
rexml (3.3.4)
strscan
rsolr (2.6.0)
builder (>= 2.1.2)
Expand Down Expand Up @@ -411,6 +409,7 @@ GEM
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand All @@ -426,6 +425,7 @@ DEPENDENCIES
faraday (~> 1.9)
ffi
goo!
google-apis-core (= 0.15.0)
haml (~> 5.2.2)
json-ld
json-schema (~> 2.0)
Expand Down Expand Up @@ -468,4 +468,4 @@ DEPENDENCIES
webmock (~> 3.19.1)

BUNDLED WITH
2.3.15
2.3.23
219 changes: 111 additions & 108 deletions controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,147 +22,150 @@ class AgentsController < ApplicationController
reply agents
end

namespace "/agents" do
get do
check_last_modified_collection(LinkedData::Models::Agent)
query = LinkedData::Models::Agent.where
query = apply_filters(LinkedData::Models::Agent, query)
query = query.include(LinkedData::Models::Agent.goo_attrs_to_load(includes_param))
if page?
page, size = page_params
agents = query.page(page, size).all
else
agents = query.to_a
end
%w[agents Agents].each do |namespace|
namespace "/#{namespace}" do
get do
check_last_modified_collection(LinkedData::Models::Agent)
query = LinkedData::Models::Agent.where
query = apply_filters(LinkedData::Models::Agent, query)
query = query.include(LinkedData::Models::Agent.goo_attrs_to_load(includes_param))
if page?
page, size = page_params
agents = query.page(page, size).all
else
agents = query.to_a
end

if includes_param.include?(:all) || includes_param.include?(:usages)
LinkedData::Models::Agent.load_agents_usages(agents)
end

if includes_param.include?(:all) || includes_param.include?(:usages)
LinkedData::Models::Agent.load_agents_usages(agents)
reply agents
end

reply agents
end
# Display a single agent
get '/:id' do
check_last_modified_collection(LinkedData::Models::Agent)
id = params["id"]
agent = LinkedData::Models::Agent.find(id).include(LinkedData::Models::Agent.goo_attrs_to_load(includes_param)).first
error 404, "Agent #{id} not found" if agent.nil?
reply 200, agent
end

# Display a single agent
get '/:id' do
check_last_modified_collection(LinkedData::Models::Agent)
id = params["id"]
agent = LinkedData::Models::Agent.find(id).include(LinkedData::Models::Agent.goo_attrs_to_load(includes_param)).first
error 404, "Agent #{id} not found" if agent.nil?
reply 200, agent
end
# Create a agent with the given acronym
post do
reply 201, create_new_agent
end

# Create a agent with the given acronym
post do
reply 201, create_new_agent
end
# Create a agent with the given acronym
put '/:acronym' do
reply 201, create_new_agent
end

# Create a agent with the given acronym
put '/:acronym' do
reply 201, create_new_agent
end
# Update an existing submission of a agent
patch '/:id' do
acronym = params["id"]
agent = LinkedData::Models::Agent.find(acronym).include(LinkedData::Models::Agent.attributes).first

# Update an existing submission of a agent
patch '/:id' do
acronym = params["id"]
agent = LinkedData::Models::Agent.find(acronym).include(LinkedData::Models::Agent.attributes).first
if agent.nil?
error 400, "Agent does not exist, please create using HTTP PUT before modifying"
else
agent = update_agent(agent, params)

if agent.nil?
error 400, "Agent does not exist, please create using HTTP PUT before modifying"
else
agent = update_agent(agent, params)
error 400, agent.errors unless agent.errors.empty?
end
halt 204
end

error 400, agent.errors unless agent.errors.empty?
# Delete a agent
delete '/:id' do
agent = LinkedData::Models::Agent.find(params["id"]).first
agent.delete
halt 204
end
halt 204
end

# Delete a agent
delete '/:id' do
agent = LinkedData::Models::Agent.find(params["id"]).first
agent.delete
halt 204
end
private

private
def update_identifiers(identifiers)
Array(identifiers).map do |i|
next nil if i.empty?

def update_identifiers(identifiers)
Array(identifiers).map do |i|
next nil if i.empty?
id = i["id"] || LinkedData::Models::AgentIdentifier.generate_identifier(i['notation'], i['schemaAgency'])
identifier = LinkedData::Models::AgentIdentifier.find(RDF::URI.new(id)).first

id = i["id"] || LinkedData::Models::AgentIdentifier.generate_identifier(i['notation'], i['schemaAgency'])
identifier = LinkedData::Models::AgentIdentifier.find(RDF::URI.new(id)).first
if identifier
identifier.bring_remaining
else
identifier = LinkedData::Models::AgentIdentifier.new
end

if identifier
identifier.bring_remaining
else
identifier = LinkedData::Models::AgentIdentifier.new
end
i.delete "id"

i.delete "id"
next identifier if i.keys.size.zero?

next identifier if i.keys.size.zero?
populate_from_params(identifier, i)

populate_from_params(identifier, i)
if identifier.valid?
identifier.save
else
error 400, identifier.errors
end
identifier
end.compact
end

if identifier.valid?
identifier.save
else
error 400, identifier.errors
end
identifier
end.compact
end
def update_affiliations(affiliations)
Array(affiliations).map do |aff|
affiliation = aff["id"] ? LinkedData::Models::Agent.find(RDF::URI.new(aff["id"])).first : nil

def update_affiliations(affiliations)
Array(affiliations).map do |aff|
affiliation = aff["id"] ? LinkedData::Models::Agent.find(RDF::URI.new(aff["id"])).first : nil
if affiliation
affiliation.bring_remaining
affiliation.identifiers.each{|i| i.bring_remaining}
end

if affiliation
affiliation.bring_remaining
affiliation.identifiers.each{|i| i.bring_remaining}
end
next affiliation if aff.keys.size.eql?(1) && aff["id"]

next affiliation if aff.keys.size.eql?(1) && aff["id"]
if affiliation
affiliation = update_agent(affiliation, aff)
else
affiliation = create_new_agent(aff["id"], aff)
end

if affiliation
affiliation = update_agent(affiliation, aff)
else
affiliation = create_new_agent(aff["id"], aff)
error 400, affiliation.errors unless affiliation.errors.empty?

affiliation
end
end

error 400, affiliation.errors unless affiliation.errors.empty?
def create_new_agent (id = @params['id'], params = @params)
agent = nil
agent = LinkedData::Models::Agent.find(id).include(LinkedData::Models::Agent.goo_attrs_to_load(includes_param)).first if id

affiliation
if agent.nil?
agent = update_agent(LinkedData::Models::Agent.new, params)
error 400, agent.errors unless agent.errors.empty?

return agent
else
error 400, "Agent exists, please use HTTP PATCH to update"
end
end
end

def create_new_agent (id = @params['id'], params = @params)
agent = nil
agent = LinkedData::Models::Agent.find(id).include(LinkedData::Models::Agent.goo_attrs_to_load(includes_param)).first if id
def update_agent(agent, params)
return agent unless agent

if agent.nil?
agent = update_agent(LinkedData::Models::Agent.new, params)
error 400, agent.errors unless agent.errors.empty?
identifiers = params.delete "identifiers"
affiliations = params.delete "affiliations"
params.delete "id"
populate_from_params(agent, params)
agent.identifiers = update_identifiers(identifiers)
agent.affiliations = update_affiliations(affiliations)

agent.save if agent.valid?
return agent
else
error 400, "Agent exists, please use HTTP PATCH to update"
end
end

def update_agent(agent, params)
return agent unless agent

identifiers = params.delete "identifiers"
affiliations = params.delete "affiliations"
params.delete "id"
populate_from_params(agent, params)
agent.identifiers = update_identifiers(identifiers)
agent.affiliations = update_affiliations(affiliations)

agent.save if agent.valid?
return agent
end

end

end
4 changes: 4 additions & 0 deletions controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ class HomeController < ApplicationController
expires 3600, :public
last_modified @@root_last_modified ||= Time.now.httpdate
routes = routes_list

#TODO: delete when ccv will be on production
routes.delete("/ccv")
if LinkedData.settings.enable_resource_index == false
routes.delete("/resource_index")
end

routes.delete('/Agents')

routes_hash = {}
context = {}
routes.each do |route|
Expand Down
Loading

0 comments on commit 5d40e76

Please sign in to comment.