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

Inherits:
VersionedService show all
Defined in:
lib/dor/services/client/object.rb

Overview

API calls that are about a repository object

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)


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

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.



8
9
10
# File 'lib/dor/services/client/object.rb', line 8

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_tagsObject



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

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:



86
87
88
# File 'lib/dor/services/client/object.rb', line 86

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

#embargoObject



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

def embargo
  @embargo ||= Embargo.new(**parent_params)
end

#eventsObject



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

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

#findCocina::Models::DRO, ...

Retrieves the Cocina model

Returns:

  • (Cocina::Models::DRO, Cocina::Models::Collection, Cocina::Models::AdminPolicy)

    the returned model

Raises:



54
55
56
57
58
59
60
61
62
# File 'lib/dor/services/client/object.rb', line 54

def find
  resp = connection.get do |req|
    req.url object_path
  end

  return Cocina::Models.build(JSON.parse(resp.body)) if resp.success?

  raise_exception_based_on_response!(resp)
end

#membersArray<Members::Member>

Get a list of the members

Returns:

Raises:



93
94
95
# File 'lib/dor/services/client/object.rb', line 93

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

#metadataObject



18
19
20
# File 'lib/dor/services/client/object.rb', line 18

def 
  @metadata ||= Metadata.new(**parent_params)
end

#notify_goobiboolean

Notify the external Goobi system for a new object that was registered in DOR

Returns:

  • (boolean)

    true on success

Raises:



178
179
180
181
182
183
184
185
# File 'lib/dor/services/client/object.rb', line 178

def notify_goobi
  resp = connection.post do |req|
    req.url "#{object_path}/notify_goobi"
  end
  return true if resp.success?

  raise_exception_based_on_response!(resp)
end

#preserve(lane_id: nil) ⇒ String

Preserve an object (send to SDR)

Parameters:

  • lane_id (String) (defaults to: nil)

    for prioritization (default or low)

Returns:

  • (String)

    URL from Location response header if no errors

Raises:



123
124
125
126
127
128
129
130
131
# File 'lib/dor/services/client/object.rb', line 123

def preserve(lane_id: nil)
  query_string = lane_id ? "?lane-id=#{lane_id}" : ''
  resp = connection.post do |req|
    req.url "#{object_path}/preserve#{query_string}"
  end
  return resp.headers['Location'] if resp.success?

  raise_exception_based_on_response!(resp)
end

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

Publish an object (send to PURL)

Parameters:

  • workflow (String) (defaults to: nil)

    (‘accessionWF’) which workflow to callback to.

  • lane_id (String) (defaults to: nil)

    for prioritization (default or low)

Returns:

  • (boolean)

    true on success

Raises:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/dor/services/client/object.rb', line 103

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

#refresh_metadataboolean

Pull in metadata from Symphony and update descMetadata

Returns:

  • (boolean)

    true on success

Raises:



165
166
167
168
169
170
171
172
# File 'lib/dor/services/client/object.rb', line 165

def 
  resp = connection.post do |req|
    req.url "#{object_path}/refresh_metadata"
  end
  return true if resp.success?

  raise_exception_based_on_response!(resp)
end

#release_tagsObject



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

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

#shelve(lane_id: nil) ⇒ boolean

Shelve an object (send to Stacks)

Parameters:

  • lane_id (String) (defaults to: nil)

    for prioritization (default or low)

Returns:

  • (boolean)

    true on success

Raises:



138
139
140
141
142
143
144
145
146
# File 'lib/dor/services/client/object.rb', line 138

def shelve(lane_id: nil)
  query_string = lane_id ? "?lane-id=#{lane_id}" : ''
  resp = connection.post do |req|
    req.url "#{object_path}/shelve#{query_string}"
  end
  return resp.headers['Location'] if resp.success?

  raise_exception_based_on_response!(resp)
end

#update(params:) ⇒ Cocina::Models::DRO, ...

Updates the object

Parameters:

  • params (Cocina::Models::RequestDRO, Cocina::Models::RequestCollection, Cocina::Models::RequestAPO)

    model object

Returns:

  • (Cocina::Models::DRO, Cocina::Models::Collection, Cocina::Models::AdminPolicy)

    the returned model

Raises:



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

def update(params:)
  resp = connection.patch do |req|
    req.url object_path
    req.headers['Content-Type'] = 'application/json'
    # asking the service to return JSON (else it'll be plain text)
    req.headers['Accept'] = 'application/json'
    req.body = params.to_json
  end

  return Cocina::Models.build(JSON.parse(resp.body)) if resp.success?

  raise_exception_based_on_response!(resp)
end

#update_marc_recordboolean

Update the marc record for the given object

Returns:

  • (boolean)

    true on success

Raises:



152
153
154
155
156
157
158
159
# File 'lib/dor/services/client/object.rb', line 152

def update_marc_record
  resp = connection.post do |req|
    req.url "#{object_path}/update_marc_record"
  end
  return true if resp.success?

  raise_exception_based_on_response!(resp)
end

#versionObject



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

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

#workspaceObject



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

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