]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/changeset.rb
api06: simplify exception handling and add exception handling to the diff
[rails.git] / app / models / changeset.rb
index 85621dce234663ea885bfcba29f8b802be47c9fa..c9eeb0018371cf1b9107fabbf9c487c167f8a22b 100644 (file)
@@ -70,4 +70,42 @@ class Changeset < ActiveRecord::Base
       end
     end
   end
+  
+  def to_xml
+    doc = OSM::API.new.get_xml_doc
+    doc.root << to_xml_node()
+    return doc
+  end
+  def to_xml_node(user_display_name_cache = nil)
+    el1 = XML::Node.new 'changeset'
+    el1['id'] = self.id.to_s
+
+    user_display_name_cache = {} if user_display_name_cache.nil?
+
+    if user_display_name_cache and user_display_name_cache.key?(self.user_id)
+      # use the cache if available
+    elsif self.user.data_public?
+      user_display_name_cache[self.user_id] = self.user.display_name
+    else
+      user_display_name_cache[self.user_id] = nil
+    end
+
+    el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
+
+    self.tags.each do |k,v|
+      el2 = XML::Node.new('tag')
+      el2['k'] = k.to_s
+      el2['v'] = v.to_s
+      el1 << el2
+    end
+    
+    el1['created_at'] = self.created_at.xmlschema
+    el1['open'] = self.open.to_s
+
+    # FIXME FIXME FIXME: This does not include changes yet! There is 
+    # currently no changeset_id column in the tables as far as I can tell,
+    # so this is just a scaffold to build on, not a complete to_xml
+
+    return el1
+  end
 end