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

Feature: implement ontology agents endpoint #84

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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: 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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comment

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
Loading