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

pulibrary / pdc_describe / 1aaf6302-d8cf-4943-bb96-5e86951c32a3

pending completion
1aaf6302-d8cf-4943-bb96-5e86951c32a3

Pull #1079

circleci

Bess Sadler
Nil safe doi gsub
Pull Request #1079: Nil safe collection title

2 of 2 new or added lines in 1 file covered. (100.0%)

1777 of 2063 relevant lines covered (86.14%)

100.37 hits per line

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

94.52
/app/models/work.rb
1
# frozen_string_literal: true
2

3
# rubocop:disable Metrics/ClassLength
4
class Work < ApplicationRecord
1✔
5
  # Errors for cases where there is no valid Collection
6
  class InvalidCollectionError < ::ArgumentError; end
1✔
7

8
  has_many :work_activity, -> { order(updated_at: :desc) }, dependent: :destroy
148✔
9
  has_many :user_work, -> { order(updated_at: :desc) }, dependent: :destroy
9✔
10
  has_many :upload_snapshots, -> { order(updated_at: :desc) }, dependent: :destroy
6✔
11
  has_many_attached :pre_curation_uploads, service: :amazon_pre_curation
1✔
12

13
  belongs_to :collection
1✔
14
  belongs_to :curator, class_name: "User", foreign_key: "curator_user_id", optional: true
1✔
15

16
  attribute :work_type, :string, default: "DATASET"
1✔
17
  attribute :profile, :string, default: "DATACITE"
1✔
18

19
  attr_accessor :user_entered_doi
1✔
20

21
  alias state_history user_work
1✔
22

23
  include AASM
1✔
24

25
  aasm column: :state do
1✔
26
    state :none, inital: true
1✔
27
    state :draft, :awaiting_approval, :approved, :withdrawn, :tombstone
1✔
28

29
    event :draft, after: :draft_doi do
1✔
30
      transitions from: :none, to: :draft, guard: :valid_to_draft
1✔
31
    end
32

33
    event :complete_submission do
1✔
34
      transitions from: :draft, to: :awaiting_approval, guard: :valid_to_submit
1✔
35
    end
36

37
    event :request_changes do
1✔
38
      transitions from: :awaiting_approval, to: :awaiting_approval, guard: :valid_to_submit
1✔
39
    end
40

41
    event :approve do
1✔
42
      transitions from: :awaiting_approval, to: :approved, guard: :valid_to_approve, after: :publish
1✔
43
    end
44

45
    event :withdraw do
1✔
46
      transitions from: [:draft, :awaiting_approval, :approved], to: :withdrawn
1✔
47
    end
48

49
    event :resubmit do
1✔
50
      transitions from: :withdrawn, to: :draft
1✔
51
    end
52

53
    event :remove do
1✔
54
      transitions from: :withdrawn, to: :tombstone
1✔
55
    end
56

57
    after_all_events :track_state_change
1✔
58
  end
59

60
  def state=(new_state)
1✔
61
    new_state_sym = new_state.to_sym
180✔
62
    valid_states = self.class.aasm.states.map(&:name)
180✔
63
    raise(StandardError, "Invalid state '#{new_state}'") unless valid_states.include?(new_state_sym)
180✔
64
    aasm_write_state_without_persistence(new_state_sym)
179✔
65
  end
66

67
  ##
68
  # Is this work editable by a given user?
69
  # A work is editable when:
70
  # * it is being edited by the person who made it
71
  # * it is being edited by a collection admin of the collection where is resides
72
  # * it is being edited by a super admin
73
  # @param [User]
74
  # @return [Boolean]
75
  def editable_by?(user)
1✔
76
    submitted_by?(user) || administered_by?(user)
70✔
77
  end
78

79
  def editable_in_current_state?(user)
1✔
80
    # anyone with edit privleges can edit a work while it is in draft or awaiting approval
81
    return editable_by?(user) if draft? || awaiting_approval?
50✔
82

83
    # Only admisitrators can edit a work in other states
84
    administered_by?(user)
11✔
85
  end
86

87
  def submitted_by?(user)
1✔
88
    created_by_user_id == user.id
70✔
89
  end
90

91
  def administered_by?(user)
1✔
92
    user.has_role?(:collection_admin, collection)
32✔
93
  end
94

95
  class << self
1✔
96
    def find_by_doi(doi)
1✔
97
      prefix = "10.34770/"
×
98
      doi = "#{prefix}#{doi}" unless doi.start_with?(prefix)
×
99
      Work.find_by!("metadata @> ?", JSON.dump(doi: doi))
×
100
    end
101

102
    def find_by_ark(ark)
1✔
103
      prefix = "ark:/"
×
104
      ark = "#{prefix}#{ark}" unless ark.start_with?(prefix)
×
105
      Work.find_by!("metadata @> ?", JSON.dump(ark: ark))
×
106
    end
107

108
    delegate :resource_type_general_values, to: PDCMetadata::Resource
1✔
109

110
    # Determines whether or not a test DOI should be referenced
111
    # (this avoids requests to the DOI API endpoint for non-production deployments)
112
    # @return [Boolean]
113
    def publish_test_doi?
1✔
114
      (Rails.env.development? || Rails.env.test?) && Rails.configuration.datacite.user.blank?
35✔
115
    end
116
  end
117

118
  include Rails.application.routes.url_helpers
1✔
119

120
  before_save do |work|
1✔
121
    # Ensure that the metadata JSONB postgres field is persisted properly
122
    work.metadata = JSON.parse(work.resource.to_json)
453✔
123
    work.save_pre_curation_uploads
453✔
124
  end
125

126
  after_save do |work|
1✔
127
    if work.approved?
453✔
128
      work.reload
54✔
129
    end
130
  end
131

132
  validate do |work|
1✔
133
    if none?
476✔
134
      work.validate_doi
94✔
135
    elsif draft?
382✔
136
      work.valid_to_draft
217✔
137
    else
138
      work.valid_to_submit
165✔
139
    end
140
  end
141

142
  # Overload ActiveRecord.reload method
143
  # https://apidock.com/rails/ActiveRecord/Base/reload
144
  #
145
  # NOTE: Usually `after_save` is a better place to put this kind of code:
146
  #
147
  #   after_save do |work|
148
  #     work.resource = nil
149
  #   end
150
  #
151
  # but that does not work in this case because the block points to a different
152
  # memory object for `work` than the we want we want to reload.
153
  def reload(options = nil)
1✔
154
    super
109✔
155
    # Force `resource` to be reloaded
156
    @resource = nil
109✔
157
    self
109✔
158
  end
159

160
  def validate_doi
1✔
161
    return true unless user_entered_doi
94✔
162
    if /^10.\d{4,9}\/[-._;()\/:a-z0-9\-]+$/.match?(doi.downcase)
14✔
163
      response = Faraday.get("#{Rails.configuration.datacite.doi_url}#{doi}")
13✔
164
      errors.add(:base, "Invalid DOI: can not verify it's authenticity") unless response.success? || response.status == 302
13✔
165
    else
166
      errors.add(:base, "Invalid DOI: does not match format")
1✔
167
    end
168
    errors.count == 0
14✔
169
  end
170

171
  def valid_to_draft
1✔
172
    errors.add(:base, "Must provide a title") if resource.main_title.blank?
466✔
173
    validate_ark
466✔
174
    validate_creators
466✔
175
    errors.count == 0
466✔
176
  end
177

178
  def valid_to_submit
1✔
179
    valid_to_draft
221✔
180
    validate_metadata
221✔
181
    errors.count == 0
221✔
182
  end
183

184
  def valid_to_approve(user)
1✔
185
    valid_to_submit
22✔
186
    unless user.has_role? :collection_admin, collection
22✔
187
      errors.add :base, "Unauthorized to Approve"
1✔
188
    end
189
    errors.count == 0
22✔
190
  end
191

192
  def title
1✔
193
    resource.main_title
231✔
194
  end
195

196
  def uploads_attributes
1✔
197
    return [] if approved? # once approved we no longer allow the updating of uploads via the application
33✔
198
    uploads.map do |upload|
31✔
199
      {
200
        id: upload.id,
9✔
201
        key: upload.key,
202
        filename: upload.filename.to_s,
203
        created_at: upload.created_at,
204
        url: upload.url
205
      }
206
    end
207
  end
208

209
  def form_attributes
1✔
210
    {
211
      uploads: uploads_attributes
33✔
212
    }
213
  end
214

215
  def draft_doi
1✔
216
    return if resource.doi.present?
29✔
217
    resource.doi = if self.class.publish_test_doi?
16✔
218
                     Rails.logger.info "Using hard-coded test DOI during development."
1✔
219
                     "10.34770/tbd"
1✔
220
                   else
221
                     result = data_cite_connection.autogenerate_doi(prefix: Rails.configuration.datacite.prefix)
15✔
222
                     if result.success?
15✔
223
                       result.success.doi
14✔
224
                     else
225
                       raise("Error generating DOI. #{result.failure.status} / #{result.failure.reason_phrase}")
1✔
226
                     end
227
                   end
228
    save!
15✔
229
  end
230

231
  def created_by_user
1✔
232
    User.find(created_by_user_id)
184✔
233
  rescue ActiveRecord::RecordNotFound
234
    nil
1✔
235
  end
236

237
  def resource=(resource)
1✔
238
    @resource = resource
288✔
239
    # Ensure that the metadata JSONB postgres field is persisted properly
240
    self.metadata = JSON.parse(resource.to_json)
288✔
241
  end
242

243
  def resource
1✔
244
    @resource ||= PDCMetadata::Resource.new_from_jsonb(metadata)
8,634✔
245
  end
246

247
  def url
1✔
248
    return unless persisted?
3✔
249

250
    @url ||= url_for(self)
3✔
251
  end
252

253
  def files_location_upload?
1✔
254
    files_location.blank? || files_location == "file_upload"
6✔
255
  end
256

257
  def files_location_cluster?
1✔
258
    files_location == "file_cluster"
35✔
259
  end
260

261
  def files_location_other?
1✔
262
    files_location == "file_other"
35✔
263
  end
264

265
  def change_curator(curator_user_id, current_user)
1✔
266
    if curator_user_id == "no-one"
2✔
267
      clear_curator(current_user)
×
268
    else
269
      update_curator(curator_user_id, current_user)
2✔
270
    end
271
  end
272

273
  def clear_curator(current_user)
1✔
274
    # Update the curator on the Work
275
    self.curator_user_id = nil
1✔
276
    save!
1✔
277

278
    # ...and log the activity
279
    WorkActivity.add_work_activity(id, "Unassigned existing curator", current_user.id, activity_type: WorkActivity::SYSTEM)
1✔
280
  end
281

282
  def update_curator(curator_user_id, current_user)
1✔
283
    # Update the curator on the Work
284
    self.curator_user_id = curator_user_id
3✔
285
    save!
3✔
286

287
    # ...and log the activity
288
    new_curator = User.find(curator_user_id)
3✔
289
    message = if curator_user_id == current_user.id
3✔
290
                "Self-assigned as curator"
1✔
291
              else
292
                "Set curator to @#{new_curator.uid}"
2✔
293
              end
294
    WorkActivity.add_work_activity(id, message, current_user.id, activity_type: WorkActivity::SYSTEM)
3✔
295
  end
296

297
  def curator_or_current_uid(user)
1✔
298
    persisted = if curator.nil?
3✔
299
                  user
2✔
300
                else
301
                  curator
1✔
302
                end
303
    persisted.uid
3✔
304
  end
305

306
  def add_message(message, current_user_id)
1✔
307
    WorkActivity.add_work_activity(id, message, current_user_id, activity_type: WorkActivity::MESSAGE)
4✔
308
  end
309

310
  def add_provenance_note(date, note, current_user_id)
1✔
311
    WorkActivity.add_work_activity(id, note, current_user_id, activity_type: WorkActivity::PROVENANCE_NOTES, created_at: date)
×
312
  end
313

314
  def log_changes(resource_compare, current_user_id)
1✔
315
    return if resource_compare.identical?
10✔
316
    WorkActivity.add_work_activity(id, resource_compare.differences.to_json, current_user_id, activity_type: WorkActivity::CHANGES)
9✔
317
  end
318

319
  def log_file_changes(changes, current_user_id)
1✔
320
    return if changes.count == 0
4✔
321
    WorkActivity.add_work_activity(id, changes.to_json, current_user_id, activity_type: WorkActivity::FILE_CHANGES)
4✔
322
  end
323

324
  def activities
1✔
325
    WorkActivity.activities_for_work(id, WorkActivity::MESSAGE_ACTIVITY_TYPES + WorkActivity::CHANGE_LOG_ACTIVITY_TYPES)
41✔
326
  end
327

328
  def new_notification_count_for_user(user_id)
1✔
329
    WorkActivityNotification.joins(:work_activity)
79✔
330
                            .where(user_id: user_id, read_at: nil)
331
                            .where(work_activity: { work_id: id })
332
                            .count
333
  end
334

335
  # Marks as read the notifications for the given user_id in this work.
336
  # In practice, the user_id is the id of the current user and therefore this method marks the current's user
337
  # notifications as read.
338
  def mark_new_notifications_as_read(user_id)
1✔
339
    activities.each do |activity|
41✔
340
      unread_notifications = WorkActivityNotification.where(user_id: user_id, work_activity_id: activity.id, read_at: nil)
63✔
341
      unread_notifications.each do |notification|
63✔
342
        notification.read_at = Time.now.utc
25✔
343
        notification.save
25✔
344
      end
345
    end
346
  end
347

348
  def current_transition
1✔
349
    aasm.current_event.to_s.humanize.delete("!")
2✔
350
  end
351

352
  def uploads
1✔
353
    return post_curation_uploads if approved?
311✔
354

355
    pre_curation_uploads_fast
269✔
356
  end
357

358
  # Fetches the data from S3 directly bypassing ActiveStorage
359
  def pre_curation_uploads_fast
1✔
360
    s3_query_service.client_s3_files.sort_by(&:filename)
345✔
361
  end
362

363
  # This ensures that new ActiveStorage::Attachment objects can be modified before they are persisted
364
  def save_pre_curation_uploads
1✔
365
    return if pre_curation_uploads.empty?
453✔
366

367
    new_attachments = pre_curation_uploads.reject(&:persisted?)
15✔
368
    return if new_attachments.empty?
15✔
369

370
    save_new_attachments(new_attachments: new_attachments)
14✔
371
  end
372

373
  # Accesses post-curation S3 Bucket Objects
374
  def post_curation_s3_resources
1✔
375
    return [] unless approved?
98✔
376

377
    s3_resources
65✔
378
  end
379
  alias post_curation_uploads post_curation_s3_resources
1✔
380

381
  def s3_client
1✔
382
    s3_query_service.client
15✔
383
  end
384

385
  delegate :bucket_name, to: :s3_query_service
1✔
386

387
  # Generates the S3 Object key
388
  # @return [String]
389
  def s3_object_key
1✔
390
    "#{doi}/#{id}"
30✔
391
  end
392

393
  # Transmit a HEAD request for the S3 Bucket directory for this Work
394
  # @param bucket_name location to be checked to be found
395
  # @return [Aws::S3::Types::HeadObjectOutput]
396
  def find_post_curation_s3_dir(bucket_name:)
1✔
397
    # TODO: Directories really do not exists in S3
398
    #      if we really need this check then we need to do something else to check the bucket
399
    s3_client.head_object({
15✔
400
                            bucket: bucket_name,
401
                            key: s3_object_key
402
                          })
403
    true
×
404
  rescue Aws::S3::Errors::NotFound
405
    nil
15✔
406
  end
407

408
  def as_json(*)
1✔
409
    # Pre-curation files are not accessible externally,
410
    # so we are not interested in listing them in JSON.
411
    # (The items in pre_curation_uploads also have different properties.)
412
    files = post_curation_uploads.map do |upload|
50✔
413
      {
414
        "filename": upload.filename,
33✔
415
        "size": upload.size,
416
        "url": upload.globus_url
417
      }
418
    end
419

420
    # to_json returns a string of serialized JSON.
421
    # as_json returns the corresponding hash.
422
    {
423
      "resource" => resource.as_json,
50✔
424
      "files" => files,
425
      "collection" => collection.as_json.except("id")
426
    }
427
  end
428

429
  def pre_curation_uploads_count
1✔
430
    s3_query_service.file_count
2✔
431
  end
432

433
  delegate :ark, :doi, :resource_type, :resource_type=, :resource_type_general, :resource_type_general=,
1✔
434
           :to_xml, to: :resource
435

436
  # S3QueryService object associated with this Work
437
  # @return [S3QueryService]
438
  def s3_query_service
1✔
439
    @s3_query_service ||= S3QueryService.new(self, !approved?)
471✔
440
  end
441

442
  protected
1✔
443

444
    # This must be protected, NOT private for ActiveRecord to work properly with this attribute.
445
    #   Protected will still keep others from setting the metatdata, but allows ActiveRecord the access it needs
446
    def metadata=(metadata)
1✔
447
      super
741✔
448
      @resource = PDCMetadata::Resource.new_from_jsonb(metadata)
741✔
449
    end
450

451
  private
1✔
452

453
    def publish(user)
1✔
454
      publish_doi(user)
21✔
455
      update_ark_information
21✔
456
      publish_precurated_files
21✔
457
      save!
21✔
458
    end
459

460
    # Update EZID (our provider of ARKs) with the new information for this work.
461
    def update_ark_information
1✔
462
      # We only want to update the ark url under certain conditions.
463
      # Set this value in config/update_ark_url.yml
464
      if Rails.configuration.update_ark_url
21✔
465
        if ark.present?
9✔
466
          Ark.update(ark, url)
3✔
467
        end
468
      end
469
    end
470

471
    # Generates the key for ActiveStorage::Attachment and Attachment::Blob objects
472
    # @param attachment [ActiveStorage::Attachment]
473
    # @return [String]
474
    def generate_attachment_key(attachment)
1✔
475
      attachment_filename = attachment.filename.to_s
10✔
476
      attachment_key = attachment.key
10✔
477

478
      # Files actually coming from S3 include the DOI and bucket as part of the file name
479
      #  Files being attached in another manner may not have it, so we should include it.
480
      #  This is really for testing only.
481
      key_base = "#{doi}/#{id}"
10✔
482
      attachment_key = [key_base, attachment_filename].join("/") unless attachment_key.include?(key_base)
10✔
483

484
      attachment_ext = File.extname(attachment_filename)
10✔
485
      attachment_query = attachment_key.gsub(attachment_ext, "")
10✔
486
      results = ActiveStorage::Blob.where("key LIKE :query", query: "%#{attachment_query}%")
10✔
487
      blobs = results.to_a
10✔
488

489
      if blobs.present?
10✔
490
        index = blobs.length + 1
×
491
        attachment_key = attachment_key.gsub(/\.([a-zA-Z0-9\.]+)$/, "_#{index}.\\1")
×
492
      end
493

494
      attachment_key
10✔
495
    end
496

497
    def track_state_change(user, state = aasm.to_state)
1✔
498
      uw = UserWork.new(user_id: user.id, work_id: id, state: state)
109✔
499
      uw.save!
109✔
500
      WorkActivity.add_work_activity(id, "marked as #{state.to_s.titleize}", user.id, activity_type: WorkActivity::SYSTEM)
109✔
501
      WorkStateTransitionNotification.new(self, user.id).send
109✔
502
    end
503

504
    def data_cite_connection
1✔
505
      @data_cite_connection ||= Datacite::Client.new(username: Rails.configuration.datacite.user,
32✔
506
                                                     password: Rails.configuration.datacite.password,
507
                                                     host: Rails.configuration.datacite.host)
508
    end
509

510
    def validate_ark
1✔
511
      return if ark.blank?
466✔
512
      first_save = id.blank?
112✔
513
      changed_value = metadata["ark"] != ark
112✔
514
      if first_save || changed_value
112✔
515
        errors.add(:base, "Invalid ARK provided for the Work: #{ark}") unless Ark.valid?(ark)
39✔
516
      end
517
    end
518

519
    # rubocop:disable Metrics/AbcSize
520
    def validate_metadata
1✔
521
      return if metadata.blank?
221✔
522
      errors.add(:base, "Must provide a title") if resource.main_title.blank?
221✔
523
      errors.add(:base, "Must provide a description") if resource.description.blank?
221✔
524
      errors.add(:base, "Must indicate the Publisher") if resource.publisher.blank?
221✔
525
      errors.add(:base, "Must indicate the Publication Year") if resource.publication_year.blank?
221✔
526
      errors.add(:base, "Must indicate a Rights statement") if resource.rights.nil?
221✔
527
      errors.add(:base, "Must provide a Version number") if resource.version_number.blank?
221✔
528
      validate_creators
221✔
529
      validate_related_objects
221✔
530
    end
531
    # rubocop:enable Metrics/AbcSize
532

533
    def validate_creators
1✔
534
      if resource.creators.count == 0
687✔
535
        errors.add(:base, "Must provide at least one Creator")
1✔
536
      else
537
        resource.creators.each do |creator|
686✔
538
          if creator.orcid.present? && Orcid.invalid?(creator.orcid)
1,260✔
539
            errors.add(:base, "ORCID for creator #{creator.value} is not in format 0000-0000-0000-0000")
1✔
540
          end
541
        end
542
      end
543
    end
544

545
    def validate_related_objects
1✔
546
      return if resource.related_objects.empty?
221✔
547
      invalid = resource.related_objects.reject(&:valid?)
12✔
548
      errors.add(:base, "Related Objects are invalid: #{invalid.map(&:errors).join(', ')}") if invalid.count.positive?
12✔
549
    end
550

551
    def publish_doi(user)
1✔
552
      return Rails.logger.info("Publishing hard-coded test DOI during development.") if self.class.publish_test_doi?
19✔
553

554
      if doi&.starts_with?(Rails.configuration.datacite.prefix)
19✔
555
        result = data_cite_connection.update(id: doi, attributes: doi_attributes)
17✔
556
        if result.failure?
17✔
557
          resolved_user = curator_or_current_uid(user)
2✔
558
          message = "@#{resolved_user} Error publishing DOI. #{result.failure.status} / #{result.failure.reason_phrase}"
2✔
559
          WorkActivity.add_work_activity(id, message, user.id, activity_type: WorkActivity::DATACITE_ERROR)
2✔
560
        end
561
      elsif ark.blank? # we can not update the url anywhere
2✔
562
        Honeybadger.notify("Publishing for a DOI we do not own and no ARK is present: #{doi}")
1✔
563
      end
564
    end
565

566
    def doi_attribute_url
1✔
567
      "https://datacommons.princeton.edu/discovery/doi/#{doi}"
17✔
568
    end
569

570
    def doi_attribute_resource
1✔
571
      PDCMetadata::Resource.new_from_jsonb(metadata)
17✔
572
    end
573

574
    def doi_attribute_xml
1✔
575
      unencoded = doi_attribute_resource.to_xml
17✔
576
      Base64.encode64(unencoded)
17✔
577
    end
578

579
    def doi_attributes
1✔
580
      {
581
        "event" => "publish",
17✔
582
        "xml" => doi_attribute_xml,
583
        "url" => doi_attribute_url
584
      }
585
    end
586

587
    # This needs to be called #before_save
588
    # This ensures that new ActiveStorage::Attachment objects are persisted with custom keys (which are generated from the file name and DOI)
589
    # @param new_attachments [Array<ActiveStorage::Attachment>]
590
    def save_new_attachments(new_attachments:)
1✔
591
      new_attachments.each do |attachment|
14✔
592
        # There are cases (race conditions?) where the ActiveStorage::Blob objects are not persisted
593
        next if attachment.frozen?
14✔
594

595
        # This ensures that the custom key for the ActiveStorage::Attachment and ActiveStorage::Blob objects are generated
596
        generated_key = generate_attachment_key(attachment)
10✔
597
        attachment.blob.key = generated_key
10✔
598
        attachment.blob.save
10✔
599

600
        attachment.save
10✔
601
      end
602
    end
603

604
    # Request S3 Bucket Objects associated with this Work
605
    # @return [Array<S3File>]
606
    def s3_resources
1✔
607
      data_profile = s3_query_service.data_profile
65✔
608
      data_profile.fetch(:objects, [])
65✔
609
    end
610
    alias pre_curation_s3_resources s3_resources
1✔
611

612
    def s3_object_persisted?(s3_file)
1✔
613
      uploads_keys = uploads.map(&:key)
×
614
      uploads_keys.include?(s3_file.key)
×
615
    end
616

617
    def add_pre_curation_s3_object(s3_file)
1✔
618
      return if s3_object_persisted?(s3_file)
×
619

620
      persisted = s3_file.to_blob
×
621
      pre_curation_uploads.attach(persisted)
×
622
    end
623

624
    def publish_precurated_files
1✔
625
      # An error is raised if there are no files to be moved
626
      raise(StandardError, "Attempting to publish a Work without attached uploads for #{s3_object_key}") if pre_curation_uploads_fast.empty? && post_curation_uploads.empty?
15✔
627

628
      # We need to explicitly access to post-curation services here.
629
      # Lets explicitly create it so the state of the work does not have any impact.
630
      s3_post_curation_query_service = S3QueryService.new(self, false)
15✔
631

632
      s3_dir = find_post_curation_s3_dir(bucket_name: s3_post_curation_query_service.bucket_name)
15✔
633
      raise(StandardError, "Attempting to publish a Work with an existing S3 Bucket directory for: #{s3_object_key}") unless s3_dir.nil?
15✔
634

635
      # Copy the pre-curation S3 Objects to the post-curation S3 Bucket...
636
      transferred_file_errors = s3_query_service.publish_files
15✔
637

638
      # ...check that the files are indeed now in the post-curation bucket...
639
      if transferred_file_errors.count > 0
15✔
640
        raise(StandardError, "Failed to validate the uploaded S3 Object #{transferred_file_errors.map(&:key).join(', ')}")
×
641
      end
642
    end
643
end
644
# rubocop:enable Metrics/ClassLength
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