Class: WorkPreservationService

Inherits:
Object
  • Object
show all
Defined in:
app/services/work_preservation_service.rb

Overview

A service to create and store the preservation data for a given work. Currently it assumes this data will be stored in an AWS S3 bucket accessible with our AWS credentials. This preservation bucket is configured in our s3.yml file and we store it in a different availability region to make sure the data is properly distributed.

Constant Summary collapse

PRESERVATION_DIRECTORY =
"princeton_data_commons"

Instance Method Summary collapse

Constructor Details

#initialize(work_id:, path:, localhost: false) ⇒ WorkPreservationService

Returns a new instance of WorkPreservationService.

Parameters:

  • work_id (Integer)

    The ID of the work to preserve.

  • path (String)

    The path where the work will be preserved.

  • localhost (Bool) (defaults to: false)

    Set to true to preserve the files locally, i.e. not in AWS



13
14
15
16
17
18
# File 'app/services/work_preservation_service.rb', line 13

def initialize(work_id:, path:, localhost: false)
  @work = Work.find(work_id)
  @path = path
  @localhost = localhost
  @s3_query_service = nil
end

Instance Method Details

#preservation_metadataObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/services/work_preservation_service.rb', line 31

def 
  # Always use the post-curation file list
   = JSON.parse(@work.to_json(force_post_curation: true))
  # Make sure we don't include the preservation files as part of
  # the work's preservation metadata.
  ["files"] = ["files"].map do |file|
    if file["filename"].include?("/#{PRESERVATION_DIRECTORY}/")
      nil
    else
      file
    end
  end.compact
  .to_json
end

#preserve!String

Creates and stores the preservation files for the work.

Returns:

  • (String)

    The AWS S3 path where the files were stored



22
23
24
25
26
27
28
29
# File 'app/services/work_preservation_service.rb', line 22

def preserve!
  create_preservation_directory
  preserve_file(io: , filename: "metadata.json")
  preserve_file(io: datacite_io, filename: "datacite.xml")
  preserve_file(io: provenance_io, filename: "provenance.json")
  Rails.logger.info "Preservation files for work #{@work.id} saved to #{target_location}"
  target_location
end