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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/cpee-eval-ruby/implementation.rb', line 62
def response
mode = @a[0]
code = @p.shift.value
dataelements = JSON::parse(@p.shift.value.read)
local = nil
local = JSON::parse(@p.shift.value.read) if @p[0].name == 'local'
endpoints = JSON::parse(@p.shift.value.read)
additional = JSON::parse(@p.shift.value.read)
status = JSON::parse(@p.shift.value.read) if @p.any? && @p[0].name == 'status'
status = WEEL::Status.new(status['id'],status['message']) if status
call_result = JSON::parse(@p.shift.value.read) if @p.any? && @p[0].name == 'call_result'
= JSON::parse(@p.shift.value.read) if @p.any? && @p[0].name == 'call_headers'
local = local[0] if local && local.is_a?(Array)
dataelements.transform_keys!{|k| k.to_sym}
local.transform_keys!{|k| k.to_sym} if local
endpoints.transform_keys!{|k| k.to_sym}
additional.transform_keys!{|k| k.to_sym}
additional.each_value do |v|
v.transform_keys!{|k| k.to_sym}
end
if status || call_result ||
struct = WEEL::ManipulateStructure.new(dataelements,endpoints,status,local,additional)
execresult = exec struct, code, CPEE::EvalRuby::Translation::simplify_structurized_result(call_result),
send = []
send << Riddl::Parameter::Complex.new('result','application/json',execresult[:res] || '')
if execresult[:signal]
send << Riddl::Parameter::Simple.new('signal',execresult[:signal])
send << Riddl::Parameter::Simple.new('signal_text',execresult[:signal_text] || '')
@status = 555
end
res = {}
struct.changed_data.each do |e|
res[e] = struct.data[e]
end
if res.any?
send << Riddl::Parameter::Complex.new('dataelements','application/json',JSON::generate(dataelements)) if mode == :full
send << Riddl::Parameter::Complex.new('changed_dataelements','application/json',JSON::generate(res))
end
res = {}
struct.changed_endpoints.each do |e|
res[e] = struct.endpoints[e]
end
if res.any?
send << Riddl::Parameter::Complex.new('endpoints','application/json',JSON::generate(endpoints)) if mode == :full
send << Riddl::Parameter::Complex.new('changed_endpoints','application/json',JSON::generate(res))
end
send << Riddl::Parameter::Complex.new('changed_status','application/json',JSON::generate(status)) if struct.changed_status
send
else
struct = WEEL::ReadStructure.new(dataelements,endpoints,local,additional)
execresult = exec struct, code
send = []
send << Riddl::Parameter::Complex.new('result','application/json',execresult[:res])
if execresult[:signal]
send << Riddl::Parameter::Simple.new('signal',execresult[:signal])
send << Riddl::Parameter::Simple.new('signal_text',execresult[:signal_text] || '')
@status = 555
end
send
end
end
|