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
|
# File 'lib/restful_objects/object_actions.rb', line 39
def get_action_invoke(action, json)
raise 'action does not exists' if not rs_type.actions.include?(action)
action_description = rs_type.actions[action]
json == '' ? {} : arguments = JSON.parse(json)
parameters = []
action_description.parameters.each do |name, parameter|
case parameter.type
when :int
parameters << arguments[name.to_s]['value'].to_i
else
parameters << arguments[name.to_s]['value']
end
end
result = send(action.to_sym, *parameters)
action_link = link_to(:self, "/objects/#{self.class.name}/#{object_id}/actions/#{action}/invoke", :action_result)
action_link['arguments'] = arguments
response = {
'links' => [ action_link ],
'resultType' => 'scalar',
'result' => {
'links' => [],
'extensions' => { }
},
'extensions' => { }
}
response['resultType'] = action_description.kind_result_type.to_s
if result.nil?
response['result'] = nil
else
case action_description.kind_result_type
when :scalar
response['resultType'] = 'scalar'
response['result']['value'] = encode_value(result, action_description.result_type)
response['result']['links'] = [ link_to(:return_type, '/domain-types/int', :domain_type) ]
when :object
response['resultType'] = 'object'
response['result'] = result.representation
when :proto_object
response['resultType'] = 'object'
response['result'] = result
when :list
response['resultType'] = 'list'
response['result']['links'] =
[ link_to(:element_type, "/domain-types/#{action_description.result_type.to_s}", :domain_type) ]
list = []
result.each do |member|
member_link = link_to(:element, "/objects/#{action_description.result_type.to_s}/#{member.rs_instance_id}", :object)
member_link['title'] = member.title
list << member_link
end
response['result']['value'] = list
end
end
response.to_json
end
|