global-registry-bindings 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +79 -35
  3. data/lib/global_registry_bindings/entity/entity_type_methods.rb +35 -33
  4. data/lib/global_registry_bindings/entity/mdm_methods.rb +9 -19
  5. data/lib/global_registry_bindings/entity/push_entity_methods.rb +31 -38
  6. data/lib/global_registry_bindings/entity/push_relationship_methods.rb +61 -47
  7. data/lib/global_registry_bindings/entity/relationship_type_methods.rb +48 -37
  8. data/lib/global_registry_bindings/exceptions.rb +1 -0
  9. data/lib/global_registry_bindings/global_registry_bindings.rb +129 -46
  10. data/lib/global_registry_bindings/{entity/delete_entity_methods.rb → model/delete_entity.rb} +5 -5
  11. data/lib/global_registry_bindings/model/entity.rb +64 -0
  12. data/lib/global_registry_bindings/model/pull_mdm.rb +23 -0
  13. data/lib/global_registry_bindings/model/push_entity.rb +21 -0
  14. data/lib/global_registry_bindings/model/push_relationship.rb +79 -0
  15. data/lib/global_registry_bindings/model/relationship.rb +68 -0
  16. data/lib/global_registry_bindings/options.rb +26 -59
  17. data/lib/global_registry_bindings/options/entity_class_options.rb +34 -0
  18. data/lib/global_registry_bindings/options/entity_instance_options.rb +90 -0
  19. data/lib/global_registry_bindings/options/entity_options_parser.rb +76 -0
  20. data/lib/global_registry_bindings/options/relationship_class_options.rb +37 -0
  21. data/lib/global_registry_bindings/options/relationship_instance_options.rb +131 -0
  22. data/lib/global_registry_bindings/options/relationship_options_parser.rb +98 -0
  23. data/lib/global_registry_bindings/railtie.rb +2 -1
  24. data/lib/global_registry_bindings/version.rb +1 -1
  25. data/lib/global_registry_bindings/worker.rb +25 -0
  26. data/lib/global_registry_bindings/workers/{delete_gr_entity_worker.rb → delete_entity_worker.rb} +1 -6
  27. data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +12 -13
  28. data/lib/global_registry_bindings/workers/push_entity_worker.rb +24 -0
  29. data/lib/global_registry_bindings/workers/push_relationship_worker.rb +17 -7
  30. data/spec/acceptance/global_registry_bindings_spec.rb +50 -40
  31. data/spec/factories/factories.rb +24 -0
  32. data/spec/fixtures/get_entity_types_area.json +44 -0
  33. data/spec/fixtures/post_entities_community.json +8 -0
  34. data/spec/fixtures/post_relationship_types_fancy_org_area.json +16 -0
  35. data/spec/fixtures/put_entities_community_relationship.json +16 -0
  36. data/spec/fixtures/put_entities_fancy_org_area_relationship.json +8 -0
  37. data/spec/fixtures/put_entities_fancy_org_relationship.json +17 -0
  38. data/spec/fixtures/put_entities_person_country_relationship.json +23 -0
  39. data/spec/fixtures/put_entities_relationship_400.json +3 -0
  40. data/spec/fixtures/put_relationship_types_fields_fancy_org_area.json +25 -0
  41. data/spec/helpers/sidekiq_helpers.rb +14 -0
  42. data/spec/internal/app/models/address.rb +7 -2
  43. data/spec/internal/app/models/area.rb +7 -0
  44. data/spec/internal/app/models/assignment.rb +5 -4
  45. data/spec/internal/app/models/community.rb +19 -0
  46. data/spec/internal/app/models/country.rb +8 -0
  47. data/spec/internal/app/models/namespaced/person.rb +48 -2
  48. data/spec/internal/app/models/organization.rb +26 -3
  49. data/spec/internal/db/schema.rb +28 -0
  50. data/spec/internal/log/test.log +71023 -0
  51. data/spec/models/address_spec.rb +6 -204
  52. data/spec/models/assignment_spec.rb +40 -186
  53. data/spec/models/organization_spec.rb +106 -92
  54. data/spec/models/person_spec.rb +158 -214
  55. data/spec/models/user_edited_person_spec.rb +2 -2
  56. data/spec/spec_helper.rb +5 -6
  57. data/spec/workers/delete_gr_entity_worker_spec.rb +4 -4
  58. data/spec/workers/pull_mdm_id_worker_spec.rb +94 -32
  59. data/spec/workers/push_entity_worker_spec.rb +476 -0
  60. data/spec/workers/push_relationship_worker_spec.rb +344 -15
  61. metadata +45 -10
  62. data/lib/global_registry_bindings/entity/entity_methods.rb +0 -62
  63. data/lib/global_registry_bindings/options/class_options.rb +0 -62
  64. data/lib/global_registry_bindings/options/instance_options.rb +0 -63
  65. data/lib/global_registry_bindings/workers/push_gr_entity_worker.rb +0 -22
  66. data/spec/workers/push_gr_entity_worker_spec.rb +0 -27
@@ -9,6 +9,10 @@ FactoryGirl.define do
9
9
  guid '98711710-acb5-4a41-ba51-e0fc56644b53'
10
10
  global_registry_id nil
11
11
  global_registry_mdm_id nil
12
+ country_of_service_id nil
13
+ country_of_service_gr_id nil
14
+ country_of_residence_id nil
15
+ country_of_residence_gr_id nil
12
16
  end
13
17
 
14
18
  factory :user_edited, class: Namespaced::Person::UserEdited do
@@ -33,6 +37,8 @@ FactoryGirl.define do
33
37
  start_date { Time.zone.today }
34
38
  parent_id nil
35
39
  gr_id nil
40
+ area_id nil
41
+ global_registry_area_id nil
36
42
  end
37
43
 
38
44
  factory :assignment do
@@ -42,4 +48,22 @@ FactoryGirl.define do
42
48
  organization_id nil
43
49
  global_registry_id nil
44
50
  end
51
+
52
+ factory :area do
53
+ area_name 'Best Area'
54
+ area_code 'BEST'
55
+ is_active true
56
+ end
57
+
58
+ factory :country do
59
+ global_registry_id nil
60
+ name 'Sokovia'
61
+ end
62
+
63
+ factory :community do
64
+ global_registry_id nil
65
+ infobase_gr_id nil
66
+ name 'Community'
67
+ infobase_id 1
68
+ end
45
69
  end
@@ -0,0 +1,44 @@
1
+ {
2
+ "entity_types": [
3
+ {
4
+ "id": "548852c6-d55e-11e3-897f-12725f8f377c",
5
+ "name": "area",
6
+ "description": "Areas",
7
+ "data_visibility": "public",
8
+ "fields": [
9
+ {
10
+ "id": "428acf06-d6ab-11e3-ae81-12725f8f377c",
11
+ "name": "area_code",
12
+ "data_visibility": "public",
13
+ "field_type": "string",
14
+ "is_editable": true,
15
+ "unique_value": false
16
+ },
17
+ {
18
+ "id": "39b33954-d6ab-11e3-aa70-12725f8f377c",
19
+ "name": "area_name",
20
+ "data_visibility": "public",
21
+ "field_type": "string",
22
+ "is_editable": true,
23
+ "unique_value": false
24
+ },
25
+ {
26
+ "id": "4f12bd4c-d6ab-11e3-b0c9-12725f8f377c",
27
+ "name": "is_active",
28
+ "data_visibility": "public",
29
+ "field_type": "boolean",
30
+ "is_editable": true,
31
+ "unique_value": false
32
+ }
33
+ ],
34
+ "is_editable": true,
35
+ "unique_value": false
36
+ }
37
+ ],
38
+ "meta": {
39
+ "page": 1,
40
+ "next_page": false,
41
+ "from": 1,
42
+ "to": 1
43
+ }
44
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "entity": {
3
+ "community": {
4
+ "id": "6133f6fe-c63a-425a-bb46-68917c689723",
5
+ "client_integration_id": "1"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "relationship_type": {
3
+ "id": "f03b947e-6644-11e7-93dd-129bd0521531",
4
+ "relationship_entity_type_id": "f03a929a-6644-11e7-93dd-129bd0521531",
5
+ "relationship1": {
6
+ "entity_type": "fancy_org",
7
+ "relationship_name": "fancy_org"
8
+ },
9
+ "relationship2": {
10
+ "entity_type": "area",
11
+ "relationship_name": "area"
12
+ },
13
+ "fields": [],
14
+ "is_editable": true
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "entity": {
3
+ "community": {
4
+ "id": "6133f6fe-c63a-425a-bb46-68917c689723",
5
+ "ministry:relationship": [
6
+ {
7
+ "ministry": "41f767fd-86f4-42e2-8d24-cbc3f697b794",
8
+ "relationship_entity_id": "ee40f9ed-d625-405b-8ce6-aec821611ec6",
9
+ "client_integration_id": "1"
10
+ }
11
+ ],
12
+ "client_integration_id": "1"
13
+ }
14
+ },
15
+ "meta": {}
16
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "entity": {
3
+ "fancy_org_assignment": {
4
+ "id": "c99d7d7e-8b14-4fe6-9c11-e5359ee03637",
5
+ "client_integration_id": "1"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "entity": {
3
+ "fancy_org": {
4
+ "id": "aebb4170-3f34-11e7-bba6-129bd0521531",
5
+ "area:relationship": [
6
+ {
7
+ "area": "0fdb70c5-f51e-4628-a1fe-caa37fae53cd",
8
+ "relationship_entity_id": "c99d7d7e-8b14-4fe6-9c11-e5359ee03637",
9
+ "client_integration_id": "1",
10
+ "priority": "High"
11
+ }
12
+ ],
13
+ "client_integration_id": "1"
14
+ }
15
+ },
16
+ "meta": {}
17
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "entity": {
3
+ "person": {
4
+ "id": "2f0c62f1-5738-4860-88bd-5706fb801d7b",
5
+ "country:relationship": [
6
+ {
7
+ "country": "0f9089a3-2b93-4de8-9b81-92be0261f325",
8
+ "relationship_entity_id": "420d2fd1-7a73-41ed-9d8f-5dc79b00a688",
9
+ "client_integration_id": "cos_1",
10
+ "country_of_service": true
11
+ },
12
+ {
13
+ "country": "7cdaf399-d449-4008-8c6b-3c64a2b2730c",
14
+ "relationship_entity_id": "a4c030ce-13f2-44f5-8131-4003eb21c0ae",
15
+ "client_integration_id": "cor_1",
16
+ "country_of_residence": true
17
+ }
18
+ ],
19
+ "client_integration_id": "1"
20
+ }
21
+ },
22
+ "meta": {}
23
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Validation failed: A fancy_org_assignment entity with a client_integeration_id of 1 already exists"
3
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "relationship_type": {
3
+ "id": "f03b947e-6644-11e7-93dd-129bd0521531",
4
+ "relationship_entity_type_id": "f03a929a-6644-11e7-93dd-129bd0521531",
5
+ "relationship1": {
6
+ "entity_type": "fancy_org",
7
+ "relationship_name": "fancy_org"
8
+ },
9
+ "relationship2": {
10
+ "entity_type": "area",
11
+ "relationship_name": "area"
12
+ },
13
+ "fields": [
14
+ {
15
+ "id": "ac0bde52-6645-11e7-80e8-129bd0521531",
16
+ "name": "priority",
17
+ "data_visibility": "public",
18
+ "field_type": "string",
19
+ "is_editable": true,
20
+ "unique_value": false
21
+ }
22
+ ],
23
+ "is_editable": true
24
+ }
25
+ }
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqHelpers
4
+ def clear_sidekiq_jobs_and_locks
5
+ # Drop sidekiq-unique-jobs locks
6
+ MOCK_REDIS.keys.each do |key|
7
+ MOCK_REDIS.del(key)
8
+ end
9
+
10
+ # Clear sidekiq queues and workers
11
+ Sidekiq::Queues.clear_all
12
+ Sidekiq::Worker.clear_all
13
+ end
14
+ end
@@ -1,11 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Address < ApplicationRecord
4
+ EXCLUDE_GR_FIELDS = %i[id created_at updated_at global_registry_id person_id address1].freeze
4
5
  belongs_to :person, class_name: 'Namespaced::Person', inverse_of: :addresses
5
6
  global_registry_bindings parent_association: :person,
6
- exclude_fields: %i[address1],
7
- extra_fields: { line1: :string, line2: :string, postal_code: :string }
7
+ exclude_fields: proc { |_type, _model| EXCLUDE_GR_FIELDS },
8
+ extra_fields: :global_registry_extra_fields
8
9
 
9
10
  alias_attribute :line1, :address1
10
11
  alias_attribute :postal_code, :zip
12
+
13
+ def global_registry_extra_fields(_type)
14
+ { line1: :string, line2: :string, postal_code: :string }
15
+ end
11
16
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Area < ApplicationRecord
4
+ has_many :organizations
5
+
6
+ global_registry_bindings
7
+ end
@@ -3,8 +3,9 @@
3
3
  class Assignment < ApplicationRecord
4
4
  belongs_to :person, class_name: 'Namespaced::Person'
5
5
  belongs_to :organization
6
- global_registry_bindings parent_association: :person,
7
- related_association: :organization,
8
- parent_relationship_name: :person,
9
- related_relationship_name: :fancy_org
6
+
7
+ global_registry_bindings binding: :relationship,
8
+ type: :assignment,
9
+ primary_association: :person,
10
+ related_association: :organization
10
11
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Community < ApplicationRecord
4
+ global_registry_bindings ensure_entity_type: false,
5
+ exclude_fields: %i[infobase_id infobase_gr_id]
6
+
7
+ global_registry_bindings binding: :relationship,
8
+ type: :infobase_ministry,
9
+ id_column: :infobase_gr_id,
10
+ related_relationship_name: :ministry,
11
+ related_association_type: :ministry,
12
+ related_association_foreign_key: :infobase_id,
13
+ related_global_registry_id: :pull_infobase_global_registry_id,
14
+ ensure_relationship_type: false
15
+
16
+ def pull_infobase_global_registry_id(_type)
17
+ '41f767fd-86f4-42e2-8d24-cbc3f697b794'
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Country < ApplicationRecord
4
+ has_many :employees, class_name: 'Namespaced::Person', inverse_of: :country_of_service
5
+ has_many :residents, class_name: 'Namespaced::Person', inverse_of: :country_of_residence
6
+
7
+ global_registry_bindings ensure_entity_type: false
8
+ end
@@ -4,15 +4,61 @@ module Namespaced
4
4
  class Person < ApplicationRecord
5
5
  has_many :addresses, dependent: :destroy, inverse_of: :person
6
6
  has_many :assignments
7
+ has_many :organizations, through: :assignments
8
+ belongs_to :country_of_service,
9
+ class_name: 'Country',
10
+ foreign_key: :country_of_service_id,
11
+ inverse_of: :employees
12
+ belongs_to :country_of_residence,
13
+ class_name: 'Country',
14
+ foreign_key: :country_of_residence_id,
15
+ inverse_of: :residents
7
16
 
8
- global_registry_bindings mdm_id_column: :global_registry_mdm_id,
17
+ global_registry_bindings binding: :entity,
18
+ mdm_id_column: :global_registry_mdm_id,
9
19
  mdm_timeout: 24.hours,
10
- exclude_fields: %i[guid]
20
+ exclude_fields: %i[guid country_of_service_gr_id country_of_service_id
21
+ country_of_residence_gr_id country_of_residence_id]
22
+
23
+ global_registry_bindings binding: :relationship,
24
+ type: :country_of_service,
25
+ id_column: :country_of_service_gr_id,
26
+ client_integration_id: ->(model) { "cos_#{model.id}" },
27
+ related_association: :country_of_service,
28
+ exclude_fields: :exclude_cos_fields,
29
+ extra_fields: :extra_cos_fields,
30
+ ensure_relationship_type: false
31
+
32
+ global_registry_bindings binding: :relationship,
33
+ type: :country_of_residence,
34
+ id_column: :country_of_residence_gr_id,
35
+ client_integration_id: ->(model) { "cor_#{model.id}" },
36
+ related_association: :country_of_residence,
37
+ ensure_relationship_type: false
11
38
 
12
39
  def entity_attributes_to_push
13
40
  entity_attributes = super
14
41
  entity_attributes[:authentication] = { key_guid: guid }
15
42
  entity_attributes
16
43
  end
44
+
45
+ def exclude_cos_fields(_type)
46
+ %i[]
47
+ end
48
+
49
+ def extra_cos_fields(_type)
50
+ {}
51
+ end
52
+
53
+ def relationship_attributes_to_push(type)
54
+ entity_attributes = super(type)
55
+ case type
56
+ when :country_of_service
57
+ entity_attributes[:country_of_service] = true
58
+ when :country_of_residence
59
+ entity_attributes[:country_of_residence] = true
60
+ end
61
+ entity_attributes
62
+ end
17
63
  end
18
64
  end
@@ -5,8 +5,31 @@ class Organization < ApplicationRecord
5
5
  belongs_to :parent, class_name: 'Organization'
6
6
 
7
7
  has_many :assignments
8
+ has_many :people, class_name: 'Namespaced::Person', through: :assignments
9
+
10
+ belongs_to :area
11
+
8
12
  global_registry_bindings id_column: :gr_id,
9
- type: :fancy_org,
10
- push_on: %i[create delete],
11
- parent_association: :parent
13
+ type: ->(_model) { :fancy_org },
14
+ push_on: %i[create destroy],
15
+ parent_association: :parent,
16
+ exclude_fields: :exclude_gr_fields,
17
+ extra_fields: proc { |_type, _model| {} }
18
+
19
+ global_registry_bindings binding: :relationship,
20
+ type: :area,
21
+ id_column: :global_registry_area_id,
22
+ related_association: :area,
23
+ exclude_fields: proc { |_type, _model| %i[] },
24
+ extra_fields: proc { |_type, _model| { priority: :string } }
25
+
26
+ def exclude_gr_fields(_type)
27
+ %i[id created_at updated_at gr_id parent_id area_id global_registry_area_id]
28
+ end
29
+
30
+ def relationship_attributes_to_push(type)
31
+ entity_attributes = super(type)
32
+ entity_attributes[:priority] = 'High' if type == :area
33
+ entity_attributes
34
+ end
12
35
  end
@@ -9,6 +9,10 @@ ActiveRecord::Schema.define(version: 0) do
9
9
  t.string :first_name
10
10
  t.string :last_name
11
11
  t.string :guid
12
+ t.references :country_of_service, index: true
13
+ t.references :country_of_residence, index: true
14
+ t.string :country_of_service_gr_id
15
+ t.string :country_of_residence_gr_id
12
16
  t.timestamps
13
17
  end
14
18
 
@@ -27,6 +31,8 @@ ActiveRecord::Schema.define(version: 0) do
27
31
  t.text :description
28
32
  t.date :start_date
29
33
  t.references :parent, index: true
34
+ t.references :area, index: true
35
+ t.string :global_registry_area_id
30
36
  t.timestamps
31
37
  end
32
38
 
@@ -38,4 +44,26 @@ ActiveRecord::Schema.define(version: 0) do
38
44
  t.references :organization, index: true
39
45
  t.timestamps
40
46
  end
47
+
48
+ create_table :areas, force: true do |t|
49
+ t.string :global_registry_id
50
+ t.string :area_name
51
+ t.string :area_code
52
+ t.boolean :is_active
53
+ t.timestamps
54
+ end
55
+
56
+ create_table :countries, force: true do |t|
57
+ t.string :name
58
+ t.string :global_registry_id
59
+ t.timestamps
60
+ end
61
+
62
+ create_table :communities, force: true do |t|
63
+ t.string :name
64
+ t.string :global_registry_id
65
+ t.integer :infobase_id
66
+ t.string :infobase_gr_id
67
+ t.timestamps
68
+ end
41
69
  end