Skip to content

Commit

Permalink
Store the resource type and resource type general in the correct data…
Browse files Browse the repository at this point in the history
…cite fields (#1962)

fixes #1934
  • Loading branch information
carolyncole authored Oct 9, 2024
1 parent f33156d commit 9864c96
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 62 deletions.
12 changes: 6 additions & 6 deletions app/models/pdc_serialization/datacite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def valid?
# @param [String] publisher
# @param [String] publication_year
# @param [String] resource_type
def self.skeleton_datacite_xml(identifier:, title:, creator:, publisher:, publication_year:, resource_type:)
def self.skeleton_datacite_xml(identifier:, title:, creator:, publisher:, publication_year:, resource_type:, resource_type_general:)
mapping = ::Datacite::Mapping::Resource.new(
identifier: ::Datacite::Mapping::Identifier.new(value: identifier),
creators: [] << ::Datacite::Mapping::Creator.new(name: creator),
titles: [] << ::Datacite::Mapping::Title.new(value: title),
publisher: ::Datacite::Mapping::Publisher.new(value: publisher),
publication_year:,
resource_type: datacite_resource_type(resource_type)
resource_type: datacite_resource_type(resource_type_general, resource_type)
)
mapping.write_xml
end
Expand All @@ -94,7 +94,7 @@ def self.new_from_work_resource(resource)
titles: titles_from_work_resource(resource.titles),
publisher: ::Datacite::Mapping::Publisher.new(value: resource.publisher),
publication_year: resource.publication_year,
resource_type: datacite_resource_type(resource.resource_type),
resource_type: datacite_resource_type(resource.resource_type_general, resource.resource_type),
related_identifiers: related_identifiers_from_work_resource(resource),
rights_list: rights_from_work_resource(resource),
version: resource.version_number,
Expand All @@ -105,9 +105,9 @@ def self.new_from_work_resource(resource)
# rubocop:enable Metrics/MethodLength

class << self
def datacite_resource_type(value)
resource_type = ::Datacite::Mapping::ResourceTypeGeneral.find_by_value(value)
::Datacite::Mapping::ResourceType.new(resource_type_general: resource_type)
def datacite_resource_type(resource_type_general, value)
resource_type = ::Datacite::Mapping::ResourceTypeGeneral.find_by_value(resource_type_general)
::Datacite::Mapping::ResourceType.new(resource_type_general: resource_type, value:)
end

def datacite_contributor_type(key)
Expand Down
45 changes: 22 additions & 23 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions spec/factories/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"creators" => [
{ "value" => "Kotin, Joshua", "name_type" => "Personal", "given_name" => "Joshua", "family_name" => "Kotin", "affiliations" => [], "sequence" => "1" }
],
"resource_type" => "Dataset", "publisher" => "Princeton University", "publication_year" => "2020",
"resource_type_general" => "Dataset", "resource_type" => "Data in set", "publisher" => "Princeton University", "publication_year" => "2020",
"version_number" => "1",
"rights" => { "identifier" => "CC BY" }
}
Expand All @@ -102,7 +102,7 @@
"creators" => [
{ "value" => "Rafiq, Tariq", "name_type" => "Personal", "given_name" => "Tariq", "family_name" => "Rafiq", "affiliations" => [], "sequence" => "1" }
],
"resource_type" => "Dataset", "publisher" => "Princeton University", "publication_year" => "2022",
"resource_type_general" => "Dataset", "resource_type" => "Data in set", "publisher" => "Princeton University", "publication_year" => "2022",
"version_number" => "1",
"rights" => { "identifier" => "CC BY" }
})
Expand All @@ -122,7 +122,7 @@
"creators" => [
{ "value" => "Rafiq, Tariq", "name_type" => "Personal", "given_name" => "Tariq", "family_name" => "Rafiq", "affiliations" => [], "sequence" => "1" }
],
"resource_type" => "Dataset", "publisher" => "Princeton University", "publication_year" => "2022",
"resource_type_general" => "Dataset", "resource_type" => "Data in set", "publisher" => "Princeton University", "publication_year" => "2022",
"version_number" => "1",
"rights" => { "identifier" => "CC BY" }
})
Expand All @@ -143,7 +143,7 @@
"creators" => [
{ "value" => "Rafiq, Tariq", "name_type" => "Personal", "given_name" => "Tariq", "family_name" => "Rafiq", "affiliations" => [], "sequence" => "1" }
],
"resource_type" => "Dataset", "publisher" => "Princeton University", "publication_year" => "2022",
"resource_type_general" => "Dataset", "resource_type" => "Data in set", "publisher" => "Princeton University", "publication_year" => "2022",
"version_number" => "1",
"rights" => { "identifier" => "CC BY" }
})
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/datacite_basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<title>hello world</title>
</titles>
<publisher>Princeton University</publisher>
<resourceType resourceTypeGeneral='Dataset'/>
<resourceType resourceTypeGeneral='Dataset'>Dataset</resourceType>
<publicationYear>2022</publicationYear>
<contributors>
<contributor contributorType='ProjectLeader'>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/resource-to-datacite/basic.datacite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<title>This is the title</title>
</titles>
<publisher>Princeton University</publisher>
<resourceType resourceTypeGeneral='Dataset'/>
<resourceType resourceTypeGeneral='Dataset'>Dataset</resourceType>
<publicationYear>2019</publicationYear>
<contributors>
<contributor contributorType='Other'>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/resource-to-datacite/old.datacite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<title>This is the title</title>
</titles>
<publisher>Princeton University</publisher>
<resourceType resourceTypeGeneral='Dataset'/>
<resourceType resourceTypeGeneral='Dataset'>Dataset</resourceType>
<publicationYear>2019</publicationYear>
<contributors>
<contributor contributorType='Other'>
Expand Down
46 changes: 26 additions & 20 deletions spec/models/pdc_serialization/datacite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
let(:creator) { "Doctor Bones" }
let(:publisher) { "Femur Inc." }
let(:publication_year) { 1654 }
let(:resource_type) { "Dataset" }
let(:resource_type_general) { "Dataset" }
let(:resource_type) { "Data in a set" }
let(:skeleton_datacite_xml) do
described_class.skeleton_datacite_xml(
identifier:,
title:,
creator:,
publisher:,
publication_year:,
resource_type:
resource_type:,
resource_type_general:
)
end
let(:parsed_xml) { Datacite::Mapping::Resource.parse_xml(skeleton_datacite_xml) }
Expand All @@ -28,7 +30,8 @@
expect(parsed_xml.creators.first.creator_name.value).to eq creator
expect(parsed_xml.publisher.value).to eq publisher
expect(parsed_xml.publication_year).to eq publication_year
expect(parsed_xml.resource_type.resource_type_general.value).to eq resource_type
expect(parsed_xml.resource_type.resource_type_general.value).to eq resource_type_general
expect(parsed_xml.resource_type.value).to eq resource_type
end
end

Expand Down Expand Up @@ -75,7 +78,8 @@
"creators" => [
{ "value" => "Kotin, Joshua", "name_type" => "Personal", "given_name" => "Joshua", "family_name" => "Kotin", "affiliations" => [{ "value" => "Example" }], "sequence" => "1" }
],
"resource_type" => "Dataset",
"resource_type_general" => "Dataset",
"resource_type" => "data in a set",
"publisher" => "Princeton University",
"publication_year" => "2020"
}
Expand Down Expand Up @@ -143,63 +147,64 @@

context "resource types" do
it "maps dataset" do
resource_type = described_class.datacite_resource_type("Dataset")
resource_type = described_class.datacite_resource_type("Dataset", "Data in a set")
expect(resource_type.resource_type_general.value).to eq "Dataset"
expect(resource_type.value).to eq "Data in a set"
end
it "Audiovisual" do
resource_type = described_class.datacite_resource_type("Audiovisual")
resource_type = described_class.datacite_resource_type("Audiovisual", "visual data")
expect(resource_type.resource_type_general.value).to eq "Audiovisual"
end
it "Collection" do
resource_type = described_class.datacite_resource_type("Collection")
resource_type = described_class.datacite_resource_type("Collection", "Stamp")
expect(resource_type.resource_type_general.value).to eq "Collection"
end
it "DataPaper" do
resource_type = described_class.datacite_resource_type("DataPaper")
resource_type = described_class.datacite_resource_type("DataPaper", "about science")
expect(resource_type.resource_type_general.value).to eq "DataPaper"
end
it "Event" do
resource_type = described_class.datacite_resource_type("Event")
resource_type = described_class.datacite_resource_type("Event", "Rubyconf")
expect(resource_type.resource_type_general.value).to eq "Event"
end
it "Image" do
resource_type = described_class.datacite_resource_type("Image")
resource_type = described_class.datacite_resource_type("Image", "cat pics")
expect(resource_type.resource_type_general.value).to eq "Image"
end
it "InteractiveResource" do
resource_type = described_class.datacite_resource_type("InteractiveResource")
resource_type = described_class.datacite_resource_type("InteractiveResource", "kitten video")
expect(resource_type.resource_type_general.value).to eq "InteractiveResource"
end
it "Model" do
resource_type = described_class.datacite_resource_type("Model")
resource_type = described_class.datacite_resource_type("Model", "aeroplane")
expect(resource_type.resource_type_general.value).to eq "Model"
end
it "PhysicalObject" do
resource_type = described_class.datacite_resource_type("PhysicalObject")
resource_type = described_class.datacite_resource_type("PhysicalObject", "a rock")
expect(resource_type.resource_type_general.value).to eq "PhysicalObject"
end
it "Service" do
resource_type = described_class.datacite_resource_type("Service")
resource_type = described_class.datacite_resource_type("Service", "cleaning")
expect(resource_type.resource_type_general.value).to eq "Service"
end
it "Software" do
resource_type = described_class.datacite_resource_type("Software")
resource_type = described_class.datacite_resource_type("Software", "code base")
expect(resource_type.resource_type_general.value).to eq "Software"
end
it "Sound" do
resource_type = described_class.datacite_resource_type("Sound")
resource_type = described_class.datacite_resource_type("Sound", "pop music")
expect(resource_type.resource_type_general.value).to eq "Sound"
end
it "Text" do
resource_type = described_class.datacite_resource_type("Text")
resource_type = described_class.datacite_resource_type("Text", "story")
expect(resource_type.resource_type_general.value).to eq "Text"
end
it "Workflow" do
resource_type = described_class.datacite_resource_type("Workflow")
resource_type = described_class.datacite_resource_type("Workflow", "recipe")
expect(resource_type.resource_type_general.value).to eq "Workflow"
end
it "Other" do
resource_type = described_class.datacite_resource_type("Other")
resource_type = described_class.datacite_resource_type("Other", "stuff")
expect(resource_type.resource_type_general.value).to eq "Other"
end
end
Expand All @@ -221,7 +226,8 @@
"creators" => [
{ "value" => "Kotin, Joshua", "name_type" => "Personal", "given_name" => "Joshua", "family_name" => "Kotin", "affiliations" => [], "sequence" => "1" }
],
"resource_type" => "Dataset",
"resource_type_general" => "Dataset",
"resource_type" => "data in a set",
"publisher" => "Princeton University",
"publication_year" => "2020"
}
Expand Down
4 changes: 2 additions & 2 deletions spec/models/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"collection_tags" => [],
"creators" => [{ "value" => "Rafiq, Tariq", "name_type" => "Personal", "given_name" => "Tariq", "family_name" => "Rafiq", "identifier" => nil, "affiliations" => [], "sequence" => 1 }],
"organizational_contributors" => [],
"resource_type" => "Dataset",
"resource_type_general" => nil,
"resource_type" => "Data in set",
"resource_type_general" => "Dataset",
"publisher" => "Princeton University",
"publication_year" => "2022",
"ark" => "ark:/88435/dsp015d86p342b",
Expand Down
2 changes: 1 addition & 1 deletion spec/services/form_to_resource_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{ "orcid" => "", "given_name" => "Toni", "family_name" => "Morrison" },
{ "orcid" => "1234-1234-1234-1234", "given_name" => "Sonia", "family_name" => "Sotomayor" }
],
resource_type: "Dataset",
resource_type: "Visual Stuff",
resource_type_general: "Audiovisual",
related_objects: [{ related_identifier: "", related_identifier_type: "", relation_type: "" }]
}.with_indifferent_access
Expand Down
3 changes: 2 additions & 1 deletion spec/services/resource_compare_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
publication_year: [{ action: :changed, from: "2020", to: "" }],
version_number: [{ action: :changed, from: "1", to: "" }],
publisher: [{ action: :changed, from: "Princeton University", to: "" }],
resource_type: [{ action: :changed, from: "Dataset", to: "" }],
resource_type_general: [{ action: :changed, from: "Dataset", to: "" }],
resource_type: [{ action: :changed, from: "Data in set", to: "" }],
rights_many: [{ action: :changed, from: "Creative Commons Attribution 4.0 International", to: "" }],
titles: [{ action: :changed, from: "Shakespeare and Company Project Dataset: Lending Library Members, Books, Events ()", to: "new title ()" }],
collection_tags: [{ action: :changed, from: "", to: "fake" }],
Expand Down
Loading

0 comments on commit 9864c96

Please sign in to comment.