Class: Collection

Inherits:
Ddr::Models::Base show all
Includes:
Ddr::Models::HasAttachments, Ddr::Models::HasChildren, Hydra::AdminPolicyBehavior
Defined in:
app/models/collection.rb

Overview

A Collection is a conceptual and administrative entity containing a set of items.

Provides default permissions (Hydra admin policy) for objects associated with the collection via an isGovernedBy relation.

Constant Summary

Constants included from Ddr::Models::HasWorkflow

Ddr::Models::HasWorkflow::PUBLISHED, Ddr::Models::HasWorkflow::UNPUBLISHED

Constants included from Ddr::IndexFields

Ddr::IndexFields::ACTIVE_FEDORA_MODEL, Ddr::IndexFields::COLLECTION_URI, Ddr::IndexFields::CONTENT_CONTROL_GROUP, Ddr::IndexFields::CONTENT_METADATA_PARSED, Ddr::IndexFields::CONTENT_SIZE, Ddr::IndexFields::CONTENT_SIZE_HUMAN, Ddr::IndexFields::HAS_MODEL, Ddr::IndexFields::IDENTIFIER, Ddr::IndexFields::INTERNAL_URI, Ddr::IndexFields::IS_ATTACHED_TO, Ddr::IndexFields::IS_EXTERNAL_TARGET_FOR, Ddr::IndexFields::IS_GOVERNED_BY, Ddr::IndexFields::IS_MEMBER_OF, Ddr::IndexFields::IS_MEMBER_OF_COLLECTION, Ddr::IndexFields::IS_PART_OF, Ddr::IndexFields::LAST_FIXITY_CHECK_ON, Ddr::IndexFields::LAST_FIXITY_CHECK_OUTCOME, Ddr::IndexFields::LAST_VIRUS_CHECK_ON, Ddr::IndexFields::LAST_VIRUS_CHECK_OUTCOME, Ddr::IndexFields::MEDIA_MAJOR_TYPE, Ddr::IndexFields::MEDIA_SUB_TYPE, Ddr::IndexFields::MEDIA_TYPE, Ddr::IndexFields::OBJECT_CREATE_DATE, Ddr::IndexFields::OBJECT_MODIFIED_DATE, Ddr::IndexFields::OBJECT_PROFILE, Ddr::IndexFields::OBJECT_STATE, Ddr::IndexFields::ORIGINAL_FILENAME, Ddr::IndexFields::PERMANENT_ID, Ddr::IndexFields::PERMANENT_URL, Ddr::IndexFields::TITLE, Ddr::IndexFields::WORKFLOW_STATE

Constants included from Ddr::Models::FileManagement

Ddr::Models::FileManagement::EXTERNAL_FILE_PERMISSIONS

Instance Method Summary collapse

Methods included from Ddr::Models::HasChildren

#first_child

Methods inherited from Ddr::Models::Base

#association_query, #copy_admin_policy_or_permissions_from, #model_pid

Methods included from Ddr::Models::HasPreservationMetadata

#assign_permanent_id!, #permanent_id_manager

Methods included from Ddr::Models::HasWorkflow

#publish!, #published?, #unpublish!, #workflow_state

Methods included from Ddr::Models::Indexing

#identifier_sort, #index_fields, #title_display, #to_solr

Methods included from Ddr::IndexFields

solr_name

Methods included from Ddr::Models::FileManagement

#add_external_datastream, #add_external_file, #add_file, #create_external_file_path!, #external_datastream_file_paths, #external_datastreams, #generate_external_file_path

Methods included from Ddr::Models::FixityCheckable

#datastreams_to_validate, #fixity_check, #fixity_checks

Methods included from Ddr::Models::EventLoggable

#events, #has_events?, #notify_event, #update_events

Methods included from Ddr::Models::HasThumbnail

#copy_thumbnail_from, #thumbnail_changed?

Methods included from Ddr::Models::Licensable

#license, #license=

Methods included from Ddr::Models::AccessControllable

#copy_permissions_from, #set_initial_permissions

Methods included from Ddr::Models::Governable

#copy_admin_policy_from, #inherited_license, #inherited_permissions, #inherited_rights

Methods included from Ddr::Models::Describable

#desc_metadata_attributes, #desc_metadata_terms, #desc_metadata_values, #desc_metadata_vocabs, #has_desc_metadata?, #set_desc_metadata, #set_desc_metadata_values

Instance Method Details

#components_from_solrObject

Returns the SolrDocuments for Components associated with the Collection through its member Items.

Returns:

  • A lazy enumerator of SolrDocuments.



29
30
31
32
33
34
35
36
37
# File 'app/models/collection.rb', line 29

def components_from_solr
  outer = Ddr::IndexFields::IS_PART_OF
  inner = Ddr::IndexFields::INTERNAL_URI
  where = ActiveFedora::SolrService.construct_query_for_rel(:is_member_of_collection => internal_uri)
  query = "{!join to=#{outer} from=#{inner}}#{where}"
  filter = ActiveFedora::SolrService.construct_query_for_rel(:has_model => Component.to_class_uri)
  results = ActiveFedora::SolrService.query(query, fq: filter, rows: 100000)
  results.lazy.map {|doc| SolrDocument.new(doc)}
end

#default_entities_for_permission(type, access) ⇒ Array<String>

Returns a list of entities (either users or groups) having a default access level on objects governed by the Collection.

Parameters:

  • type (String)

    the type of entity, “user” or “group”.

  • access (String)

    the default access level, “discover”, “read”, or “edit”.

Returns:

  • (Array<String>)

    the entities (users or groups)



62
63
64
# File 'app/models/collection.rb', line 62

def default_entities_for_permission(type, access)
  default_permissions.collect { |p| p[:name] if p[:type] == type and p[:access] == access }.compact
end

#default_licenseHash

Returns the license attributes provided as default values for objects governed by the Collection.

Returns:

  • (Hash)

    the attributes, ‘:title`, `:description`, and `:url`.



42
43
44
45
46
# File 'app/models/collection.rb', line 42

def default_license
  if default_license_title.present? or default_license_description.present? or default_license_url.present?
    {title: default_license_title, description: default_license_description, url: default_license_url}
  end
end

#default_license=(new_license) ⇒ Object

Sets the default license attributes for objects governed by the Collection.

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
# File 'app/models/collection.rb', line 49

def default_license=(new_license)
  raise ArgumentError unless new_license.is_a?(Hash) # XXX don't do this - not duck-typeable
  l = new_license.with_indifferent_access
  self.default_license_title = l[:title]
  self.default_license_description = l[:description]
  self.default_license_url = l[:url]
end