# Create a node from XML.
def create
- if request.put?
- node = Node.from_xml(request.raw_post, true)
- # FIXME remove debug
- logger.debug request.raw_post
- logger.debug node
-
- if node
- node.version = 0
- #node.changeset_id = node.changeset
- node.visible = true
- node.save_with_history!
+ begin
+ if request.put?
+ node = Node.from_xml(request.raw_post, true)
- render :text => node.id.to_s, :content_type => "text/plain"
+ if node
+ node.create_with_history @user
+ render :text => node.id.to_s, :content_type => "text/plain"
+ else
+ render :nothing => true, :status => :bad_request
+ end
else
- render :nothing => true, :status => :bad_request
+ render :nothing => true, :status => :method_not_allowed
end
- else
- render :nothing => true, :status => :method_not_allowed
+ rescue OSM::APIError => ex
+ render ex.render_opts
end
end
after_filter :compress_output
def create
- if request.put?
- relation = Relation.from_xml(request.raw_post, true)
-
- if relation
- if !relation.preconditions_ok?
- render :text => "", :status => :precondition_failed
- else
- relation.version = 0
- #relation.user_id = @user.id
- relation.save_with_history!
+ begin
+ if request.put?
+ relation = Relation.from_xml(request.raw_post, true)
+ if relation
+ relation.create_with_history @user
render :text => relation.id.to_s, :content_type => "text/plain"
+ else
+ render :nothing => true, :status => :bad_request
end
else
- render :nothing => true, :status => :bad_request
+ render :nothing => true, :status => :method_not_allowed
end
- else
- render :nothing => true, :status => :method_not_allowed
+ rescue OSM::APIError => ex
+ render ex.render_opts
end
end
after_filter :compress_output
def create
- if request.put?
- way = Way.from_xml(request.raw_post, true)
-
- if way
- # FIXME move some of this to the model. The controller shouldn't need to
- # know about the fact that the first version number is 0 on creation
- # it will also allow use to run a variation on the check_consistency
- # so that we don't get exceptions thrown when the changesets are not right
- unless way.preconditions_ok?
- render :text => "", :status => :precondition_failed
- else
- way.version = 0
- way.save_with_history!
+ begin
+ if request.put?
+ way = Way.from_xml(request.raw_post, true)
+ if way
+ way.create_with_history @user
render :text => way.id.to_s, :content_type => "text/plain"
+ else
+ render :nothing => true, :status => :bad_request
end
else
- render :nothing => true, :status => :bad_request
+ render :nothing => true, :status => :method_not_allowed
end
- else
- render :nothing => true, :status => :method_not_allowed
+ rescue OSM::APIError => ex
+ render ex.render_opts
end
end
self.visible = true
save_with_history!
end
+
+ def create_with_history(user)
+ check_create_consistency(self, user)
+ self.version = 0
+ self.visible = true
+ save_with_history!
+ end
def to_xml
doc = OSM::API.new.get_xml_doc
self.visible = true
save_with_history!
end
+
+ def create_with_history(user)
+ check_create_consistency(self, user)
+ if !self.preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new
+ end
+ self.version = 0
+ self.visible = true
+ save_with_history!
+ end
def preconditions_ok?
# These are hastables that store an id in the index of all
save_with_history!
end
+ def create_with_history(user)
+ check_create_consistency(self, user)
+ if !self.preconditions_ok?
+ raise OSM::APIPreconditionsFailedError.new
+ end
+ self.version = 0
+ self.visible = true
+ save_with_history!
+ end
+
def preconditions_ok?
return false if self.nds.empty?
self.nds.each do |n|
raise OSM::APIChangesetAlreadyClosedError.new
end
end
+
+ # This is similar to above, just some validations don't apply
+ def check_create_consistency(new, user)
+ if new.changeset.nil?
+ raise OSM::APIChangesetMissingError.new
+ elsif new.changeset.user_id != user.id
+ raise OSM::APIUserChangesetMismatchError.new
+ elsif not new.changeset.is_open?
+ raise OSM::APIChangesetAlreadyClosedError.new
+ end
+ end
end