class CPEE::Properties::PutDescription
Public Class Methods
Source
# File lib/cpee/implementation_properties.rb, line 801 def self::set(id,opts,xml,exposition=[],copy=false) dslx, dsl, de, ep = if copy PutDescription::transform( xml, '', 'copy', '', 'none', '', 'none', CPEE::Persistence::extract_item(id,opts,'executionhandler'), id, opts ) else PutDescription::transform( xml, CPEE::Persistence::extract_item(id,opts,'transformation/description'), CPEE::Persistence::extract_item(id,opts,'transformation/description/@type'), CPEE::Persistence::extract_item(id,opts,'transformation/dataelements'), CPEE::Persistence::extract_item(id,opts,'transformation/dataelements/@type'), CPEE::Persistence::extract_item(id,opts,'transformation/endpoints'), CPEE::Persistence::extract_item(id,opts,'transformation/endpoints/@type'), CPEE::Persistence::extract_item(id,opts,'executionhandler'), id, opts ) end attrs = CPEE::Persistence::extract_list(id,opts,'attributes').to_h change_uuid = Digest::SHA1.hexdigest(dslx) CPEE::Persistence::set_item(id,opts,'description', :description => xml, :dslx => dslx, :change_uuid => change_uuid, :dsl => dsl, :dataelements => CPEE::Persistence::extract_list(id,opts,'dataelements').to_h, :endpoints => CPEE::Persistence::extract_list(id,opts,'endpoints').to_h, :attributes => attrs ) PatchItems::set_hash('dataelements',id,opts,de) unless de.empty? PatchItems::set_hash('endpoints',id,opts,ep) unless ep.empty? exposition.each do |exp| content = { :change_uuid => change_uuid, :exposition => exp.value.read, :attributes => attrs } CPEE::Message::send(:event,'description/exposition',File.join(opts[:url],'/'),id,attrs['uuid'],attrs['info'],content,opts[:redis]) end end
Source
# File lib/cpee/implementation_properties.rb, line 701 def self::transform(descxml,tdesc,tdesctype,tdata,tdatatype,tendp,tendptype,hw,id,opts) #{{{ desc = XML::Smart::string(descxml) rescue nil if desc.nil? if descxml.empty? tdesctype = tdatatype = tendptype = 'clean' end else desc.register_namespace 'p', 'http://cpee.org/ns/description/1.0' if desc.root.children.empty? tdesctype = tdatatype = tendptype = 'clean' end end dslx = nil dsl = nil de = {} ep = {} ### endpoints extraction addit = if tendptype == 'rest' && !tendp.empty? srv = Riddl::Client.new(tendp) status, res = srv.post [ desc.nil? ? Riddl::Parameter::Complex.new("description","text/plain",descxml) : Riddl::Parameter::Complex.new("description","text/xml",descxml), Riddl::Parameter::Simple.new("type","endpoints") ] if status >= 200 && status < 300 res else raise 'Could not extract endpoints' end elsif tendptype == 'xslt' && !tendp.empty? trans = XML::Smart::open_unprotected(tendp.text) desc.transform_with(trans) elsif tendptype == 'clean' [] else nil end unless addit.nil? addit.each_slice(2).each do |k,v| ep[k.value.to_sym] = v.value end end ### description transformation, including dslx to dsl addit = if tdesctype == 'copy' || tdesc.empty? desc || '' elsif tdesctype == 'rest' && !tdesc.empty? srv = Riddl::Client.new(tdesc) status, res = srv.post [ desc.nil? ? Riddl::Parameter::Complex.new("description","text/plain",descxml) : Riddl::Parameter::Complex.new("description","text/xml",descxml), Riddl::Parameter::Simple.new("type","description") ] if status >= 200 && status < 300 XML::Smart::string(res[0].value.read) else raise 'Could not extract dslx' end elsif tdesctype == 'xslt' && !tdesc.empty? trans = XML::Smart::open_unprotected(tdesc) desc.transform_with(trans) elsif tdesctype == 'clean' XML::Smart::open_unprotected(opts[:empty_dslx]) else nil end unless addit.nil? dslx = addit.to_s dsl = Object.const_get('CPEE::ExecutionHandler::' + hw.capitalize)::dslx_to_dsl(addit,CPEE::Persistence::extract_list(id,opts,'endpoints').to_h.merge(ep)) end ### dataelements extraction addit = if tdatatype == 'rest' && !tdata.empty? srv = Riddl::Client.new(tdata) status, res = srv.post [ desc.nil? ? Riddl::Parameter::Complex.new("description","text/plain",descxml) : Riddl::Parameter::Complex.new("description","text/xml",descxml), Riddl::Parameter::Simple.new("type","dataelements") ] if status >= 200 && status < 300 res else raise 'Could not extract dataelements' end elsif tdatatype == 'xslt' && !tdata.empty? trans = XML::Smart::open_unprotected(tdata) desc.transform_with(trans) elsif tdatatype == 'clean' [] else nil end unless addit.nil? addit.each_slice(2).each do |k,v| de[k.value.to_sym] = v.value end end [dslx, dsl, de, ep] end
Public Instance Methods
Source
# File lib/cpee/implementation_properties.rb, line 852 def response id = @a[0] opts = @a[1] copy = @a[2] if opts[:statemachine].readonly? id @status = 423 elsif opts[:statemachine].final? id @status = 410 else begin # force-encoding because johannes managed to sneak in ascii special characters. why the browser is not sanitizing it is beyond me. PutDescription::set(id,opts,@p[0].value.read.force_encoding('UTF-8'),@p[1..-1],copy) rescue => e puts e.message puts e.backtrace @status = 400 end end nil end