Class: PEngine

Inherits:
Object
  • Object
show all
Includes:
ApplyMTA, Marshaller, Payment, REXML, RefineQuote, Search, VPMSHelper, XMLDiff
Defined in:
lib/processengine/engine.rb

Constant Summary collapse

PRODUCTMODELS =
Hash.new

Instance Method Summary collapse

Methods included from VPMSHelper

#buildVPMSMessage, #callVPMS, #deriveComputes, #extractPremiums, #mergeIntoXMLDoc, #parseVPMSresponse, #viewPremiumComputeErrors

Methods included from RefineQuote

#integrateData

Methods included from Payment

#complete_payment, gateway_creator=, #get_gateway_payment_details, #payment_gateway, #setup_payment

Methods included from Search

#executeSearch, #explodeHash

Methods included from ApplyMTA

#applyMTA

Methods included from XMLDiff

#determineDiff, #runCommand

Instance Method Details

#addDefaults(p1) ⇒ Object



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
# File 'lib/processengine/engine.rb', line 44

def addDefaults(p1)
  #adds default values where no value currently exists
  #these values should be extracted from the data model!!
  p2 = {"ContentsCoverCoverDetailOtherContentsSumInsured" => {"Amount" => "1000000"},
      "ContentsCoverCoverDetailOtherStockSumInsured" => {"Amount" => "1000000"},
      "ContentsCoverCoverDetailTargetStockSumInsured" => {"Amount" => "1000000"},
      "BuildingsCoverCoverDetailShopFrontCoverDetailSumInsured" => {"Amount" => "1000000"},
      "BuildingsCoverCoverDetailTenantsImprovementsCoverDetailSumInsured" => {"Amount" => "1000000"},
      "BookDebtsCoverCoverDetailSumInsured" => {"Amount" => "1000000"},
      "BusinessInterruptionCoverCoverDetailSumInsured" => {"Amount" => "1000000"},
      "EmployersLiabilityCoverCoverDetailSumInsured" => {"Amount" => "1000000"},
      "GlassCoverCoverDetailSumInsured" => {"Amount" => "1000000"},
      "LossOfLicenceCoverCoverDetailSumInsured" => {"Amount" => "1000000"},
      "MoneyCoverCoverDetailSumInsured" => {"Amount" => "1000000"},
      "ProductLiabilityCoverCoverDetailSumInsured" => {"Amount" => "1000000"},
      "PublicLiabilityCoverCoverDetailSumInsured" => {"Amount" => "1000000"}}
    
  p2.each do |k,v|
    if p1.has_key?(k)
        v.each do |ik,iv|
          if (!p1[k].has_key?(ik) or p1[k][ik].length == 0)
            #puts "replacing value for:#{k},#{ik}"
            p1[k][ik] = iv
          end
        end
    else
      #puts "replacing value for:#{k}"
      p1[k] = v
    end
  end
  return p1
end

#deriveActiveRecordDefinitionOfProduct(product) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/processengine/engine.rb', line 36

def deriveActiveRecordDefinitionOfProduct(product)
    if (PRODUCTMODELS.has_key?(product))
      return PRODUCTMODELS[product.to_sym]
    else
      return getRAILSClassRequiresForProductModelFromOilDef(product)
    end
end

#drill(params, tweak) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/processengine/engine.rb', line 77

def drill(params,tweak)
  params.each do |p,v|
    if (v.class.to_s == "HashWithIndifferentAccess")
      drill(v,tweak)
    elsif Kerrylondon.mapping.has_key?(p)
      newkey = Kerrylondon.mapping[p]
      tweak[newkey] = v
    end
  end
end

#push(session, process, params) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/processengine/engine.rb', line 88

def push(session,process,params)
  package = 'CommercialProperty'

  case process
  when "ProcessDefinition"
    require 'RailsProcessInterpreter'
    open("#{PRODUCT_ROOT.gsub(/%product/,session[:product])}/DSL/processes.oil") {|f| @contents = f.read }
    dsl = @contents.to_s
    action_methods = RailsProcessInterpreter.execute(dsl)
    action_methods

  when "GetNBQuote"
    eval(deriveActiveRecordDefinitionOfProduct(session[:product]))
    xml = createXMLMessage(session[:product],params,false) { |k,v| "<#{k}>#{v}</#{k}>" }
    require 'models/persist'
    persist = Persist.instance
    key = persist.put("UUID",xml)
    session[:policyKey] = key

    if APP_CONFIG['use_rating_engine']
      nvpxml = buildVPMSMessage(session[:product],package,session[:brand],params)
      response = callVPMS(nvpxml)
      parseVPMSresponse(response,session[:product])
      xml = mergeIntoXMLDoc(xml,@premiums)
    end
    prepareModels(session[:product],xml)
    #cmd = SBroker.RequestRatingService("NB",session[:product],true,false,false)
    #quote = cmd.call(xml)

  when "GetBrokerQuotes"
    eval(deriveActiveRecordDefinitionOfProduct(session[:product]))      
    dataTweak = Hash.new
    drill(params,dataTweak)
    #dataTweaks contains values that override the kerry london adapter defaults
    result = Kerrylondon.makeQuote("Tony Lorriman","liability1","CSP",false,Kerrylondon.keyfacts(dataTweak))
    premiums = "<ContractorPlant><Quotes>#{result}#{result}</Quotes></ContractorPlant>"
    prepareModels(session[:product],premiums)

  when "RefineNBQuote"
    eval(deriveActiveRecordDefinitionOfProduct(session[:product]))
    require 'models/persist'
    persist = Persist.instance
    origxml = persist.get(session[:policyKey])
    h = prepareModels(session[:product],origxml)
    params = h.deep_merge(params)
    combinedxml = createXMLMessage(session[:product],params,false) { |k,v| "<#{k}>#{v}</#{k}>" }
    key = persist.put(session[:policyKey],combinedxml)
   
    if APP_CONFIG['use_rating_engine']
      nvpxml = buildVPMSMessage(session[:product],package,session[:brand],params)
      response = callVPMS(nvpxml)
      parseVPMSresponse(response,session[:product])
      combinedxml = mergeIntoXMLDoc(combinedxml,@premiums)
    end
    
    prepareModels(session[:product],combinedxml)

  when "Search"
    executeSearch(session[:product],params)      

  when "FindPolicyOrQuote"
    require 'models/persist'
    persist = Persist.instance
    xml = persist.get(params[:choosen][:one])
    prepareModels(session[:product],xml)

  when "Authenticate"
    begin
      if params[:User] and params[:User][:User] and params[:User][:User].length > 0
        session[:user_email] = params[:User][:User]
      elsif params[:ProfilePersonalDetailsClientContact] and params[:ProfilePersonalDetailsClientContact][:Email]
        session[:user_email] = params[:ProfilePersonalDetailsClientContact][:Email]
      end

      eval(deriveActiveRecordDefinitionOfProduct(session[:product]))
      open("#{File.dirname(__FILE__)}/../bizLogic/xquery2") {|f| @query = f.read }
      require 'models/persist'
      persist = Persist.instance
      results = persist.find(@query.gsub('EMAIL',session[:user_email]))
      key = results[0]
      xml = persist.get(key)
      doc = Document.new(xml)
      node = doc.elements['Telenexus/Profile/PersonalDetails/Client']
      node.parent.delete(node) if node and session[:user_email].index("telenexus.com")
      prepareModels(session[:product],doc.to_s)
    rescue
      if !session[:user_email]
        raise "Credentials missing - you have not logged in"
      end
      raise "An error occurred during the authentication process"
    end

  when "SaveProfile"
    begin
      session[:user_email] = params[:ProfilePersonalDetailsClientContact][:Email]
      eval(deriveActiveRecordDefinitionOfProduct(session[:product]))
      xml = createXMLMessage(session[:product],params,false) { |k,v| "<#{k}>#{v}</#{k}>" }
      open("#{File.dirname(__FILE__)}/../bizLogic/xquery2") {|f| @query = f.read }
      require 'models/persist'
      persist = Persist.instance
      results = persist.find(@query.gsub('EMAIL',session[:user_email]))
      key = nil
      if !results
        key = persist.create_key_and_doc(xml)
      else
        key = results[0]
        persist.put(key,xml)
      end
      xml = persist.get(key)
      prepareModels(session[:product],xml)
    rescue
      if !session[:user_email]
        raise "Credentials missing for new customer"
      end
      raise "An error occurred whilst saving a new profile"
    end


  when "SectionRating"
    "1553.25"

  when "MTAReason"
    require 'models/persist'
    persist = Persist.instance
    xml = persist.get(session[:policyKey])
    prepareModels(session[:product],xml)      

  when "GetMTAQuote"
    require 'models/persist'
    persist = Persist.instance
    origImage = persist.get(session[:policyKey])
    #TODO: the origImage will need any MTAs layering on there
    xml = createXMLMessage(session[:product],params,false) { |k,v| "<#{k}>#{v}</#{k}>" }      
    applyMTA(session[:mtaStartDate],session[:mtaEndDate],session[:policyKey],origImage,xml)
    prepareModels(session[:product],xml)

  when "PolicyDocumentation"
     #get XML quote/policy document
    require 'models/persist'
    persist = Persist.instance
    xml = persist.get(session[:policyKey])
    #call the rating engine (again!) until we've preserved the quote
    cmd = SBroker.RequestRatingService("NB",session[:product],true,false,false)
    quote = cmd.call(xml)
    prepareModels(session[:product],xml)

  when "Checkout"
    next_url = setup_payment(params)
    next_url

  when "ConfirmPayment"
    get_gateway_payment_details(params)

  when "CompletedPayment"
    complete_payment(params)

  when "CaptureInputXML"
    eval(deriveActiveRecordDefinitionOfProduct(session[:product]))
    xml = createXMLMessage(session[:product],params,false) { |k,v| "<#{k}>#{v}</#{k}>" }
    File.open("dump.xml", 'w') {|f| f.write(xml) }


  else
    puts "**********> #{process} logic performed once it has been written <**********"
  end
end