Class: AtlasRb::Collection
- Defined in:
- lib/atlas_rb/collection.rb
Overview
A grouping of Works and nested Collections, parented by a Community or another Collection.
Collections nest, exactly as they did in DRS v1: a Collection holds Works and/or child Collections, and its own parent may be a Community or a Collection (Community → Community|Collection, Collection → Collection|Work, Work → leaf). A consumer that flattens a subtree must recurse into descendant Collections rather than stopping at direct children.
Constant Summary collapse
- ROUTE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Atlas REST endpoint prefix for this resource.
"/collections/"
Constants inherited from Resource
Constants included from FaradayHelper
FaradayHelper::ASSERTION_AUDIENCE, FaradayHelper::ASSERTION_ISSUER, FaradayHelper::ASSERTION_TTL, FaradayHelper::INSTRUMENTATION_EVENT
Class Method Summary collapse
-
.children(id, nuid: nil, on_behalf_of: nil) ⇒ Array<String>?
List the Works in a Collection.
-
.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: nil, depositor: nil) ⇒ Hash
Create a new Collection under an existing Community or parent Collection.
-
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash?
Fetch a single Collection by ID.
-
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String?
Fetch the Collection's MODS representation in the requested format.
-
.set_featured(id, featured, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Toggle the showcase "Featured" flag on an existing Collection.
Methods inherited from Resource
class_for, descendant_works, find_many, history, mods_version, mods_versions, permissions, preview, put_mods, reparent, set_permissions, set_thumbnails, tombstone
Methods included from FaradayHelper
#connection, #multipart, #read_body, #read_raw, #system_connection, #with_file_part
Class Method Details
.children(id, nuid: nil, on_behalf_of: nil) ⇒ Array<String>?
List the Works in a Collection.
The endpoint returns just the noids; resolve each through Resource.find (or Work.find) when a full payload is needed.
children answers noids only. To render them, resolve the whole list in
one call with Resource.find_many, which returns a
title/thumbnail digest per id — calling find per noid costs a
round-trip per child. For a whole subtree flattened to Works, use
Resource.descendant_works.
147 148 149 |
# File 'lib/atlas_rb/collection.rb', line 147 def self.children(id, nuid: nil, on_behalf_of: nil) read_body(connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id + '/children')) end |
.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: nil, depositor: nil) ⇒ Hash
Create a new Collection under an existing Community or parent Collection.
The id parameter is the parent's ID — a Community or a Collection,
since Collections nest (a Collection may hold child Collections as well as
Works).
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/atlas_rb/collection.rb', line 79 def self.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: nil, depositor: nil) params = { parent_id: id, featured: featured } params[:depositor] = depositor if depositor result = AtlasRb::Mash.new(write_resource( connection(params, nuid, on_behalf_of: on_behalf_of).post(ROUTE) ))["collection"] return result if xml_path.to_s.empty? # The MODS seed is a second call: create takes the parent and the # provenance slots, and the document goes through the write that owns it. AtlasRb::Resource.put_mods(result["id"], xml_path, nuid: nuid, on_behalf_of: on_behalf_of) find(result["id"], nuid: nuid, on_behalf_of: on_behalf_of) end |
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash?
Fetch a single Collection by ID.
36 37 38 39 |
# File 'lib/atlas_rb/collection.rb', line 36 def self.find(id, nuid: nil, on_behalf_of: nil) body = fetch_resource(ROUTE + id, nuid: nuid, on_behalf_of: on_behalf_of) body && AtlasRb::Mash.new(body)["collection"] end |
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String?
Fetch the Collection's MODS representation in the requested format.
171 172 173 174 175 176 |
# File 'lib/atlas_rb/collection.rb', line 171 def self.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) # json default, html, xml read_raw(connection({}, nuid, on_behalf_of: on_behalf_of).get( ROUTE + id + '/mods' + (kind.to_s.empty? ? '' : ".#{kind}") )) end |
.set_featured(id, featured, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Toggle the showcase "Featured" flag on an existing Collection.
A resource-attribute write (not a MODS update), so it does not touch
descriptive metadata. Cerberus reads the projected featured_bsi to
badge the Collection in a community's browse.
112 113 114 115 116 117 |
# File 'lib/atlas_rb/collection.rb', line 112 def self.set_featured(id, featured, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(write_resource( connection({ featured: featured }, nuid, on_behalf_of: on_behalf_of) .patch(ROUTE + id + '/featured') ))["collection"] end |