1 class WayController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_write_availability, :only => [:create, :update, :delete]
7 before_filter :check_read_availability, :except => [:create, :update, :delete]
8 after_filter :compress_output
12 way = Way.from_xml(request.raw_post, true)
15 # FIXME move some of this to the model. The controller shouldn't need to
16 # know about the fact that the first version number is 0 on creation
17 # it will also allow use to run a variation on the check_consistency
18 # so that we don't get exceptions thrown when the changesets are not right
19 unless way.preconditions_ok?
20 render :text => "", :status => :precondition_failed
23 way.save_with_history!
25 render :text => way.id.to_s, :content_type => "text/plain"
28 render :nothing => true, :status => :bad_request
31 render :nothing => true, :status => :method_not_allowed
37 way = Way.find(params[:id])
39 response.headers['Last-Modified'] = way.timestamp.rfc822
42 render :text => way.to_xml.to_s, :content_type => "text/xml"
44 render :text => "", :status => :gone
46 rescue OSM::APIError => ex
48 rescue ActiveRecord::RecordNotFound
49 render :nothing => true, :status => :not_found
55 way = Way.find(params[:id])
56 new_way = Way.from_xml(request.raw_post)
58 if new_way and new_way.id == way.id
59 way.update_from(new_way, @user)
60 render :text => way.version.to_s, :content_type => "text/plain"
62 render :nothing => true, :status => :bad_request
64 rescue OSM::APIError => ex
66 rescue ActiveRecord::RecordNotFound
67 render :nothing => true, :status => :not_found
71 # This is the API call to delete a way
74 way = Way.find(params[:id])
75 new_way = Way.from_xml(request.raw_post)
76 if new_way and new_way.id == way.id
77 way.delete_with_history(@user)
79 # if we get here, all is fine, otherwise something will catch below.
80 render :nothing => true
82 render :nothing => true, :status => :bad_request
84 rescue OSM::APIError => ex
86 rescue ActiveRecord::RecordNotFound
87 render :nothing => true, :status => :not_found
93 way = Way.find(params[:id])
96 nd_ids = way.nds + [-1]
97 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{nd_ids.join(',')})")
100 doc = OSM::API.new.get_xml_doc
102 doc.root << node.to_xml_node()
104 doc.root << way.to_xml_node()
106 render :text => doc.to_s, :content_type => "text/xml"
108 render :text => "", :status => :gone
110 rescue ActiveRecord::RecordNotFound
111 render :nothing => true, :status => :not_found
117 ids = params['ways'].split(',').collect { |w| w.to_i }
123 doc = OSM::API.new.get_xml_doc
125 Way.find(ids).each do |way|
126 doc.root << way.to_xml_node
129 render :text => doc.to_s, :content_type => "text/xml"
131 render :nothing => true, :status => :bad_request
136 wayids = WayNode.find(:all, :conditions => ['node_id = ?', params[:id]]).collect { |ws| ws.id[0] }.uniq
138 doc = OSM::API.new.get_xml_doc
140 Way.find(wayids).each do |way|
141 doc.root << way.to_xml_node
144 render :text => doc.to_s, :content_type => "text/xml"