1 class SegmentController < ApplicationController
4 before_filter :authorize, :only => [:create, :update, :delete]
5 after_filter :compress_output
9 segment = Segment.from_xml(request.raw_post, true)
12 if segment.node_a == segment.node_b
13 render :nothing => true, :status => :expectation_failed
14 elsif !segment.preconditions_ok?
15 render :nothing => true, :status => :precondition_failed
17 segment.user_id = @user.id
18 segment.from_node = Node.find(segment.node_a.to_i)
19 segment.to_node = Node.find(segment.node_b.to_i)
21 if segment.save_with_history
22 render :text => segment.id.to_s, :content_type => "text/plain"
24 render :nothing => true, :status => :internal_server_error
28 render :nothing => true, :status => :bad_request
31 render :nothing => true, :status => :method_not_allowed
37 segment = Segment.find(params[:id])
40 render :text => segment.to_xml.to_s, :content_type => "text/xml"
42 render :nothing => true, :status => :gone
44 rescue ActiveRecord::RecordNotFound
45 render :nothing => true, :status => :not_found
47 render :nothing => true, :status => :internal_server_error
53 segment = Segment.find(params[:id])
56 new_segment = Segment.from_xml(request.raw_post)
58 if new_segment and new_segment.id == segment.id
59 if new_segment.node_a == new_segment.node_b
60 render :nothing => true, :status => :expectation_failed
61 elsif !new_segment.preconditions_ok?
62 render :nothing => true, :status => :precondition_failed
64 segment.user_id = @user.id
65 segment.node_a = new_segment.node_a
66 segment.node_b = new_segment.node_b
67 segment.tags = new_segment.tags
68 segment.visible = new_segment.visible
70 if segment.save_with_history
71 render :nothing => true
73 render :nothing => true, :status => :internal_server_error
77 render :nothing => true, :status => :bad_request
80 render :nothing => true, :status => :gone
82 rescue ActiveRecord::RecordNotFound
83 render :nothing => true, :status => :not_found
85 render :nothing => true, :status => :internal_server_error
91 segment = Segment.find(params[:id])
94 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 ])
95 render :nothing => true, :status => :precondition_failed
97 segment.user_id = @user.id
100 if segment.save_with_history
101 render :nothing => true
103 render :nothing => true, :status => :internal_server_error
107 render :nothing => true, :status => :gone
109 rescue ActiveRecord::RecordNotFound
110 render :nothing => true, :status => :not_found
112 render :nothing => true, :status => :internal_server_error
117 ids = params['segments'].split(',').collect { |s| s.to_i }
120 doc = OSM::API.new.get_xml_doc
122 Segment.find(ids).each do |segment|
123 doc.root << segment.to_xml_node
126 render :text => doc.to_s, :content_type => "text/xml"
128 render :nothing => true, :status => :bad_request
132 def segments_for_node
133 segmentids = Segment.find(:all, :conditions => ['node_a = ? OR node_b = ?', params[:id], params[:id]]).collect { |s| s.id }.uniq
135 if segmentids.length > 0
136 doc = OSM::API.new.get_xml_doc
138 Segment.find(segmentids).each do |segment|
139 doc.root << segment.to_xml_node
142 render :text => doc.to_s, :content_type => "text/xml"
144 render :nothing => true, :status => :bad_request