Class: AtlasRb::Community
- Defined in:
- lib/atlas_rb/community.rb
Overview
A top-level grouping in the Atlas hierarchy.
Communities are organizational containers — they hold Collections and, optionally, sub-Communities. Most institutional structure (departments, programs, projects) is modeled as a tree of Communities with Collections at the leaves.
See also: Collection, Work.
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.
"/communities/"
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 immediate children (sub-Communities and Collections) of a Community.
-
.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: nil, depositor: nil) ⇒ Hash
Create a new Community, optionally seeded with MODS metadata.
-
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash?
Fetch a single Community 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 Community's MODS representation in the requested format.
-
.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Move a Community to a different parent Community — or to the top of the tree.
-
.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 Community.
-
.tombstone(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Tombstone (withdraw) a Community.
-
.update(id, xml_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace a Community'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 immediate children (sub-Communities and Collections) of a Community.
The endpoint returns just the noids; resolve each through Resource.find (which dispatches by type) when richer payloads are needed.
169 170 171 172 173 |
# File 'lib/atlas_rb/community.rb', line 169 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 = nil, xml_path = nil, nuid: nil, on_behalf_of: nil, depositor: nil) ⇒ Hash
Create a new Community, optionally seeded with MODS metadata.
Pass id = nil to create a top-level Community; pass a Community ID to
nest the new Community beneath an existing one.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/atlas_rb/community.rb', line 73 def self.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: nil, depositor: nil) params = { parent_id: id } params[:depositor] = depositor if depositor result = AtlasRb::Mash.new(JSON.parse( connection(params, nuid, on_behalf_of: on_behalf_of).post(ROUTE)&.body ))["community"] 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 Community by ID.
34 35 36 37 |
# File 'lib/atlas_rb/community.rb', line 34 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)["community"] 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.
218 219 220 221 222 |
# File 'lib/atlas_rb/community.rb', line 218 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 Community's MODS representation in the requested format.
275 276 277 278 279 280 |
# File 'lib/atlas_rb/community.rb', line 275 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 Community to a different parent Community — or to the top of the tree.
Wraps PATCH /communities/<id>/parent with a parent_id of the new
parent Community. Pass new_parent_id = nil to promote the Community to
a top-level node (no parent) — mirroring how create treats a nil
id; the gem omits the blank param and Atlas reads it as "move to top".
Atlas re-parents the Community and synchronously cascades the ancestry
index over its descendant Collections and Works; the structural rules
(cycle, tombstone guards) are enforced server-side and surface as a
422.
122 123 124 125 126 127 |
# File 'lib/atlas_rb/community.rb', line 122 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 ))["community"] 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 Community.
Community-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.
250 251 252 253 254 255 256 |
# File 'lib/atlas_rb/community.rb', line 250 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 Community.
The Community 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 Community
still has live (non-tombstoned) members.
147 148 149 |
# File 'lib/atlas_rb/community.rb', line 147 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 Community's metadata by uploading a MODS XML document.
189 190 191 192 193 194 195 196 |
# File 'lib/atlas_rb/community.rb', line 189 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 |