Skip to content

Commit

Permalink
Adds preservation_event for fileset creation and saves the event on f…
Browse files Browse the repository at this point in the history
…ileset in fedora (#680)
  • Loading branch information
Devanshu Matlawala authored and alexBLR committed Oct 16, 2019
1 parent 8c1e18f commit 180156a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/actors/hyrax/actors/file_set_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Actors
# Actions are decoupled from controller logic so that they may be called from a controller or a background job.
class FileSetActor
include Lockable
include PreservationEvents
attr_reader :file_set, :user, :attributes

def initialize(file_set, user)
Expand All @@ -23,7 +24,10 @@ def create_content(file, relation = :original_file, from_url: false)
# If the file set doesn't have a title or label assigned, set a default.
file_set.label ||= label_for(file)
file_set.title = [file_set.label] if file_set.title.blank?
event_start = DateTime.current
return false unless file_set.save # Need to save to get an id
# create preservation_event for fileset creation (method in PreservationEvents module)
create_preservation_event(file_set, 'Replication (FileSet created)', event_start)
if from_url
# If ingesting from URL, don't spawn an IngestJob; instead
# reach into the FileActor and run the ingest with the file instance in
Expand Down
20 changes: 20 additions & 0 deletions app/lib/preservation_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# This module will be used to define preservation_event
# methods for work and fileset
module PreservationEvents
# @param object - work or file_set object
# @param event_type - preservation_event type
# @param event_start - start time for event
# @param event_details - details of the preservation_event
# @param software_version - software_version used if any
def create_preservation_event(object, event_type, event_start, event_details = nil, software_version = nil)
object.preservation_event_attributes = [{ event_details: event_details,
event_end: DateTime.current,
event_start: event_start,
event_type: event_type,
outcome: 'Success',
software_version: software_version }]
object.save!
end
end
12 changes: 12 additions & 0 deletions spec/actors/hyrax/actors/file_set_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,17 @@
expect(file_set.label).to eql(label)
end
end

context 'when a fileset is saved' do
before do
actor.create_content(file)
end

it 'adds a new preservation_event for fileset creation' do
expect(file_set.preservation_event.first.event_type).to eq ['Replication (FileSet created)']
expect(file_set.preservation_event.first.outcome).to eq ['Success']
expect(file_set.preservation_event.count).to eq 1
end
end
end
end

0 comments on commit 180156a

Please sign in to comment.