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 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) ⇒ 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.
-
.metadata(id, values, nuid: nil, on_behalf_of: nil) ⇒ Hash
Patch individual descriptive-metadata fields without uploading a full MODS document.
-
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String
Fetch the Collection's MODS representation in the requested format.
-
.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Move a Collection to a different parent (Community or Collection).
-
.set_featured(id, featured, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Toggle the showcase "Featured" flag on an existing Collection.
-
.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Attach the three thumbnail/preview Delegate URIs to a Collection.
-
.tombstone(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Tombstone (withdraw) a Collection.
-
.update(id, xml_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace a Collection's metadata by uploading a MODS XML document.
Methods inherited from Resource
descendant_works, find_many, history, mods_version, mods_versions, permissions, preview
Methods included from FaradayHelper
#connection, #multipart, #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.
174 175 176 177 178 |
# File 'lib/atlas_rb/collection.rb', line 174 def self.children(id, nuid: nil, on_behalf_of: nil) JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id + '/children')&.body ) end |
.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: 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).
65 66 67 68 69 70 71 72 73 |
# File 'lib/atlas_rb/collection.rb', line 65 def self.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: nil) result = AtlasRb::Mash.new(JSON.parse( connection({ parent_id: id, featured: featured }, nuid, on_behalf_of: on_behalf_of).post(ROUTE)&.body ))["collection"] return result if xml_path.to_s.empty? update(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 |
.metadata(id, values, nuid: nil, on_behalf_of: nil) ⇒ Hash
Patch individual descriptive-metadata fields without uploading a full MODS document.
Scoped to user-authored descriptive metadata only. Programmatic writes of machine-set Delegate URIs (thumbnails) have their own purpose-specific endpoint — see set_thumbnails.
222 223 224 225 226 |
# File 'lib/atlas_rb/collection.rb', line 222 def self.(id, values, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({ metadata: values }, nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id)&.body )) end |
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String
Fetch the Collection's MODS representation in the requested format.
277 278 279 280 281 282 |
# File 'lib/atlas_rb/collection.rb', line 277 def self.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) # json default, html, xml connection({}, nuid, on_behalf_of: on_behalf_of).get( ROUTE + id + '/mods' + (kind.to_s.empty? ? '' : ".#{kind}") )&.body end |
.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Move a Collection to a different parent (Community or Collection).
Wraps PATCH /collections/<id>/parent with a parent_id of the new
parent. Atlas re-parents the Collection and synchronously cascades
the ancestry index over its Works; the structural rules (type, cycle,
tombstone guards) are enforced server-side and surface as a 422.
Mirrors create's "single parent id" shape — same kwarg threading, the only difference is the verb and that the Collection already exists.
128 129 130 131 132 133 |
# File 'lib/atlas_rb/collection.rb', line 128 def self.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({ parent_id: new_parent_id }, nuid, on_behalf_of: on_behalf_of) .patch(ROUTE + id + '/parent')&.body ))["collection"] 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.
90 91 92 93 94 |
# File 'lib/atlas_rb/collection.rb', line 90 def self.set_featured(id, featured, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({ featured: featured }, nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id)&.body ))["collection"] end |
.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Attach the three thumbnail/preview Delegate URIs to a Collection.
Collection-level mirror of Work.set_thumbnails. Atlas dispatches
each non-blank URI to its matching Delegate role
(thumbnail_image / thumbnail_image_2x / preview_image) via
DelegateUpdater. Missing keys are left untouched.
254 255 256 257 258 259 260 |
# File 'lib/atlas_rb/collection.rb', line 254 def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) body = { thumbnail: thumbnail, thumbnail_2x: thumbnail_2x, preview: preview }.compact AtlasRb::Mash.new(JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of) .patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body )) end |
.tombstone(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Tombstone (withdraw) a Collection.
The Collection remains in Atlas storage but is marked as withdrawn:
search and show pages return a withdrawn stub for every user. Atlas
rejects the request with 422 has_live_children if the Collection
still has live (non-tombstoned) Works.
153 154 155 |
# File 'lib/atlas_rb/collection.rb', line 153 def self.tombstone(id, nuid: nil, on_behalf_of: nil) connection({}, nuid, on_behalf_of: on_behalf_of).post(ROUTE + id + '/tombstone') end |
.update(id, xml_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace a Collection's metadata by uploading a MODS XML document.
194 195 196 197 198 199 200 201 |
# File 'lib/atlas_rb/collection.rb', line 194 def self.update(id, xml_path, nuid: nil, on_behalf_of: nil) payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path), "application/xml", File.basename(xml_path)) } AtlasRb::Mash.new(JSON.parse( multipart(nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id, payload)&.body )) end |