Class: CPEE::Instantiation::ContinueTask

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee/instantiation.rb

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/cpee/instantiation.rb', line 281

def response
  cpee         = @h['X_CPEE'] || @a[0]
  cblist       = @a[1]
  topic        = @p[1].value
  event_name   = @p[2].value
  notification = JSON.parse(@p[3].value)

  key = @r.last
  cb, condition, instance, uuid, instance_url = cblist.lrange(key,0,-1)

  orisend = {
    'CPEE-INSTANCE' => instance,
    'CPEE-INSTANCE-URL' => instance_url,
    'CPEE-INSTANCE-UUID' => uuid,
    'CPEE-STATE' => notification['state']
  }
  send = orisend.dup

  if notification['state'] == condition
    cblist.del(key)
    srv = Riddl::Client.new(cpee, cpee + "?riddl-description")
    res = srv.resource("/#{instance}/properties/values/dataelements")
    status, response = res.get
    if status >= 200 && status < 300
      doc = XML::Smart.string(response[0].value.read)
      doc.register_namespace 'p', 'http://riddl.org/ns/common-patterns/properties/1.0'
      doc.find('/p:value/*').each do |e|
        send[e.qname.name] = CPEE::ValueHelper::parse(e.text)
      end
    end
    Riddl::Client.new(cb).put Riddl::Parameter::Complex.new('dataelements','application/json',JSON::generate(send))
  else
    Riddl::Client.new(cb).put [
      Riddl::Header.new('CPEE-UPDATE','true'),
      Riddl::Parameter::Complex.new('dataelements','application/json',JSON::generate(send))
    ]
  end
end