end
end
+ def delete_with_history(user)
+ if self.visible
+ if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='relation' and member_id=?", self.id ])
+ raise OSM::APIPreconditionFailedError.new
+ else
+ self.user_id = user.id
+ self.tags = []
+ self.members = []
+ self.visible = false
+ save_with_history!
+ end
+ else
+ raise OSM::APIAlreadyDeletedError.new
+ end
+ end
+
+ def update_from(new_relation, user)
+ if !new_relation.preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new
+ elsif new_relation.version != version
+ raise OSM::APIVersionMismatchError.new(new_relation.version, version)
+ else
+ self.user_id = user.id
+ self.tags = new_relation.tags
+ self.members = new_relation.members
+ self.visible = true
+ save_with_history!
+ end
+ end
+
def preconditions_ok?
+ # These are hastables that store an id in the index of all
+ # the nodes/way/relations that have already been added.
+ # Once we know the id of the node/way/relation exists
+ # we check to see if it is already existing in the hashtable
+ # if it does, then we return false. Otherwise
+ # we add it to the relevant hash table, with the value true..
+ # Thus if you have nodes with the ids of 50 and 1 already in the
+ # relation, then the hash table nodes would contain:
+ # => {50=>true, 1=>true}
+ nodes = Hash.new
+ ways = Hash.new
+ relations = Hash.new
self.members.each do |m|
if (m[0] == "node")
n = Node.find(:first, :conditions => ["id = ?", m[1]])
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'
# Application constants needed for routes.rb - must go before Initializer call
-API_VERSION = ENV['OSM_API_VERSION'] || '0.5'
+API_VERSION = ENV['OSM_API_VERSION'] || '0.6'
- # Set to :readonly to put the API in read-only mode or :offline to
- # take it completely offline
- API_STATUS = :online
+ # Set application status - possible settings are:
+ #
+ # :online - online and operating normally
+ # :api_readonly - site online but API in read-only mode
+ # :api_offline - site online but API offline
+ # :database_offline - database offline with site in emergency mode
+ #
+ OSM_STATUS = :online
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')