diff --git a/lib/ruby_odata/service.rb b/lib/ruby_odata/service.rb
index b59385b..e988077 100644
--- a/lib/ruby_odata/service.rb
+++ b/lib/ruby_odata/service.rb
@@ -390,7 +390,7 @@ def entry_to_class(entry)
# Fill properties
for prop in properties
prop_name = prop.name
- klass.send "#{prop_name}=", parse_value(prop)
+ klass.send "#{prop_name}=", parse_value_xml(prop)
end
# Fill properties represented outside of the properties collection
@@ -652,9 +652,13 @@ def complex_type_to_class(complex_type_xml)
# extract the elements from the collection
elements = complex_type_xml.xpath(".//d:element", @namespaces)
elements.each do |e|
- element = @classes[klass_name].new
- fill_complex_type_properties(e, element)
- collection << element
+ if type.match(/^Edm/)
+ collection << parse_value(e.content, type)
+ else
+ element = @classes[klass_name].new
+ fill_complex_type_properties(e, element)
+ collection << element
+ end
end
return collection
else
@@ -669,7 +673,7 @@ def complex_type_to_class(complex_type_xml)
def fill_complex_type_properties(complex_type_xml, klass)
properties = complex_type_xml.xpath(".//*")
properties.each do |prop|
- klass.send "#{prop.name}=", parse_value(prop)
+ klass.send "#{prop.name}=", parse_value_xml(prop)
end
end
@@ -693,31 +697,36 @@ def parse_date(sdate)
end
# Parses a value into the proper type based on an xml property element
- def parse_value(property_xml)
+ def parse_value_xml(property_xml)
property_type = Helpers.get_namespaced_attribute(property_xml, 'type', 'm')
property_null = Helpers.get_namespaced_attribute(property_xml, 'null', 'm')
+ if property_type.nil? || (property_type && property_type.match(/^Edm/))
+ return parse_value(property_xml.content, property_type, property_null)
+ end
+
+ complex_type_to_class(property_xml)
+ end
+
+ def parse_value(content, property_type = nil, property_null = nil)
# Handle a nil property type, this is a string
- return property_xml.content if property_type.nil?
+ return content if property_type.nil?
# Handle anything marked as null
return nil if !property_null.nil? && property_null == "true"
- # Handle complex types
- return complex_type_to_class(property_xml) if !property_type.match(/^Edm/)
-
# Handle integers
- return property_xml.content.to_i if property_type.match(/^Edm.Int/)
+ return content.to_i if property_type.match(/^Edm.Int/)
# Handle decimals
- return property_xml.content.to_d if property_type.match(/Edm.Decimal/)
+ return content.to_d if property_type.match(/Edm.Decimal/)
# Handle DateTimes
# return Time.parse(property_xml.content) if property_type.match(/Edm.DateTime/)
- return parse_date(property_xml.content) if property_type.match(/Edm.DateTime/)
+ return parse_date(content) if property_type.match(/Edm.DateTime/)
# If we can't parse the value, just return the element's content
- property_xml.content
+ content
end
# Parses a value into the proper type based on a specified return type
diff --git a/spec/fixtures/ms_system_center/vm_templates.xml b/spec/fixtures/ms_system_center/vm_templates.xml
new file mode 100644
index 0000000..38f5af2
--- /dev/null
+++ b/spec/fixtures/ms_system_center/vm_templates.xml
@@ -0,0 +1,1193 @@
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates/
+ VMTemplates
+ 2013-06-19T12:49:08Z
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'45c55fc3-4abc-4a0f-8a38-3306e7d291f7',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ 45c55fc3-4abc-4a0f-8a38-3306e7d291f7
+
+ 2013-05-08T10:45:14.54+02:00
+ root
+ true
+ gitlab
+ 2
+ 100
+ 0
+
+ 2013-05-08T10:45:14.54+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ true
+
+ WORKGROUP
+
+ false
+ false
+
+ 3500
+ false
+ 2013-06-19T13:36:52.757+02:00
+ Temporary Template44658d7a-fb6c-4bf9-9d5f-3686d3ed1f4f
+ 0
+ Other Linux (64 bit)
+
+
+ xx-yyy\zzzz
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 42949672960
+ false
+ false
+ Public
+
+
+ false
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ true
+
+
+
+
+
+
+
+ false
+
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ HyperV
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'67e1a108-7b72-45f7-a3cf-ac73e1b76aeb',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ 67e1a108-7b72-45f7-a3cf-ac73e1b76aeb
+
+ 2013-05-08T10:45:14.54+02:00
+ root
+ true
+ *
+ 2
+ 100
+ 0
+
+ 2013-05-08T10:45:14.54+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ true
+
+ WORKGROUP
+
+ false
+ false
+
+ 3500
+ false
+ 2013-06-19T13:54:07.32+02:00
+ Temporary Template9cd81051-3eb0-4fee-84a6-2f6d39f2f5c2
+ 0
+ Other Linux (64 bit)
+
+
+ xx-yyy\ffff
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 42949672960
+ false
+ false
+ Public
+
+
+ false
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ true
+
+
+
+
+
+
+
+ false
+
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ HyperV
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'73e0c54d-7ea0-426d-bf35-0ab4ea361038',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ 73e0c54d-7ea0-426d-bf35-0ab4ea361038
+
+ 2013-05-08T10:45:14.54+02:00
+ root
+ true
+ *
+ 2
+ 100
+ 0
+
+ 2013-05-08T10:45:14.54+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ true
+
+ WORKGROUP
+
+ false
+ false
+
+ 3500
+ false
+ 2013-06-19T13:56:45.33+02:00
+ Temporary Template5291c00b-cd96-4608-b5ba-a29dc8d51924
+ 0
+ Other Linux (64 bit)
+
+
+ xx-yyy\ffff
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 42949672960
+ false
+ false
+ Public
+
+
+ false
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ true
+
+
+
+
+
+
+
+ false
+
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ HyperV
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'9e028e3c-3288-4d41-82de-bbee1f58f5c8',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ 9e028e3c-3288-4d41-82de-bbee1f58f5c8
+
+ 2013-06-08T01:27:11.88+02:00
+ Administrator
+ true
+ *
+ 2
+ 100
+ 0
+
+ 2013-06-08T01:27:11.88+02:00
+ 0
+ bs-unsi\admin
+ true
+ 20
+ true
+
+ false
+ true
+ bs.unsi.no
+
+
+ false
+ false
+
+ 4096
+ false
+ 2013-06-10T19:52:31.72+02:00
+ [VM] - Windows Server 2012 Datacenter - Domain BS.UNSI.NO
+ 0
+ 64-bit edition of Windows Server 2012 Datacenter
+
+
+ xx-yyy\ffff
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 64424509440
+ false
+ false
+ Public
+
+
+ true
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ false
+
+
+
+
+
+
+ 20
+ true
+ 8192
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ Unknown
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'b91792cf-13a7-45da-b34f-fb38ec79ae92',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ b91792cf-13a7-45da-b34f-fb38ec79ae92
+
+ 2013-05-08T10:45:14.54+02:00
+ root
+ true
+ *
+ 2
+ 100
+ 0
+
+ 2013-05-08T10:45:14.54+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ true
+
+ WORKGROUP
+
+ false
+ false
+
+ 3500
+ true
+ 2013-06-19T14:22:17.8700372+02:00
+ Temporary Template00552cc8-2432-4d8f-83e2-307bfdb9d7de
+ 0
+ Other Linux (64 bit)
+
+
+ xx-yyy\gggg
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 42949672960
+ false
+ false
+ Public
+
+
+ false
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ true
+
+
+
+
+
+
+
+ false
+
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ HyperV
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'bcb712ce-a0b2-4501-85bd-59c8437a3ab9',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ bcb712ce-a0b2-4501-85bd-59c8437a3ab9
+
+ 2013-05-08T10:45:14.54+02:00
+ root
+ true
+ gitlab
+ 2
+ 100
+ 0
+
+ 2013-05-08T10:45:14.54+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ true
+
+ WORKGROUP
+
+ false
+ false
+
+ 3500
+ false
+ 2013-06-19T13:49:21.307+02:00
+ Temporary Templatef2217481-582b-4974-97f4-198b2746133c
+ 0
+ Other Linux (64 bit)
+
+
+ xx-yyy\hhhh
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 42949672960
+ false
+ false
+ Public
+
+
+ false
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ true
+
+
+
+
+
+
+
+ false
+
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ HyperV
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'bd884799-ea41-44e6-9a89-cddd140f201f',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ bd884799-ea41-44e6-9a89-cddd140f201f
+
+ 2013-05-08T10:45:14.54+02:00
+ root
+ true
+ gitlab
+ 2
+ 100
+ 0
+
+ 2013-05-08T10:45:14.54+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ true
+
+ WORKGROUP
+
+ false
+ false
+
+ 3500
+ true
+ 2013-06-19T14:46:29.4357848+02:00
+ Temporary Template8e176bea-b31e-4318-8b93-3c3d207b7c7c
+ 0
+ Other Linux (64 bit)
+
+
+ xx-yyy\iiii
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 42949672960
+ false
+ false
+ Public
+
+
+ false
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ true
+
+
+
+
+
+
+
+ false
+
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ Unknown
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'be2d74ae-68ea-4127-8ec0-3c75bd1a9e6c',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ be2d74ae-68ea-4127-8ec0-3c75bd1a9e6c
+
+ 2013-05-08T10:45:14.54+02:00
+ root
+ true
+ *
+ 1
+ 100
+ 0
+
+ 2013-05-08T10:45:14.54+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ false
+
+ WORKGROUP
+
+ false
+ false
+
+ 512
+ true
+ 2013-06-19T14:45:29.6251096+02:00
+ Debian 7.0 Test Template
+ 0
+ Other Linux (64 bit)
+
+
+ xx-yyy\jjjj
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+
+
+ aaa Users
+ 17781df7-d938-4795-974d-3607bc9ee184
+
+
+
+ bbb Admins
+ f2191c72-7671-4b5c-b022-3a2460a6bd46
+
+
+
+ wewf
+ 58ce4833-1101-4bd8-8bc6-b72fe4c87cb8
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 42949672960
+ false
+ false
+ Public
+
+
+ false
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ false
+
+
+
+
+
+
+
+ false
+
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ Unknown
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'c0f268bb-db87-4cb8-a6d4-f20c79a8dceb',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ c0f268bb-db87-4cb8-a6d4-f20c79a8dceb
+
+ 2013-05-08T10:45:14.54+02:00
+ root
+ true
+ gitlab
+ 2
+ 100
+ 0
+
+ 2013-05-08T10:45:14.54+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ true
+
+ WORKGROUP
+
+ false
+ false
+
+ 3500
+ true
+ 2013-06-19T14:02:46.9771552+02:00
+ Temporary Templatec95c6fb3-96f2-4c91-a23a-b9eb16c26e71
+ 0
+ Other Linux (64 bit)
+
+
+ xx-yyy\kkkk
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 42949672960
+ false
+ false
+ Public
+
+
+ false
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ true
+
+
+
+
+
+
+
+ false
+
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ HyperV
+ Hyper-V
+
+
+
+
+
+
+
+ https://srv-spf-98.bs.unsi.no:8090/SC2012/VMM/Microsoft.Management.Odata.svc/VMTemplates(ID=guid'f25bf79e-c00b-4da6-af11-871aed0de5e1',StampId=guid'a68f9b8b-f8af-46b2-8636-255248c9b5ab')
+
+
+
+
+
+
+
+
+ 2013-06-19T12:49:08Z
+
+
+
+
+
+ a68f9b8b-f8af-46b2-8636-255248c9b5ab
+ f25bf79e-c00b-4da6-af11-871aed0de5e1
+
+ 2013-06-14T17:20:18.387+02:00
+ Administrator
+ true
+ *
+ 2
+ 100
+ 0
+
+ 2013-06-14T17:20:18.387+02:00
+ 0
+
+ false
+ 20
+ true
+
+ false
+ true
+
+ WORKGROUP
+
+ false
+ false
+
+ 4096
+ false
+ 2013-06-14T17:20:19.22+02:00
+ [VM] - Windows Server 2012 - Intern IKT
+ 0
+ 64-bit edition of Windows Server 2012 Datacenter
+
+
+ xx-yyy\llll
+ Administrator
+ 75700cd5-893e-4f68-ada7-50ef4668acc6
+
+
+ 1
+ false
+ 100
+ false
+ (none)
+ 110
+ 64424509440
+ false
+ false
+ Public
+
+
+ true
+ 1
+ false
+ Not Detected
+ true
+ false
+ false
+ false
+
+
+
+
+
+
+ 20
+ true
+ 8192
+ 5000
+
+
+
+
+ CD
+ IdeHardDrive
+ PxeBoot
+ Floppy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Normal
+ Unknown
+ Hyper-V
+
+
+
+
+
+
+
diff --git a/spec/service_spec.rb b/spec/service_spec.rb
index 9cf12ee..256f73e 100644
--- a/spec/service_spec.rb
+++ b/spec/service_spec.rb
@@ -776,6 +776,11 @@ module OData
stub_request(:get, "http://blabla:@test.com/test.svc/HardwareProfiles?$filter=Memory%20eq%203500").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/hardware_profiles.xml", __FILE__)), :headers => {})
+
+ stub_request(:get, "http://blabla:@test.com/test.svc/VMTemplates").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/vm_templates.xml", __FILE__)), :headers => {})
+
end
it "should successfully return a virtual machine" do
@@ -791,6 +796,7 @@ module OData
results = svc.execute
results.first.should be_a_kind_of(VMM::HardwareProfile)
end
+
it "should successfully return a collection of complex types" do
svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
svc.HardwareProfiles.filter("Memory eq 3500")
@@ -799,7 +805,24 @@ module OData
granted_list.should be_a_kind_of(Array)
granted_list.first.should be_a_kind_of(VMM::UserAndRole)
granted_list.first.RoleName.should == "Important Tenant"
+ end
+
+ it "should successfully return results that include a collection of Edm types" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.VMTemplates
+ results = svc.execute
+ results.first.should be_a_kind_of(VMM::VMTemplate)
+ end
+
+ it "should successfully return a collection of Edm types" do
+ svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
+ svc.VMTemplates
+ results = svc.execute
+ boot_order = results.first.BootOrder
+ boot_order.should be_a_kind_of(Array)
+ boot_order.first.should be_a_kind_of(String)
+ boot_order.should eq ['CD', 'IdeHardDrive', 'PxeBoot', 'Floppy']
end
end
end
@@ -817,7 +840,7 @@ module OData
# This date was returned in the Netflix OData service and failed with an ArgumentError: out of range using 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
svc = OData::Service.new "http://test.com/test.svc/"
element_to_parse = Nokogiri::XML.parse('2100-01-01T00:00:00').elements[0]
- lambda { svc.parse_value(element_to_parse) }.should_not raise_exception
+ lambda { svc.parse_value_xml(element_to_parse) }.should_not raise_exception
end
end
end