• 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/models/migration_upload_snapshot.rb
1
# frozen_string_literal: true
UNCOV
2
class MigrationUploadSnapshot < UploadSnapshot
×
UNCOV
3
  def store_files(s3_files, pre_existing_files: [])
×
UNCOV
4
    self.files = s3_files.map { |file| { "filename" => file.filename_display, "checksum" => file.checksum, "migrate_status" => "started" } }
×
UNCOV
5
    files.concat pre_existing_files if pre_existing_files.present?
×
UNCOV
6
  end
×
7

UNCOV
8
  def mark_error(s3_file, error_message)
×
UNCOV
9
    index = find_file(s3_file.filename_display)
×
UNCOV
10
    if index.present?
×
UNCOV
11
      files[index]["migrate_status"] = "error"
×
UNCOV
12
      files[index]["migrate_error"] = error_message
×
UNCOV
13
    end
×
UNCOV
14
  end
×
15

16
  # Rename a file
UNCOV
17
  def rename(old_filename, new_filename)
×
UNCOV
18
    index = find_file(old_filename)
×
UNCOV
19
    files[index]["original_filename"] = old_filename
×
UNCOV
20
    files[index]["filename"] = new_filename
×
UNCOV
21
  end
×
22

UNCOV
23
  def mark_complete(s3_file)
×
UNCOV
24
    index = find_file(s3_file.filename)
×
UNCOV
25
    if index.present?
×
UNCOV
26
      files[index]["migrate_status"] = "complete"
×
UNCOV
27
      files[index].delete("migrate_error")
×
28

29
      # Retrieve the checksum from AWS, as this often differs from what is migrated from DSpace
30
      # Please see https://github.com/pulibrary/pdc_describe/issues/1413
UNCOV
31
      updated = s3_file.s3_query_service.get_s3_object_attributes(key: s3_file.filename)
×
UNCOV
32
      updated_checksum = updated[:etag]
×
33

UNCOV
34
      files[index]["checksum"] = updated_checksum
×
UNCOV
35
      finalize_migration if migration_complete?
×
UNCOV
36
    end
×
UNCOV
37
  end
×
38

UNCOV
39
  def complete?(s3_file)
×
UNCOV
40
    index = find_complete_file(s3_file.filename, s3_file.checksum)
×
UNCOV
41
    !index.nil?
×
UNCOV
42
  end
×
43

UNCOV
44
  def migration_complete?
×
UNCOV
45
    files.select { |file| file.keys.include?("migrate_status") }.map { |file| file["migrate_status"] }.uniq == ["complete"]
×
UNCOV
46
  end
×
47

UNCOV
48
  def migration_complete_with_errors?
×
UNCOV
49
    return false if migration_complete?
×
UNCOV
50
    files.select { |file| file.keys.include?("migrate_status") }.map { |file| file["migrate_status"] }.uniq.exclude?("started")
×
UNCOV
51
  end
×
52

UNCOV
53
  def existing_files
×
UNCOV
54
    super.select { |file| file["migrate_status"].nil? || file["migrate_status"] == "complete" }
×
UNCOV
55
  end
×
56

UNCOV
57
  def finalize_migration
×
UNCOV
58
    migration_start = WorkActivity.activities_for_work(work.id, [WorkActivity::MIGRATION_START]).order(created_at: :desc)
×
UNCOV
59
    if migration_start.count == 0
×
UNCOV
60
      Honeybadger.notify("Finalized a migration with no start! Work: #{work.id} Migration Snapshot: #{id}")
×
UNCOV
61
      WorkActivity.add_work_activity(work.id, { migration_id: id, message: "Migration from Dataspace is complete." }.to_json,
×
UNCOV
62
                                     nil, activity_type: WorkActivity::MIGRATION_COMPLETE)
×
UNCOV
63
    else
×
UNCOV
64
      migration = migration_start.first
×
UNCOV
65
      data = JSON.parse(migration.message)
×
UNCOV
66
      message = "#{data['file_count']} #{'file'.pluralize(data['file_count'])} and #{data['directory_count']} #{'directory'.pluralize(data['directory_count'])} have migrated from Dataspace."
×
UNCOV
67
      WorkActivity.add_work_activity(work.id, { migration_id: id, message: }.to_json,
×
UNCOV
68
                                                migration.created_by_user_id, activity_type: WorkActivity::MIGRATION_COMPLETE)
×
UNCOV
69
    end
×
UNCOV
70
  end
×
71

UNCOV
72
  private
×
73

UNCOV
74
    def find_file(filename)
×
UNCOV
75
      index = files.index { |file| file["filename"] == filename && (file["migrate_status"] == "started" || file["migrate_status"] == "error") }
×
UNCOV
76
      if index.nil?
×
UNCOV
77
        Honeybadger.notify("Migrated a file that was not part of the orginal Migration: #{id} for work #{work_id}: #{filename}")
×
UNCOV
78
      end
×
UNCOV
79
      index
×
UNCOV
80
    end
×
81

UNCOV
82
    def find_complete_file(filename, checksum)
×
UNCOV
83
      files.index { |file| (file["filename"] == filename) && (file["checksum"] == checksum) && (file["migrate_status"] == "complete") }
×
UNCOV
84
    end
×
UNCOV
85
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