Class: CPEE::Properties::PutDescription

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee/implementation_properties.rb

Overview

}}}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.set(id, opts, xml) ⇒ Object

}}}



755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# 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) ⇒ Object

{{{



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
# 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

Instance Method Details

#responseObject



776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# 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