class CPEE::ModelManagement::ShiftItem

Public Instance Methods

response() click to toggle source
# File lib/cpee-model-management/implementation.rb, line 227
def response
  where = @a[0] == :main ? '' : Riddl::Protocols::Utils::unescape(@r[-2])
  conns = @a[1]
  themes = @a[2]
  models = @a[3]
  name  = File.basename(@r.last,'.xml')
  nstage = @p[0].value
  fname  = File.join(models,where,name + '.xml')

  dn = CPEE::ModelManagement::get_dn @h['DN']
  author = dn['GN'] + ' ' + dn['SN']

  attrs = {}
  XML::Smart::modify(fname) do |doc|
    doc.register_namespace 'p', 'http://cpee.org/ns/properties/2.0'
    doc.find('/p:testset/p:attributes/p:author').each do |ele|
      ele.text = author
    end
    doc.find('/p:testset/p:attributes/p:design_stage').each do |ele|
      ele.text = nstage
    end
    doc.find('/p:testset/p:attributes/p:theme').each do |ele|
      ele.text = themes[nstage] || 'model'
    end
    attrs = doc.find('/p:testset/p:attributes/*').map do |e|
      [e.qname.name,e.text]
    end.to_h
  end
  File.write(fname + '.attrs',JSON::pretty_generate(attrs))

  CPEE::ModelManagement::op author, 'shift', models, File.join('.', where, name + '.xml'), File.join('.', where, name + '.xml')
  CPEE::ModelManagement::notify conns, 'shift', models, fname, fname
  nil
end