Class: WorkPublishService

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

Overview

A service to move work data from the post-curation bucket to the embargo bucket for currently embargoed works

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work:, current_user:) ⇒ WorkPublishService

Returns a new instance of WorkPublishService.

Parameters:

  • work_id (Integer)

    The ID of the work to preserve.



9
10
11
12
13
# File 'app/services/work_publish_service.rb', line 9

def initialize(work:, current_user:)
  @work = work
  @current_user = current_user
  @pul_s3_client = S3QueryService.new(work, PULS3Client::PRECURATION)
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



6
7
8
# File 'app/services/work_publish_service.rb', line 6

def current_user
  @current_user
end

#pul_s3_clientObject (readonly)

Returns the value of attribute pul_s3_client.



6
7
8
# File 'app/services/work_publish_service.rb', line 6

def pul_s3_client
  @pul_s3_client
end

#workObject (readonly)

Returns the value of attribute work.



6
7
8
# File 'app/services/work_publish_service.rb', line 6

def work
  @work
end

Instance Method Details

#publishObject

Copies the existing files from the pre-curation bucket to the target bucket (postcuration or embargo).

Notice that the copy process happens at AWS (i.e. the files are not downloaded and re-uploaded).

Raises:

  • (StandardError)


17
18
19
20
21
22
23
24
25
# File 'app/services/work_publish_service.rb', line 17

def publish
  s3_target_query_service = S3QueryService.new(work, target_mode)

  s3_dir = work.find_bucket_s3_dir(bucket_name: s3_target_query_service.bucket_name)
  raise(StandardError, "Attempting to publish a Work with an existing S3 Bucket directory for: #{target_bucket}/#{work.s3_object_key}") unless s3_dir.nil?

  # Copy the pre-curation S3 Objects to the target S3 Bucket.
  publish_files(current_user)
end