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 all commits
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
24 changes: 22 additions & 2 deletions controllers/agents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
class AgentsController < ApplicationController

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.each do |key, value|
agents.concat(value.map{ |agent| agent.bring_remaining})
end
agents.uniq!

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

Check warning on line 19 in controllers/agents_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/agents_controller.rb#L19

Added line #L19 was not covered by tests
end

reply agents
end

namespace "/agents" do
get do
check_last_modified_collection(LinkedData::Models::Agent)
Expand Down Expand Up @@ -143,6 +165,4 @@
end

end


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

def test_ontology_agents
ontologies_and_submissions = create_ontologies_and_submissions(ont_count: 2, submission_count: 1, process_submission: true)
submission1 = ontologies_and_submissions[2].first.submissions.last
submission2 = ontologies_and_submissions[2].last.submissions.last

ontology_acronym1 = ontologies_and_submissions[1].first
ontology_acronym2 = ontologies_and_submissions[1].last

submission1.bring(*OntologySubmission.agents_attrs)
submission2.bring(*OntologySubmission.agents_attrs)

# To insure that we don't have duplicated agents in the response
agent_syphax = _create_agent(name: 'Syphax', type: 'person')

submission1.publisher = [_create_agent(name: 'Bilel', type: 'person'), agent_syphax]
submission1.hasContributor = [_create_agent(name: 'Clement', type: 'person'), agent_syphax]

submission2.publisher = [_create_agent(name: 'Imad', type: 'person'), _create_agent(name: 'Serine', type: 'person')]

submission1.save
submission2.save


get "/ontologies/#{ontology_acronym1}/agents"

response = MultiJson.load(last_response.body)
assert_equal response.length, 3
response.each do |r|
assert_includes ['Bilel', 'Syphax', 'Clement'], r["name"]
end

get "/ontologies/#{ontology_acronym2}/agents"

response = MultiJson.load(last_response.body)
assert_equal response.length, 2
response.each do |r|
assert_includes ['Imad', 'Serine'], r["name"]
end
end

private

def check400(response)
assert response.status >= 400
assert MultiJson.load(response.body)["errors"]
end

def _create_agent(name: 'name', type: 'person')
agent = LinkedData::Models::Agent.new({
agentType: type,
name: name,
creator: User.find('tim').first
})
agent.save
agent
end

end
Loading