1 class SegmentController < ApplicationController
4 before_filter :authorize, :only => [:create, :update, :delete]
5 before_filter :check_availability, :only => [:create, :update, :delete]
6 after_filter :compress_output
10 segment = Segment.from_xml(request.raw_post, true)
13 if segment.node_a == segment.node_b
14 render :nothing => true, :status => :expectation_failed
15 elsif !segment.preconditions_ok?
16 render :nothing => true, :status => :precondition_failed
18 segment.user_id = @user.id
19 segment.from_node = Node.find(segment.node_a.to_i)
20 segment.to_node = Node.find(segment.node_b.to_i)
22 if segment.save_with_history
23 render :text => segment.id.to_s, :content_type => "text/plain"
25 render :nothing => true, :status => :internal_server_error
29 render :nothing => true, :status => :bad_request
32 render :nothing => true, :status => :method_not_allowed
38 segment = Segment.find(params[:id])
41 render :text => segment.to_xml.to_s, :content_type => "text/xml"
43 render :nothing => true, :status => :gone
45 rescue ActiveRecord::RecordNotFound
46 render :nothing => true, :status => :not_found
48 render :nothing => true, :status => :internal_server_error
54 segment = Segment.find(params[:id])
57 new_segment = Segment.from_xml(request.raw_post)
59 if new_segment and new_segment.id == segment.id
60 if new_segment.node_a == new_segment.node_b
61 render :nothing => true, :status => :expectation_failed
62 elsif !new_segment.preconditions_ok?
63 render :nothing => true, :status => :precondition_failed
65 segment.user_id = @user.id
66 segment.node_a = new_segment.node_a
67 segment.node_b = new_segment.node_b
68 segment.tags = new_segment.tags
69 segment.visible = new_segment.visible
71 if segment.save_with_history
72 render :nothing => true
74 render :nothing => true, :status => :internal_server_error
78 render :nothing => true, :status => :bad_request
81 render :nothing => true, :status => :gone
83 rescue ActiveRecord::RecordNotFound
84 render :nothing => true, :status => :not_found
86 render :nothing => true, :status => :internal_server_error
92 segment = Segment.find(params[:id])
95 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 ])
96 render :nothing => true, :status => :precondition_failed
98 segment.user_id = @user.id
101 if segment.save_with_history
102 render :nothing => true
104 render :nothing => true, :status => :internal_server_error
108 render :nothing => true, :status => :gone
110 rescue ActiveRecord::RecordNotFound
111 render :nothing => true, :status => :not_found
113 render :nothing => true, :status => :internal_server_error
118 ids = params['segments'].split(',').collect { |s| s.to_i }
121 doc = OSM::API.new.get_xml_doc
123 Segment.find(ids).each do |segment|
124 doc.root << segment.to_xml_node
127 render :text => doc.to_s, :content_type => "text/xml"
129 render :nothing => true, :status => :bad_request
133 def segments_for_node
134 segmentids = Segment.find(:all, :conditions => ['node_a = ? OR node_b = ?', params[:id], params[:id]]).collect { |s| s.id }.uniq
136 if segmentids.length > 0
137 doc = OSM::API.new.get_xml_doc
139 Segment.find(segmentids).each do |segment|
140 doc.root << segment.to_xml_node
143 render :text => doc.to_s, :content_type => "text/xml"
145 render :nothing => true, :status => :bad_request