Module: Hyrax::CollectionBehavior

Extended by:
ActiveSupport::Concern
Includes:
Hydra::AccessControls::WithAccessRight, Hydra::WithDepositor, Hydra::Works::CollectionBehavior, CollectionNesting, CoreMetadata, HasRepresentative, HumanReadableType, Noid, Permissions
Included in:
Collection
Defined in:
app/models/concerns/hyrax/collection_behavior.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from CollectionNesting

#find_children_of, #reindex_extent, #reindex_extent=, #update_index, #use_nested_reindexing?

Methods included from Permissions::Readable

#private?, #public?, #registered?

Methods included from Permissions::Writable

#paranoid_permissions

Methods included from HumanReadableType

#human_readable_type, #to_solr

Methods included from Noid

#assign_id

Instance Method Details

#add_member_objects(new_member_ids) ⇒ Object

Add member objects by adding this collection to the objects' member_of_collection association.

Parameters:

  • the (Enumerable<String>)

    ids of the new child collections and works collection ids


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 63

def add_member_objects(new_member_ids)
  Array(new_member_ids).collect do |member_id|
    member = Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: member_id, use_valkyrie: false)
    message = Hyrax::MultipleMembershipChecker.new(item: member).check(collection_ids: id, include_current_members: true)
    if message
      member.errors.add(:collections, message)
    else
      member.member_of_collections << self
      member.save!
    end
    member
  end
end

#add_members(new_member_ids) ⇒ Object

Add members using the members association. TODO: Confirm if this is ever used. I believe all relationships are done through

add_member_objects using the member_of_collections relationship.  Deprecate?

56
57
58
59
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 56

def add_members(new_member_ids)
  return if new_member_ids.blank?
  members << Hyrax.custom_queries.find_many_by_alternate_ids(alternate_ids: new_member_ids, use_valkyrie: false)
end

#bytesFixnum

Deprecated.

to be removed in 4.0.0; this feature was replaced with a hard-coded null implementation

Returns 0.

Returns:

  • (Fixnum)

    0


112
113
114
115
116
117
118
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 112

def bytes
  Deprecation.warn('#bytes has been deprecated for removal in Hyrax 4.0.0; ' \
                   'The implementation of the indexed Collection size ' \
                   'feature is extremely inefficient, so it has been removed. ' \
                   'This method now returns a hard-coded `0` for compatibility.')
  0
end

#collection_typeObject

Get the collection_type when accessed


45
46
47
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 45

def collection_type
  @collection_type ||= Hyrax::CollectionType.find_by_gid!(collection_type_gid)
end

#collection_type=(new_collection_type) ⇒ Object


49
50
51
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 49

def collection_type=(new_collection_type)
  self.collection_type_gid = new_collection_type.to_global_id
end

#member_object_idsObject

Use this query to get the ids of the member objects (since the containment association has been flipped)


84
85
86
87
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 84

def member_object_ids
  return [] unless id
  member_objects.map(&:id)
end

#member_objectsEnumerable<ActiveFedora::Base>

Returns an enumerable over the children of this collection.

Returns:


78
79
80
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 78

def member_objects
  ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id}")
end

#permission_templateHyrax::PermissionTemplate

Retrieve the permission template for this collection.

Returns:

Raises:

  • (ActiveRecord::RecordNotFound)

124
125
126
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 124

def permission_template
  Hyrax::PermissionTemplate.find_by!(source_id: id)
end

#reset_access_controls!Object

Calculate and update who should have read/edit access to the collections based on who has access in PermissionTemplateAccess


130
131
132
133
134
135
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 130

def reset_access_controls!
  update!(edit_users: permission_template_edit_users,
          edit_groups: permission_template_edit_groups,
          read_users: permission_template_read_users,
          read_groups: (permission_template_read_groups + visibility_group).uniq)
end

#to_sObject


89
90
91
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 89

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