class CPEE::Properties::PutDescription
Public Class Methods
set(id,opts,xml)
click to toggle source
# File lib/cpee/implementation_properties.rb, line 755 def self::set(id,opts,xml) dslx, dsl, de, ep = 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'), opts ) CPEE::Persistence::set_item(id,opts,'description', :description => xml, :dslx => dslx, :dsl => dsl ) PatchItems::set_hash('dataelements',id,opts,de) unless de.empty? PatchItems::set_hash('dataelements',id,opts,ep) unless ep.empty? end
transform(descxml,tdesc,tdesctype,tdata,tdatatype,tendp,tendptype,hw,opts)
click to toggle source
# File lib/cpee/implementation_properties.rb, line 655 def self::transform(descxml,tdesc,tdesctype,tdata,tdatatype,tendp,tendptype,hw,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 = {} ### description transformation, including dslx to dsl addit = if tdesctype == 'copy' || tdesc.empty? desc || '' elsif tdesctype == 'rest' && !tdesc.empty? srv = Riddl::Client.interface(tdesc,opts[:transformation_service]) status, res = srv.post [ 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) end ### dataelements extraction addit = if tdatatype == 'rest' && !tdata.empty? srv = Riddl::Client.interface(tdata,opts[:transformation_service]) status, res = srv.post [ 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 ### endpoints extraction addit = if tendptype == 'rest' && !tdata.empty? srv = Riddl::Client.interface(tendp,opts[:transformation_service]) status, res = srv.post [ 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' && !tdata.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 [dslx, dsl, de, ep] end
Public Instance Methods
response()
click to toggle source
# File lib/cpee/implementation_properties.rb, line 776 def response id = @a[0] opts = @a[1] if opts[:statemachine].readonly? id @status = 422 # semantic error 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')) rescue => e puts e.message puts e.backtrace @status = 400 end end nil end