12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/services/jumbotron/services/canonical/record_observation_evidence.rb', line 12
def call
unless change_set.any?
context.observation_batch_id = nil
context.historical_change_count = 0
return
end
batch = ObservationBatch.create!(
provider: provider,
adapter_scope: adapter_scope,
observed_at: observed_at,
metadata: {}
)
change_set.each do |entry|
HistoricalChange.create!(
observation_batch: batch,
subject_type: entry.subject.class.name,
subject_id: entry.subject.id,
attribute_name: entry.attribute,
previous_value: entry.previous,
new_value: entry.new_value,
observed_at: observed_at,
provider: provider
)
end
context.observation_batch_id = batch.id
context.historical_change_count = change_set.size
rescue ActiveRecord::RecordInvalid => e
context.fail!(
application_error: Jumbotron::Errors::Canonical::ObservationEvidenceFailedError.new(
details: { message: e.message }
)
)
end
|