Class: Dor::Services::Client::ObjectVersion
- Inherits:
-
VersionedService
- Object
- VersionedService
- Dor::Services::Client::ObjectVersion
- 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
-
#close(**params) ⇒ String
Close current version for an object.
-
#current ⇒ String
Get the current version for a DOR object.
-
#discard ⇒ Object
Discard current version for an object.
-
#find(version) ⇒ Cocina::Models::DROWithMetadata, Dor::Services::Client::InvalidCocina
The object version or an InvalidCocina instance that behaves similarly to a Cocina object.
-
#initialize(connection:, version:, object_identifier:) ⇒ ObjectVersion
constructor
A new instance of ObjectVersion.
-
#inventory ⇒ Array
A list of the versions.
-
#open(**params) ⇒ Cocina::Models::DROWithMetadata|CollectionWithMetadata|AdminPolicyWithMetadata
Open new version for an object.
-
#solr(version, validate: true) ⇒ Hash
The solr document for the user version.
-
#status ⇒ VersionStatus
Status of the version.
Methods inherited from VersionedService
Constructor Details
#initialize(connection:, version:, object_identifier:) ⇒ ObjectVersion
Returns a new instance of ObjectVersion.
51 52 53 54 |
# File 'lib/dor/services/client/object_version.rb', line 51 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
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/dor/services/client/object_version.rb', line 113 def close(**params) resp = connection.post do |req| req.url close_version_path req.params = params.compact req.headers['Content-Type'] = 'application/json' end return resp.body if resp.success? raise_exception_based_on_response!(resp) end |
#current ⇒ String
Get the current version for a DOR object. This comes from ObjectVersion table in the DSA
77 78 79 80 81 82 83 84 |
# File 'lib/dor/services/client/object_version.rb', line 77 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 |
#discard ⇒ Object
Discard current version for an object
160 161 162 163 164 165 166 167 |
# File 'lib/dor/services/client/object_version.rb', line 160 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, Dor::Services::Client::InvalidCocina
Returns the object version or an InvalidCocina instance that behaves similarly to a Cocina object.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dor/services/client/object_version.rb', line 59 def find(version) resp = connection.get do |req| req.url "#{base_path}/#{version}" end if resp.success? build_cocina_from_response(JSON.parse(resp.body), headers: resp.headers, validate: false) elsif resp.status == 409 # Signals the Cocina is present but invalid build_invalid_cocina_from_response(resp) else raise_exception_based_on_response!(resp) end end |
#inventory ⇒ Array
Returns a list of the versions.
126 127 128 129 130 131 132 133 |
# File 'lib/dor/services/client/object_version.rb', line 126 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
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/dor/services/client/object_version.rb', line 93 def open(**params) resp = connection.post do |req| req.url open_new_version_path req.params = params req.headers['Content-Type'] = 'application/json' end raise_exception_based_on_response!(resp) unless resp.success? build_cocina_from_response(JSON.parse(resp.body), headers: resp.headers) end |
#solr(version, validate: true) ⇒ Hash
Returns the solr document for the user version.
148 149 150 151 152 153 154 155 |
# File 'lib/dor/services/client/object_version.rb', line 148 def solr(version, validate: true) resp = connection.get do |req| req.url "#{base_path}/#{version}/solr?validate=#{validate}" end raise_exception_based_on_response!(resp) unless resp.success? JSON.parse(resp.body) end |
#status ⇒ VersionStatus
Returns status of the version.
137 138 139 140 141 142 143 144 |
# File 'lib/dor/services/client/object_version.rb', line 137 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 |