# Read in xml as text and return it's Way object representation
def self.from_xml(xml, create = false)
# Read in xml as text and return it's Way object representation
def self.from_xml(xml, create = false)
doc = p.parse
doc.find("//osm/way").each do |pt|
return Way.from_xml_node(pt, create)
end
doc = p.parse
doc.find("//osm/way").each do |pt|
return Way.from_xml_node(pt, create)
end
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("way", xml, ex.message)
end
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("way", xml, ex.message)
end
- fail OSM::APIBadXMLError.new("way", pt, "Version is required when updating") unless create || !pt["version"].nil?
+ raise OSM::APIBadXMLError.new("way", pt, "Version is required when updating") unless create || !pt["version"].nil?
way.id = pt["id"].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway
way.id = pt["id"].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway
- fail OSM::APIBadXMLError.new("way", pt, "tag is missing key") if tag["k"].nil?
- fail OSM::APIBadXMLError.new("way", pt, "tag is missing value") if tag["v"].nil?
+ raise OSM::APIBadXMLError.new("way", pt, "tag is missing key") if tag["k"].nil?
+ raise OSM::APIBadXMLError.new("way", pt, "tag is missing value") if tag["v"].nil?
# duplicate tags are now forbidden, so we can't allow values
# in the hash to be overwritten.
# duplicate tags are now forbidden, so we can't allow values
# in the hash to be overwritten.
check_consistency(self, new_way, user)
unless new_way.preconditions_ok?(nds)
check_consistency(self, new_way, user)
unless new_way.preconditions_ok?(nds)
def create_with_history(user)
check_create_consistency(self, user)
def create_with_history(user)
check_create_consistency(self, user)
- unless self.preconditions_ok?
- fail OSM::APIPreconditionFailedError.new("Cannot create way: data is invalid.")
+ unless preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new("Cannot create way: data is invalid.")
def preconditions_ok?(old_nodes = [])
return false if nds.empty?
if nds.length > MAX_NUMBER_OF_WAY_NODES
def preconditions_ok?(old_nodes = [])
return false if nds.empty?
if nds.length > MAX_NUMBER_OF_WAY_NODES
- db_nds = Node.where(:id => new_nds, :visible => true)
+ # NOTE: nodes are locked here to ensure they can't be deleted before
+ # the current transaction commits.
+ db_nds = Node.where(:id => new_nds, :visible => true).lock("for share")
- fail OSM::APIPreconditionFailedError.new("Way #{id} requires the nodes with id in (#{missing.join(',')}), which either do not exist, or are not visible.")
+ raise OSM::APIPreconditionFailedError.new("Way #{id} requires the nodes with id in (#{missing.join(',')}), which either do not exist, or are not visible.")
# need to start the transaction here, so that the database can
# provide repeatable reads for the used-by checks. this means it
# shouldn't be possible to get race conditions.
Way.transaction do
# need to start the transaction here, so that the database can
# provide repeatable reads for the used-by checks. this means it
# shouldn't be possible to get race conditions.
Way.transaction do
check_consistency(self, new_way, user)
rels = Relation.joins(:relation_members).where(:visible => true, :current_relation_members => { :member_type => "Way", :member_id => id }).order(:id)
check_consistency(self, new_way, user)
rels = Relation.joins(:relation_members).where(:visible => true, :current_relation_members => { :member_type => "Way", :member_id => id }).order(:id)
# update the bounding box, note that this has to be done both before
# and after the save, so that nodes from both versions are included in the
# bbox. we use a copy of the changeset so that it isn't reloaded
# update the bounding box, note that this has to be done both before
# and after the save, so that nodes from both versions are included in the
# bbox. we use a copy of the changeset so that it isn't reloaded