From 1c4ca0b248622d7cb1830e36b2033c8c111050c4 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 14 Dec 2023 17:27:32 -0800 Subject: [PATCH 1/3] index certain fields to the parent object --- Gemfile.lock | 2 +- app/indexers/ams/valkyrie_work_indexer.rb | 26 +++++++++++++++++++ app/indexers/ams/work_indexer.rb | 2 +- app/indexers/asset_resource_indexer.rb | 2 +- app/indexers/contribution_resource_indexer.rb | 2 +- .../digital_instantiation_resource_indexer.rb | 2 +- .../essence_track_resource_indexer.rb | 2 +- ...physical_instantiation_resource_indexer.rb | 2 +- .../instantiation_admin_data_presenter.rb | 4 +-- .../.#physical_instantiation_resource.yaml | 1 + config/metadata/contribution_resource.yaml | 2 ++ .../digital_instantiation_resource.yaml | 5 ++++ .../physical_instantiation_resource.yaml | 4 +++ docker-compose.yml | 16 +++--------- 14 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 app/indexers/ams/valkyrie_work_indexer.rb create mode 120000 config/metadata/.#physical_instantiation_resource.yaml diff --git a/Gemfile.lock b/Gemfile.lock index ce8a7e78..d560e5a6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,7 +41,7 @@ GIT GIT remote: https://github.com/samvera/hyrax.git - revision: 0108fed6c83dd4a449b37cc1a6c19787ec54921d + revision: b7891b758411c59f71ff54212e0d250fcc47e35f branch: double_combo specs: hyrax (5.0.0.rc2) diff --git a/app/indexers/ams/valkyrie_work_indexer.rb b/app/indexers/ams/valkyrie_work_indexer.rb new file mode 100644 index 00000000..f86e60d3 --- /dev/null +++ b/app/indexers/ams/valkyrie_work_indexer.rb @@ -0,0 +1,26 @@ +module AMS + class ValkyrieWorkIndexer < Hyrax::ValkyrieWorkIndexer + include SolrHelper + + def to_solr + find_index_child_attributes(super) + end + + private + def find_index_child_attributes(solr_doc) + resource.members.each do |child| + parent_indexable_properties = [ "language", "contributor"] + child.class.fields.each do |field_name| + parent_indexable_properties << field_name if child.class.schema.key(field_name).meta['index_to_parent'] + end + parent_indexable_properties.uniq.each do |prop| + solr_doc["#{child.class.to_s.underscore}_#{prop}_ssim"] ||= [] + solr_doc["#{child.class.to_s.underscore}_#{prop}_ssim"] |= Array.wrap(child.send(prop)) + solr_doc["#{prop}_ssim"] ||= [] + solr_doc["#{prop}_ssim"] |= Array.wrap(child.send(prop)) + end + end + solr_doc + end + end +end diff --git a/app/indexers/ams/work_indexer.rb b/app/indexers/ams/work_indexer.rb index 83227237..cc44186c 100644 --- a/app/indexers/ams/work_indexer.rb +++ b/app/indexers/ams/work_indexer.rb @@ -24,4 +24,4 @@ def find_index_child_attributes(solr_doc) solr_doc end end -end \ No newline at end of file +end diff --git a/app/indexers/asset_resource_indexer.rb b/app/indexers/asset_resource_indexer.rb index 9e6202d0..0ed8b24b 100644 --- a/app/indexers/asset_resource_indexer.rb +++ b/app/indexers/asset_resource_indexer.rb @@ -2,7 +2,7 @@ # Generated via # `rails generate hyrax:work_resource AssetResource` -class AssetResourceIndexer < Hyrax::ValkyrieWorkIndexer +class AssetResourceIndexer < AMS::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) include Hyrax::Indexer(:asset_resource) diff --git a/app/indexers/contribution_resource_indexer.rb b/app/indexers/contribution_resource_indexer.rb index 36758448..cdc99f1f 100644 --- a/app/indexers/contribution_resource_indexer.rb +++ b/app/indexers/contribution_resource_indexer.rb @@ -2,7 +2,7 @@ # Generated via # `rails generate hyrax:work_resource ContributionResource` -class ContributionResourceIndexer < Hyrax::ValkyrieWorkIndexer +class ContributionResourceIndexer < AMS::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) include Hyrax::Indexer(:contribution_resource) diff --git a/app/indexers/digital_instantiation_resource_indexer.rb b/app/indexers/digital_instantiation_resource_indexer.rb index ee541e93..e7b9bc0c 100644 --- a/app/indexers/digital_instantiation_resource_indexer.rb +++ b/app/indexers/digital_instantiation_resource_indexer.rb @@ -2,7 +2,7 @@ # Generated via # `rails generate hyrax:work_resource DigitalInstantiationResource` -class DigitalInstantiationResourceIndexer < Hyrax::ValkyrieWorkIndexer +class DigitalInstantiationResourceIndexer < AMS::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) include Hyrax::Indexer(:digital_instantiation_resource) diff --git a/app/indexers/essence_track_resource_indexer.rb b/app/indexers/essence_track_resource_indexer.rb index 3666a646..9eb8a554 100644 --- a/app/indexers/essence_track_resource_indexer.rb +++ b/app/indexers/essence_track_resource_indexer.rb @@ -2,7 +2,7 @@ # Generated via # `rails generate hyrax:work_resource EssenceTrackResource` -class EssenceTrackResourceIndexer < Hyrax::ValkyrieWorkIndexer +class EssenceTrackResourceIndexer < AMS::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) include Hyrax::Indexer(:essence_track_resource) diff --git a/app/indexers/physical_instantiation_resource_indexer.rb b/app/indexers/physical_instantiation_resource_indexer.rb index 194a3f5e..bf1e4433 100644 --- a/app/indexers/physical_instantiation_resource_indexer.rb +++ b/app/indexers/physical_instantiation_resource_indexer.rb @@ -2,7 +2,7 @@ # Generated via # `rails generate hyrax:work_resource PhysicalInstantiationResource` -class PhysicalInstantiationResourceIndexer < Hyrax::ValkyrieWorkIndexer +class PhysicalInstantiationResourceIndexer < AMS::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) include Hyrax::Indexer(:physical_instantiation_resource) diff --git a/app/presenters/aapb/instantiation_admin_data_presenter.rb b/app/presenters/aapb/instantiation_admin_data_presenter.rb index d1d80e45..ee1089e0 100644 --- a/app/presenters/aapb/instantiation_admin_data_presenter.rb +++ b/app/presenters/aapb/instantiation_admin_data_presenter.rb @@ -15,9 +15,9 @@ def attribute_to_html(field, options = {}) options.merge!({:html_dl=> true}) solr_document = ::SolrDocument.find(id) - old_models = ['Asset', 'PhysicalInstantiation', 'DigitalInstantiation', 'Contribution'] - work_class = old_models.include?(solr_document['has_model_ssim'].first) ? "#{solr_document['has_model_ssim'].first}Resource" : solr_document['has_model_ssim'].first + work_class = solr_document['has_model_ssim'].first work_class = work_class.constantize + work_class = Wings::ModelRegistry.reverse_lookup(work_class) || work_class if attribute_indexed_to_parent?(field, work_class) && attribute_facetable?(field, work_class) # Use :symbol for field_name since all attributes indexed to parent are indexed as symbols. diff --git a/config/metadata/.#physical_instantiation_resource.yaml b/config/metadata/.#physical_instantiation_resource.yaml new file mode 120000 index 00000000..55389b66 --- /dev/null +++ b/config/metadata/.#physical_instantiation_resource.yaml @@ -0,0 +1 @@ +rob@Robs-MacBook-Pro.local.83041 \ No newline at end of file diff --git a/config/metadata/contribution_resource.yaml b/config/metadata/contribution_resource.yaml index 0d46bbe4..8a9a04e6 100644 --- a/config/metadata/contribution_resource.yaml +++ b/config/metadata/contribution_resource.yaml @@ -38,6 +38,7 @@ attributes: portrayal: type: string multiple: false + index_to_parent: true index_keys: - "portrayal_tesim" form: @@ -47,6 +48,7 @@ attributes: affiliation: type: string multiple: false + index_to_parent: true index_keys: - "affiliation_tesim" form: diff --git a/config/metadata/digital_instantiation_resource.yaml b/config/metadata/digital_instantiation_resource.yaml index 1803948d..e0f83d44 100644 --- a/config/metadata/digital_instantiation_resource.yaml +++ b/config/metadata/digital_instantiation_resource.yaml @@ -33,6 +33,7 @@ attributes: date: type: string multiple: true + index_to_parent: true index_keys: - "date_sim" - "date_tesim" @@ -79,6 +80,7 @@ attributes: media_type: type: string multiple: false + index_to_parent: true index_keys: - "media_type_sim" - "media_type_tesim" @@ -89,6 +91,7 @@ attributes: generations: type: string multiple: true + index_to_parent: true index_keys: - "generations_sim" - "generations_tesim" @@ -171,6 +174,7 @@ attributes: local_instantiation_identifier: type: string multiple: true + index_to_parent: true index_keys: - "local_instantiation_identifier_tesim" form: @@ -207,6 +211,7 @@ attributes: holding_organization: type: string multiple: false + index_to_parent: true index_keys: - "holding_organization_sim" - "holding_organization_tesim" diff --git a/config/metadata/physical_instantiation_resource.yaml b/config/metadata/physical_instantiation_resource.yaml index 14d8b2fa..bb221fea 100644 --- a/config/metadata/physical_instantiation_resource.yaml +++ b/config/metadata/physical_instantiation_resource.yaml @@ -33,6 +33,7 @@ attributes: date: type: string multiple: true + index_to_parent: true index_keys: - "date_sim" - "date_tesim" @@ -61,6 +62,7 @@ attributes: format: type: string multiple: false + index_to_parent: true index_keys: - "format_tesim" form: @@ -88,6 +90,7 @@ attributes: media_type: type: string multiple: false + index_to_parent: true index_keys: - "media_type_sim" - "media_type_tesim" @@ -162,6 +165,7 @@ attributes: local_instantiation_identifier: type: string multiple: true + index_to_parent: true index_keys: - "local_instantiation_identifier_tesim" form: diff --git a/docker-compose.yml b/docker-compose.yml index 9f373e48..954d99d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -185,17 +185,7 @@ services: # we need to do seed seperate because activerecord doesn't reload properly otherwise command: - > - if [ -v DEPENDENCIES_NEXT ]; then - export BUNDLE_GEMFILE=Gemfile_next; - export BUNDLER_VERSION=2.0.1 - else - export BUNDLE_GEMFILE=Gemfile; - fi; - solrcloud-upload-configset.sh /app/samvera/hyrax-webapp/solr/config && - solrcloud-assign-configset.sh && - SOLR_COLLECTION_NAME=hydra-test solrcloud-assign-configset.sh && - rails db:create db:schema:load db:migrate && - rails db:seed + true depends_on: postgres: condition: service_started @@ -213,6 +203,7 @@ services: environment: - VIRTUAL_PORT=3000 - VIRTUAL_HOST=.ams.test + command: sh -l -c "sleep infinity" # command: sh -l -c "bundle && bundle exec puma -v -b tcp://0.0.0.0:3000" cap_add: - SYS_PTRACE @@ -237,9 +228,10 @@ services: condition: service_started initialize_app: condition: service_completed_successfully - expose: - 3000 + ports: + - "3005:3000" worker: <<: *app From 636c08da7f6909550e1117e3e7258bb3e6c8567f Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 14 Dec 2023 17:29:18 -0800 Subject: [PATCH 2/3] put docker compose back --- docker-compose.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 954d99d5..05a41e2b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -185,7 +185,17 @@ services: # we need to do seed seperate because activerecord doesn't reload properly otherwise command: - > - true + if [ -v DEPENDENCIES_NEXT ]; then + export BUNDLE_GEMFILE=Gemfile_next; + export BUNDLER_VERSION=2.0.1 + else + export BUNDLE_GEMFILE=Gemfile; + fi; + solrcloud-upload-configset.sh /app/samvera/hyrax-webapp/solr/config && + solrcloud-assign-configset.sh && + SOLR_COLLECTION_NAME=hydra-test solrcloud-assign-configset.sh && + rails db:create db:schema:load db:migrate && + rails db:seed depends_on: postgres: condition: service_started @@ -203,8 +213,7 @@ services: environment: - VIRTUAL_PORT=3000 - VIRTUAL_HOST=.ams.test - command: sh -l -c "sleep infinity" - # command: sh -l -c "bundle && bundle exec puma -v -b tcp://0.0.0.0:3000" + # command: sh -l -c "sleep infinity" cap_add: - SYS_PTRACE depends_on: @@ -230,8 +239,6 @@ services: condition: service_completed_successfully expose: - 3000 - ports: - - "3005:3000" worker: <<: *app From b2cdad7f4c6968b335ed966bfa75ed747a705e84 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Fri, 15 Dec 2023 10:18:44 -0800 Subject: [PATCH 3/3] handle blanks in xml export --- app/models/ams/pbcore_xml_export_extension.rb | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/app/models/ams/pbcore_xml_export_extension.rb b/app/models/ams/pbcore_xml_export_extension.rb index 2bff1b6c..3b70699a 100644 --- a/app/models/ams/pbcore_xml_export_extension.rb +++ b/app/models/ams/pbcore_xml_export_extension.rb @@ -103,10 +103,10 @@ def prepare_asset(xml) members(only: Contribution).each do |contribution| xml.pbcoreContributor do |contributor_node| - contributor_node.contributor { contributor_node.text(contribution.contributor.first) } + contributor_node.contributor { contributor_node.text(contribution&.contributor&.first) } # contributorRole is not required! - contributor_node.contributorRole { contributor_node.text(contribution.contributor_role.first) } if contribution.contributor_role + contributor_node.contributorRole { contributor_node.text(contribution&.contributor_role&.first) } if contribution.contributor_role end end # people_with_types = members(only: Contribution).sort_by {|peep| peep.contributor_role } @@ -176,54 +176,54 @@ def prepare_physical_instantiation(xml, instantiation) instantiation_node.instantiationIdentifier(source: 'Filename') { instantiation_node.text(instantiation.id) } instantiation.local_instantiation_identifier.to_a.each { |local_instantiation_identifier| instantiation_node.instantiationIdentifier { instantiation_node.text(local_instantiation_identifier) } } - instantiation.date.to_a.each { |date| instantiation_node.instantiationDate { instantiation_node.text(date) } } - instantiation.digitization_date.to_a.each { |date| instantiation_node.instantiationDate(dateType: 'digitized') { instantiation_node.text(date) } } + instantiation.date&.to_a&.each { |date| instantiation_node.instantiationDate { instantiation_node.text(date) } } + instantiation.digitization_date&.to_a&.each { |date| instantiation_node.instantiationDate(dateType: 'digitized') { instantiation_node.text(date) } } - instantiation.dimensions.to_a.each { |dimension| instantiation_node.instantiationDimensions { instantiation_node.text(dimension) } } + instantiation.dimensions&.to_a&.each { |dimension| instantiation_node.instantiationDimensions { instantiation_node.text(dimension) } } - instantiation.format.to_a.each { |format| instantiation_node.instantiationPhysical { instantiation_node.text(format) } } + instantiation.format&.to_a&.each { |format| instantiation_node.instantiationPhysical { instantiation_node.text(format) } } - instantiation.standard.to_a.each { |standard| instantiation_node.instantiationStandard { instantiation_node.text(standard) } } + instantiation.standard&.to_a&.each { |standard| instantiation_node.instantiationStandard { instantiation_node.text(standard) } } - instantiation.location.to_a.each { |location| instantiation_node.instantiationLocation { instantiation_node.text(location) } } + instantiation.location&.to_a&.each { |location| instantiation_node.instantiationLocation { instantiation_node.text(location) } } - instantiation.media_type.to_a.each { |media_type| instantiation_node.instantiationMediaType { instantiation_node.text(media_type) } } + instantiation.media_type&.to_a&.each { |media_type| instantiation_node.instantiationMediaType { instantiation_node.text(media_type) } } - instantiation.generations.to_a.each { |generation| instantiation_node.instantiationGenerations { instantiation_node.text(generation) } } + instantiation.generations&.to_a&.each { |generation| instantiation_node.instantiationGenerations { instantiation_node.text(generation) } } - instantiation.time_start.to_a.each { |time_start| instantiation_node.instantiationTimeStart { instantiation_node.text(time_start) } } + instantiation.time_start&.to_a&.each { |time_start| instantiation_node.instantiationTimeStart { instantiation_node.text(time_start) } } - instantiation.duration.to_a.each { |duration| instantiation_node.instantiationDuration { instantiation_node.text(duration) } } + instantiation.duration&.to_a&.each { |duration| instantiation_node.instantiationDuration { instantiation_node.text(duration) } } - instantiation.colors.to_a.each { |color| instantiation_node.instantiationColors { instantiation_node.text(color) } } + instantiation.colors&.to_a&.each { |color| instantiation_node.instantiationColors { instantiation_node.text(color) } } - instantiation.tracks.to_a.each { |tracks| instantiation_node.instantiationTracks { instantiation_node.text(tracks) } } + instantiation.tracks&.to_a&.each { |tracks| instantiation_node.instantiationTracks { instantiation_node.text(tracks) } } - instantiation.channel_configuration.to_a.each { |channel_config| instantiation_node.instantiationChannelConfiguration { instantiation_node.text(channel_config) } } + instantiation.channel_configuration&.to_a&.each { |channel_config| instantiation_node.instantiationChannelConfiguration { instantiation_node.text(channel_config) } } - instantiation.language.to_a.each { |language| instantiation_node.instantiationLanguage { instantiation_node.text(language) } } + instantiation.language&.to_a&.each { |language| instantiation_node.instantiationLanguage { instantiation_node.text(language) } } - instantiation.alternative_modes.to_a.each { |alternative_mode| instantiation_node.instantiationAlternativeModes { instantiation_node.text(alternative_mode) } } + instantiation.alternative_modes&.to_a&.each { |alternative_mode| instantiation_node.instantiationAlternativeModes { instantiation_node.text(alternative_mode) } } # Prepare Essence Track node instantiation.members(only: EssenceTrack).each do |essence_track| prepare_essence_track(instantiation_node, essence_track) end - instantiation.rights_summary.to_a.each do |rights_summary| + instantiation.rights_summary&.to_a&.each do |rights_summary| instantiation.instantiationRights do |instrights_node| instrights_node.rightsSummary { instantiation_node.cdata(rights_summary) } end end - instantiation.rights_link.to_a.each do |rights_link| + instantiation.rights_link&.to_a&.each do |rights_link| instantiation.instantiationRights do |instrights_node| instrights_node.rightsLink { instantiation_node.cdata(rights_link) } end end - instantiation.annotation.to_a.each { |annTxt| instantiation_node.instantiationAnnotation { instantiation_node.cdata(annTxt) } } - instantiation.holding_organization.to_a.each { |org| instantiation_node.instantiationAnnotation(annotationType: 'organization') { instantiation_node.text(org) } } + instantiation.annotation&.to_a&.each { |annTxt| instantiation_node.instantiationAnnotation { instantiation_node.cdata(annTxt) } } + instantiation.holding_organization&.to_a&.each { |org| instantiation_node.instantiationAnnotation(annotationType: 'organization') { instantiation_node.text(org) } } end end @@ -233,40 +233,40 @@ def prepare_digital_instantiation(xml, instantiation) instantiation_node.instantiationIdentifier { instantiation_node.text(instantiation.id) } instantiation.local_instantiation_identifier.to_a.each { |local_instantiation_identifier| instantiation_node.instantiationIdentifier { instantiation_node.text(local_instantiation_identifier) } } - instantiation.md5.to_a.each { |md5| instantiation_node.instantiationIdentifier(source: 'md5') { instantiation_node.text(md5) } } + instantiation.md5&.to_a&.each { |md5| instantiation_node.instantiationIdentifier(source: 'md5') { instantiation_node.text(md5) } } - instantiation.date.to_a.each { |date| instantiation_node.instantiationDate { instantiation_node.text(date) } } - instantiation.digitization_date.to_a.each { |date| instantiation_node.instantiationDate(dateType: 'digitized') { instantiation_node.text(date) } } + instantiation.date&.to_a&.each { |date| instantiation_node.instantiationDate { instantiation_node.text(date) } } + instantiation.digitization_date&.to_a&.each { |date| instantiation_node.instantiationDate(dateType: 'digitized') { instantiation_node.text(date) } } - instantiation.dimensions.to_a.each { |dimension| instantiation_node.instantiationDimensions(unitsOfMeasure: '') { instantiation_node.text(dimension) } } + instantiation.dimensions&.to_a&.each { |dimension| instantiation_node.instantiationDimensions(unitsOfMeasure: '') { instantiation_node.text(dimension) } } - instantiation.digital_format.to_a.each { |format| instantiation_node.instantiationDigital { instantiation_node.text(format) } } + instantiation.digital_format&.to_a&.each { |format| instantiation_node.instantiationDigital { instantiation_node.text(format) } } - instantiation.standard.to_a.each { |standard| instantiation_node.instantiationStandard { instantiation_node.text(standard) } } + instantiation.standard&.to_a&.each { |standard| instantiation_node.instantiationStandard { instantiation_node.text(standard) } } - instantiation.location.to_a.each { |location| instantiation_node.instantiationLocation { instantiation_node.text(location) } } + instantiation.location&.to_a&.each { |location| instantiation_node.instantiationLocation { instantiation_node.text(location) } } - instantiation.media_type.to_a.each { |media_type| instantiation_node.instantiationMediaType { instantiation_node.text(media_type) } } + instantiation.media_type&.to_a&.each { |media_type| instantiation_node.instantiationMediaType { instantiation_node.text(media_type) } } - instantiation.generations.to_a.each { |generation| instantiation_node.instantiationGenerations { instantiation_node.text(generation) } } + instantiation.generations&.to_a&.each { |generation| instantiation_node.instantiationGenerations { instantiation_node.text(generation) } } - instantiation.file_size.to_a.each { |file_size| instantiation_node.instantiationFileSize { instantiation_node.text(file_size) } } + instantiation.file_size&.to_a&.each { |file_size| instantiation_node.instantiationFileSize { instantiation_node.text(file_size) } } - instantiation.time_start.to_a.each { |time_start| instantiation_node.instantiationTimeStart { instantiation_node.text(time_start) } } + instantiation.time_start&.to_a&.each { |time_start| instantiation_node.instantiationTimeStart { instantiation_node.text(time_start) } } - instantiation.duration.to_a.each { |duration| instantiation_node.instantiationDuration { instantiation_node.text(duration) } } + instantiation.duration&.to_a&.each { |duration| instantiation_node.instantiationDuration { instantiation_node.text(duration) } } # no dataRate - instantiation.colors.to_a.each { |color| instantiation_node.instantiationColors { instantiation_node.text(color) } } + instantiation.colors&.to_a&.each { |color| instantiation_node.instantiationColors { instantiation_node.text(color) } } - instantiation.tracks.to_a.each { |tracks| instantiation_node.instantiationTracks { instantiation_node.text(tracks) } } + instantiation.tracks&.to_a&.each { |tracks| instantiation_node.instantiationTracks { instantiation_node.text(tracks) } } - instantiation.channel_configuration.to_a.each { |channel_config| instantiation_node.instantiationChannelConfiguration { instantiation_node.text(channel_config) } } + instantiation.channel_configuration&.to_a&.each { |channel_config| instantiation_node.instantiationChannelConfiguration { instantiation_node.text(channel_config) } } - instantiation.language.to_a.each { |language| instantiation_node.instantiationLanguage { instantiation_node.text(language) } } + instantiation.language&.to_a&.each { |language| instantiation_node.instantiationLanguage { instantiation_node.text(language) } } - instantiation.alternative_modes.to_a.each { |alternative_mode| instantiation_node.instantiationAlternativeModes { instantiation_node.text(alternative_mode) } } + instantiation.alternative_modes&.to_a&.each { |alternative_mode| instantiation_node.instantiationAlternativeModes { instantiation_node.text(alternative_mode) } } # Prepare Essence Track node instantiation.members(only: EssenceTrack).each do |essence_track| @@ -287,43 +287,43 @@ def prepare_digital_instantiation(xml, instantiation) end end - instantiation.annotation.to_a.each { |annTxt| instantiation_node.instantiationAnnotation { instantiation_node.cdata(annTxt) } } - instantiation.holding_organization.to_a.each { |org| instantiation_node.instantiationAnnotation(annotationType: 'organization') { instantiation_node.text(org) } } + instantiation.annotation&.to_a&.each { |annTxt| instantiation_node.instantiationAnnotation { instantiation_node.cdata(annTxt) } } + instantiation.holding_organization&.to_a&.each { |org| instantiation_node.instantiationAnnotation(annotationType: 'organization') { instantiation_node.text(org) } } end end def prepare_essence_track(instantiation_node, essence_track) instantiation_node.instantiationEssenceTrack do |essence_track_node| - essence_track_node.essenceTrackType { essence_track_node.text(essence_track.track_type.first) } + essence_track_node.essenceTrackType { essence_track_node.text(essence_track.track_type&.first) } - essence_track.track_id.to_a.each { |track_id| essence_track_node.essenceTrackIdentifier { essence_track_node.text(track_id) } } + essence_track.track_id&.to_a&.each { |track_id| essence_track_node.essenceTrackIdentifier { essence_track_node.text(track_id) } } - essence_track_node.essenceTrackStandard { essence_track_node.text(essence_track.standard.first) } if content?(essence_track.standard) + essence_track_node.essenceTrackStandard { essence_track_node.text(essence_track.standard&.first) } if content?(essence_track.standard) - essence_track_node.essenceTrackEncoding { essence_track_node.text(essence_track.encoding.first) } if content?(essence_track.encoding) + essence_track_node.essenceTrackEncoding { essence_track_node.text(essence_track.encoding&.first) } if content?(essence_track.encoding) - essence_track_node.essenceTrackDataRate(unitsOfMeasure: 'kb/s') { essence_track_node.text(essence_track.data_rate.first) } if content?(essence_track.data_rate) + essence_track_node.essenceTrackDataRate(unitsOfMeasure: 'kb/s') { essence_track_node.text(essence_track.data_rate&.first) } if content?(essence_track.data_rate) - essence_track_node.essenceTrackFrameRate { essence_track_node.text(essence_track.frame_rate.first) } if content?(essence_track.frame_rate) + essence_track_node.essenceTrackFrameRate { essence_track_node.text(essence_track.frame_rate&.first) } if content?(essence_track.frame_rate) essence_track_node.essenceTrackPlaybackSpeed(unitsOfMeasure: essence_track.playback_speed_units) { essence_track_node.text(essence_track.playback_speed) } if content?(essence_track.playback_speed) - essence_track_node.essenceTrackSamplingRate { essence_track_node.text(essence_track.sample_rate.first) } if content?(essence_track.sample_rate) + essence_track_node.essenceTrackSamplingRate { essence_track_node.text(essence_track.sample_rate&.first) } if content?(essence_track.sample_rate) - essence_track_node.essenceTrackBitDepth { essence_track_node.text(essence_track.bit_depth.first) } if content?(essence_track.bit_depth) + essence_track_node.essenceTrackBitDepth { essence_track_node.text(essence_track.bit_depth&.first) } if content?(essence_track.bit_depth) essence_track_node.essenceTrackFrameSize { essence_track_node.text("#{essence_track.frame_width} x #{essence_track.frame_height}") } if essence_track.frame_width && essence_track.frame_height - essence_track_node.essenceTrackAspectRatio { essence_track_node.text(essence_track.aspect_ratio.first) } if content?(essence_track.aspect_ratio) + essence_track_node.essenceTrackAspectRatio { essence_track_node.text(essence_track.aspect_ratio&.first) } if content?(essence_track.aspect_ratio) - essence_track_node.essenceTrackTimeStart { essence_track_node.text(essence_track.time_start.first) } if content?(essence_track.time_start) + essence_track_node.essenceTrackTimeStart { essence_track_node.text(essence_track.time_start&.first) } if content?(essence_track.time_start) - essence_track_node.essenceTrackDuration { essence_track_node.text(essence_track.duration.first) } if content?(essence_track.duration) + essence_track_node.essenceTrackDuration { essence_track_node.text(essence_track.duration&.first) } if content?(essence_track.duration) - essence_track.language.to_a.each { |lang| essence_track_node.essenceTrackLanguage { essence_track_node.text(lang) } } + essence_track.language&.to_a&.each { |lang| essence_track_node.essenceTrackLanguage { essence_track_node.text(lang) } } - essence_track.annotation.to_a.each { |annTxt| essence_track_node.essenceTrackAnnotation { essence_track_node.text(annTxt) } } + essence_track.annotation&.to_a&.each { |annTxt| essence_track_node.essenceTrackAnnotation { essence_track_node.text(annTxt) } } end end