Skip to content

Commit

Permalink
Allow APOs to be retrieved by the show handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 20, 2019
1 parent 3506f3f commit ee15257
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 75 deletions.
24 changes: 15 additions & 9 deletions app/services/cocina/mapper.rb
Expand Up @@ -36,15 +36,19 @@ def build

def build_administrative
{}.tap do |admin|
admin[:releaseTags] = item.identityMetadata.ng_xml.xpath('//release').map do |node|
{
to: node.attributes['to'].value,
what: node.attributes['what'].value,
date: node.attributes['when'].value,
who: node.attributes['who'].value,
release: node.text
}
end
admin[:releaseTags] = build_release_tags unless type == 'admin_policy'
end
end

def build_release_tags
item.identityMetadata.ng_xml.xpath('//release').map do |node|
{
to: node.attributes['to'].value,
what: node.attributes['what'].value,
date: node.attributes['when'].value,
who: node.attributes['who'].value,
release: node.text
}
end
end

Expand All @@ -55,6 +59,8 @@ def type
'object'
when Dor::Collection
'collection'
when Dor::AdminPolicyObject
'admin_policy'
else
raise "Unknown type for #{item.class}"
end
Expand Down
3 changes: 2 additions & 1 deletion openapi.json
Expand Up @@ -857,7 +857,7 @@
"objects"
],
"summary": "Retrieve the object COCINA metadata",
"description": "",
"description": "Returns a JSON representation (not yet complete) of an object, collection or admin policy.",
"operationId": "objects#show",
"responses": {
"200": {
Expand Down Expand Up @@ -916,6 +916,7 @@
"properties": {
"type": {
"type": "string",
"enum": ["item", "collection", "admin_policy"],
"example": "item"
},
"externalIdentifier": {
Expand Down
163 changes: 98 additions & 65 deletions spec/requests/show_object_spec.rb
Expand Up @@ -3,83 +3,116 @@
require 'rails_helper'

RSpec.describe 'Get the object' do
let(:object) { Dor::Item.new(pid: 'druid:1234') }

before do
allow(Dor).to receive(:find).and_return(object)
end

context 'when the object exists with minimal metadata' do
before do
object.descMetadata.title_info.main_title = 'Hello'
object.label = 'foo'
end
context 'when the requested object is an item' do
let(:object) { Dor::Item.new(pid: 'druid:1234') }

context 'when the object exists with minimal metadata' do
before do
object.descMetadata.title_info.main_title = 'Hello'
object.label = 'foo'
end

let(:expected) do
{
externalIdentifier: 'druid:1234',
type: 'object',
label: 'foo',
version: 1,
access: {},
administrative: {
releaseTags: []
},
identification: {},
structural: {}
}
let(:expected) do
{
externalIdentifier: 'druid:1234',
type: 'object',
label: 'foo',
version: 1,
access: {},
administrative: {
releaseTags: []
},
identification: {},
structural: {}
}
end

it 'returns the object' do
get '/v1/objects/druid:mk420bs7601',
headers: { 'Authorization' => "Bearer #{jwt}" }
expect(response).to have_http_status(:ok)
expect(response.body).to eq expected.to_json
end
end

it 'returns the object' do
get '/v1/objects/druid:mk420bs7601',
headers: { 'Authorization' => "Bearer #{jwt}" }
expect(response).to have_http_status(:ok)
expect(response.body).to eq expected.to_json
context 'when the object exists with full metadata' do
before do
object.descMetadata.title_info.main_title = 'Hello'
object.label = 'foo'
object.embargoMetadata.release_date = DateTime.parse '2019-09-26T07:00:00Z'
ReleaseTags.create(object, release: true,
what: 'self',
to: 'Searchworks',
who: 'petucket',
when: '2014-08-30T01:06:28Z')
end

let(:expected) do
{
externalIdentifier: 'druid:1234',
type: 'object',
label: 'foo',
version: 1,
access: {
embargoReleaseDate: '2019-09-26T07:00:00.000+00:00'
},
administrative: {
releaseTags: [
{
to: 'Searchworks',
what: 'self',
date: '2014-08-30T01:06:28.000+00:00',
who: 'petucket',
release: true
}
]
},
identification: {},
structural: {}
}
end

it 'returns the object' do
get '/v1/objects/druid:mk420bs7601',
headers: { 'Authorization' => "Bearer #{jwt}" }
expect(response).to have_http_status(:ok)
expect(response.body).to eq expected.to_json
end
end
end

context 'when the object exists with full metadata' do
before do
object.descMetadata.title_info.main_title = 'Hello'
object.label = 'foo'
object.embargoMetadata.release_date = DateTime.parse '2019-09-26T07:00:00Z'
ReleaseTags.create(object, release: true,
what: 'self',
to: 'Searchworks',
who: 'petucket',
when: '2014-08-30T01:06:28Z')
end
context 'when the requested object is an APO' do
let(:object) { Dor::AdminPolicyObject.new(pid: 'druid:1234') }

let(:expected) do
{
externalIdentifier: 'druid:1234',
type: 'object',
label: 'foo',
version: 1,
access: {
embargoReleaseDate: '2019-09-26T07:00:00.000+00:00'
},
administrative: {
releaseTags: [
{
to: 'Searchworks',
what: 'self',
date: '2014-08-30T01:06:28.000+00:00',
who: 'petucket',
release: true
}
]
},
identification: {},
structural: {}
}
end
context 'when the object exists with minimal metadata' do
before do
object.descMetadata.title_info.main_title = 'Hello'
object.label = 'foo'
end

let(:expected) do
{
externalIdentifier: 'druid:1234',
type: 'admin_policy',
label: 'foo',
version: 1,
access: {},
administrative: {},
identification: {},
structural: {}
}
end

it 'returns the object' do
get '/v1/objects/druid:mk420bs7601',
headers: { 'Authorization' => "Bearer #{jwt}" }
expect(response).to have_http_status(:ok)
expect(response.body).to eq expected.to_json
it 'returns the object' do
get '/v1/objects/druid:mk420bs7601',
headers: { 'Authorization' => "Bearer #{jwt}" }
expect(response).to have_http_status(:ok)
expect(response.body).to eq expected.to_json
end
end
end
end

0 comments on commit ee15257

Please sign in to comment.