Module: WolfCore::FkmOperations

Includes:
HttpOperations
Defined in:
lib/wolf_core/application/fkm_operations.rb

Instance Method Summary collapse

Methods included from HttpOperations

#http_get, #http_post, #parse_http_response, #validate_http_response

Methods included from ExceptionOperations

#raise_service_error

Instance Method Details

#create_foreign_key(tenant:, source:, source_id:, destination:, destination_id:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/wolf_core/application/fkm_operations.rb', line 21

def create_foreign_key(tenant:, source:, source_id:, destination:, destination_id:)
  response = http_post(
    url: "#{ENV['FKM_URL']}/Prod/create",
    body: {
      tenant: tenant,
      source: source,
      source_id: source_id,
      destination: destination,
      destination_id: destination_id
    }
  )
  puts 'create foreign key response is'
  pp response
  validate_http_response(response: response, message: 'Error creating foreign key')
  parse_http_response(response).body
end

#get_foreign_key_destination_id(tenant:, source:, source_id:, destination:) ⇒ Object



5
6
7
8
9
# File 'lib/wolf_core/application/fkm_operations.rb', line 5

def get_foreign_key_destination_id(tenant:, source:, source_id:, destination:)
  foreign_keys = get_foreign_keys(tenant: tenant, source: source, source_id: source_id)
  foreign_key = foreign_keys.find { |fk| fk['destination'] == destination }
  foreign_key&.dig('destination_id')
end

#get_foreign_keys(tenant:, source:, source_id:) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/wolf_core/application/fkm_operations.rb', line 11

def get_foreign_keys(tenant:, source:, source_id:)
  response = http_get(
    url: "#{ENV['FKM_URL']}/Prod/lookup?tenant=#{tenant}&source=#{source}&source_id=#{source_id}"
  )
  puts 'foreign keys response is'
  pp response
  validate_http_response(response: response, message: 'Error getting foreign keys')
  parse_http_response(response).body
end