Class: CqlElm::CqlToElmHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/measures/cql_to_elm_helper.rb

Class Method Summary collapse

Class Method Details

.translate_cql_to_elm(cql) ⇒ Object

Translates the cql to elm json using a post request to CQLTranslation Jar. Returns an array of JSON ELM and an Array of XML ELM



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
# File 'lib/measures/cql_to_elm_helper.rb', line 5

def self.translate_cql_to_elm(cql)
  begin
    request = RestClient::Request.new(
      :method => :post,
      :accept => :json,
      :content_type => :json,
      :url => 'http://localhost:8080/cql/translator',
      :payload => {
        :multipart => true,
        :file => cql
      }
    )
   
    elm_json = request.execute

    # now get the XML ELM
    request = RestClient::Request.new(
      :method => :post,
      :headers => {
        :accept => 'multipart/form-data',
        'X-TargetFormat' => 'application/elm+xml'
      },
      :content_type => 'multipart/form-data',
      :url => 'http://localhost:8080/cql/translator',
      :payload => {
        :multipart => true,
        :file => cql
      }
    )
    elm_xmls = request.execute
    
    return parse_elm_response(elm_json), parse_multipart_response(elm_xmls)
  rescue RestClient::BadRequest => e
    begin
      # If there is a response, include it in the error else just include the error message
      cqlError = JSON.parse(e.response)
      errorMsg = JSON.pretty_generate(cqlError).to_s
    rescue
      errorMsg = e.message
    end
    # The error text will be written to a load_error file and will not be displayed in the error dialog displayed to the user since
    # measures_controller.rb does not handle this type of exception
    raise MeasureLoadingException.new "Error Translating CQL to ELM: " + errorMsg
  end
end