1 class SegmentController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_write_availability, :only => [:create, :update, :delete]
7 before_filter :check_read_availability, :except => [:create, :update, :delete]
8 after_filter :compress_output
12 segment = Segment.from_xml(request.raw_post, true)
15 if segment.node_a == segment.node_b
16 render :nothing => true, :status => :expectation_failed
17 elsif !segment.preconditions_ok?
18 render :nothing => true, :status => :precondition_failed
20 segment.user_id = @user.id
21 segment.from_node = Node.find(segment.node_a.to_i)
22 segment.to_node = Node.find(segment.node_b.to_i)
23 segment.save_with_history!
25 render :text => segment.id.to_s, :content_type => "text/plain"
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
51 segment = Segment.find(params[:id])
54 new_segment = Segment.from_xml(request.raw_post)
56 if new_segment and new_segment.id == segment.id
57 if new_segment.node_a == new_segment.node_b
58 render :nothing => true, :status => :expectation_failed
59 elsif !new_segment.preconditions_ok?
60 render :nothing => true, :status => :precondition_failed
62 segment.user_id = @user.id
63 segment.node_a = new_segment.node_a
64 segment.node_b = new_segment.node_b
65 segment.tags = new_segment.tags
66 segment.visible = new_segment.visible
67 segment.save_with_history!
69 render :nothing => true
72 render :nothing => true, :status => :bad_request
75 render :nothing => true, :status => :gone
77 rescue ActiveRecord::RecordNotFound
78 render :nothing => true, :status => :not_found
84 segment = Segment.find(params[:id])
87 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 ])
88 render :nothing => true, :status => :precondition_failed
90 segment.user_id = @user.id
92 segment.save_with_history!
94 render :nothing => true
97 render :nothing => true, :status => :gone
99 rescue ActiveRecord::RecordNotFound
100 render :nothing => true, :status => :not_found
105 ids = params['segments'].split(',').collect { |s| s.to_i }
108 doc = OSM::API.new.get_xml_doc
110 Segment.find(ids).each do |segment|
111 doc.root << segment.to_xml_node
114 render :text => doc.to_s, :content_type => "text/xml"
116 render :nothing => true, :status => :bad_request
120 def segments_for_node
121 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 doc = OSM::API.new.get_xml_doc
126 Segment.find(segmentids).each do |segment|
127 doc.root << segment.to_xml_node
130 render :text => doc.to_s, :content_type => "text/xml"
132 render :nothing => true, :status => :bad_request