Class: Dor::Services::Client::Mutate

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

Overview

API calls that update the data.

Constant Summary

Constants inherited from VersionedService

VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE

Instance Method Summary collapse

Methods inherited from VersionedService

#async_result, #with_querystring

Constructor Details

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

Returns a new instance of Mutate.

Parameters:

  • object_identifier (String)

    the pid for the object



9
10
11
12
# File 'lib/dor/services/client/mutate.rb', line 9

def initialize(connection:, version:, object_identifier:)
  super(connection: connection, version: version)
  @object_identifier = object_identifier
end

Instance Method Details

#apply_admin_policy_defaultsboolean

Copies the values from the admin policy to the item

Returns:

  • (boolean)

    true on success

Raises:



18
19
20
21
22
23
24
25
26
# File 'lib/dor/services/client/mutate.rb', line 18

def apply_admin_policy_defaults
  resp = connection.post do |req|
    req.url "#{object_path}/apply_admin_policy_defaults"
  end

  raise_exception_based_on_response!(resp) unless resp.success?

  true
end

#destroy(user_name: nil) ⇒ Boolean

Destroys an object

Parameters:

  • user_name (String) (defaults to: nil)

    (nil) the user name of the user doing the destroy

Returns:

  • (Boolean)

    true if successful

Raises:



79
80
81
82
83
84
85
86
87
88
# File 'lib/dor/services/client/mutate.rb', line 79

def destroy(user_name: nil)
  path = object_path
  path += "?user_name=#{user_name}" if user_name
  resp = connection.delete do |req|
    req.url path
  end
  raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

  true
end

#refresh_descriptive_metadata_from_ilsboolean

Pull in metadata from Symphony and updates descriptive metadata

Returns:

  • (boolean)

    true on success

Raises:



64
65
66
67
68
69
70
71
72
# File 'lib/dor/services/client/mutate.rb', line 64

def 
  resp = connection.post do |req|
    req.url "#{object_path}/refresh_metadata"
  end

  raise_exception_based_on_response!(resp) unless resp.success?

  true
end

#update(params:, skip_lock: false, validate: false) ⇒ Cocina::Models::DROWithMetadata, ...

Updates the object rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

Parameters:

  • params (Cocina::Models::DROWithMetadata|CollectionWithMetadata|AdminPolicyWithMetadata|DRO|Collection|AdminPolicy)

    model object

  • skip_lock (boolean) (defaults to: false)

    do not provide ETag

  • validate (boolean) (defaults to: false)

    validate the response object

Returns:

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

    the returned model

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dor/services/client/mutate.rb', line 38

def update(params:, skip_lock: false, validate: false)
  raise ArgumentError, 'Cocina object not provided.' unless params.respond_to?(:externalIdentifier)

  # Raised if Cocina::Models::*WithMetadata not provided.
  raise ArgumentError, 'ETag not provided.' unless skip_lock || params.respond_to?(:lock)

  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.headers['If-Match'] = params.lock unless skip_lock
    req.body = build_json_from_cocina(params)
  end

  raise_exception_based_on_response!(resp) unless resp.success?

  build_cocina_from_response(resp, validate: validate)
end