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: Add mapping update endpoint #103

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ test/test_run.log
test/data/ontology_files/catalog-v001.xml

create_permissions.log

ontologies_api.iml
27 changes: 17 additions & 10 deletions controllers/mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class MappingsController < ApplicationController
reply mappings
end



namespace "/mappings" do
# Display all mappings
get do
Expand Down Expand Up @@ -76,16 +78,7 @@ class MappingsController < ApplicationController

# Display a single mapping - only rest
get '/:mapping' do
mapping_id = nil
if params[:mapping] and params[:mapping].start_with?("http")
mapping_id = params[:mapping]
mapping_id = mapping_id.gsub("/mappings/","/rest_backup_mappings/")
mapping_id = RDF::URI.new(params[:mapping])
else
mapping_id =
"http://data.bioontology.org/rest_backup_mappings/#{mapping_id}"
mapping_id = RDF::URI.new(mapping_id)
end
mapping_id = request_mapping_id
mapping = LinkedData::Mappings.get_rest_mapping(mapping_id)
if mapping
reply populate_mapping_classes([mapping].first)
Expand Down Expand Up @@ -147,6 +140,20 @@ class MappingsController < ApplicationController
reply(201, mapping)
end


patch '/:mapping' do
mapping = LinkedData::Mappings.get_rest_mapping(request_mapping_id)
process = mapping.process
populate_from_params(process, params)
if process.valid?
process.save
else
error 422, process.errors
end
halt 204
end


# Delete a mapping
delete '/:mapping' do
mapping_id = RDF::URI.new(replace_url_prefix(params[:mapping]))
Expand Down
12 changes: 12 additions & 0 deletions helpers/mappings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ def populate_mapping_classes(mappings)

mappings
end

def request_mapping_id
mapping_id = nil
if params[:mapping] and params[:mapping].start_with?("http")
mapping_id = RDF::URI.new(params[:mapping])
else
mapping_id =
"http://data.bioontology.org/rest_backup_mappings/#{params[:mapping]}"
mapping_id = RDF::URI.new(mapping_id)
end
mapping_id
end
end
end
end
Expand Down