def self.from_xml_node(pt, create=false)
node = Node.new
- node.version = pt['version']
node.lat = pt['lat'].to_f
node.lon = pt['lon'].to_f
node.changeset_id = pt['changeset'].to_i
return nil unless node.in_world?
+ # version must be present unless creating
+ return nil unless create or not pt['version'].nil?
+ node.version = pt['version'].to_i
+
unless create
if pt['id'] != '0'
node.id = pt['id'].to_i
end
end
- node.visible = pt['visible'] and pt['visible'] == 'true'
+ # visible if it says it is, or as the default if the attribute
+ # is missing.
+ node.visible = pt['visible'].nil? or pt['visible'] == 'true'
if create
node.timestamp = Time.now
end
# Should probably be renamed delete_from to come in line with update
- def delete_with_history(new_node, user)
+ def delete_with_history!(new_node, user)
if self.visible
check_consistency(self, new_node, user)
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 = ?", self.id ])
raise OSM::APIPreconditionFailedError.new
- 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=?", self.id])
+ 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=? ", self.id])
raise OSM::APIPreconditionFailedError.new
else
self.changeset_id = new_node.changeset_id
def add_tag_key_val(k,v)
@tags = Hash.new unless @tags
+
+ # duplicate tags are now forbidden, so we can't allow values
+ # in the hash to be overwritten.
+ raise OSM::APIDuplicateTagsError.new if @tags.include? k
+
@tags[k] = v
end
+ ##
+ # dummy method to make the interfaces of node, way and relation
+ # more consistent.
+ def fix_placeholders!(id_map)
+ # nodes don't refer to anything, so there is nothing to do here
+ end
+
end