class CPEE::ModelManagement::Create
Public Instance Methods
response()
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 359 def response where = @a[0] == :main ? '' : Riddl::Protocols::Utils::unescape(@r.last) stage = if @a[1] == :cre @p.shift.value else nil end views = @a[2] conns = @a[3] templates = @a[4] models = @a[5] name = @p[0].value source = @p[1] ? File.join(models,where,@p[1].value) : (templates[stage] ? templates[stage] : 'testset.xml') fname = File.join(models,where,name + '.xml') attrs = JSON::load File.open(fname + '.attrs') rescue {} stage = attrs['design_stage'] if stage.nil? && attrs['design_stage'] stage = views[stage] if views && views[stage] counter = 0 while File.exists?(fname) counter += 1 fname = File.join(models,where,name + counter.to_s + '.xml') end dn = CPEE::ModelManagement::get_dn @h['DN'] creator = dn['GN'] + ' ' + dn['SN'] FileUtils.cp(source,fname) 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:info').each do |ele| ele.text = File.basename(fname,'.xml') end doc.find('/p:testset/p:attributes/p:creator').each do |ele| ele.text = creator end doc.find('/p:testset/p:attributes/p:author').each do |ele| ele.text = creator end doc.find('/p:testset/p:attributes/p:design_dir').each do |ele| ele.text = where end doc.find('/p:testset/p:attributes/p:model_uuid').each do |ele| ele.text = SecureRandom.uuid end if stage doc.find('/p:testset/p:attributes/p:design_stage').each do |ele| ele.text = stage end 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 creator, 'add', models, File.join('.', where, name + '.xml') CPEE::ModelManagement::notify conns, 'create', models, fname nil end