Class: Dor::Services::Client::Object

Inherits:
VersionedService show all
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

Instance Method Summary collapse

Methods inherited from VersionedService

#async_result

Constructor Details

#initialize(connection:, version:, object_identifier:) ⇒ Object

Returns a new instance of Object.

Parameters:

  • object_identifier (String)

    the pid for the object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/dor/services/client/object.rb', line 14

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_identifierObject (readonly)

Returns the value of attribute object_identifier.



11
12
13
# File 'lib/dor/services/client/object.rb', line 11

def object_identifier
  @object_identifier
end

Instance Method Details

#accession(params = {}) ⇒ Object



45
46
47
# File 'lib/dor/services/client/object.rb', line 45

def accession(params = {})
  @accession ||= Accession.new(**parent_params.merge(params))
end

#administrative_tagsObject



29
30
31
# File 'lib/dor/services/client/object.rb', line 29

def administrative_tags
  @administrative_tags ||= AdministrativeTags.new(**parent_params)
end

#collectionsArray<Cocina::Models::DRO>

Get a list of the collections. (Similar to Valkyrie’s find_inverse_references_by)

Returns:

  • (Array<Cocina::Models::DRO>)

Raises:



114
115
116
# File 'lib/dor/services/client/object.rb', line 114

def collections
  Collections.new(**parent_params).collections
end

#eventsObject



21
22
23
# File 'lib/dor/services/client/object.rb', line 21

def events
  @events ||= Events.new(**parent_params)
end

#find(validate: false) ⇒ Cocina::Models::DROWithMetadata, ...

Retrieves the Cocina model

Parameters:

  • validate (boolean) (defaults to: false)

    validate the response object

Returns:

  • (Cocina::Models::DROWithMetadata, Cocina::Models::CollectionWithMetadata, Cocina::Models::AdminPolicyWithMetadata)

    the returned model

Raises:



73
74
75
76
77
78
79
80
# File 'lib/dor/services/client/object.rb', line 73

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(resp, 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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dor/services/client/object.rb', line 89

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

#membersArray<Members::Member>

Get a list of the members

Returns:

Raises:



121
122
123
# File 'lib/dor/services/client/object.rb', line 121

def members
  Members.new(**parent_params).members
end

#milestonesObject



49
50
51
# File 'lib/dor/services/client/object.rb', line 49

def milestones
  @milestones ||= Milestones.new(**parent_params)
end

#mutateObject



129
130
131
# File 'lib/dor/services/client/object.rb', line 129

def mutate
  Mutate.new(**parent_params)
end

#publish(workflow: nil, lane_id: nil) ⇒ String

Publish an object (send to PURL) rubocop:disable Metrics/MethodLength

Parameters:

  • workflow (String) (defaults to: nil)

    (nil) which workflow to callback to.

  • lane_id (String) (defaults to: nil)

    for prioritization (default or low)

Returns:

  • (String)

    the URL of the background job on dor-service-app

Raises:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/dor/services/client/object.rb', line 158

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

#reindexboolean

Reindex the object in Solr.

Returns:

  • (boolean)

    true on success

Raises:



142
143
144
145
146
147
148
149
# File 'lib/dor/services/client/object.rb', line 142

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_tagsObject



33
34
35
# File 'lib/dor/services/client/object.rb', line 33

def release_tags
  @release_tags ||= ReleaseTags.new(**parent_params)
end

#transferObject



125
126
127
# File 'lib/dor/services/client/object.rb', line 125

def transfer
  Transfer.new(**parent_params)
end

#user_versionObject



41
42
43
# File 'lib/dor/services/client/object.rb', line 41

def user_version
  @user_version ||= UserVersion.new(**parent_params)
end

#versionObject



37
38
39
# File 'lib/dor/services/client/object.rb', line 37

def version
  @version ||= ObjectVersion.new(**parent_params)
end

#workflow(workflow_name) ⇒ Object

Raises:

  • (ArgumentError)


57
58
59
60
61
62
63
64
65
66
# File 'lib/dor/services/client/object.rb', line 57

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

#workflowsObject



53
54
55
# File 'lib/dor/services/client/object.rb', line 53

def workflows
  ObjectWorkflows.new(**parent_params).list
end

#workspaceObject



25
26
27
# File 'lib/dor/services/client/object.rb', line 25

def workspace
  @workspace ||= Workspace.new(**parent_params)
end