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.
177 178 179 180 181 |
# File 'lib/atlas_rb/community.rb', line 177 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.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/atlas_rb/community.rb', line 77 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(write_resource( connection(params, nuid, on_behalf_of: on_behalf_of).post(ROUTE) ))["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.
234 235 236 237 238 |
# File 'lib/atlas_rb/community.rb', line 234 def self.(id, values, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(write_resource( connection({ metadata: values }, nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id) )) end |
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String
Fetch the Community's MODS representation in the requested format.
295 296 297 298 299 300 |
# File 'lib/atlas_rb/community.rb', line 295 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.
130 131 132 133 134 135 |
# File 'lib/atlas_rb/community.rb', line 130 def self.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(write_resource( connection({ parent_id: new_parent_id }, nuid, on_behalf_of: on_behalf_of) .patch(ROUTE + id + '/parent') ))["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.
270 271 272 273 274 275 276 |
# File 'lib/atlas_rb/community.rb', line 270 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(write_resource( connection({}, nuid, on_behalf_of: on_behalf_of) .patch(ROUTE + id + '/thumbnails', JSON.dump(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.
155 156 157 |
# File 'lib/atlas_rb/community.rb', line 155 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.
201 202 203 204 205 206 207 208 |
# File 'lib/atlas_rb/community.rb', line 201 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(write_resource( multipart(nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id, payload) )) end |