1 class SegmentController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_availability, :only => [:create, :update, :delete]
7 after_filter :compress_output
11 segment = Segment.from_xml(request.raw_post, true)
14 if segment.node_a == segment.node_b
15 render :nothing => true, :status => :expectation_failed
16 elsif !segment.preconditions_ok?
17 render :nothing => true, :status => :precondition_failed
19 segment.user_id = @user.id
20 segment.from_node = Node.find(segment.node_a.to_i)
21 segment.to_node = Node.find(segment.node_b.to_i)
23 if segment.save_with_history
24 render :text => segment.id.to_s, :content_type => "text/plain"
26 render :nothing => true, :status => :internal_server_error
30 render :nothing => true, :status => :bad_request
33 render :nothing => true, :status => :method_not_allowed
39 segment = Segment.find(params[:id])
42 render :text => segment.to_xml.to_s, :content_type => "text/xml"
44 render :nothing => true, :status => :gone
46 rescue ActiveRecord::RecordNotFound
47 render :nothing => true, :status => :not_found
49 render :nothing => true, :status => :internal_server_error
55 segment = Segment.find(params[:id])
58 new_segment = Segment.from_xml(request.raw_post)
60 if new_segment and new_segment.id == segment.id
61 if new_segment.node_a == new_segment.node_b
62 render :nothing => true, :status => :expectation_failed
63 elsif !new_segment.preconditions_ok?
64 render :nothing => true, :status => :precondition_failed
66 segment.user_id = @user.id
67 segment.node_a = new_segment.node_a
68 segment.node_b = new_segment.node_b
69 segment.tags = new_segment.tags
70 segment.visible = new_segment.visible
72 if segment.save_with_history
73 render :nothing => true
75 render :nothing => true, :status => :internal_server_error
79 render :nothing => true, :status => :bad_request
82 render :nothing => true, :status => :gone
84 rescue ActiveRecord::RecordNotFound
85 render :nothing => true, :status => :not_found
87 render :nothing => true, :status => :internal_server_error
93 segment = Segment.find(params[:id])
96 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 ])
97 render :nothing => true, :status => :precondition_failed
99 segment.user_id = @user.id
102 if segment.save_with_history
103 render :nothing => true
105 render :nothing => true, :status => :internal_server_error
109 render :nothing => true, :status => :gone
111 rescue ActiveRecord::RecordNotFound
112 render :nothing => true, :status => :not_found
114 render :nothing => true, :status => :internal_server_error
119 ids = params['segments'].split(',').collect { |s| s.to_i }
122 doc = OSM::API.new.get_xml_doc
124 Segment.find(ids).each do |segment|
125 doc.root << segment.to_xml_node
128 render :text => doc.to_s, :content_type => "text/xml"
130 render :nothing => true, :status => :bad_request
134 def segments_for_node
135 segmentids = Segment.find(:all, :conditions => ['node_a = ? OR node_b = ?', params[:id], params[:id]]).collect { |s| s.id }.uniq
137 if segmentids.length > 0
138 doc = OSM::API.new.get_xml_doc
140 Segment.find(segmentids).each do |segment|
141 doc.root << segment.to_xml_node
144 render :text => doc.to_s, :content_type => "text/xml"
146 render :nothing => true, :status => :bad_request