lib/ddr/models/solr_document.rb in ddr-models-2.8.0 vs lib/ddr/models/solr_document.rb in ddr-models-2.9.0.rc1

- old
+ new

@@ -139,10 +139,14 @@ def has_content? has_datastream?(Ddr::Datastreams::CONTENT) end + def has_intermediate_file? + has_datastream?(Ddr::Datastreams::INTERMEDIATE_FILE) + end + def has_extracted_text? has_datastream?(Ddr::Datastreams::EXTRACTED_TEXT) end def content_ds @@ -231,14 +235,81 @@ if ead_id FindingAid.new(ead_id) end end + def intermediate_type + if has_intermediate_file? + datastreams[Ddr::Datastreams::INTERMEDIATE_FILE]["dsMIME"] + end + end + + def intermediate_path + if has_intermediate_file? + Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::INTERMEDIATE_FILE]["dsLocation"]) + end + end + + def intermediate_extension + if has_intermediate_file? + extensions = Ddr::Models.preferred_file_extensions + if extensions.include? intermediate_type + extensions[intermediate_type] + else + intermediate_extension_default + end + end + end + + def captionable? + has_datastream?(Ddr::Datastreams::CAPTION) + end + + def caption_type + if captionable? + datastreams[Ddr::Datastreams::CAPTION]["dsMIME"] + end + end + + def caption_extension + if captionable? + extensions = Ddr::Models.preferred_file_extensions + if extensions.include? caption_type + extensions[caption_type] + else + caption_extension_default + end + end + end + + def caption_path + if captionable? + Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::CAPTION]["dsLocation"]) + end + end + def streamable? has_datastream?(Ddr::Datastreams::STREAMABLE_MEDIA) end + def streamable_media_extension + if streamable? + extensions = Ddr::Models.preferred_file_extensions + if extensions.include? streamable_media_type + extensions[streamable_media_type] + else + streamable_media_extension_default + end + end + end + + def streamable_media_type + if streamable? + datastreams[Ddr::Datastreams::STREAMABLE_MEDIA]["dsMIME"] + end + end + def streamable_media_path if streamable? Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::STREAMABLE_MEDIA]["dsLocation"]) end end @@ -246,10 +317,14 @@ # FIXME - Probably need a more general solution mapping object reader methods to index field names. def rights self["rights_tesim"] end + def children + children_query.docs rescue [] + end + private def targets_query "#{Ddr::Index::Fields::IS_EXTERNAL_TARGET_FOR}:#{internal_uri_for_query}" end @@ -294,7 +369,31 @@ def default_struct_map structure['default'] || structure.values.first end + def intermediate_extension_default + datastreams[Ddr::Datastreams::INTERMEDIATE_FILE].default_file_extension + end + + def caption_extension_default + datastreams[Ddr::Datastreams::CAPTION].default_file_extension + end + + def streamable_media_extension_default + datastreams[Ddr::Datastreams::STREAMABLE_MEDIA].default_file_extension + end + + def children_query + case self[Ddr::Index::Fields::ACTIVE_FEDORA_MODEL] + when 'Collection' + Ddr::Index::Query.build(self) do |parent| + is_member_of_collection parent.id + end + when 'Item' + Ddr::Index::Query.build(self) do |parent| + is_part_of parent.id + end + end + end end end