Class: Dor::Services::Client::ObjectVersion

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

Overview

API calls that are about versions

Defined Under Namespace

Classes: Version

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:) ⇒ ObjectVersion

Returns a new instance of ObjectVersion.

Parameters:

  • object_identifier (String)

    the pid for the object



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

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

Instance Method Details

#close(**params) ⇒ String

Close current version for an object

Parameters:

  • description (String)

    (optional) - a description of the object version being opened

  • significance (String)

    (optional) - ‘major’ ‘minor’ or ‘admin’

  • user_name (String)

    (optional) - sunetid

  • start_accession (Boolean)

    (optional) - whether to start accessioning workflow; defaults to true

Returns:

  • (String)

    a message confirming successful closing

Raises:



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

def close(**params)
  resp = connection.post do |req|
    req.url with_querystring(url: close_version_path, params: params)
    req.headers['Content-Type'] = 'application/json'
  end
  return resp.body if resp.success?

  raise_exception_based_on_response!(resp)
end

#currentString

Get the current version for a DOR object. This comes from ObjectVersion table in the DSA

Returns:

  • (String)

    the version identifier

Raises:



20
21
22
23
24
25
26
27
# File 'lib/dor/services/client/object_version.rb', line 20

def current
  resp = connection.get do |req|
    req.url "#{base_path}/current"
  end
  return resp.body if resp.success?

  raise_exception_based_on_response!(resp)
end

#inventoryArray

Returns a list of the versions.

Returns:

  • (Array)

    a list of the versions

Raises:



91
92
93
94
95
96
97
98
# File 'lib/dor/services/client/object_version.rb', line 91

def inventory
  resp = connection.get do |req|
    req.url base_path
  end
  raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

  JSON.parse(resp.body).fetch('versions').map { |params| Version.new(**params.symbolize_keys!) }
end

#open(**params) ⇒ Cocina::Models::DROWithMetadata|CollectionWithMetadata|AdminPolicyWithMetadata

Open new version for an object

Parameters:

  • description (String)

    a description of the object version being opened - required

  • significance (String)

    ‘major’ ‘minor’ or ‘admin’ - required

  • opening_user_name (String)

    sunetid - defaults to nil

  • assume_accessioned (Boolean)

    if true, does not check whether object has been accessioned; defaults to false

Returns:

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

    cocina model with updated version

Raises:



60
61
62
63
64
65
66
67
68
69
# File 'lib/dor/services/client/object_version.rb', line 60

def open(**params)
  resp = connection.post do |req|
    req.url with_querystring(url: open_new_version_path, params: params)
    req.headers['Content-Type'] = 'application/json'
  end

  raise_exception_based_on_response!(resp) unless resp.success?

  build_cocina_from_response(resp)
end

#openable?Boolean

Determines if a new version can be opened for a DOR object. rubocop:disable Metrics/MethodLength

Returns:

  • (Boolean)

    true if a new version can be opened

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dor/services/client/object_version.rb', line 34

def openable?
  resp = connection.get do |req|
    req.url "#{base_path}/openable"
  end

  raise_exception_based_on_response!(resp) unless resp.success?

  case resp.body
  when 'true'
    true
  when 'false'
    false
  else
    raise MalformedResponse, "Expected true or false, not #{resp.body}"
  end
end