Skip to content

Commit

Permalink
Move ontology agents method out of agents namespace in agents_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Jul 16, 2024
1 parent 68fcdf6 commit 2eded90
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion 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: a5b56a68e6dc8ecfc9db708d44350342dac38ce6
revision: fd78d689dac4a7393e20a36ac930c6c9d191a619
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand Down
38 changes: 20 additions & 18 deletions controllers/agents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
class AgentsController < ApplicationController

# Ontology agents
get '/ontologies/:acronym/agents' do
ont = Ontology.find(params["acronym"]).first
latest = ont.latest_submission(status: :any)
latest.bring(OntologySubmission.agents_attrs)
properties_agents= {}
OntologySubmission.agents_attrs.each do |attr|
properties_agents[attr] = Array(latest.send(attr))
end

agents = properties_agents.values.flatten.uniq {|x| x.id }

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

reply agents
end

%w[/agents /Agents].each do |namespace|
namespace namespace do
# Display all agents
Expand All @@ -22,23 +41,6 @@ class AgentsController < ApplicationController
reply agents
end

get '/ontologies/:acronym/agents' do
ont = Ontology.find(params["acronym"]).first
latest = ont.latest_submission(status: :any)
latest.bring(OntologySubmission.agents_attrs)
properties_agents= {}
OntologySubmission.agents_attrs.each do |attr|
properties_agents[attr] = Array(latest.send(attr))
end

agents = properties_agents.values.flatten.uniq {|x| x.id }

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

reply agents
end

# Display a single agent
get '/:id' do
Expand Down Expand Up @@ -165,4 +167,4 @@ def update_agent(agent, params)
end
end

end
end
9 changes: 9 additions & 0 deletions test/controllers/test_ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ def test_detach_a_view
assert_equal onto["viewOf"], ont.id.to_s
end

def test_ontology_agents
get '/ontologies/TEST-ONT-1/latest_submission?display=all'
submission = MultiJson.load(last_response.body)
agent = agent_data(type: 'person')
submission["hasCreator"] = agent
get '/ontologies/TEST-ONT-1/agents'
binding.pry
end

private

def check400(response)
Expand Down

0 comments on commit 2eded90

Please sign in to comment.