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
92 render :nothing => true
94 render :nothing => true, :status => 410
98 new_way = Way.from_xml(request.raw_post)
101 unless new_way.preconditions_ok? # are the segments (and their nodes) visible?
102 render :nothing => true, :status => HTTP_PRECONDITION_FAILED
106 way.user_id = @user.id
107 way.tags = new_way.tags
108 way.segs = new_way.segs
109 way.timestamp = new_way.timestamp
112 if way.id == new_way.id and way.save_with_history
113 render :nothing => true
115 render :nothing => true, :status => 500
118 render :nothing => true, :status => 400 # if we got here the doc didnt parse
124 response.headers["Content-Type"] = 'text/xml'
125 ids = params['ways'].split(',').collect {|w| w.to_i }
127 waylist = Way.find(ids)
128 doc = OSM::API.new.get_xml_doc
129 waylist.each do |way|
130 doc.root << way.to_xml_node
132 render :text => doc.to_s
134 render :nothing => true, :status => 400