Sha256: f747c0e0f7f1c323996f044150e485ed9a7cebafde71392f816c9c722822710a

Contents?: true

Size: 1.28 KB

Versions: 33

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module SdrClient
  module Deposit
    # Updates a DRO so that the structural metadata references the uploaded file ids
    class UpdateDroWithFileIdentifiers
      # @param [Cocina::Model::RequestDRO] request_dro for depositing
      # @param [Array<Files::DirectUploadResponse>] upload_responses the responses from uploading files
      # @returns [Cocina::Models::RequestDRO]
      def self.update(request_dro:, upload_responses:)
        # Manipulating request_dro as hash since immutable
        structural = request_dro.to_h[:structural]
        return request_dro.new({}) unless structural

        signed_ids = signed_id_map(upload_responses)
        request_dro.new(structural: updated_structural(structural, signed_ids))
      end

      def self.signed_id_map(upload_responses)
        Hash[upload_responses.map { |response| [response.filename, response.signed_id] }]
      end
      private_class_method :signed_id_map

      def self.updated_structural(structural, signed_ids)
        structural[:contains].each do |file_set|
          file_set[:structural][:contains].each do |file|
            file[:externalIdentifier] = signed_ids[file[:filename]]
          end
        end
        structural
      end
      private_class_method :updated_structural
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
sdr-client-0.63.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.62.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.61.1 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.61.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.60.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.59.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.58.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.57.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.56.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.55.1 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.55.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.54.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.53.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.52.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.51.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.51.0.beta.1 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.50.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.49.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.48.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-0.47.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb