Top Level Namespace

Defined Under Namespace

Modules: CPEE Classes: AttributesHelper, ParaStruct

Instance Method Summary collapse

Instance Method Details

#transform(descxml, tdesc, tdesctype, tdata, tdatatype, tendp, tendptype, opts) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cpee/transform.rb', line 1

def transform(descxml,tdesc,tdesctype,tdata,tdatatype,tendp,tendptype,opts)
  desc = XML::Smart::string(descxml)
  desc.register_namespace  'p', 'http://cpee.org/ns/description/1.0'

  dslx = nil
  dsl = nil
  de = {}
  ep = {}

  if desc.root.children.empty?
    tdesctype = tdatatype = tendptype = 'clean'
  end

  ### 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).root
    else
      raise 'Could not extract dslx'
    end
  elsif tdesctype == 'xslt' && !tdesc.empty?
    trans = XML::Smart::open_unprotected(tdesc)
    desc.transform_with(trans).root
  elsif tdesctype == 'clean'
    XML::Smart::open_unprotected(opts[:empty_dslx]).root
  else
    nil
  end
  unless addit.nil?
    trans = XML::Smart::open_unprotected(opts[:transformation_dslx])
    dslx = addit.to_s
    dsl = addit.transform_with(trans).to_s
  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

#(a) ⇒ Object



30
# File 'lib/cpee/controller.rb', line 30

def (a); ParaStruct.new(a); end

#(a) ⇒ Object



31
# File 'lib/cpee/controller.rb', line 31

def (a); ParaStruct.new(a); end