dmao-generic-ingesters 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dmao/ingesters/errors/ingest_entity_error.rb +15 -0
- data/lib/dmao/ingesters/errors/ingest_funder_error.rb +17 -0
- data/lib/dmao/ingesters/errors/ingest_organisation_unit_error.rb +3 -1
- data/lib/dmao/ingesters/errors/ingest_person_error.rb +3 -1
- data/lib/dmao/ingesters/generic/funders_ingester.rb +34 -0
- data/lib/dmao/ingesters/generic/ingester.rb +26 -6
- data/lib/dmao/ingesters/generic/people_ingester.rb +3 -26
- data/lib/dmao/ingesters/generic/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a71389705fcf4841e99d08ff0095a27663f0502
|
4
|
+
data.tar.gz: 998ac6edd53d0b9cb88d634825e33d6540221789
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2f670e91b1df80c0fbbf1ecae5f0e1ee3f89cc834b91eb8ab6cda7cd0b8d8da5f543151af1bf25358b6f420125001a5aabf16adbba2c016bddf942db2ff9c79
|
7
|
+
data.tar.gz: 35a6f05547877fd292b65af83ba9e1ca2a63f8f09338e5243bc0d7d5ca236cd51a9f9c6bbf55f0e0f32f4517cc64a8b0e6c94927ba102ab99b06b06639cb5231
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'dmao/ingesters/errors/ingest_entity_error'
|
2
|
+
|
3
|
+
module DMAO
|
4
|
+
module Ingesters
|
5
|
+
module Errors
|
6
|
+
|
7
|
+
class IngestFunderError < IngestEntityError
|
8
|
+
|
9
|
+
def initialize(msg="Error ingesting funder.")
|
10
|
+
super(msg)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'dmao/ingesters/errors/ingest_entity_error'
|
2
|
+
|
1
3
|
module DMAO
|
2
4
|
module Ingesters
|
3
5
|
module Errors
|
4
6
|
|
5
|
-
class IngestOrganisationUnitError <
|
7
|
+
class IngestOrganisationUnitError < IngestEntityError
|
6
8
|
|
7
9
|
def initialize(msg="Error ingesting organisation unit.")
|
8
10
|
super(msg)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'dmao_api'
|
2
|
+
require 'dmao/ingesters/generic/ingester'
|
3
|
+
require 'dmao/ingesters/errors/ingest_funder_error'
|
4
|
+
|
5
|
+
module DMAO
|
6
|
+
module Ingesters
|
7
|
+
module Generic
|
8
|
+
|
9
|
+
class FundersIngester< Ingester
|
10
|
+
|
11
|
+
ENTITY = DMAO::API::Funder
|
12
|
+
ENTITY_ERROR = DMAO::Ingesters::Errors::IngestFunderError
|
13
|
+
INVALID_ENTITY_ERROR = DMAO::API::Errors::InvalidFunder
|
14
|
+
ENTITY_ERROR_MESSAGE = "Invalid funder details"
|
15
|
+
|
16
|
+
def ingest_funder attributes={}
|
17
|
+
ingest_entity attributes
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def add_funder attributes
|
23
|
+
add_entity attributes
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_funder id, attributes
|
27
|
+
update_entity id, attributes
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -2,6 +2,7 @@ require 'time'
|
|
2
2
|
require 'dmao_api'
|
3
3
|
require 'dmao/ingesters/errors/generic_ingester'
|
4
4
|
require 'dmao/ingesters/errors/empty_attributes'
|
5
|
+
require 'dmao/ingesters/errors/ingest_entity_error'
|
5
6
|
|
6
7
|
module DMAO
|
7
8
|
module Ingesters
|
@@ -11,6 +12,7 @@ module DMAO
|
|
11
12
|
|
12
13
|
ENTITY = nil
|
13
14
|
ENTITY_ERROR = nil
|
15
|
+
INVALID_ENTITY_ERROR = nil
|
14
16
|
ENTITY_ERROR_MESSAGE = nil
|
15
17
|
|
16
18
|
def initialize(api_url=nil, api_token=nil, institution_id=nil)
|
@@ -27,8 +29,6 @@ module DMAO
|
|
27
29
|
|
28
30
|
def ingest_entity attributes = {}
|
29
31
|
|
30
|
-
entity_name = self.class::ENTITY.to_s.split('::')[-1].gsub(/[A-Z]/, " \\0").strip.downcase
|
31
|
-
|
32
32
|
raise DMAO::Ingesters::Errors::EmptyAttributes.new("Cannot ingest #{entity_name} without attributes.") if attributes.nil? || attributes.empty?
|
33
33
|
|
34
34
|
begin
|
@@ -66,12 +66,32 @@ module DMAO
|
|
66
66
|
|
67
67
|
end
|
68
68
|
|
69
|
-
def add_entity
|
70
|
-
|
69
|
+
def add_entity attributes={}
|
70
|
+
|
71
|
+
begin
|
72
|
+
self.class::ENTITY.create attributes
|
73
|
+
rescue DMAO::API::Errors::InstitutionNotFound
|
74
|
+
raise self.class::ENTITY_ERROR.new("Institution not found, cannot ingest #{entity_name} to non-existent institution")
|
75
|
+
rescue self.class::INVALID_ENTITY_ERROR => e
|
76
|
+
parse_unprocessable_errors(e.errors)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def update_entity entity_id, attributes={}
|
82
|
+
|
83
|
+
begin
|
84
|
+
self.class::ENTITY.update entity_id, attributes
|
85
|
+
rescue DMAO::API::Errors::EntityNotFound
|
86
|
+
raise self.class::ENTITY_ERROR.new("#{entity_name.capitalize} not found, cannot update #{entity_name} that does not exist")
|
87
|
+
rescue self.class::INVALID_ENTITY_ERROR => e
|
88
|
+
parse_unprocessable_errors(e.errors)
|
89
|
+
end
|
90
|
+
|
71
91
|
end
|
72
92
|
|
73
|
-
def
|
74
|
-
|
93
|
+
def entity_name
|
94
|
+
self.class::ENTITY.to_s.split('::')[-1].gsub(/[A-Z]/, " \\0").strip.downcase
|
75
95
|
end
|
76
96
|
|
77
97
|
end
|
@@ -14,6 +14,7 @@ module DMAO
|
|
14
14
|
|
15
15
|
ENTITY = DMAO::API::Person
|
16
16
|
ENTITY_ERROR = DMAO::Ingesters::Errors::IngestPersonError
|
17
|
+
INVALID_ENTITY_ERROR = DMAO::API::Errors::InvalidPerson
|
17
18
|
ENTITY_ERROR_MESSAGE = "Invalid person details"
|
18
19
|
|
19
20
|
def ingest_person attributes={}
|
@@ -22,36 +23,12 @@ module DMAO
|
|
22
23
|
|
23
24
|
private
|
24
25
|
|
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
26
|
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
|
-
|
27
|
+
add_entity attributes
|
43
28
|
end
|
44
29
|
|
45
30
|
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
|
-
|
31
|
+
update_entity id, attributes
|
55
32
|
end
|
56
33
|
|
57
34
|
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.4.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-04-
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dmao_api
|
@@ -125,10 +125,13 @@ files:
|
|
125
125
|
- dmao-generic-ingesters.gemspec
|
126
126
|
- lib/dmao/ingesters/errors/empty_attributes.rb
|
127
127
|
- lib/dmao/ingesters/errors/generic_ingester.rb
|
128
|
+
- lib/dmao/ingesters/errors/ingest_entity_error.rb
|
129
|
+
- lib/dmao/ingesters/errors/ingest_funder_error.rb
|
128
130
|
- lib/dmao/ingesters/errors/ingest_organisation_unit_error.rb
|
129
131
|
- lib/dmao/ingesters/errors/ingest_person_error.rb
|
130
132
|
- lib/dmao/ingesters/errors/link_organisation_unit_error.rb
|
131
133
|
- lib/dmao/ingesters/generic.rb
|
134
|
+
- lib/dmao/ingesters/generic/funders_ingester.rb
|
132
135
|
- lib/dmao/ingesters/generic/ingester.rb
|
133
136
|
- lib/dmao/ingesters/generic/organisation_ingester.rb
|
134
137
|
- lib/dmao/ingesters/generic/people_ingester.rb
|