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 if !way.preconditions_ok?
16 render :nothing => true, :status => :precondition_failed
18 way.user_id = @user.id
19 way.save_with_history!
21 render :text => way.id.to_s, :content_type => "text/plain"
24 render :nothing => true, :status => :bad_request
27 render :nothing => true, :status => :method_not_allowed
33 way = Way.find(params[:id])
36 render :text => way.to_xml.to_s, :content_type => "text/xml"
38 render :nothing => true, :status => :gone
40 rescue ActiveRecord::RecordNotFound
41 render :nothing => true, :status => :not_found
47 way = Way.find(params[:id])
50 new_way = Way.from_xml(request.raw_post)
52 if new_way and new_way.id == way.id
53 if !new_way.preconditions_ok?
54 render :nothing => true, :status => :precondition_failed
56 way.user_id = @user.id
57 way.tags = new_way.tags
58 way.segs = new_way.segs
60 way.save_with_history!
62 render :nothing => true
65 render :nothing => true, :status => :bad_request
68 render :nothing => true, :status => :gone
70 rescue ActiveRecord::RecordNotFound
71 render :nothing => true, :status => :not_found
77 way = Way.find(params[:id])
80 way.user_id = @user.id
84 way.save_with_history!
86 render :nothing => true
88 render :nothing => true, :status => :gone
90 rescue ActiveRecord::RecordNotFound
91 render :nothing => true, :status => :not_found
97 way = Way.find(params[:id])
100 # In future, we might want to do all the data fetch in one step
101 seg_ids = way.segs + [-1]
102 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
104 node_ids = segments.collect {|segment| segment.node_a }
105 node_ids += segments.collect {|segment| segment.node_b }
107 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
110 doc = OSM::API.new.get_xml_doc
112 doc.root << node.to_xml_node()
114 segments.each do |segment|
115 doc.root << segment.to_xml_node()
117 doc.root << way.to_xml_node()
119 render :text => doc.to_s, :content_type => "text/xml"
121 render :nothing => true, :status => :gone
123 rescue ActiveRecord::RecordNotFound
124 render :nothing => true, :status => :not_found
130 ids = params['ways'].split(',').collect { |w| w.to_i }
136 doc = OSM::API.new.get_xml_doc
138 Way.find(ids).each do |way|
139 doc.root << way.to_xml_node
142 render :text => doc.to_s, :content_type => "text/xml"
144 render :nothing => true, :status => :bad_request
149 wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
152 doc = OSM::API.new.get_xml_doc
154 Way.find(wayids).each do |way|
155 doc.root << way.to_xml_node
158 render :text => doc.to_s, :content_type => "text/xml"
160 render :nothing => true, :status => :bad_request