Class: Kaui::AdminTenant

Inherits:
KillBillClient::Model::Tenant
  • Object
show all
Defined in:
app/models/kaui/admin_tenant.rb

Class Method Summary collapse

Class Method Details

.format_plugin_config(plugin_key, plugin_type, props) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/kaui/admin_tenant.rb', line 46

def format_plugin_config(plugin_key, plugin_type, props)
  return nil unless props.present?
  return props['raw_config'].gsub(/\r\n?/, "\n") if props['raw_config']

  if plugin_type == 'ruby'
    require 'yaml'
    props = reformat_plugin_config(plugin_type, props)
    hsh = {}
    hsh[plugin_key.to_sym] = {}
    props.each do |k,v|
      hsh[plugin_key.to_sym][k.to_sym] = v
    end
    hsh.to_yaml
  elsif plugin_type == 'java'
    props = reformat_plugin_config(plugin_type, props)
    res = ""
    props.each do |k, v|
      res = "#{res}#{k.to_s}=#{v.to_s}\n"
    end
    res
  else
    props['raw_config']
  end
end

.get_tenant_plugin_config(options) ⇒ Object

Return a map of plugin_name => config


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/kaui/admin_tenant.rb', line 30

def get_tenant_plugin_config(options)
  raw_tenant_config = KillBillClient::Model::Tenant::search_tenant_config("PLUGIN_CONFIG_", options)

  tenant_config = raw_tenant_config.inject({}) do |hsh, e|
    # Strip prefix '/PLUGIN_CONFIG_'
    plugin_name = e.key.gsub!(/PLUGIN_CONFIG_/, '')

    # Construct simple hash with one property (first value)
    hsh[plugin_name] = e.values[0]

    hsh
  end

  tenant_config
end

.is_kv?(candidate_string) ⇒ Boolean

checks if string could be parse as key value pair

Returns:

  • (Boolean)

101
102
103
104
105
106
107
# File 'app/models/kaui/admin_tenant.rb', line 101

def is_kv?(candidate_string)
  return false if candidate_string.blank? || is_yaml?(candidate_string)
  lines = candidate_string.split("\n")
  return false if lines.blank?

  lines.all? { |kv| kv.split('=').count >= 1 }
end

.is_yaml?(candidate_string) ⇒ Boolean

checks if string could be parse as yaml

Returns:

  • (Boolean)

86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/models/kaui/admin_tenant.rb', line 86

def is_yaml?(candidate_string)
  is_yaml = false
  return is_yaml if candidate_string.blank?

  begin
    is_yaml = !!YAML::load(candidate_string)
    is_yaml = is_yaml && YAML.load(candidate_string).instance_of?(Hash)
  rescue
    is_yaml = false
  end

  is_yaml
end

.reformat_plugin_config(plugin_type, props) ⇒ Object


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/kaui/admin_tenant.rb', line 71

def reformat_plugin_config(plugin_type, props)
  unless props['raw_config'].blank?
    new_props = {}
    props['raw_config'].split("\n").each do |p|
      line = p.split('=')
      new_props[line[0]] = line[1].blank? ? '' : line[1].delete("\r")
    end

    return new_props
  end

  props
end

.upload_catalog(catalog_xml, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object


5
6
7
# File 'app/models/kaui/admin_tenant.rb', line 5

def upload_catalog(catalog_xml, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Catalog.upload_tenant_catalog(catalog_xml, user, reason, comment, options)
end

.upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object


21
22
23
# File 'app/models/kaui/admin_tenant.rb', line 21

def upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Invoice.upload_catalog_translation(catalog_translation, locale, delete_if_exists, user, reason, comment, options)
end

.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object


13
14
15
# File 'app/models/kaui/admin_tenant.rb', line 13

def upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Invoice.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user, reason, comment, options)
end

.upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object


17
18
19
# File 'app/models/kaui/admin_tenant.rb', line 17

def upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Invoice.upload_invoice_translation(invoice_translation, locale, delete_if_exists, user, reason, comment, options)
end

.upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object


9
10
11
# File 'app/models/kaui/admin_tenant.rb', line 9

def upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Overdue.upload_tenant_overdue_config_xml(overdue_config_xml, user, reason, comment, options)
end

.upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object


25
26
27
# File 'app/models/kaui/admin_tenant.rb', line 25

def upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Tenant.upload_tenant_plugin_config(plugin_name, plugin_config, user, reason, comment, options)
end