• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

07 Apr 2025 06:36PM UTC coverage: 1.283% (-94.6%) from 95.862%
4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

Pull #1994

circleci

hectorcorrea
Switched to use the autocomplete that we aleady use for ROR. Integrated it with the existing logic for creators
Pull Request #1994: Started adding auto complete to contributors

0 of 46 new or added lines in 2 files covered. (0.0%)

4806 existing lines in 74 files now uncovered.

65 of 5065 relevant lines covered (1.28%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/services/file_rename_mapping_service.rb
1
# frozen_string_literal: true
2

3
# We sometimes have data with filenames that contain characters that AWS S3 cannot handle. In those cases we want to:
4
# 1.  Rename the files to something that is AWS legal. Replace all illegal characters with a _ (underscore)
5
# 2.  Ensure there are no duplicate file names after the renaming by appending a (1), (2) at the end of the filename
6
#     if the file has been renamed
7
# 3.  Keep a record of all of the file names as they originally existed and what they were renamed to
8
# 4.  The record goes into a file called files_renamed.txt, which contains a list of all files that have been renamed
9
#     and what they were renamed to, along with a timestamp
10
# 5.  This files_renamed.txt file gets added to the dataset as a payload file, akin to a README.txt or license.txt
UNCOV
11
class FileRenameMappingService
×
UNCOV
12
  attr_reader :upload_snapshot, :files, :renamed_files, :original_filenames
×
13

UNCOV
14
  def initialize(upload_snapshot:)
×
UNCOV
15
    @upload_snapshot = upload_snapshot
×
UNCOV
16
    @original_filenames = @upload_snapshot.files.map { |a| a["filename"] }
×
UNCOV
17
    @files = parse_files_to_rename
×
UNCOV
18
    @renamed_files = rename_files
×
UNCOV
19
  end
×
20

UNCOV
21
  def parse_files_to_rename
×
UNCOV
22
    files = []
×
UNCOV
23
    @original_filenames.each do |original_filename|
×
UNCOV
24
      files << FileRenameService.new(filename: original_filename)
×
UNCOV
25
    end
×
UNCOV
26
    files
×
UNCOV
27
  end
×
28

29
  # Make a hash containing all files that need renaming.
30
  # The key of the hash is the original filename.
31
  # The value of the hash is the re-named file with an index number appended.
UNCOV
32
  def rename_files
×
UNCOV
33
    @upload_snapshot.with_lock do
×
UNCOV
34
      @upload_snapshot.reload
×
UNCOV
35
      rename_index = 1
×
UNCOV
36
      renamed_files = {}
×
UNCOV
37
      @files.each do |file|
×
UNCOV
38
        next unless file.needs_rename?
×
UNCOV
39
        new_filename = file.new_filename(rename_index)
×
UNCOV
40
        renamed_files[file.original_filename] = new_filename
×
41
        # Also update the filename in the MigrationSnapshot
UNCOV
42
        @upload_snapshot.rename(file.original_filename, new_filename)
×
UNCOV
43
        rename_index += 1
×
UNCOV
44
      end
×
UNCOV
45
      @upload_snapshot.save
×
UNCOV
46
      renamed_files
×
UNCOV
47
    end
×
UNCOV
48
  end
×
49

50
  # A rename is needed if any of the original filenames need renaming
UNCOV
51
  def rename_needed?
×
UNCOV
52
    @files.each do |file|
×
UNCOV
53
      return true if file.needs_rename?
×
UNCOV
54
    end
×
UNCOV
55
    false
×
UNCOV
56
  end
×
57

58
  # Format: "Sep 19 2023"
UNCOV
59
  def rename_date
×
UNCOV
60
    Time.zone.now.strftime("%d %b %Y")
×
UNCOV
61
  end
×
62

UNCOV
63
  def renaming_document
×
UNCOV
64
    message = "Some files have been renamed to comply with AWS S3 storage requirements\n"
×
UNCOV
65
    message += "Rename date: #{rename_date}\n"
×
UNCOV
66
    message += "Original Filename\t Renamed File\n"
×
UNCOV
67
    @files.each do |file|
×
UNCOV
68
      next unless file.needs_rename?
×
UNCOV
69
      message += "#{file.original_filename}\t#{@renamed_files[file.original_filename]}\n"
×
UNCOV
70
    end
×
UNCOV
71
    message
×
UNCOV
72
  end
×
UNCOV
73
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc