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, VersionStatus

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



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

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

  • user_name (String)

    (optional) - sunetid

  • start_accession (Boolean)

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

  • user_versions (String)

    (optional - values are none, new, or update) - create, update, or do nothing with user versions on close; defaults to none.

Returns:

  • (String)

    a message confirming successful closing

Raises:



104
105
106
107
108
109
110
111
112
# File 'lib/dor/services/client/object_version.rb', line 104

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:



69
70
71
72
73
74
75
76
# File 'lib/dor/services/client/object_version.rb', line 69

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

#discardObject

Discard current version for an object

Raises:



150
151
152
153
154
155
156
157
# File 'lib/dor/services/client/object_version.rb', line 150

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

  raise_exception_based_on_response!(resp)
end

#find(version) ⇒ Cocina::Models::DROWithMetadata

Returns the object metadata.

Returns:

  • (Cocina::Models::DROWithMetadata)

    the object metadata

Raises:



56
57
58
59
60
61
62
63
# File 'lib/dor/services/client/object_version.rb', line 56

def find(version)
  resp = connection.get do |req|
    req.url "#{base_path}/#{version}"
  end
  raise_exception_based_on_response!(resp) unless resp.success?

  build_cocina_from_response(resp, validate: false)
end

#inventoryArray

Returns a list of the versions.

Returns:

  • (Array)

    a list of the versions

Raises:



116
117
118
119
120
121
122
123
# File 'lib/dor/services/client/object_version.rb', line 116

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

  • 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:



85
86
87
88
89
90
91
92
93
94
# File 'lib/dor/services/client/object_version.rb', line 85

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

#solr(version) ⇒ Hash

Returns the solr document for the user version.

Returns:

  • (Hash)

    the solr document for the user version

Raises:



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

def solr(version)
  resp = connection.get do |req|
    req.url "#{base_path}/#{version}/solr"
  end
  raise_exception_based_on_response!(resp) unless resp.success?

  JSON.parse(resp.body)
end

#statusVersionStatus

Returns status of the version.

Returns:

Raises:



127
128
129
130
131
132
133
134
# File 'lib/dor/services/client/object_version.rb', line 127

def status
  resp = connection.get do |req|
    req.url "#{base_path}/status"
  end
  raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

  VersionStatus.new(JSON.parse(resp.body).symbolize_keys!)
end