Sha256: f4e55bf6702348f84e4c9054be09e8bc411d0438856155532422546c90e8ca64

Contents?: true

Size: 1.31 KB

Versions: 31

Compression:

Stored size: 1.31 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)
        upload_responses.to_h { |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]] if signed_ids.key?(file[:filename])
          end
        end
        structural
      end
      private_class_method :updated_structural
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
sdr-client-2.18.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.17.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.16.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.13.2 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.13.1 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.13.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.13.0.beta2 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.13.0.beta1 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.12.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.11.1 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.11.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.10.1 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.10.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.9.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.8.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.7.1 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.7.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.6.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.5.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
sdr-client-2.4.0 lib/sdr_client/deposit/update_dro_with_file_identifiers.rb