Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Updating to send uploaded year and correct resource types for datacite
Browse files Browse the repository at this point in the history
refs #1237
  • Loading branch information
carolyncole committed Feb 5, 2019
1 parent b6a1440 commit 68fa830
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/services/doi_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DOIService
EZID_RESOURCE_TYPES = {
'Article' => 'Text',
'Audio' => 'Sound',
'Book' => 'Book',
'Book' => 'Text',
'Capstone Project' => 'Text',
'Conference Proceeding' => 'Text',
'Dataset' => 'Dataset',
Expand Down Expand Up @@ -60,7 +60,7 @@ def base_body(object)
'datacite.creator' => formatted_creators(object),
'datacite.title' => object.title.first,
'datacite.publisher' => 'ScholarSphere',
'datacite.publicationyear' => '2018',
'datacite.publicationyear' => object.date_uploaded.year.to_s,
target: object.url
}
end
Expand Down
64 changes: 60 additions & 4 deletions spec/services/doi_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
let(:first_creator) { create(:alias, display_name: 'First Creator', agent: Agent.new(given_name: 'First', sur_name: 'Creator')) }
let(:second_creator) { create(:alias, display_name: 'Second Creator', agent: Agent.new(given_name: 'Second', sur_name: 'Creator')) }

let(:upload_date) { Time.now }
let(:object) do
create(:work,
title: ['DOI Title'],
creators: [first_creator, second_creator],
identifier: identifier,
resource_type: ['Article'])
resource_type: ['Article'],
date_uploaded: upload_date)
end

context 'existing doi' do
Expand All @@ -32,7 +34,7 @@
let(:metadata) { { 'datacite.creator' => 'Creator, First; Creator, Second',
'datacite.title' => 'DOI Title',
'datacite.publisher' => 'ScholarSphere',
'datacite.publicationyear' => '2018',
'datacite.publicationyear' => upload_date.year.to_s,
'datacite.resourcetype' => 'Text',
target: object.url } }

Expand All @@ -49,15 +51,15 @@
end

context 'with a collection' do
let(:object) { create(:collection, title: ['DOI Collection']) }
let(:object) { create(:collection, title: ['DOI Collection'], date_uploaded: upload_date) }
let(:doi) { 'doi:10.5072/FK2VT1Q90B' }
let(:response_body) { 'success: doi:10.5072/FK2VT1Q90B | ark:/b5072/fk2vt1q90b' }
let(:client) { instance_double(Ezid::Client) }
let(:response) { instance_double(Ezid::MintIdentifierResponse, id: doi) }
let(:metadata) { { 'datacite.creator' => 'Creator, Creator C.',
'datacite.title' => 'DOI Collection',
'datacite.publisher' => 'ScholarSphere',
'datacite.publicationyear' => '2018',
'datacite.publicationyear' => upload_date.year.to_s,
target: object.url } }

before do
Expand All @@ -70,4 +72,58 @@
expect(minted_id).to eq(doi)
end
end

context 'all the resource types' do
let(:doi) { 'doi:10.5072/FK2VT1Q90B' }
let(:response_body) { 'success: doi:10.5072/FK2VT1Q90B | ark:/b5072/fk2vt1q90b' }
let(:client) { instance_double(Ezid::Client) }
let(:response) { instance_double(Ezid::MintIdentifierResponse, id: doi) }
let(:work) do
create(:work, title: ['DOI Title'],
creators: [first_creator, second_creator],
resource_type: [], date_uploaded: upload_date)
end

it 'maps the resource type correctly' do
allow(Ezid::Client).to receive(:new).and_return(client)
check_resource_type(work: work, client: client,
resource_types: ['Audio'], datacite_type: 'Sound')
check_resource_type(work: work, client: client,
resource_types: ['Dataset'], datacite_type: 'Dataset')
check_resource_type(work: work, client: client,
resource_types: ['Image', 'Map or Cartographic Material'],
datacite_type: 'Image')
check_resource_type(work: work, client: client,
resource_types: ['Poster', 'Presentation', 'Video'],
datacite_type: 'Audiovisual')
check_resource_type(work: work, client: client,
resource_types: ['Project', 'Other'],
datacite_type: 'Other')
check_resource_type(work: work, client: client,
resource_types: [
'Software or Program Code'
], datacite_type: 'Software')
check_resource_type(work: work, client: client,
resource_types: ['Article', 'Book', 'Capstone Project',
'Conference Proceeding', 'Journal', 'Part of Book',
'Report', 'Research Paper'],
datacite_type: 'Text')
end
end
end

def check_resource_type(work:, client:, resource_types:, datacite_type:)
resource_types.each do |resource_type|
work.resource_type = [resource_type]
work.identifier = []

metadata = { 'datacite.creator' => 'Creator, First; Creator, Second',
'datacite.title' => 'DOI Title',
'datacite.publisher' => 'ScholarSphere',
'datacite.publicationyear' => work.date_uploaded.year.to_s,
'datacite.resourcetype' => datacite_type,
target: work.url }
expect(client).to receive(:mint_identifier).with('testhandle', metadata).and_return(response)
service.run(work)
end
end

0 comments on commit 68fa830

Please sign in to comment.