deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 3/3] CIMI: Report sub-collection :href attribute properly (DTACLOUD-433)
Date Wed, 23 Jan 2013 15:51:57 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/models/base.rb | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb
index 1393ae4..7995e07 100644
--- a/server/lib/cimi/models/base.rb
+++ b/server/lib/cimi/models/base.rb
@@ -173,8 +173,8 @@ class CIMI::Model::Resource
       if !@filter_attrs.empty? and !@filter_attrs.include?(n)
         @attribute_values[n] = nil
       else
-        self[n].href = "#{self.id}/#{n}" if !self[n].href
-        self[n].id = "#{self.id}/#{n}" if !self[n].entries.empty?
+        self[n].href = "#{self.base_id}/#{n}" if !self[n].href
+        self[n].id = "#{self.base_id}/#{n}" if !self[n].entries.empty?
       end
     end
   end
@@ -185,12 +185,20 @@ class CIMI::Model::Resource
   def initialize(values = {})
     names = self.class.schema.attribute_names
     @filter_attrs = values[:filter_attr_list] || []
+    # Make sure we always have the :id of the entity even
+    # the $select parameter is used and :id is filtered out
+    #
+    @_base_id = values[:base_id] || values[:id]
     @attribute_values = names.inject(OrderedHash.new) do |hash, name|
       hash[name] = self.class.schema.convert(name, values[name])
       hash
     end
   end
 
+  def base_id
+    self.id || @_base_id
+  end
+
   # Construct a new object from the XML representation +xml+
   def self.from_xml(text)
     xml = XmlSimple.xml_in(text, :force_content => true)
@@ -290,7 +298,10 @@ class CIMI::Model::Base < CIMI::Model::Resource
       result[attr.to_sym] = self.send(attr) if self.respond_to?(attr)
       result
     end
-    self.class.new(attrs.merge(:filter_attr_list => attr_list))
+    self.class.new(attrs.merge(
+      :filter_attr_list => attr_list,
+      :base_id => self.send(:id)
+    ))
   end
 
 end
-- 
1.8.1


Mime
View raw message