atlas_rb 1.29.4 → 1.29.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc6d758d43135f85f61b7a8a0aa8ba86af108d4894d84f17cee9d91b7bdffbb8
4
- data.tar.gz: ca3e2c5a080af089e4fd2734b2a8b185f3ad54d2ee58a53b3aef61ec3b518691
3
+ metadata.gz: f25cd02a3fdd7a916ead4b71c784798f2a8eea61c58690f1caba0b841b46681e
4
+ data.tar.gz: c4707259a5cdce5d8861031ea7347b38a2dd0544f891acc582ddc64314e81651
5
5
  SHA512:
6
- metadata.gz: fd67f7abf09587a4dc0d5fc284a76108e618fa34e0c32f38a900a5ccda11d5e31255f5ab01461435674a03d08a067b71eabba49a37ceada0ad034ee5dc7d1531
7
- data.tar.gz: eae45b648e6322aeefefc3e67f4e35c53fda0a87a36a29613b2b7d27183237a104ec5ecd5082bde721b6dfe6f049109aa247ea7d027f7762574adc9e50ab6ea7
6
+ metadata.gz: 9cb8668bd08869e86278deae33e14c0822bc4ce628fd7fe6ada78d797726767b845f4386311056375121348b456e4dcafef2279ee95febbad94d0e98e4290faa
7
+ data.tar.gz: d52af1dadb11eb38eb7fabc55ea859457d9644cefcf10c9051ce87dbb7cb882943d50625d5476070749d156036dd26f985b98e4b632a376ae82d3bb5812238b4
data/.version CHANGED
@@ -1 +1 @@
1
- 1.29.4
1
+ 1.29.6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.29.6
4
+
5
+ Needs an Atlas with the scoped search routes. An older Atlas answers `404`,
6
+ and each method returns `nil`.
7
+
8
+ ### Added — `Compilation.search`, `Collection.search` and `Community.search`
9
+
10
+ Wrap `GET /compilations/<id>/search`, `GET /collections/<id>/search` and
11
+ `GET /communities/<id>/search`: a keyword, filters and facet counts over the
12
+ Works of one Set or one container's subtree. Each returns a `Mash` with
13
+ `works`, `pagination` and `facets`, or `nil` on a `404`. `filters:` is sent
14
+ as `f[field][]=value` and `facets:` as `facet[]=field`.
15
+
16
+ Embargoed, in-progress and incomplete Works never appear, even for an admin
17
+ token. A facet or filter field that Atlas does not allow, or an unknown
18
+ `sort`, raises `ResourceError` with status `400` and Atlas's message.
19
+
20
+ `Collection.search` and `Community.search` shadow the catalog-wide
21
+ `Resource.search` on those two classes. Call `Resource.search` for the
22
+ catalog.
23
+
24
+ ## 1.29.5
25
+
26
+ Needs an Atlas that records a v1 pid (0.6.279 or later). An older Atlas ignores
27
+ the `legacy_pid:` param, and the lookup answers `nil`.
28
+
29
+ ### Changed — needs Ruby 3.2 or later
30
+
31
+ `required_ruby_version` rises from 2.6 to 3.2, the oldest Ruby a consumer runs
32
+ (Cerberus). The gem's CI already builds on 3.4 only.
33
+
34
+ ### Added — `legacy_pid:` on `Community.create`, `Collection.create` and `Work.create`
35
+
36
+ Records the v1 pid a migrated object came from, on its first save. Admin only:
37
+ anyone else gets `ForbiddenError` with `action` `"supply_legacy_pid"`, and
38
+ nothing is created. There is no way to change the pid after the create.
39
+
40
+ ### Added — `LegacyPidError`
41
+
42
+ Raised when Atlas refuses the pid: `code` is `"invalid_legacy_pid"` (a `422`)
43
+ or `"legacy_pid_taken"` (a `409`). On a `409`, `holder_id` is the NOID of the
44
+ resource that holds the pid. A subclass of `ResourceError`.
45
+
46
+ ### Added — `Resource.find_by_legacy_pid` and `System.find_by_legacy_pid`
47
+
48
+ Wrap `GET /resources/legacy/<pid>` and return `id`, `type` and `tombstoned`, or
49
+ `nil` when nothing holds the pid. A tombstoned holder is still returned. The
50
+ user-path method answers `nil` for a holder the caller may not read; the system
51
+ method reads past that gate, so a host can redirect an old v1 URL for any
52
+ visitor.
53
+
3
54
  ## 1.29.4
4
55
 
5
56
  Needs an Atlas that accepts a supplied handle (0.6.277 or later). An older
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (1.29.4)
4
+ atlas_rb (1.29.6)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.3.0)
7
7
  faraday-multipart (~> 1)
@@ -14,7 +14,7 @@ GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
16
  base64 (0.3.0)
17
- connection_pool (2.5.5)
17
+ connection_pool (3.0.2)
18
18
  diff-lcs (1.6.1)
19
19
  faraday (2.15.1)
20
20
  faraday-net_http (>= 2.0, < 3.6)
@@ -72,10 +72,18 @@ module AtlasRb
72
72
  # while attributing it to the anonymous NUID, since nobody personally owns
73
73
  # those containers and access to them is via Grouper groups. The depositor
74
74
  # is immutable post-create; there is no setter on the update surface.
75
+ # @param legacy_pid [String, nil] optional v1 pid the Collection migrated
76
+ # from, such as `"neu:5678"`. Admin only; anyone else gets
77
+ # {ForbiddenError} with `action` `"supply_legacy_pid"`. It lands on the
78
+ # first save, so send it here and not on a later `put_mods`. There is no
79
+ # way to change it after the create. Needs Atlas 0.6.279 or later.
75
80
  # @return [Hash] the created Collection payload (post-update if
76
81
  # `xml_path` was supplied).
77
82
  # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
78
83
  # resource, so the write did not happen.
84
+ # @raise [AtlasRb::LegacyPidError] if Atlas refuses the `legacy_pid:` as
85
+ # malformed (`422`) or held by another resource (`409`, with
86
+ # {LegacyPidError#holder_id}).
79
87
  # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
80
88
  # and body.
81
89
  #
@@ -84,9 +92,14 @@ module AtlasRb
84
92
  #
85
93
  # @example An institutional container owned by nobody
86
94
  # AtlasRb::Collection.create("c-123", depositor: "000000099")
87
- def self.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: nil, depositor: nil)
95
+ #
96
+ # @example A migrated Collection that records its v1 pid
97
+ # AtlasRb::Collection.create("c-123", legacy_pid: "neu:5678", nuid: admin_nuid)
98
+ def self.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: nil, depositor: nil,
99
+ legacy_pid: nil)
88
100
  params = { parent_id: id, featured: featured }
89
- params[:depositor] = depositor if depositor
101
+ params[:depositor] = depositor if depositor
102
+ params[:legacy_pid] = legacy_pid if legacy_pid
90
103
  result = AtlasRb::Mash.new(write_resource(
91
104
  connection(params, nuid, on_behalf_of: on_behalf_of).post(ROUTE)
92
105
  ))["collection"]
@@ -182,5 +195,56 @@ module AtlasRb
182
195
  ROUTE + id + '/mods' + (kind.to_s.empty? ? '' : ".#{kind}")
183
196
  ))
184
197
  end
198
+
199
+ # Search the Works beneath a Collection, at any depth, with filters and facet
200
+ # counts.
201
+ #
202
+ # Wraps `GET /collections/<id>/search`. The rows are the same Work digests
203
+ # {Resource.descendant_works} returns, gated to what the caller may read.
204
+ #
205
+ # **Embargoed, in-progress and incomplete Works never appear, for any
206
+ # caller.** That includes an admin token: the route is a public feed. Use
207
+ # {Resource.descendant_works} or {Compilation.contents} to see them.
208
+ #
209
+ # @param id [String] the Collection ID.
210
+ # @param q [String, nil] keyword query; `nil` lists the whole scope.
211
+ # @param filters [Hash{String => String, Array<String>}] field to values,
212
+ # e.g. `{ "genre_ssim" => ["Photographs"] }`. Values in one field match
213
+ # any; every field must match. Sent as `f[field][]=value`.
214
+ # @param facets [Array<String>] the fields to count values for. Sent as
215
+ # `facet[]=field`.
216
+ # @param facet_limit [Integer, nil] values per facet (Atlas: default 20, at
217
+ # most 100).
218
+ # @param sort [String, nil] `"relevance"`, `"title"` or `"date"` (newest
219
+ # first). Atlas sorts by relevance when `q` is given, and by a stable
220
+ # order otherwise.
221
+ # @param page [Integer, nil] 1-based page (default 1).
222
+ # @param per_page [Integer, nil] page size (default 25, at most 100).
223
+ # @param include_linked [Boolean, nil] also search Works linked into the
224
+ # subtree from elsewhere when truthy; structural members only by default.
225
+ # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
226
+ # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
227
+ # path it is ignored (identity lives in the token).
228
+ # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
229
+ # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
230
+ # omitted.
231
+ # @return [AtlasRb::Mash, nil] `{ "works" => [...], "pagination" => {...},
232
+ # "facets" => { "genre_ssim" => [{ "value", "count" }] } }`. The counts
233
+ # cover the whole result, not just the page. `nil` when Atlas answers `404`.
234
+ # @raise [AtlasRb::ResourceError] on any non-2xx other than `404` / `410`.
235
+ # A `400` means a facet or filter field Atlas does not allow, or an
236
+ # unknown sort; the error's message carries Atlas's explanation.
237
+ # @example
238
+ # page = AtlasRb::Collection.search("x-123", filters: { "genre_ssim" => ["Maps"] }, sort: "title")
239
+ # page.works.map(&:noid)
240
+ def self.search(id, q: nil, filters: {}, facets: [], facet_limit: nil, sort: nil,
241
+ page: nil, per_page: nil, include_linked: nil, nuid: nil, on_behalf_of: nil)
242
+ params = scoped_search_params(q: q, filters: filters, facets: facets, facet_limit: facet_limit,
243
+ sort: sort, page: page, per_page: per_page)
244
+ params[:include_linked] = include_linked unless include_linked.nil?
245
+ read_body(connection(params, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id + '/search')) do |body|
246
+ AtlasRb::Mash.new(body)
247
+ end
248
+ end
185
249
  end
186
250
  end
@@ -67,10 +67,18 @@ module AtlasRb
67
67
  # while attributing it to the anonymous NUID, since nobody personally owns
68
68
  # those containers and access to them is via Grouper groups. The depositor
69
69
  # is immutable post-create; there is no setter on the update surface.
70
+ # @param legacy_pid [String, nil] optional v1 pid the Community migrated
71
+ # from, such as `"neu:1"`. Admin only; anyone else gets
72
+ # {ForbiddenError} with `action` `"supply_legacy_pid"`. It lands on the
73
+ # first save, so send it here and not on a later `put_mods`. There is no
74
+ # way to change it after the create. Needs Atlas 0.6.279 or later.
70
75
  # @return [Hash] the created Community payload (post-update if `xml_path`
71
76
  # was supplied).
72
77
  # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
73
78
  # resource, so the write did not happen.
79
+ # @raise [AtlasRb::LegacyPidError] if Atlas refuses the `legacy_pid:` as
80
+ # malformed (`422`) or held by another resource (`409`, with
81
+ # {LegacyPidError#holder_id}).
74
82
  # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
75
83
  # and body.
76
84
  #
@@ -82,9 +90,13 @@ module AtlasRb
82
90
  #
83
91
  # @example An institutional container owned by nobody
84
92
  # AtlasRb::Community.create("c-parent", depositor: "000000099")
85
- def self.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: nil, depositor: nil)
93
+ #
94
+ # @example The migrated repository root, which stands in for v1's neu:1
95
+ # AtlasRb::Community.create(nil, legacy_pid: "neu:1", nuid: admin_nuid)
96
+ def self.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: nil, depositor: nil, legacy_pid: nil)
86
97
  params = { parent_id: id }
87
- params[:depositor] = depositor if depositor
98
+ params[:depositor] = depositor if depositor
99
+ params[:legacy_pid] = legacy_pid if legacy_pid
88
100
  result = AtlasRb::Mash.new(write_resource(
89
101
  connection(params, nuid, on_behalf_of: on_behalf_of).post(ROUTE)
90
102
  ))["community"]
@@ -157,5 +169,56 @@ module AtlasRb
157
169
  ROUTE + id + '/mods' + (kind.to_s.empty? ? '' : ".#{kind}")
158
170
  ))
159
171
  end
172
+
173
+ # Search the Works beneath a Community, at any depth, with filters and facet
174
+ # counts.
175
+ #
176
+ # Wraps `GET /communities/<id>/search`. The rows are the same Work digests
177
+ # {Resource.descendant_works} returns, gated to what the caller may read.
178
+ #
179
+ # **Embargoed, in-progress and incomplete Works never appear, for any
180
+ # caller.** That includes an admin token: the route is a public feed. Use
181
+ # {Resource.descendant_works} or {Compilation.contents} to see them.
182
+ #
183
+ # @param id [String] the Community ID.
184
+ # @param q [String, nil] keyword query; `nil` lists the whole scope.
185
+ # @param filters [Hash{String => String, Array<String>}] field to values,
186
+ # e.g. `{ "genre_ssim" => ["Photographs"] }`. Values in one field match
187
+ # any; every field must match. Sent as `f[field][]=value`.
188
+ # @param facets [Array<String>] the fields to count values for. Sent as
189
+ # `facet[]=field`.
190
+ # @param facet_limit [Integer, nil] values per facet (Atlas: default 20, at
191
+ # most 100).
192
+ # @param sort [String, nil] `"relevance"`, `"title"` or `"date"` (newest
193
+ # first). Atlas sorts by relevance when `q` is given, and by a stable
194
+ # order otherwise.
195
+ # @param page [Integer, nil] 1-based page (default 1).
196
+ # @param per_page [Integer, nil] page size (default 25, at most 100).
197
+ # @param include_linked [Boolean, nil] also search Works linked into the
198
+ # subtree from elsewhere when truthy; structural members only by default.
199
+ # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
200
+ # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
201
+ # path it is ignored (identity lives in the token).
202
+ # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
203
+ # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
204
+ # omitted.
205
+ # @return [AtlasRb::Mash, nil] `{ "works" => [...], "pagination" => {...},
206
+ # "facets" => { "genre_ssim" => [{ "value", "count" }] } }`. The counts
207
+ # cover the whole result, not just the page. `nil` when Atlas answers `404`.
208
+ # @raise [AtlasRb::ResourceError] on any non-2xx other than `404` / `410`.
209
+ # A `400` means a facet or filter field Atlas does not allow, or an
210
+ # unknown sort; the error's message carries Atlas's explanation.
211
+ # @example
212
+ # page = AtlasRb::Community.search("x-123", filters: { "genre_ssim" => ["Maps"] }, sort: "title")
213
+ # page.works.map(&:noid)
214
+ def self.search(id, q: nil, filters: {}, facets: [], facet_limit: nil, sort: nil,
215
+ page: nil, per_page: nil, include_linked: nil, nuid: nil, on_behalf_of: nil)
216
+ params = scoped_search_params(q: q, filters: filters, facets: facets, facet_limit: facet_limit,
217
+ sort: sort, page: page, per_page: per_page)
218
+ params[:include_linked] = include_linked unless include_linked.nil?
219
+ read_body(connection(params, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id + '/search')) do |body|
220
+ AtlasRb::Mash.new(body)
221
+ end
222
+ end
160
223
  end
161
224
  end
@@ -445,5 +445,53 @@ module AtlasRb
445
445
  AtlasRb::Mash.new(body)
446
446
  end
447
447
  end
448
+
449
+ # Search the Works in a Set (its resolved recipe), with filters and facet counts.
450
+ #
451
+ # Wraps `GET /compilations/<id>/search`. The rows are the same Work digests
452
+ # {Resource.descendant_works} returns, gated to what the caller may read.
453
+ #
454
+ # **Embargoed, in-progress and incomplete Works never appear, for any
455
+ # caller.** That includes an admin token: the route is a public feed. Use
456
+ # {Resource.descendant_works} or {Compilation.contents} to see them.
457
+ #
458
+ # @param id [String] the Compilation ID.
459
+ # @param q [String, nil] keyword query; `nil` lists the whole scope.
460
+ # @param filters [Hash{String => String, Array<String>}] field to values,
461
+ # e.g. `{ "genre_ssim" => ["Photographs"] }`. Values in one field match
462
+ # any; every field must match. Sent as `f[field][]=value`.
463
+ # @param facets [Array<String>] the fields to count values for. Sent as
464
+ # `facet[]=field`.
465
+ # @param facet_limit [Integer, nil] values per facet (Atlas: default 20, at
466
+ # most 100).
467
+ # @param sort [String, nil] `"relevance"`, `"title"` or `"date"` (newest
468
+ # first). Atlas sorts by relevance when `q` is given, and by a stable
469
+ # order otherwise.
470
+ # @param page [Integer, nil] 1-based page (default 1).
471
+ # @param per_page [Integer, nil] page size (default 25, at most 100).
472
+ # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
473
+ # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
474
+ # path it is ignored (identity lives in the token).
475
+ # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
476
+ # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
477
+ # omitted.
478
+ # @return [AtlasRb::Mash, nil] `{ "works" => [...], "pagination" => {...},
479
+ # "facets" => { "genre_ssim" => [{ "value", "count" }] } }`. The counts
480
+ # cover the whole result, not just the page. `nil` when Atlas answers `404`.
481
+ # @raise [AtlasRb::ResourceError] on any non-2xx other than `404` / `410`.
482
+ # A `400` means a facet or filter field Atlas does not allow, or an
483
+ # unknown sort; the error's message carries Atlas's explanation.
484
+ # @example
485
+ # page = AtlasRb::Compilation.search("c-123", q: "harbor", facets: ["genre_ssim"])
486
+ # page.works.map(&:noid)
487
+ # page.facets.genre_ssim.map { |row| [row.value, row.count] }
488
+ def self.search(id, q: nil, filters: {}, facets: [], facet_limit: nil, sort: nil,
489
+ page: nil, per_page: nil, nuid: nil, on_behalf_of: nil)
490
+ params = scoped_search_params(q: q, filters: filters, facets: facets, facet_limit: facet_limit,
491
+ sort: sort, page: page, per_page: per_page)
492
+ read_body(connection(params, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id + '/search')) do |body|
493
+ AtlasRb::Mash.new(body)
494
+ end
495
+ end
448
496
  end
449
497
  end
@@ -378,6 +378,50 @@ module AtlasRb
378
378
  # a caller that only wants "the write failed" can rescue the parent.
379
379
  class NotFoundError < ResourceError; end
380
380
 
381
+ # Raised when Atlas refuses a create's `legacy_pid:`: a value that is not a
382
+ # v1 pid (`422`, `invalid_legacy_pid`), or one another resource already
383
+ # holds (`409`, `legacy_pid_taken`).
384
+ #
385
+ # On a `409`, {#holder_id} is the holder's NOID. A migration that crashed
386
+ # between the create and its own bookkeeping reads it to recover, rather
387
+ # than parsing the message:
388
+ #
389
+ # rescue AtlasRb::LegacyPidError => e
390
+ # raise unless e.code == "legacy_pid_taken"
391
+ # ledger.record(pid, e.holder_id)
392
+ #
393
+ # A subclass of {ResourceError}, so a caller that only wants "the create
394
+ # failed" can rescue the parent. Needs Atlas 0.6.279 or later.
395
+ class LegacyPidError < ResourceError
396
+ # The discriminators Atlas renders. An exact-match wire contract.
397
+ CODES = %w[invalid_legacy_pid legacy_pid_taken].freeze
398
+
399
+ # @return [String] the envelope's `error` code.
400
+ attr_reader :code
401
+
402
+ # @return [String, nil] NOID of the resource that holds the pid, on a `409`.
403
+ attr_reader :holder_id
404
+
405
+ # @param message [String] human-readable refusal description.
406
+ # @param envelope [Hash] Atlas's parsed refusal body.
407
+ # @param response [Faraday::Response, nil] the originating response.
408
+ def initialize(message, envelope, response: nil)
409
+ super(message, response: response)
410
+ @code = envelope["error"]
411
+ @holder_id = envelope["resource_id"]
412
+ end
413
+
414
+ # @return [Hash, nil] the envelope when `body` is a legacy-pid refusal,
415
+ # parsed; `nil` for any other body.
416
+ # @api private
417
+ def self.envelope(body)
418
+ parsed = body.is_a?(Hash) ? body : JSON.parse(body.to_s)
419
+ parsed if parsed.is_a?(Hash) && CODES.include?(parsed["error"])
420
+ rescue JSON::ParserError
421
+ nil
422
+ end
423
+ end
424
+
381
425
  # Raised when Atlas withholds a file, or a Work's file list, because of a
382
426
  # tombstone: an HTTP `410` whose body carries `error: "tombstoned"`.
383
427
  #
@@ -133,6 +133,38 @@ module AtlasRb
133
133
  "resource" => result.first[1])
134
134
  end
135
135
 
136
+ # Find the Community, Collection or Work a v1 pid migrated to.
137
+ #
138
+ # Wraps `GET /resources/legacy/<pid>`. A tombstoned holder is still
139
+ # answered, flagged, so an old v1 URL can land on its tombstone page. Atlas
140
+ # answers a holder the caller may not read exactly as an unknown pid, so
141
+ # `nil` means "nothing this caller can see holds it". To resolve a pid for
142
+ # any visitor, use {AtlasRb::System.find_by_legacy_pid}.
143
+ #
144
+ # @param pid [String] a v1 pid, `neu:` prefix included.
145
+ # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
146
+ # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
147
+ # path it is ignored (identity lives in the token).
148
+ # @return [AtlasRb::Mash, nil] `id` (the NOID), `type` (`"Community"`,
149
+ # `"Collection"` or `"Work"`) and `tombstoned`, or `nil` on a `404`.
150
+ # @raise [AtlasRb::ResourceError] on any other non-2xx.
151
+ #
152
+ # @example
153
+ # AtlasRb::Resource.find_by_legacy_pid("neu:1234")
154
+ # # => { "id" => "abc123", "type" => "Work", "tombstoned" => false }
155
+ def self.find_by_legacy_pid(pid, nuid: nil)
156
+ result = fetch_resource(legacy_pid_path(pid), nuid: nuid)
157
+ result && AtlasRb::Mash.new(result["resource"])
158
+ end
159
+
160
+ # The lookup path for a pid. The colon is put back after encoding,
161
+ # because Atlas's route matches the literal `neu:` prefix.
162
+ #
163
+ # @api private
164
+ def self.legacy_pid_path(pid)
165
+ "/resources/legacy/#{URI.encode_uri_component(pid.to_s).gsub('%3A', ':')}"
166
+ end
167
+
136
168
  # Resolve many resources by NOID in a single round-trip.
137
169
  #
138
170
  # Wraps Atlas's `POST /resources/find_many`, which returns one lightweight
@@ -606,7 +638,11 @@ module AtlasRb
606
638
  end
607
639
  return if resp.success? || resp.status == 410
608
640
 
609
- raise AtlasRb::ResourceError.new("#{request_target(resp)} → #{resp.status}: #{resp.body}", response: resp)
641
+ message = "#{request_target(resp)} → #{resp.status}: #{resp.body}"
642
+ envelope = AtlasRb::LegacyPidError.envelope(resp.body)
643
+ raise AtlasRb::LegacyPidError.new(message, envelope, response: resp) if envelope
644
+
645
+ raise AtlasRb::ResourceError.new(message, response: resp)
610
646
  end
611
647
  private_class_method :guard_write
612
648
 
@@ -632,5 +668,30 @@ module AtlasRb
632
668
  payload
633
669
  end
634
670
  private_class_method :xml_upload_payload
671
+
672
+ # The query parameters of a scoped search: {Compilation.search},
673
+ # {Collection.search} and {Community.search}.
674
+ #
675
+ # Ruby-friendly names in, Atlas's wire names out: `filters:` becomes `f`
676
+ # and `facets:` becomes `facet`. Faraday's nested encoder then sends
677
+ # `f[genre_ssim][]=Photographs` and `facet[]=genre_ssim`, which is the
678
+ # shape Atlas reads. A parameter the caller left `nil` or empty is not
679
+ # sent at all, so Atlas applies its own default.
680
+ #
681
+ # @param q [String, nil] the keyword.
682
+ # @param filters [Hash{String => String, Array<String>}, nil] field to values.
683
+ # @param facets [Array<String>, String, nil] the fields to count.
684
+ # @param options [Hash] `facet_limit`, `sort`, `page`, `per_page`, sent when
685
+ # not `nil`.
686
+ # @return [Hash] the query parameters.
687
+ # @api private
688
+ def self.scoped_search_params(q:, filters:, facets:, **options)
689
+ params = options.compact
690
+ params[:q] = q unless q.nil?
691
+ params[:f] = filters.to_h { |field, values| [field.to_s, Array(values)] } unless filters.nil? || filters.empty?
692
+ params[:facet] = Array(facets) unless facets.nil? || Array(facets).empty?
693
+ params
694
+ end
695
+ private_class_method :scoped_search_params
635
696
  end
636
697
  end
@@ -76,5 +76,23 @@ module AtlasRb
76
76
  path = since ? "/embargoes/release?since=#{since.iso8601}" : "/embargoes/release"
77
77
  JSON.parse(system_connection.post(path).body)["released"]
78
78
  end
79
+
80
+ # Find the Community, Collection or Work a v1 pid migrated to, whoever the
81
+ # visitor is. The `:system` role reads past the per-resource gate, so a
82
+ # host redirecting an old v1 URL gets the holder even when the visitor
83
+ # could not read it; the destination page applies the visitor's own gate.
84
+ # {AtlasRb::Resource.find_by_legacy_pid} is the user-path lookup.
85
+ #
86
+ # @param pid [String] a v1 pid, `neu:` prefix included.
87
+ # @return [AtlasRb::Mash, nil] `id`, `type` and `tombstoned`, or `nil`
88
+ # when no resource holds the pid.
89
+ # @raise [AtlasRb::ResourceError] on any other non-2xx.
90
+ #
91
+ # @example Redirect an inbound /files/neu:xyz
92
+ # holder = AtlasRb::System.find_by_legacy_pid("neu:xyz")
93
+ def self.find_by_legacy_pid(pid)
94
+ result = read_body(system_connection.get(AtlasRb::Resource.legacy_pid_path(pid)))
95
+ result && AtlasRb::Mash.new(result["resource"])
96
+ end
79
97
  end
80
98
  end
data/lib/atlas_rb/work.rb CHANGED
@@ -133,14 +133,23 @@ module AtlasRb
133
133
  # re-points it. There is no way to change it after the create. Needs
134
134
  # Atlas 0.6.277 or later; an older Atlas ignores the param and mints a
135
135
  # second handle on `complete`.
136
+ # @param legacy_pid [String, nil] optional v1 pid the Work migrated from,
137
+ # such as `"neu:1234"`. Admin only. It lands on the Work's first save, so
138
+ # send it here and not on a later `put_mods`. There is no way to change
139
+ # it after the create. Needs Atlas 0.6.279 or later; an older Atlas
140
+ # ignores it.
136
141
  # @return [Hash] the created Work payload (post-update if `xml_path` was
137
142
  # supplied).
138
143
  # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
139
144
  # resource, so the write did not happen.
140
145
  # @raise [AtlasRb::ForbiddenError] if Atlas answers `403`: the caller holds no
141
- # edit rights on the Collection, or sent `handle:` without being an admin
142
- # or delegated admin (`action` is then `"supply_handle"`). No Work is
146
+ # edit rights on the Collection, sent `handle:` without being an admin or
147
+ # delegated admin (`action` is then `"supply_handle"`), or sent
148
+ # `legacy_pid:` without being an admin (`"supply_legacy_pid"`). No Work is
143
149
  # created.
150
+ # @raise [AtlasRb::LegacyPidError] if Atlas refuses the `legacy_pid:` as
151
+ # malformed (`422`) or held by another resource (`409`, with
152
+ # {LegacyPidError#holder_id}).
144
153
  # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
145
154
  # and body. With `handle:`, a `422` (`invalid_handle`) means the value is
146
155
  # not `<prefix>/<suffix>`, and a `409` (`handle_taken`) means another
@@ -161,11 +170,15 @@ module AtlasRb
161
170
  #
162
171
  # @example Migrated Work that keeps its v1 handle
163
172
  # AtlasRb::Work.create("col-456", handle: "2047/d20001234", nuid: admin_nuid)
173
+ #
174
+ # @example Migrated Work that records its v1 pid
175
+ # AtlasRb::Work.create("col-456", legacy_pid: "neu:1234", nuid: admin_nuid)
164
176
  def self.create(id, xml_path = nil, idempotency_key: nil, nuid: nil,
165
- on_behalf_of: nil, depositor: nil, handle: nil)
177
+ on_behalf_of: nil, depositor: nil, handle: nil, legacy_pid: nil)
166
178
  params = { collection_id: id }
167
- params[:depositor] = depositor if depositor
168
- params[:handle] = handle if handle
179
+ params[:depositor] = depositor if depositor
180
+ params[:handle] = handle if handle
181
+ params[:legacy_pid] = legacy_pid if legacy_pid
169
182
  result = AtlasRb::Mash.new(write_resource(
170
183
  connection(params, nuid,
171
184
  on_behalf_of: on_behalf_of, idempotency_key: idempotency_key).post(ROUTE)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.4
4
+ version: 1.29.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff
@@ -201,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
202
  - - ">="
203
203
  - !ruby/object:Gem::Version
204
- version: 2.6.0
204
+ version: 3.2.0
205
205
  required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  requirements:
207
207
  - - ">="