Class: PULDspaceAwsConnector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work, dspace_doi) ⇒ PULDspaceAwsConnector

Returns a new instance of PULDspaceAwsConnector.



5
6
7
8
9
# File 'app/services/pul_dspace_aws_connector.rb', line 5

def initialize(work, dspace_doi)
  @work = work
  @ark = work.ark&.gsub("ark:/", "")
  @dspace_doi = dspace_doi
end

Instance Attribute Details

#arkObject (readonly)

Returns the value of attribute ark.



3
4
5
# File 'app/services/pul_dspace_aws_connector.rb', line 3

def ark
  @ark
end

#dspace_doiObject (readonly)

Returns the value of attribute dspace_doi.



3
4
5
# File 'app/services/pul_dspace_aws_connector.rb', line 3

def dspace_doi
  @dspace_doi
end

#migration_snapshotObject (readonly)

Returns the value of attribute migration_snapshot.



3
4
5
# File 'app/services/pul_dspace_aws_connector.rb', line 3

def migration_snapshot
  @migration_snapshot
end

#workObject (readonly)

Returns the value of attribute work.



3
4
5
# File 'app/services/pul_dspace_aws_connector.rb', line 3

def work
  @work
end

Instance Method Details

#aws_filesObject



28
29
30
31
# File 'app/services/pul_dspace_aws_connector.rb', line 28

def aws_files
  return [] if ark.nil? || dspace_doi.nil?
  @aws_files ||= work.s3_query_service.client_s3_files(reload: true, bucket_name: dspace_bucket_name, prefix: dspace_doi.tr(".", "-"))
end

#upload_to_s3(dspace_files) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/pul_dspace_aws_connector.rb', line 11

def upload_to_s3(dspace_files)
  dspace_files.map do |dspace_file|
    filename = dspace_file.filename
    match_dspace_file = dspace_file.clone
    basename = File.basename(dspace_file.filename_display)
    match_dspace_file.filename = dspace_file.filename_display
    io = File.open(filename)
    size = File.size(filename)
    key = work.s3_query_service.upload_file(io:, filename: basename, md5_digest: dspace_file.checksum, size:)
    if key
      { key:, file: match_dspace_file, error: nil }
    else
      { key: nil, file: match_dspace_file, error: "An error uploading #{filename}.  Please try again." }
    end
  end
end