Module: CurationConcerns::CollectionBehavior

Extended by:
ActiveSupport::Concern
Includes:
Collection, HasRepresentative, HumanReadableType, Noid, Permissions, Hydra::AccessControls::WithAccessRight
Included in:
Collection
Defined in:
app/models/concerns/curation_concerns/collection_behavior.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from Permissions::Readable

#private?, #public?, #registered?

Methods included from Permissions::Writable

#paranoid_permissions

Methods included from HumanReadableType

#to_solr

Methods included from Noid

#assign_id, #to_param

Methods included from Collection

#add_member_objects, #add_members, #member_objects

Instance Method Details

#bytesFixnum

Compute the sum of each file in the collection using Solr to avoid having to access Fedora

Returns:

  • (Fixnum)

    size of collection in bytes

Raises:

  • (RuntimeError)

    unsaved record does not exist in solr



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/concerns/curation_concerns/collection_behavior.rb', line 31

def bytes
  return 0 if member_ids.count == 0

  raise "Collection must be saved to query for bytes" if new_record?

  # One query per member_id because Solr is not a relational database
  sizes = member_ids.collect do |work_id|
    argz = { fl: "id, #{file_size_field}",
             fq: "{!join from=#{member_ids_field} to=id}id:#{work_id}"
    }
    files = ::FileSet.search_with_conditions({}, argz)
    files.reduce(0) { |sum, f| sum + f[file_size_field].to_i }
  end

  sizes.reduce(0, :+)
end

#to_sObject



16
17
18
# File 'app/models/concerns/curation_concerns/collection_behavior.rb', line 16

def to_s
  title.present? ? title.join(' | ') : 'No Title'
end