Sha256: a132df1e5ff45208ec2591a81aa94b6b287ba6ee79a8300ab863ee698e1181f3

Contents?: true

Size: 1.85 KB

Versions: 20

Compression:

Stored size: 1.85 KB

Contents

module Ddr
  module Models
    module HasStructMetadata
      extend ActiveSupport::Concern

      included do
        contains Ddr::Models::File::STRUCT_METADATA,
                 class_name: 'Ddr::Models::StructuralMetadataFile'
      end

      def structure
        unless @structure
          if attached_files[Ddr::Models::File::STRUCT_METADATA].content
            @structure = Ddr::Models::Structure.new(Nokogiri::XML(attached_files[Ddr::Models::File::STRUCT_METADATA].content))
          end
        end
        @structure
      end

      def build_default_structure
        structure = Ddr::Models::Structure.new(Ddr::Models::Structure.template)
        children = find_children
        children.each do |child|
          add_to_struct_map(structure, child)
        end
        structure
      end

      def multires_image_file_paths(type='default')
        ::SolrDocument.find(id).multires_image_file_paths(type)
      end

      private

      def find_children
        query = ActiveFedora::SolrQueryBuilder.construct_query_for_rel([[ self.class.reflect_on_association(:children), self.id ]])
        sort = "#{Ddr::Index::Fields::LOCAL_ID} ASC, #{Ddr::Index::Fields::OBJECT_CREATE_DATE} ASC"
        ActiveFedora::SolrService.query(query, sort: sort, rows: 999999)
      end

      def add_to_struct_map(stru, child)
        div = create_div(stru)
        create_fptr(stru, div, child['id'])
      end

      def create_div(stru)
        div_count = stru.structMap_node('default').xpath('xmlns:div').size
        div = Nokogiri::XML::Node.new('div', stru.as_xml_document)
        div['ORDER'] = div_count + 1
        stru.structMap_node('default').add_child(div)
        div
      end

      def create_fptr(stru, div, id)
        fptr = Nokogiri::XML::Node.new('fptr', stru.as_xml_document)
        fptr['CONTENTIDS'] = id
        div.add_child(fptr)
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ddr-models-3.0.8 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.7 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.6 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.5 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.4 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.3 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.2 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.1 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.rc6 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.rc5 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.rc4 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.rc3 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.rc2 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.rc1 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.beta.22 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.beta.21 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.beta.20 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.beta.18 lib/ddr/models/has_struct_metadata.rb
ddr-models-3.0.0.beta.17 lib/ddr/models/has_struct_metadata.rb