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.
16 node = Node.from_xml(request.raw_post, true)
19 node.create_with_history @user
20 render :text => node.id.to_s, :content_type => "text/plain"
22 render :nothing => true, :status => :bad_request
25 render :nothing => true, :status => :method_not_allowed
27 rescue OSM::APIError => ex
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 # Dump a specific version of the node based on the given params[:id] and params[:version]
50 node = Node.find(:first, :conditions => { :id => params[:id], :version => params[:version] } )
52 response.headers['Last-Modified'] = node.timestamp.rfc822
53 render :text => node.to_xml.to_s, :content_type => "text/xml"
55 render :nothing => true, :status => :gone
57 rescue ActiveRecord::RecordNotFound
58 render :nothing => true, :status => :not_found
62 # Update a node from given XML
65 node = Node.find(params[:id])
66 new_node = Node.from_xml(request.raw_post)
68 if new_node and new_node.id == node.id
69 node.update_from(new_node, @user)
70 render :text => node.version.to_s, :content_type => "text/plain"
72 render :nothing => true, :status => :bad_request
74 rescue OSM::APIError => ex
76 rescue ActiveRecord::RecordNotFound
77 render :nothing => true, :status => :not_found
81 # Delete a node. Doesn't actually delete it, but retains its history in a wiki-like way.
82 # FIXME remove all the fricking SQL
85 node = Node.find(params[:id])
86 new_node = Node.from_xml(request.raw_post)
87 # FIXME we no longer care about the user, (or maybe we want to check
88 # that the user of the changeset is the same user as is making this
89 # little change?) we really care about the
90 # changeset which must be open, and that the version that we have been
91 # given is the one that is currently stored in the database
93 if new_node and new_node.id == node.id
94 node.delete_with_history(new_node, @user)
95 render :nothing => true
97 render :nothing => true, :status => :bad_request
99 rescue ActiveRecord::RecordNotFound
100 render :nothing => true, :status => :not_found
101 rescue OSM::APIError => ex
102 render ex.render_opts
108 ids = params['nodes'].split(',').collect { |n| n.to_i }
111 doc = OSM::API.new.get_xml_doc
113 Node.find(ids).each do |node|
114 doc.root << node.to_xml_node
117 render :text => doc.to_s, :content_type => "text/xml"
119 render :nothing => true, :status => :bad_request