Class: CPEE::ModelManagement::MoveItem

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

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/cpee-model-management/implementation.rb', line 546

def response
  where = @a[0] == :main ? '' : @r[0..-2].map{ |d| Riddl::Protocols::Utils::unescape(d) }.join('/')
  conns = @a[1]
  models = @a[2]

  name  = File.basename(@r.last,'.xml')
  to = @p[0].value

  fname = File.join(models,where,name + '.xml')
  dn = CPEE::ModelManagement::get_dn @h['DN']
  author = dn['GN'] + ' ' + dn['SN']
  if !File.exist?(File.join(models,to,name + '.xml'))
    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:design_dir').each do |ele|
        ele.text = to
      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, 'mv', models, File.join('.', to, name + '.xml'), File.join('.', where, name + '.xml')
    CPEE::ModelManagement::notify conns, 'move', models, File.join(models,to,name + '.xml'), fname
  end
end