dmao-generic-ingesters 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/dmao-generic-ingesters.gemspec +1 -1
- data/lib/dmao/ingesters/errors/ingest_person_error.rb +15 -0
- data/lib/dmao/ingesters/generic/ingester.rb +81 -0
- data/lib/dmao/ingesters/generic/organisation_ingester.rb +14 -48
- data/lib/dmao/ingesters/generic/people_ingester.rb +61 -0
- data/lib/dmao/ingesters/generic/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa13700de7ef18ea8b374489d9d6f06cb85abe15
|
4
|
+
data.tar.gz: 2f68f9cc43db01df86153247ea61ee79983e7477
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1de03f96656da38f7566a4b681eb2390b6b1661e7ff8e1d93753d6c7841968f54cecb8dfc569b8f373d5b602cb39596e32cd0e952520102bd73999a421eada81
|
7
|
+
data.tar.gz: 435f9ab0ba13bd7e9ddbecd8161343285a90459886059de36bd744e2023ed05bf826a74db1ccf5e8237bbcca1cf99d91001cb25b0cb4e92cc39cc89368e7b39d
|
data/.gitignore
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_dependency "dmao_api", "~> 0.
|
33
|
+
spec.add_dependency "dmao_api", "~> 0.5.0"
|
34
34
|
|
35
35
|
spec.add_development_dependency "bundler", "~> 1.13"
|
36
36
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'dmao_api'
|
3
|
+
require 'dmao/ingesters/errors/generic_ingester'
|
4
|
+
require 'dmao/ingesters/errors/empty_attributes'
|
5
|
+
|
6
|
+
module DMAO
|
7
|
+
module Ingesters
|
8
|
+
module Generic
|
9
|
+
|
10
|
+
class Ingester
|
11
|
+
|
12
|
+
ENTITY = nil
|
13
|
+
ENTITY_ERROR = nil
|
14
|
+
ENTITY_ERROR_MESSAGE = nil
|
15
|
+
|
16
|
+
def initialize(api_url=nil, api_token=nil, institution_id=nil)
|
17
|
+
DMAO::API.configure do |config|
|
18
|
+
config.base_url = api_url
|
19
|
+
config.api_token = api_token
|
20
|
+
config.institution_id = institution_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def ingest
|
25
|
+
raise DMAO::Ingesters::Errors::GenericIngester.new("Calling ingest on generic ingester is not allowed.")
|
26
|
+
end
|
27
|
+
|
28
|
+
def ingest_entity attributes = {}
|
29
|
+
|
30
|
+
entity_name = self.class::ENTITY.to_s.split('::')[-1].gsub(/[A-Z]/, " \\0").strip.downcase
|
31
|
+
|
32
|
+
raise DMAO::Ingesters::Errors::EmptyAttributes.new("Cannot ingest #{entity_name} without attributes.") if attributes.nil? || attributes.empty?
|
33
|
+
|
34
|
+
begin
|
35
|
+
|
36
|
+
entity = self.class::ENTITY.find_by_system_uuid attributes[:system_uuid]
|
37
|
+
|
38
|
+
current_modified_at = Time.parse(entity.system_modified_at)
|
39
|
+
new_modified_at = Time.parse(attributes[:system_modified_at])
|
40
|
+
|
41
|
+
return false if current_modified_at >= new_modified_at
|
42
|
+
|
43
|
+
update_entity entity.id, attributes
|
44
|
+
|
45
|
+
rescue DMAO::API::Errors::EntityNotFound
|
46
|
+
add_entity attributes
|
47
|
+
rescue DMAO::API::Errors::InvalidResponseLength
|
48
|
+
raise self.class::ENTITY_ERROR.new("More than one #{entity_name} returned for system uuid #{attributes[:system_uuid]}.")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_unprocessable_errors errors
|
54
|
+
|
55
|
+
error_messages = ""
|
56
|
+
|
57
|
+
errors.each_with_index do |(k, v), index|
|
58
|
+
v.each_with_index do |msg, msg_index|
|
59
|
+
error_messages += "#{k} - #{msg}"
|
60
|
+
error_messages += ", " unless msg_index == v.size - 1
|
61
|
+
end
|
62
|
+
error_messages += ", " unless index == errors.size - 1
|
63
|
+
end
|
64
|
+
|
65
|
+
raise self.class::ENTITY_ERROR.new("#{self.class::ENTITY_ERROR_MESSAGE}, #{error_messages}")
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def add_entity _attributes={}
|
70
|
+
raise NotImplementedError
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_entity _entity_id, _attributes={}
|
74
|
+
raise NotImplementedError
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -2,6 +2,7 @@ require 'dmao/ingesters/errors/generic_ingester'
|
|
2
2
|
require 'dmao/ingesters/errors/empty_attributes'
|
3
3
|
require 'dmao/ingesters/errors/ingest_organisation_unit_error'
|
4
4
|
require 'dmao/ingesters/errors/link_organisation_unit_error'
|
5
|
+
require 'dmao/ingesters/generic/ingester'
|
5
6
|
require 'dmao_api'
|
6
7
|
require 'time'
|
7
8
|
|
@@ -9,41 +10,14 @@ module DMAO
|
|
9
10
|
module Ingesters
|
10
11
|
module Generic
|
11
12
|
|
12
|
-
class OrganisationIngester
|
13
|
+
class OrganisationIngester < Ingester
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
config.api_token = api_token
|
18
|
-
config.institution_id = institution_id
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def ingest
|
23
|
-
raise DMAO::Ingesters::Errors::GenericIngester.new("Calling ingest on generic organisation ingester is not allowed.")
|
24
|
-
end
|
15
|
+
ENTITY = DMAO::API::OrganisationUnit
|
16
|
+
ENTITY_ERROR = DMAO::Ingesters::Errors::IngestOrganisationUnitError
|
17
|
+
ENTITY_ERROR_MESSAGE = "Invalid organisation unit details"
|
25
18
|
|
26
19
|
def ingest_organisation_unit attributes={}
|
27
|
-
|
28
|
-
raise DMAO::Ingesters::Errors::EmptyAttributes.new("Cannot ingest organisation unit without attributes.") if attributes.nil? || attributes.empty?
|
29
|
-
|
30
|
-
begin
|
31
|
-
|
32
|
-
org_unit = DMAO::API::OrganisationUnit.find_by_system_uuid attributes[:system_uuid]
|
33
|
-
|
34
|
-
current_modified_at = Time.parse(org_unit.system_modified_at)
|
35
|
-
new_modified_at = Time.parse(attributes[:system_modified_at])
|
36
|
-
|
37
|
-
return false if current_modified_at >= new_modified_at
|
38
|
-
|
39
|
-
update_organisation_unit org_unit.id, attributes
|
40
|
-
|
41
|
-
rescue DMAO::API::Errors::OrganisationUnitNotFound
|
42
|
-
add_organisation_unit attributes
|
43
|
-
rescue DMAO::API::Errors::InvalidResponseLength
|
44
|
-
raise DMAO::Ingesters::Errors::IngestOrganisationUnitError.new("Multiple organisation units returned for system uuid #{attributes[:system_uuid]}.")
|
45
|
-
end
|
46
|
-
|
20
|
+
ingest_entity attributes
|
47
21
|
end
|
48
22
|
|
49
23
|
def link_child_to_parent child_system_uuid, parent_system_uuid
|
@@ -61,6 +35,14 @@ module DMAO
|
|
61
35
|
|
62
36
|
private
|
63
37
|
|
38
|
+
def add_entity attributes
|
39
|
+
add_organisation_unit attributes
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_entity id, attributes
|
43
|
+
update_organisation_unit id, attributes
|
44
|
+
end
|
45
|
+
|
64
46
|
def add_organisation_unit attributes
|
65
47
|
|
66
48
|
begin
|
@@ -91,22 +73,6 @@ module DMAO
|
|
91
73
|
|
92
74
|
end
|
93
75
|
|
94
|
-
def parse_unprocessable_errors errors
|
95
|
-
|
96
|
-
error_messages = ""
|
97
|
-
|
98
|
-
errors.each_with_index do |(k, v), index|
|
99
|
-
v.each_with_index do |msg, msg_index|
|
100
|
-
error_messages += "#{k} - #{msg}"
|
101
|
-
error_messages += ", " unless msg_index == v.size - 1
|
102
|
-
end
|
103
|
-
error_messages += ", " unless index == errors.size - 1
|
104
|
-
end
|
105
|
-
|
106
|
-
raise DMAO::Ingesters::Errors::IngestOrganisationUnitError.new("Invalid organisation unit details, #{error_messages}")
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
76
|
def find_unit_or_raise_link_error unit_system_uuid, error_message
|
111
77
|
|
112
78
|
begin
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'dmao_api'
|
2
|
+
require 'dmao/api/person'
|
3
|
+
require 'time'
|
4
|
+
require 'dmao/ingesters/generic/ingester'
|
5
|
+
require 'dmao/ingesters/errors/generic_ingester'
|
6
|
+
require 'dmao/ingesters/errors/empty_attributes'
|
7
|
+
require 'dmao/ingesters/errors/ingest_person_error'
|
8
|
+
|
9
|
+
module DMAO
|
10
|
+
module Ingesters
|
11
|
+
module Generic
|
12
|
+
|
13
|
+
class PeopleIngester < Ingester
|
14
|
+
|
15
|
+
ENTITY = DMAO::API::Person
|
16
|
+
ENTITY_ERROR = DMAO::Ingesters::Errors::IngestPersonError
|
17
|
+
ENTITY_ERROR_MESSAGE = "Invalid person details"
|
18
|
+
|
19
|
+
def ingest_person attributes={}
|
20
|
+
ingest_entity attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def add_entity attributes
|
26
|
+
add_person attributes
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_entity id, attributes
|
30
|
+
update_person id, attributes
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_person attributes
|
34
|
+
|
35
|
+
begin
|
36
|
+
DMAO::API::Person.create attributes
|
37
|
+
rescue DMAO::API::Errors::InstitutionNotFound
|
38
|
+
raise DMAO::Ingesters::Errors::IngestPersonError.new("Institution not found, cannot ingest person to non-existent institution")
|
39
|
+
rescue DMAO::API::Errors::InvalidPerson => e
|
40
|
+
parse_unprocessable_errors(e.errors)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_person id, attributes
|
46
|
+
|
47
|
+
begin
|
48
|
+
DMAO::API::Person.update id, attributes
|
49
|
+
rescue DMAO::API::Errors::PersonNotFound
|
50
|
+
raise DMAO::Ingesters::Errors::IngestPersonError.new("Person not found, cannot update person that does not exist")
|
51
|
+
rescue DMAO::API::Errors::InvalidPerson => e
|
52
|
+
parse_unprocessable_errors(e.errors)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dmao-generic-ingesters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Robinson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dmao_api
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.5.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,9 +126,12 @@ files:
|
|
126
126
|
- lib/dmao/ingesters/errors/empty_attributes.rb
|
127
127
|
- lib/dmao/ingesters/errors/generic_ingester.rb
|
128
128
|
- lib/dmao/ingesters/errors/ingest_organisation_unit_error.rb
|
129
|
+
- lib/dmao/ingesters/errors/ingest_person_error.rb
|
129
130
|
- lib/dmao/ingesters/errors/link_organisation_unit_error.rb
|
130
131
|
- lib/dmao/ingesters/generic.rb
|
132
|
+
- lib/dmao/ingesters/generic/ingester.rb
|
131
133
|
- lib/dmao/ingesters/generic/organisation_ingester.rb
|
134
|
+
- lib/dmao/ingesters/generic/people_ingester.rb
|
132
135
|
- lib/dmao/ingesters/generic/version.rb
|
133
136
|
homepage: https://github.com/lulibrary/DMAO-Generic-Ingesters
|
134
137
|
licenses:
|