31
32
33
34
35
36
37
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
|
# File 'lib/restful_objects/domain_model/mixins/object_actions.rb', line 31
def ro_invoke_action_and_get_response(name, json)
raise 'action does not exists' unless ro_get_action_type(name)
arguments = json == '' ? {} : JSON.parse(json)
result = send(name, *ro_parse_action_arguments(name, arguments, json))
action_link = link_to(:self, "/objects/#{self.class.name}/#{object_id}/actions/#{name}/invoke", :action_result)
action_link['arguments'] = arguments
response = {
'links' => [ action_link ],
'resultType' => 'scalar',
'result' => {
'links' => [],
'extensions' => { }
},
'extensions' => { }
}
response['resultType'] = ro_get_action_type(name).kind_result_type.to_s
if result.nil?
response['result'] = nil
else
case ro_get_action_type(name).kind_result_type
when :scalar
response['resultType'] = 'scalar'
response['result']['value'] = encode_value(result, ro_get_action_type(name).result_type)
response['result']['links'] = [ link_to(:return_type, '/domain-types/int', :domain_type) ]
when :object
response['resultType'] = 'object'
response['result'] = result.ro_get_representation
when :proto_object
response['resultType'] = 'object'
response['result'] = result
when :list
response['resultType'] = 'list'
response['result']['links'] =
[ link_to(:element_type, "/domain-types/#{ro_get_action_type(name).result_type.to_s}", :domain_type) ]
list = []
result.each do |member|
member_link = link_to(:element, "/objects/#{ro_get_action_type(name).result_type.to_s}/#{member.ro_instance_id}", :object)
member_link['title'] = member.ro_title
list << member_link
end
response['result']['value'] = list
end
end
response.to_json
end
|