38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'app/controllers/o_data_controller.rb', line 38
def resource
@last_segment = @query.segments.last
@results = @query.execute!
case @last_segment.class.segment_name
when OData::AbstractQuery::Segments::CountSegment.segment_name
render :text => @results.to_i
when OData::AbstractQuery::Segments::LinksSegment.segment_name
request.format = :xml unless request.format == :json
respond_to do |format|
format.xml { render :inline => "xml.instruct!; @results.empty? ? xml.links('xmlns' => 'http://schemas.microsoft.com/ado/2007/08/dataservices') : xml.links('xmlns' => 'http://schemas.microsoft.com/ado/2007/08/dataservices') { @results.each { |r| xml.uri(o_data_resource_url(r[1])) } }", :type => :builder }
format.json { render :json => { "links" => @results.collect { |r| { "uri" => r } } }.to_json }
end
when OData::AbstractQuery::Segments::ValueSegment.segment_name
render :text => @results.to_s
when OData::AbstractQuery::Segments::PropertySegment.segment_name
request.format = :xml unless request.format == :json
respond_to do |format|
format.xml { render :inline => "xml.instruct!; value.blank? ? xml.tag!(key.to_sym, 'm:null' => true, 'xmlns' => 'http://schemas.microsoft.com/ado/2007/08/dataservices', 'xmlns:m' => 'http://schemas.microsoft.com/ado/2007/08/dataservices') : xml.tag!(key.to_sym, value, 'edm:Type' => type, 'xmlns' => 'http://schemas.microsoft.com/ado/2007/08/dataservices', 'xmlns:edm' => 'http://schemas.microsoft.com/ado/2007/05/edm')", :locals => { :key => @results.keys.first.name, :type => @results.keys.first.return_type, :value => @results.values.first }, :type => :builder }
format.json { render :json => { @results.keys.first.name => @results.values.first }.to_json }
end
when OData::AbstractQuery::Segments::NavigationPropertySegment.segment_name
@countable = @last_segment.countable?
@navigation_property = @last_segment.navigation_property
@polymorphic = @navigation_property.to_end.polymorphic?
if @polymorphic
@entity_type = nil
@entity_type_name = @navigation_property.to_end.name.singularize
else
@entity_type = @navigation_property.to_end.entity_type
@entity_type_name = @entity_type.name
end
@collection_name = @entity_type_name.pluralize
@expand_navigation_property_paths = {}
if expand_option = @query.options.find { |o| o.option_name == OData::AbstractQuery::Options::ExpandOption.option_name }
@expand_navigation_property_paths = expand_option.navigation_property_paths
end
respond_to do |format|
format.atom format.json end
when OData::AbstractQuery::Segments::CollectionSegment.segment_name
@countable = @last_segment.countable?
@navigation_property = nil
@polymorphic = true
@entity_type = @last_segment.entity_type
@expand_navigation_property_paths = {}
if expand_option = @query.options.find { |o| o.option_name == OData::AbstractQuery::Options::ExpandOption.option_name }
@expand_navigation_property_paths = expand_option.navigation_property_paths
end
respond_to do |format|
format.atom format.json end
else
raise OData::AbstractQuery::Errors::AbstractQueryException.new(@query)
end
end
|