wolf_core 0.1.74 → 0.1.76

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea2c7642b7213912f7be0ed0d55cb8f3bab2dbf32e6208d7b505b094a36abd6d
4
- data.tar.gz: 4073fd23872f4388a46564ba875cc01cdfe40b416d519683fe3c5cb35a0ca21b
3
+ metadata.gz: 0b0bff7730ff3db46ccd6a31c14ed5b6b64f1d0b7e05c2002c3e063ee48e850d
4
+ data.tar.gz: a8d8c86518a9f0bf643d1e0accc6d0cf45f00c87d09d8b1ac2d7ed554f27b8ae
5
5
  SHA512:
6
- metadata.gz: 7516f45342dad488580974fc485c9e6d972d288d44245790d794adba1b4964172e19bf29b1c3c56ceb8d687ca2f1ce5de31991fc79a9fec3b448b875b40b0cb4
7
- data.tar.gz: 8d31afc2a95ebb7567ae3edee6965ab741ca1856c6a6fd28e047a5e3336d45d051afc17bed3cebdaca682c273550d896a89ee2a42425e16c2b164780206a62ae
6
+ metadata.gz: 3d6a120c83810ca778647da4ebf4411422c28fe2a7c1c1a430ebb058907763b46a8909b0d11798f6761e2d617bc24ff6d21c455d23aff265d7334f0418ea927f
7
+ data.tar.gz: 9c16cdde0aa2d2f053767bda90ece23fd1130b469b8609f2dee72096d69692b5e6fad87f9dc9d3a8202a943d3b6b2008af6846c97bf7bc650e7e5701291e9c30
@@ -5,11 +5,18 @@ module WolfCore
5
5
  include WolfCore::LoggingUtils
6
6
 
7
7
  def get_foreign_key_destination_id(tenant:, source:, source_id:, destination:)
8
- foreign_keys = get_foreign_keys(tenant: tenant, source: source, source_id: source_id)
9
- foreign_key = foreign_keys.find { |fk| fk['destination'] == destination }
8
+ foreign_key = get_foreign_key_by_destination(
9
+ tenant: tenant, source: source, source_id: source_id,
10
+ destination: destination
11
+ )
10
12
  foreign_key&.dig('destination_id')
11
13
  end
12
14
 
15
+ def get_foreign_key_by_destination(tenant:, source:, source_id:, destination:)
16
+ foreign_keys = get_foreign_keys(tenant: tenant, source: source, source_id: source_id)
17
+ foreign_keys.find { |fk| fk['destination'] == destination }
18
+ end
19
+
13
20
  def get_foreign_keys(tenant:, source:, source_id:)
14
21
  response = http_get(
15
22
  url: "#{ENV['FKM_URL']}/Prod/lookup?tenant=#{tenant}&source=#{source}&source_id=#{source_id}"
@@ -65,5 +72,54 @@ module WolfCore
65
72
  )
66
73
  Result.success(data: { operation: :create })
67
74
  end
75
+
76
+ def upsert_foreign_key(tenant:, auth_token:, source:, source_id:, destination:, destination_id:)
77
+ foreign_key = get_foreign_key_by_destination(
78
+ tenant: tenant, source: source, source_id: source_id,
79
+ destination: destination
80
+ )
81
+ if foreign_key.present?
82
+ update_foreign_key(
83
+ tenant: tenant, auth_token: auth_token, uuid: foreign_key['uuid'],
84
+ source: source, source_id: source_id,
85
+ destination: destination, destination_id: destination_id,
86
+ )
87
+ else
88
+ create_foreign_key(
89
+ tenant: tenant, source: source, source_id: source_id,
90
+ destination: destination, destination_id: destination_id
91
+ )
92
+ end
93
+ end
94
+
95
+ def update_foreign_key(tenant:, auth_token:, uuid:, source: nil, source_id: nil, destination: nil, destination_id: nil)
96
+ raise_service_error({ message: 'tenant is required to update a foreign key', tenant: tenant }) if tenant.blank?
97
+ raise_service_error({ message: 'auth_token is required to update a foreign key', auth_token: auth_token }) if auth_token.blank?
98
+ raise_service_error({ message: 'uuid is required to update a foreign key', uuid: uuid }) if uuid.blank?
99
+
100
+ fields_to_update = {
101
+ source: source,
102
+ source_id: source_id,
103
+ destination: destination,
104
+ destination_id: destination_id,
105
+ }.compact
106
+
107
+ raise_service_error({ message: 'At least one field to update is required to update a foreign key', source: source }) if fields_to_update.blank?
108
+
109
+ body = {
110
+ tenant: tenant,
111
+ authentication_token: auth_token,
112
+ uuid: uuid,
113
+ }.merge(fields_to_update)
114
+ log_object body, title: 'update_foreign_key body is'
115
+
116
+ response = safe_http_put(
117
+ url: "#{ENV['FKM_URL']}/Prod/create",
118
+ body: body,
119
+ title: 'update_foreign_key response is',
120
+ error_message: 'Error updating foreign key',
121
+ )
122
+ response.body
123
+ end
68
124
  end
69
125
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "0.1.74"
4
+ VERSION = "0.1.76"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolf_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.74
4
+ version: 0.1.76
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-23 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty