dor-services-client 12.17.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/object.rb +59 -1
- data/lib/dor/services/client/version.rb +1 -1
- data/lib/dor/services/client.rb +6 -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
|
|
@@ -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
|
data/lib/dor/services/client.rb
CHANGED
@@ -43,17 +43,21 @@ module Dor
|
|
43
43
|
# @param [Faraday::Response] response
|
44
44
|
# @param [String] object_identifier (nil)
|
45
45
|
# @param [Hash<String,Object>] errors (nil) the JSON-API errors object
|
46
|
+
# @param [Hash<String,Object>] graphql_errors (nil) the GraphQL errors object
|
46
47
|
# rubocop:disable Lint/MissingSuper
|
47
|
-
def initialize(response:, object_identifier: nil, errors: nil)
|
48
|
+
def initialize(response:, object_identifier: nil, errors: nil, graphql_errors: nil)
|
48
49
|
@response = response
|
49
50
|
@object_identifier = object_identifier
|
50
51
|
@errors = errors
|
52
|
+
@graphql_errors = graphql_errors
|
51
53
|
end
|
52
54
|
# rubocop:enable Lint/MissingSuper
|
53
55
|
|
54
|
-
attr_accessor :errors
|
56
|
+
attr_accessor :errors, :graphql_errors
|
55
57
|
|
56
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?
|
57
61
|
return errors.map { |e| "#{e['title']} (#{e['detail']})" }.join(', ') if errors.present?
|
58
62
|
|
59
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
|