Class: CPEE::ModelManagement::ShiftItem

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee-model-management/implementation.rb

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/cpee-model-management/implementation.rb', line 232

def response
  where = @a[0] == :main ? '' : @r[0..-2].map{ |d| Riddl::Protocols::Utils::unescape(d) }.join('/')
  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