1 class SegmentController < ApplicationController
4 before_filter :authorize
5 after_filter :compress_output
8 response.headers["Content-Type"] = 'text/xml'
10 segment = Segment.from_xml(request.raw_post, true)
13 segment.user_id = @user.id
15 segment.from_node = Node.find(segment.node_a.to_i)
16 segment.to_node = Node.find(segment.node_b.to_i)
18 if segment.from_node == segment.to_node
19 render :nothing => true, :status => HTTP_EXPECTATION_FAILED
23 unless segment.preconditions_ok? # are the nodes visible?
24 render :nothing => true, :status => HTTP_PRECONDITION_FAILED
28 if segment.save_with_history
29 render :text => segment.id.to_s
31 render :nothing => true, :status => 500
35 render :nothing => true, :status => 400 # if we got here the doc didnt parse
40 render :nothing => true, :status => 500 # something went very wrong
44 response.headers["Content-Type"] = 'text/xml'
45 unless Segment.exists?(params[:id])
46 render :nothing => true, :status => 404
50 segment = Segment.find(params[:id])
55 render :text => segment.to_xml.to_s
60 if WaySegment.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_segments.id", :conditions => [ "current_ways.visible = 1 AND current_way_segments.segment_id = ?", segment.id ])
61 render :nothing => true, :status => HTTP_PRECONDITION_FAILED
63 segment.user_id = @user.id
65 segment.save_with_history
66 render :nothing => true
69 render :nothing => true, :status => 410
73 new_segment = Segment.from_xml(request.raw_post)
76 if new_segment.node_a == new_segment.node_b
77 render :nothing => true, :status => HTTP_EXPECTATION_FAILED
81 unless new_segment.preconditions_ok? # are the nodes visible?
82 render :nothing => true, :status => HTTP_PRECONDITION_FAILED
86 segment.timestamp = Time.now
87 segment.user_id = @user.id
88 segment.node_a = new_segment.node_a
89 segment.node_b = new_segment.node_b
90 segment.tags = new_segment.tags
91 segment.visible = new_segment.visible
93 if segment.id == new_segment.id and segment.save_with_history
94 render :nothing => true
96 render :nothing => true, :status => 500
99 render :nothing => true, :status => 400 # if we got here the doc didnt parse
106 response.headers["Content-Type"] = 'text/xml'
107 ids = params['segments'].split(',').collect {|s| s.to_i }
109 segmentlist = Segment.find(ids)
110 doc = OSM::API.new.get_xml_doc
111 segmentlist.each do |segment|
112 doc.root << segment.to_xml_node
114 render :text => doc.to_s
116 render :nothing => true, :status => 400
120 def segments_for_node
121 response.headers["Content-Type"] = 'text/xml'
122 segmentids = Segment.find(:all, :conditions => ['node_a = ? OR node_b = ?', params[:id], params[:id]]).collect { |s| s.id }.uniq
123 if segmentids.length > 0
124 segmentlist = Segment.find(segmentids)
125 doc = OSM::API.new.get_xml_doc
126 segmentlist.each do |segment|
127 doc.root << segment.to_xml_node
129 render :text => doc.to_s
131 render :nothing => true, :status => 400