Class: Dor::Services::Client::Object
- Inherits:
-
VersionedService
- Object
- VersionedService
- Dor::Services::Client::Object
- Extended by:
- Deprecation
- Defined in:
- lib/dor/services/client/object.rb
Overview
API calls that are about a repository object
Constant Summary collapse
- BASE_ALLOWED_FIELDS =
%i[external_identifier cocina_version label version administrative description].freeze
- DRO_ALLOWED_FIELDS =
BASE_ALLOWED_FIELDS + %i[content_type access identification structural geographic]
Constants inherited from VersionedService
VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE
Instance Attribute Summary collapse
-
#object_identifier ⇒ Object
readonly
Returns the value of attribute object_identifier.
Instance Method Summary collapse
- #accession(params = {}) ⇒ Object
- #administrative_tags ⇒ Object
-
#collections ⇒ Array<Cocina::Models::DRO>
Get a list of the collections.
- #events ⇒ Object
-
#find(validate: false) ⇒ Cocina::Models::DROWithMetadata, ...
Retrieves the Cocina model.
-
#find_lite(administrative: true, description: true, access: true, structural: true, identification: true, geographic: true) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/ParameterLists.
-
#initialize(connection:, version:, object_identifier:) ⇒ Object
constructor
A new instance of Object.
-
#lock ⇒ String
The ETag value for the object.
-
#members ⇒ Array<Members::Member>
Get a list of the members.
- #milestones ⇒ Object
- #mutate ⇒ Object
-
#publish(workflow: nil, lane_id: nil) ⇒ String
Publish an object (send to PURL) rubocop:disable Metrics/MethodLength.
-
#reindex ⇒ boolean
Reindex the object in Solr.
- #release_tags ⇒ Object
-
#solr(validate: true) ⇒ Hash
The solr document for the head version.
- #transfer ⇒ Object
- #user_version ⇒ Object
- #version ⇒ Object
- #workflow(workflow_name) ⇒ Object
- #workflows ⇒ Object
- #workspace ⇒ Object
Methods inherited from VersionedService
Constructor Details
#initialize(connection:, version:, object_identifier:) ⇒ Object
Returns a new instance of Object.
15 16 17 18 19 20 |
# File 'lib/dor/services/client/object.rb', line 15 def initialize(connection:, version:, object_identifier:) raise ArgumentError, "The `object_identifier` parameter must be an identifier string: #{object_identifier.inspect}" unless object_identifier.is_a?(String) super(connection: connection, version: version) @object_identifier = object_identifier end |
Instance Attribute Details
#object_identifier ⇒ Object (readonly)
Returns the value of attribute object_identifier.
12 13 14 |
# File 'lib/dor/services/client/object.rb', line 12 def object_identifier @object_identifier end |
Instance Method Details
#accession(params = {}) ⇒ Object
46 47 48 |
# File 'lib/dor/services/client/object.rb', line 46 def accession(params = {}) @accession ||= Accession.new(**parent_params.merge(params)) end |
#administrative_tags ⇒ Object
30 31 32 |
# File 'lib/dor/services/client/object.rb', line 30 def @administrative_tags ||= AdministrativeTags.new(**parent_params) end |
#collections ⇒ Array<Cocina::Models::DRO>
Get a list of the collections. (Similar to Valkyrie’s find_inverse_references_by)
126 127 128 |
# File 'lib/dor/services/client/object.rb', line 126 def collections Collections.new(**parent_params).collections end |
#events ⇒ Object
22 23 24 |
# File 'lib/dor/services/client/object.rb', line 22 def events @events ||= Events.new(**parent_params) end |
#find(validate: false) ⇒ Cocina::Models::DROWithMetadata, ...
Retrieves the Cocina model
74 75 76 77 78 79 80 81 |
# File 'lib/dor/services/client/object.rb', line 74 def find(validate: false) resp = connection.get do |req| req.url object_path end raise_exception_based_on_response!(resp) unless resp.success? build_cocina_from_response(JSON.parse(resp.body), headers: resp.headers, validate: validate) end |
#find_lite(administrative: true, description: true, access: true, structural: true, identification: true, geographic: true) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/ParameterLists
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/dor/services/client/object.rb', line 101 def find_lite(administrative: true, description: true, access: true, structural: true, identification: true, geographic: true) fields = [] fields << :administrative if administrative fields << :description if description fields << :access if access fields << :structural if structural fields << :identification if identification fields << :geographic if geographic resp = connection.post '/graphql', query(fields), 'Content-Type' => 'application/json' raise_exception_based_on_response!(resp) unless resp.success? resp_json = JSON.parse(resp.body) # GraphQL returns 200 even when an error raise_graphql_exception(resp, resp_json) Cocina::Models.build_lite(resp_json['data']['cocinaObject']) end |
#lock ⇒ String
Returns the ETag value for the object.
86 87 88 89 90 91 92 |
# File 'lib/dor/services/client/object.rb', line 86 def lock resp = connection.head do |req| req.url object_path end raise_exception_based_on_response!(resp) unless resp.success? resp.headers['ETag'] end |
#members ⇒ Array<Members::Member>
Get a list of the members
133 134 135 |
# File 'lib/dor/services/client/object.rb', line 133 def members Members.new(**parent_params).members end |
#milestones ⇒ Object
50 51 52 |
# File 'lib/dor/services/client/object.rb', line 50 def milestones @milestones ||= Milestones.new(**parent_params) end |
#mutate ⇒ Object
141 142 143 |
# File 'lib/dor/services/client/object.rb', line 141 def mutate Mutate.new(**parent_params) end |
#publish(workflow: nil, lane_id: nil) ⇒ String
Publish an object (send to PURL) rubocop:disable Metrics/MethodLength
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/dor/services/client/object.rb', line 170 def publish(workflow: nil, lane_id: nil) query_params = [].tap do |params| params << "workflow=#{workflow}" if workflow params << "lane-id=#{lane_id}" if lane_id end query_string = query_params.any? ? "?#{query_params.join('&')}" : '' publish_path = "#{object_path}/publish#{query_string}" resp = connection.post do |req| req.url publish_path end return resp.headers['Location'] if resp.success? raise_exception_based_on_response!(resp) end |
#reindex ⇒ boolean
Reindex the object in Solr.
154 155 156 157 158 159 160 161 |
# File 'lib/dor/services/client/object.rb', line 154 def reindex resp = connection.post do |req| req.url "#{object_path}/reindex" end return true if resp.success? raise_exception_based_on_response!(resp) end |
#release_tags ⇒ Object
34 35 36 |
# File 'lib/dor/services/client/object.rb', line 34 def @release_tags ||= ReleaseTags.new(**parent_params) end |
#solr(validate: true) ⇒ Hash
Returns the solr document for the head version.
188 189 190 191 192 193 194 195 |
# File 'lib/dor/services/client/object.rb', line 188 def solr(validate: true) resp = connection.get do |req| req.url "#{object_path}/solr?validate=#{validate}" end raise_exception_based_on_response!(resp) unless resp.success? JSON.parse(resp.body) end |
#transfer ⇒ Object
137 138 139 |
# File 'lib/dor/services/client/object.rb', line 137 def transfer Transfer.new(**parent_params) end |
#user_version ⇒ Object
42 43 44 |
# File 'lib/dor/services/client/object.rb', line 42 def user_version @user_version ||= UserVersion.new(**parent_params) end |
#version ⇒ Object
38 39 40 |
# File 'lib/dor/services/client/object.rb', line 38 def version @version ||= ObjectVersion.new(**parent_params) end |
#workflow(workflow_name) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dor/services/client/object.rb', line 58 def workflow(workflow_name) raise ArgumentError, '`workflow_name` argument cannot be blank in call to `#workflow(workflow_name)' if workflow_name.blank? # Return memoized object instance if workflow_name value is the same # # This allows the client to interact with multiple workflows for a given object return @workflow if @workflow&.workflow_name == workflow_name @workflow = ObjectWorkflow.new(**parent_params.merge({ workflow_name: workflow_name })) end |
#workflows ⇒ Object
54 55 56 |
# File 'lib/dor/services/client/object.rb', line 54 def workflows ObjectWorkflows.new(**parent_params).list end |