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 node.update_from(new_node, @user)
55 render :text => node.version.to_s, :content_type => "text/plain"
57 render :nothing => true, :status => :bad_request
59 rescue OSM::APIVersionMismatchError => ex
60 render :text => "Version mismatch: Provided " + ex.provided.to_s +
61 ", server had: " + ex.latest.to_s, :status => :bad_request
62 rescue ActiveRecord::RecordNotFound
63 render :nothing => true, :status => :not_found
67 # Delete a node. Doesn't actually delete it, but retains its history in a wiki-like way.
68 # FIXME remove all the fricking SQL
71 node = Node.find(params[:id])
72 node.delete_with_history(@user)
73 rescue ActiveRecord::RecordNotFound
74 render :nothing => true, :status => :not_found
75 rescue OSM::APIAlreadyDeletedError
76 render :text => "", :status => :gone
77 rescue OSM::APIPreconditionFailedError
78 render :text => "", :status => :precondition_failed
84 ids = params['nodes'].split(',').collect { |n| n.to_i }
87 doc = OSM::API.new.get_xml_doc
89 Node.find(ids).each do |node|
90 doc.root << node.to_xml_node
93 render :text => doc.to_s, :content_type => "text/xml"
95 render :nothing => true, :status => :bad_request