ddr-batch 2.0.0.alpha.1 → 2.0.0.alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/ddr/batch/batch_object.rb +39 -52
- data/app/models/ddr/batch/batch_object_relationship.rb +78 -6
- data/app/models/ddr/batch/error.rb +6 -0
- data/app/models/ddr/batch/ingest_batch_object.rb +1 -8
- data/app/models/ddr/batch/update_batch_object.rb +3 -3
- data/lib/ddr/batch/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 824038c27b5269a2816f0d253891c345a69e42c6
|
4
|
+
data.tar.gz: 06b2646d38c6975037358d695ddd83d8a6231ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 293bf55a24e1fc20b7139af536965a1bff028e23c27033fca4b879c633c381faa39ef7b81d1c1888cb55d3811aaec7fec27f183ae7c0db7ddd43267e30386078
|
7
|
+
data.tar.gz: 66cbc236d73feb005e5c276b8072450462e121c69e81ebdf0fc46e36cef4e734bb28f8199b892cd220d75a769d1c245546db07354ee6f7413f2cf94a0c6ec4ec
|
@@ -31,8 +31,11 @@ module Ddr::Batch
|
|
31
31
|
return pids
|
32
32
|
end
|
33
33
|
|
34
|
+
def error_prefix
|
35
|
+
I18n.t('ddr.batch.errors.prefix', :identifier => identifier, :id => id)
|
36
|
+
end
|
37
|
+
|
34
38
|
def validate
|
35
|
-
@error_prefix = I18n.t('ddr.batch.errors.prefix', :identifier => identifier, :id => id)
|
36
39
|
errors = []
|
37
40
|
errors += validate_model if model
|
38
41
|
errors += validate_datastreams if batch_object_datastreams
|
@@ -66,7 +69,7 @@ module Ddr::Batch
|
|
66
69
|
begin
|
67
70
|
model.constantize
|
68
71
|
rescue NameError
|
69
|
-
errs << "#{
|
72
|
+
errs << "#{error_prefix} Invalid model name: #{model}"
|
70
73
|
end
|
71
74
|
return errs
|
72
75
|
end
|
@@ -76,23 +79,23 @@ module Ddr::Batch
|
|
76
79
|
batch_object_datastreams.each do |d|
|
77
80
|
if model_datastream_keys.present?
|
78
81
|
unless model_datastream_keys.include?(d.name.to_sym)
|
79
|
-
errs << "#{
|
82
|
+
errs << "#{error_prefix} Invalid datastream name for #{model}: #{d.name}"
|
80
83
|
end
|
81
84
|
end
|
82
85
|
unless BatchObjectDatastream::PAYLOAD_TYPES.include?(d.payload_type)
|
83
|
-
errs << "#{
|
86
|
+
errs << "#{error_prefix} Invalid payload type for #{d.name} datastream: #{d.payload_type}"
|
84
87
|
end
|
85
88
|
if d.payload_type.eql?(BatchObjectDatastream::PAYLOAD_TYPE_FILENAME)
|
86
89
|
unless File.readable?(d.payload)
|
87
|
-
errs << "#{
|
90
|
+
errs << "#{error_prefix} Missing or unreadable file for #{d[:name]} datastream: #{d[:payload]}"
|
88
91
|
end
|
89
92
|
end
|
90
93
|
if d.checksum && !d.checksum_type
|
91
|
-
errs << "#{
|
94
|
+
errs << "#{error_prefix} Must specify checksum type if providing checksum for #{d.name} datastream"
|
92
95
|
end
|
93
96
|
if d.checksum_type
|
94
97
|
unless Ddr::Datastreams::CHECKSUM_TYPES.include?(d.checksum_type)
|
95
|
-
errs << "#{
|
98
|
+
errs << "#{error_prefix} Invalid checksum type for #{d.name} datastream: #{d.checksum_type}"
|
96
99
|
end
|
97
100
|
end
|
98
101
|
end
|
@@ -102,44 +105,8 @@ module Ddr::Batch
|
|
102
105
|
def validate_relationships
|
103
106
|
errs = []
|
104
107
|
batch_object_relationships.each do |r|
|
105
|
-
|
106
|
-
|
107
|
-
errs << "#{@error_prefix} Invalid object_type for #{r[:name]} relationship: #{r[:object_type]}"
|
108
|
-
end
|
109
|
-
if r[:object_type].eql?(BatchObjectRelationship::OBJECT_TYPE_PID)
|
110
|
-
if batch.present? && batch.found_pids.keys.include?(r[:object])
|
111
|
-
obj_model = batch.found_pids[r[:object]]
|
112
|
-
else
|
113
|
-
begin
|
114
|
-
obj = ActiveFedora::Base.find(r[:object], :cast => true)
|
115
|
-
obj_model = obj.class.name
|
116
|
-
if batch.present?
|
117
|
-
batch.add_found_pid(obj.pid, obj_model)
|
118
|
-
end
|
119
|
-
rescue ActiveFedora::ObjectNotFoundError
|
120
|
-
pid_in_batch = false
|
121
|
-
if batch.present?
|
122
|
-
if batch.pre_assigned_pids.include?(r[:object])
|
123
|
-
pid_in_batch = true
|
124
|
-
end
|
125
|
-
end
|
126
|
-
unless pid_in_batch
|
127
|
-
errs << "#{@error_prefix} #{r[:name]} relationship object does not exist: #{r[:object]}"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
if obj_model
|
132
|
-
relationship_reflection = Ddr::Utils.relationship_object_reflection(model, r[:name])
|
133
|
-
if relationship_reflection
|
134
|
-
klass = Ddr::Utils.reflection_object_class(relationship_reflection)
|
135
|
-
if klass
|
136
|
-
errs << "#{@error_prefix} #{r[:name]} relationship object #{r[:object]} exists but is not a(n) #{klass}" unless batch.found_pids[r[:object]].eql?(klass.name)
|
137
|
-
end
|
138
|
-
else
|
139
|
-
errs << "#{@error_prefix} #{model} does not define a(n) #{r[:name]} relationship"
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
108
|
+
r.valid?
|
109
|
+
errs += r.errors.messages.values.map { |msg| "#{error_prefix} msg" }
|
143
110
|
end
|
144
111
|
return errs
|
145
112
|
end
|
@@ -147,8 +114,8 @@ module Ddr::Batch
|
|
147
114
|
def verify_repository_object
|
148
115
|
verifications = {}
|
149
116
|
begin
|
150
|
-
repo_object = ActiveFedora::Base.find(pid
|
151
|
-
rescue ActiveFedora::
|
117
|
+
repo_object = ActiveFedora::Base.find(pid)
|
118
|
+
rescue ActiveFedora::ObjectNotFoundError
|
152
119
|
verifications["Object exists in repository"] = VERIFICATION_FAIL
|
153
120
|
else
|
154
121
|
verifications["Object exists in repository"] = VERIFICATION_PASS
|
@@ -221,11 +188,23 @@ module Ddr::Batch
|
|
221
188
|
end
|
222
189
|
|
223
190
|
def verify_relationship(repo_object, relationship)
|
191
|
+
# if PID, proceed as below
|
192
|
+
# if AR rec ID,
|
193
|
+
# retrieve AR rec
|
194
|
+
# if AR rec has PID, proceed as below using AR rec PID
|
195
|
+
# if not, error (should not occur)
|
196
|
+
repo_object_id = case
|
197
|
+
when relationship.object_rec_id?
|
198
|
+
referent = batch.batch_objects.find(relationship.object)
|
199
|
+
referent.pid
|
200
|
+
when relationship.object_repo_id?
|
201
|
+
relationship.object
|
202
|
+
end
|
224
203
|
relationship_reflection = Ddr::Utils.relationship_object_reflection(model, relationship.name)
|
225
204
|
relationship_object_class = Ddr::Utils.reflection_object_class(relationship_reflection)
|
226
205
|
relationship_object = repo_object.send(relationship.name)
|
227
206
|
if !relationship_object.nil? &&
|
228
|
-
relationship_object.pid.eql?(
|
207
|
+
relationship_object.pid.eql?(repo_object_id) &&
|
229
208
|
relationship_object.is_a?(relationship_object_class)
|
230
209
|
VERIFICATION_PASS
|
231
210
|
else
|
@@ -275,11 +254,19 @@ module Ddr::Batch
|
|
275
254
|
end
|
276
255
|
|
277
256
|
def add_relationship(repo_object, relationship)
|
278
|
-
|
279
|
-
|
280
|
-
|
257
|
+
repo_object_id = case
|
258
|
+
when relationship.object_rec_id?
|
259
|
+
referent = batch.batch_objects.find(relationship[:object])
|
260
|
+
referent.pid
|
261
|
+
when relationship.object_repo_id?
|
262
|
+
relationship[:object]
|
263
|
+
end
|
264
|
+
if repo_object_id.present?
|
265
|
+
relationship_object = ActiveFedora::Base.find(repo_object_id)
|
266
|
+
repo_object.send("#{relationship[:name]}=", relationship_object)
|
267
|
+
else
|
268
|
+
raise Ddr::Batch::Error, "Unable to determine repository ID for relationship #{relationship.id}"
|
281
269
|
end
|
282
|
-
repo_object.send("#{relationship[:name]}=", relationship_object)
|
283
270
|
return repo_object
|
284
271
|
end
|
285
272
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Ddr::Batch
|
2
|
-
|
3
2
|
class BatchObjectRelationship < ActiveRecord::Base
|
4
|
-
|
3
|
+
|
5
4
|
belongs_to :batch_object, :inverse_of => :batch_object_relationships
|
6
5
|
|
7
6
|
RELATIONSHIP_ADMIN_POLICY = "admin_policy"
|
@@ -15,12 +14,85 @@ module Ddr::Batch
|
|
15
14
|
RELATIONSHIP_COMPONENT, RELATIONSHIP_ATTACHED_TO ]
|
16
15
|
|
17
16
|
OPERATION_ADD = "ADD"
|
18
|
-
OPERATION_UPDATE = "UPDATE"
|
19
17
|
OPERATION_DELETE = "DELETE"
|
18
|
+
OPERATION_UPDATE = "UPDATE"
|
20
19
|
|
21
|
-
|
20
|
+
OPERATIONS = [ OPERATION_ADD, OPERATION_DELETE, OPERATION_UPDATE ]
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
OBJECT_TYPE_REC_ID = "REC_ID"
|
23
|
+
OBJECT_TYPE_REPO_ID = "REPO_ID"
|
24
|
+
|
25
|
+
OBJECT_TYPES = [ OBJECT_TYPE_REC_ID, OBJECT_TYPE_REPO_ID ]
|
26
|
+
|
27
|
+
validates_presence_of :object, :batch_object
|
28
|
+
|
29
|
+
validates_inclusion_of :name, in: RELATIONSHIPS, message: 'Invalid relationship name'
|
30
|
+
validates_inclusion_of :operation, in: OPERATIONS, message: 'Invalid relationship operation'
|
31
|
+
validates_inclusion_of :object_type, in: OBJECT_TYPES, message: 'Invalid relationship object type'
|
32
|
+
validate :record_must_be_in_batch, if: :object_rec_id?
|
33
|
+
validate :repo_object_must_exist, if: :object_repo_id?
|
34
|
+
validate :relationship_name_must_be_valid_for_model
|
35
|
+
|
36
|
+
delegate :batch, to: :batch_object
|
37
|
+
delegate :batch_objects, to: :batch
|
38
|
+
delegate :found_pids, to: :batch
|
39
|
+
delegate :add_found_pid, to: :batch
|
25
40
|
|
41
|
+
def object_rec_id?
|
42
|
+
object_type == OBJECT_TYPE_REC_ID
|
43
|
+
end
|
44
|
+
|
45
|
+
def object_repo_id?
|
46
|
+
object_type == OBJECT_TYPE_REPO_ID
|
47
|
+
end
|
48
|
+
|
49
|
+
def record_must_be_in_batch
|
50
|
+
batch_objects.find(object).present?
|
51
|
+
rescue ActiveRecord::RecordNotFound
|
52
|
+
errors.add(:object, "#{object} not found in this batch")
|
53
|
+
end
|
54
|
+
|
55
|
+
def repo_object_must_exist
|
56
|
+
unless found_pids.keys.include?(object)
|
57
|
+
obj = ActiveFedora::Base.find(object)
|
58
|
+
add_found_pid(obj.id, obj.class.name)
|
59
|
+
end
|
60
|
+
rescue ActiveFedora::ObjectNotFoundError
|
61
|
+
errors.add(:object, "#{object} not found in repository")
|
62
|
+
end
|
63
|
+
|
64
|
+
def relationship_name_must_be_valid_for_model
|
65
|
+
unless Ddr::Utils.relationship_object_reflection(batch_object.model, name).present?
|
66
|
+
errors.add(:name, "#{batch_object.model} does not define a(n) #{name} relationship")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def object_model_must_be_correct_for_relationship
|
71
|
+
if relationship_reflection = Ddr::Utils.relationship_object_reflection(batch_object.model, name)
|
72
|
+
klass = Ddr::Utils.reflection_object_class(relationship_reflection)
|
73
|
+
if klass.present?
|
74
|
+
unless object_model == klass.name
|
75
|
+
errors.add(:object, "#{name} relationship object #{object} exists but is not a(n) #{klass}")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def object_model
|
84
|
+
case object_type
|
85
|
+
when OBJECT_TYPE_REC_ID
|
86
|
+
batch_objects.find(object).model
|
87
|
+
when OBJECT_TYPE_REPO_ID
|
88
|
+
if found_pids.keys.include?(object)
|
89
|
+
found_pids[object]
|
90
|
+
else
|
91
|
+
obj = ActiveFedora::Base.find(object)
|
92
|
+
add_found_pid(obj.id, obj.class.name)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
26
98
|
end
|
@@ -4,8 +4,7 @@ module Ddr::Batch
|
|
4
4
|
|
5
5
|
def local_validations
|
6
6
|
errors = []
|
7
|
-
errors << "#{
|
8
|
-
errors += validate_pre_assigned_pid if pid
|
7
|
+
errors << "#{error_prefix} Model required for INGEST operation" unless model
|
9
8
|
errors
|
10
9
|
end
|
11
10
|
|
@@ -28,12 +27,6 @@ module Ddr::Batch
|
|
28
27
|
|
29
28
|
private
|
30
29
|
|
31
|
-
def validate_pre_assigned_pid
|
32
|
-
errs = []
|
33
|
-
errs << "#{@error_prefix} #{pid} already exists in repository" if ActiveFedora::Base.exists?(pid)
|
34
|
-
return errs
|
35
|
-
end
|
36
|
-
|
37
30
|
def ingest(user, opts = {})
|
38
31
|
repo_object = create_repository_object
|
39
32
|
if !repo_object.nil? && !repo_object.new_record?
|
@@ -4,12 +4,12 @@ module Ddr::Batch
|
|
4
4
|
|
5
5
|
def local_validations
|
6
6
|
errs = []
|
7
|
-
errs << "#{
|
7
|
+
errs << "#{error_prefix} PID required for UPDATE operation" unless pid
|
8
8
|
if pid
|
9
9
|
if ActiveFedora::Base.exists?(pid)
|
10
|
-
errs << "#{
|
10
|
+
errs << "#{error_prefix} #{batch.user.user_key} not permitted to edit #{pid}" unless batch.user.can?(:edit, ActiveFedora::Base.find(pid, :cast => true))
|
11
11
|
else
|
12
|
-
errs << "#{
|
12
|
+
errs << "#{error_prefix} PID #{pid} not found in repository" unless ActiveFedora::Base.exists?(pid)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
errs
|
data/lib/ddr/batch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddr-batch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.alpha.
|
4
|
+
version: 2.0.0.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Coble
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- app/models/ddr/batch/batch_object_attribute.rb
|
184
184
|
- app/models/ddr/batch/batch_object_datastream.rb
|
185
185
|
- app/models/ddr/batch/batch_object_relationship.rb
|
186
|
+
- app/models/ddr/batch/error.rb
|
186
187
|
- app/models/ddr/batch/ingest_batch_object.rb
|
187
188
|
- app/models/ddr/batch/update_batch_object.rb
|
188
189
|
- app/scripts/ddr/batch/batch_processor.rb
|