1 # The NodeController is the RESTful interface to Node objects
3 class NodeController < ApplicationController
7 before_filter :authorize, :only => [:create, :update, :delete]
8 before_filter :check_write_availability, :only => [:create, :update, :delete]
9 before_filter :check_read_availability, :except => [:create, :update, :delete]
10 after_filter :compress_output
12 # Create a node from XML.
15 node = Node.from_xml(request.raw_post, true)
19 node.user_id = @user.id
21 node.save_with_history!
23 render :text => node.id.to_s, :content_type => "text/plain"
25 render :nothing => true, :status => :bad_request
28 render :nothing => true, :status => :method_not_allowed
32 # Dump the details on a node given in params[:id]
35 node = Node.find(params[:id])
37 response.headers['Last-Modified'] = node.timestamp.rfc822
38 render :text => node.to_xml.to_s, :content_type => "text/xml"
40 render :text => "", :status => :gone
42 rescue ActiveRecord::RecordNotFound
43 render :nothing => true, :status => :not_found
47 # Update a node from given XML
50 node = Node.find(params[:id])
51 new_node = Node.from_xml(request.raw_post)
53 if new_node and new_node.id == node.id
54 update_internal node, new_node
55 render :nothing => true
57 render :nothing => true, :status => :bad_request
59 rescue ActiveRecord::RecordNotFound
60 render :nothing => true, :status => :not_found
64 def update_internal(node, new_node)
65 node = Node.find(new_node.id) if node.nil?
67 node.user_id = @user.id
68 node.latitude = new_node.latitude
69 node.longitude = new_node.longitude
70 node.tags = new_node.tags
72 node.save_with_history!
77 # Delete a node. Doesn't actually delete it, but retains its history in a wiki-like way.
78 # FIXME remove all the fricking SQL
81 node = Node.find(params[:id])
83 res = delete_internal(node)
85 render :text => "", :status => :precondition_failed
87 render :text => "", :status => res
89 rescue ActiveRecord::RecordNotFound
90 render :nothing => true, :status => :not_found
94 def delete_internal(node)
96 if WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id", :conditions => [ "current_ways.visible = 1 AND current_way_nodes.node_id = ?", node.id ])
98 elsif RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='node' and member_id=?", params[:id]])
101 node.user_id = @user.id
103 node.save_with_history!
114 ids = params['nodes'].split(',').collect { |n| n.to_i }
117 doc = OSM::API.new.get_xml_doc
119 Node.find(ids).each do |node|
120 doc.root << node.to_xml_node
123 render :text => doc.to_s, :content_type => "text/xml"
125 render :nothing => true, :status => :bad_request