1 class WayController < ApplicationController
4 before_filter :authorize
5 after_filter :compress_output
8 response.headers["Content-Type"] = 'text/xml'
10 way = Way.from_xml(request.raw_post, true)
13 way.user_id = @user.id
15 unless way.preconditions_ok? # are the segments (and their nodes) visible?
16 render :nothing => true, :status => HTTP_PRECONDITION_FAILED
20 if way.save_with_history
21 render :text => way.id.to_s
23 render :nothing => true, :status => 500
27 render :nothing => true, :status => 400 # if we got here the doc didnt parse
32 render :nothing => true, :status => 500 # something went very wrong
36 unless Way.exists?(params[:id])
37 render :nothing => true, :status => 404
41 way = Way.find(params[:id])
44 render :nothing => true, :status => 410
48 # In future, we might want to do all the data fetch in one step
49 seg_ids = way.segs + [-1]
50 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
52 node_ids = segments.collect {|segment| segment.node_a }
53 node_ids += segments.collect {|segment| segment.node_b }
55 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
58 doc = OSM::API.new.get_xml_doc
60 doc.root << node.to_xml_node()
62 segments.each do |segment|
63 doc.root << segment.to_xml_node()
65 doc.root << way.to_xml_node()
67 render :text => doc.to_s
71 response.headers["Content-Type"] = 'text/xml'
72 unless Way.exists?(params[:id])
73 render :nothing => true, :status => 404
77 way = Way.find(params[:id])
83 render :nothing => true, :status => 410
86 render :text => way.to_xml.to_s
90 way.user_id = @user.id
93 render :nothing => true
95 render :nothing => true, :status => 410
99 new_way = Way.from_xml(request.raw_post)
102 unless new_way.preconditions_ok? # are the segments (and their nodes) visible?
103 render :nothing => true, :status => HTTP_PRECONDITION_FAILED
107 way.user_id = @user.id
108 way.tags = new_way.tags
109 way.segs = new_way.segs
110 way.timestamp = new_way.timestamp
113 if way.id == new_way.id and way.save_with_history
114 render :nothing => true
116 render :nothing => true, :status => 500
119 render :nothing => true, :status => 400 # if we got here the doc didnt parse
125 response.headers["Content-Type"] = 'text/xml'
126 ids = params['ways'].split(',').collect {|w| w.to_i }
128 waylist = Way.find(ids)
129 doc = OSM::API.new.get_xml_doc
130 waylist.each do |way|
131 doc.root << way.to_xml_node
133 render :text => doc.to_s
135 render :nothing => true, :status => 400
140 response.headers["Content-Type"] = 'text/xml'
141 wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
143 waylist = Way.find(wayids)
144 doc = OSM::API.new.get_xml_doc
145 waylist.each do |way|
146 doc.root << way.to_xml_node
148 render :text => doc.to_s
150 render :nothing => true, :status => 400