Skip to content

Commit

Permalink
Merge branch 'development' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jul 24, 2024
2 parents f989767 + 67bc9fb commit 69abb3f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 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: 4cd56da111c2037bf0b606574e6b325bfa74a2f1
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)
end

reply agents
end

namespace "/agents" do
get do
check_last_modified_collection(LinkedData::Models::Agent)
Expand Down Expand Up @@ -143,6 +165,4 @@ def update_agent(agent, params)
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

0 comments on commit 69abb3f

Please sign in to comment.