dor-services-client 12.16.0 → 12.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/dor/services/client/accession.rb +1 -2
- data/lib/dor/services/client/object.rb +59 -1
- data/lib/dor/services/client/object_version.rb +2 -4
- data/lib/dor/services/client/objects.rb +1 -2
- data/lib/dor/services/client/version.rb +1 -1
- data/lib/dor/services/client/versioned_service.rb +6 -0
- data/lib/dor/services/client.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a474115832894037ecf11cebc49b133d19d18c5bf43eb24c41a58a8efd7fd0a3
|
4
|
+
data.tar.gz: c39cdb3823ebfcc28acc4cbff90a680560507c3099f15826abc1a2d122b17839
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e986337c48ceab9a1a84479caa51f580c1e6cd6ab5c876fb85c64c5a5985824f23d86b9a4b9ab6a548c482532f23859e726b21f0063325f3d82c42d4f8c32da1
|
7
|
+
data.tar.gz: 86170854e8d54022a93e7a70f8527d1028153ab3f0cd1d49ac4cedb8caec39e8b1836a4b3832e38b479848a53cd4c822f2c69ddeefa5f75956c49a0f88677c9d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -141,6 +141,9 @@ object_client.version.close
|
|
141
141
|
# Return the Cocina metadata
|
142
142
|
object_client.find
|
143
143
|
|
144
|
+
# Returns "lite" Cocina metadata (excluding specified attributes)
|
145
|
+
object_client.find_lite(structural: false, geographic: false)
|
146
|
+
|
144
147
|
# Query for an object's collections
|
145
148
|
object_client.collections
|
146
149
|
|
@@ -24,8 +24,7 @@ module Dor
|
|
24
24
|
# @raise [UnexpectedResponse] when the response is not successful.
|
25
25
|
def start(params = {})
|
26
26
|
resp = connection.post do |req|
|
27
|
-
req.url path
|
28
|
-
req.params = params
|
27
|
+
req.url with_querystring(url: path, params: params)
|
29
28
|
end
|
30
29
|
return true if resp.success?
|
31
30
|
|
@@ -6,7 +6,7 @@ module Dor
|
|
6
6
|
module Services
|
7
7
|
class Client
|
8
8
|
# API calls that are about a repository object
|
9
|
-
class Object < VersionedService
|
9
|
+
class Object < VersionedService # rubocop:disable Metrics/ClassLength
|
10
10
|
extend Deprecation
|
11
11
|
attr_reader :object_identifier
|
12
12
|
|
@@ -52,6 +52,35 @@ module Dor
|
|
52
52
|
build_cocina_from_response(resp, validate: validate)
|
53
53
|
end
|
54
54
|
|
55
|
+
BASE_ALLOWED_FIELDS = %i[external_identifier cocina_version label version administrative description].freeze
|
56
|
+
DRO_ALLOWED_FIELDS = BASE_ALLOWED_FIELDS + %i[content_type access identification structural geographic]
|
57
|
+
|
58
|
+
# rubocop:disable Metrics/MethodLength
|
59
|
+
# rubocop:disable Metrics/AbcSize
|
60
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
61
|
+
# rubocop:disable Metrics/ParameterLists
|
62
|
+
def find_lite(administrative: true, description: true, access: true, structural: true, identification: true, geographic: true)
|
63
|
+
fields = []
|
64
|
+
fields << :administrative if administrative
|
65
|
+
fields << :description if description
|
66
|
+
fields << :access if access
|
67
|
+
fields << :structural if structural
|
68
|
+
fields << :identification if identification
|
69
|
+
fields << :geographic if geographic
|
70
|
+
|
71
|
+
resp = connection.post '/graphql', query(fields),
|
72
|
+
'Content-Type' => 'application/json'
|
73
|
+
raise_exception_based_on_response!(resp) unless resp.success?
|
74
|
+
resp_json = JSON.parse(resp.body)
|
75
|
+
# GraphQL returns 200 even when an error
|
76
|
+
raise_graphql_exception(resp, resp_json)
|
77
|
+
Cocina::Models.build_lite(resp_json['data']['cocinaObject'])
|
78
|
+
end
|
79
|
+
# rubocop:enable Metrics/MethodLength
|
80
|
+
# rubocop:enable Metrics/AbcSize
|
81
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
82
|
+
# rubocop:enable Metrics/ParameterLists
|
83
|
+
|
55
84
|
# Get a list of the collections. (Similar to Valkyrie's find_inverse_references_by)
|
56
85
|
# @raise [UnexpectedResponse] if the request is unsuccessful.
|
57
86
|
# @return [Array<Cocina::Models::DRO>]
|
@@ -140,6 +169,35 @@ module Dor
|
|
140
169
|
def object_path
|
141
170
|
"#{api_version}/objects/#{object_identifier}"
|
142
171
|
end
|
172
|
+
|
173
|
+
DEFAULT_FIELDS = %i[externalIdentifier type version label cocinaVersion].freeze
|
174
|
+
|
175
|
+
def query(fields)
|
176
|
+
all_fields = DEFAULT_FIELDS + fields
|
177
|
+
{
|
178
|
+
query:
|
179
|
+
<<~GQL
|
180
|
+
{
|
181
|
+
cocinaObject(externalIdentifier: "#{object_identifier}") {
|
182
|
+
#{all_fields.join("\n")}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
GQL
|
186
|
+
}.to_json
|
187
|
+
end
|
188
|
+
|
189
|
+
def raise_graphql_exception(resp, resp_json)
|
190
|
+
return unless resp_json['errors'].present?
|
191
|
+
|
192
|
+
exception_class = not_found_exception?(resp_json['errors'].first) ? NotFoundResponse : UnexpectedResponse
|
193
|
+
raise exception_class.new(response: resp,
|
194
|
+
object_identifier: object_identifier,
|
195
|
+
graphql_errors: resp_json['errors'])
|
196
|
+
end
|
197
|
+
|
198
|
+
def not_found_exception?(error)
|
199
|
+
error['message'] == 'Cocina object not found'
|
200
|
+
end
|
143
201
|
end
|
144
202
|
end
|
145
203
|
end
|
@@ -59,9 +59,8 @@ module Dor
|
|
59
59
|
# @return [Cocina::Models::DROWithMetadata|CollectionWithMetadata|AdminPolicyWithMetadata] cocina model with updated version
|
60
60
|
def open(**params)
|
61
61
|
resp = connection.post do |req|
|
62
|
-
req.url open_new_version_path
|
62
|
+
req.url with_querystring(url: open_new_version_path, params: params)
|
63
63
|
req.headers['Content-Type'] = 'application/json'
|
64
|
-
req.body = params.to_json if params.any?
|
65
64
|
end
|
66
65
|
|
67
66
|
raise_exception_based_on_response!(resp) unless resp.success?
|
@@ -79,9 +78,8 @@ module Dor
|
|
79
78
|
# @return [String] a message confirming successful closing
|
80
79
|
def close(**params)
|
81
80
|
resp = connection.post do |req|
|
82
|
-
req.url close_version_path
|
81
|
+
req.url with_querystring(url: close_version_path, params: params)
|
83
82
|
req.headers['Content-Type'] = 'application/json'
|
84
|
-
req.body = params.to_json if params.any?
|
85
83
|
end
|
86
84
|
return resp.body if resp.success?
|
87
85
|
|
@@ -14,11 +14,10 @@ module Dor
|
|
14
14
|
# @return [Cocina::Models::DROWithMetadata,Cocina::Models::CollectionWithMetadata,Cocina::Models::AdminPolicyWithMetadata] the returned model
|
15
15
|
def register(params:, assign_doi: false, validate: false)
|
16
16
|
resp = connection.post do |req|
|
17
|
-
req.url objects_path
|
17
|
+
req.url with_querystring(url: objects_path, params: { assign_doi: assign_doi })
|
18
18
|
req.headers['Content-Type'] = 'application/json'
|
19
19
|
# asking the service to return JSON (else it'll be plain text)
|
20
20
|
req.headers['Accept'] = 'application/json'
|
21
|
-
req.params[:assign_doi] = true if assign_doi
|
22
21
|
req.body = params.to_json
|
23
22
|
end
|
24
23
|
|
data/lib/dor/services/client.rb
CHANGED
@@ -5,6 +5,7 @@ require 'active_support/core_ext/module/delegation'
|
|
5
5
|
require 'active_support/core_ext/object/blank'
|
6
6
|
require 'active_support/json'
|
7
7
|
require 'active_support/core_ext/object/json'
|
8
|
+
require 'active_support/core_ext/object/to_query'
|
8
9
|
require 'cocina/models'
|
9
10
|
require 'faraday'
|
10
11
|
require 'faraday/retry'
|
@@ -42,17 +43,21 @@ module Dor
|
|
42
43
|
# @param [Faraday::Response] response
|
43
44
|
# @param [String] object_identifier (nil)
|
44
45
|
# @param [Hash<String,Object>] errors (nil) the JSON-API errors object
|
46
|
+
# @param [Hash<String,Object>] graphql_errors (nil) the GraphQL errors object
|
45
47
|
# rubocop:disable Lint/MissingSuper
|
46
|
-
def initialize(response:, object_identifier: nil, errors: nil)
|
48
|
+
def initialize(response:, object_identifier: nil, errors: nil, graphql_errors: nil)
|
47
49
|
@response = response
|
48
50
|
@object_identifier = object_identifier
|
49
51
|
@errors = errors
|
52
|
+
@graphql_errors = graphql_errors
|
50
53
|
end
|
51
54
|
# rubocop:enable Lint/MissingSuper
|
52
55
|
|
53
|
-
attr_accessor :errors
|
56
|
+
attr_accessor :errors, :graphql_errors
|
54
57
|
|
55
58
|
def to_s
|
59
|
+
# For GraphQL errors, see https://graphql-ruby.org/errors/execution_errors
|
60
|
+
return graphql_errors.map { |e| e['message'] }.join(', ') if graphql_errors.present?
|
56
61
|
return errors.map { |e| "#{e['title']} (#{e['detail']})" }.join(', ') if errors.present?
|
57
62
|
|
58
63
|
ResponseErrorFormatter.format(response: @response, object_identifier: @object_identifier)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dor-services-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 12.
|
4
|
+
version: 12.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-09-
|
12
|
+
date: 2023-09-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|