Skip to content

Commit

Permalink
update container when series_information is removed. datacite/bracco#168
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 10, 2019
1 parent 90a6b81 commit 6f9a297
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,9 @@ def safe_params

# merge attributes from xml into regular attributes
# make sure we don't accidentally set any attributes to nil
# set container even if empty, as the content is read-only and generated from other properties
read_attrs_keys.each do |attr|
p.merge!(attr.to_s.underscore => p[attr].presence || meta[attr.to_s.underscore]) if p.has_key?(attr) || meta[attr.to_s.underscore].present?
p.merge!(attr.to_s.underscore => p[attr].presence || meta[attr.to_s.underscore]) if p.has_key?(attr) || meta[attr.to_s.underscore].present? || attr == :container
end
p.merge!(version_info: p[:version] || meta["version_info"]) if p.has_key?(:version_info) || meta["version_info"].present?

Expand Down
45 changes: 45 additions & 0 deletions spec/fixtures/files/datacite_no_series_information.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<resource
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
<identifier identifierType="DOI">10.26206/T76E-RE09</identifier>
<creators>
<creator>
<creatorName>Hassenruck-Gudipati, Hima</creatorName>
<givenName>Hima</givenName>
<familyName>Hassenruck-Gudipati</familyName>
</creator>
</creators>
<titles>
<title>Percussive Scoop Sampling in Extreme Terrain</title>
</titles>
<publisher>Keck Institute for Space Studies</publisher>
<publicationYear>2016</publicationYear>
<dates>
<date dateType="Available">2016-03-09 20:28:15</date>
</dates>
<language>English</language>
<resourceType resourceTypeGeneral="Text">Discussion Paper</resourceType>
<rightsList>
<rights>No commercial reproduction, distribution, display or performance rights in this work are provided.</rights>
</rightsList>
<descriptions>
<description descriptionType="Abstract">Axel is a minimalistic cliff climbing rover that can explore
extreme terrains from the moon, Mars, and beyond. To
increase the technology readiness and scientific usability
of Axel, a sampling system needs to be designed and
build for sampling different rock and soils. To decrease
the amount of force required to sample clumpy and
possibly icy science targets, a percussive scoop could be
used. A percussive scoop uses repeated impact force to
dig into samples and a rotary actuation to collect the
samples. Percussive scooping can reduce the amount of downward force required by about two to four
times depending on the cohesion of the soil and the depth of the sampling. The goal for this project is to
build a working prototype of a percussive scoop for Axel.</description>
</descriptions>
<fundingReferences>
<fundingReference>
<funderName>Keck Institute for Space Studies (KISS)</funderName>
</fundingReference>
</fundingReferences>
</resource>
46 changes: 46 additions & 0 deletions spec/fixtures/files/datacite_series_information.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<resource
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
<identifier identifierType="DOI">10.26206/T76E-RE09</identifier>
<creators>
<creator>
<creatorName>Hassenruck-Gudipati, Hima</creatorName>
<givenName>Hima</givenName>
<familyName>Hassenruck-Gudipati</familyName>
</creator>
</creators>
<titles>
<title>Percussive Scoop Sampling in Extreme Terrain</title>
</titles>
<publisher>Keck Institute for Space Studies</publisher>
<publicationYear>2016</publicationYear>
<dates>
<date dateType="Available">2016-03-09 20:28:15</date>
</dates>
<language>English</language>
<resourceType resourceTypeGeneral="Text">Discussion Paper</resourceType>
<rightsList>
<rights>No commercial reproduction, distribution, display or performance rights in this work are provided.</rights>
</rightsList>
<descriptions>
<description descriptionType="Abstract">Axel is a minimalistic cliff climbing rover that can explore
extreme terrains from the moon, Mars, and beyond. To
increase the technology readiness and scientific usability
of Axel, a sampling system needs to be designed and
build for sampling different rock and soils. To decrease
the amount of force required to sample clumpy and
possibly icy science targets, a percussive scoop could be
used. A percussive scoop uses repeated impact force to
dig into samples and a rotary actuation to collect the
samples. Percussive scooping can reduce the amount of downward force required by about two to four
times depending on the cohesion of the soil and the depth of the sampling. The goal for this project is to
build a working prototype of a percussive scoop for Axel.</description>
<description descriptionType="SeriesInformation">Keck Institute for Space Studies</description>
</descriptions>
<fundingReferences>
<fundingReference>
<funderName>Keck Institute for Space Studies (KISS)</funderName>
</fundingReference>
</fundingReferences>
</resource>
78 changes: 78 additions & 0 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,84 @@
end
end

context 'remove series_information' do
let(:xml) { File.read(file_fixture('datacite_series_information.xml')) }
let(:descriptions) { [{ "description" => "Axel is a minimalistic cliff climbing rover that can explore
extreme terrains from the moon, Mars, and beyond. To
increase the technology readiness and scientific usability
of Axel, a sampling system needs to be designed and
build for sampling different rock and soils. To decrease
the amount of force required to sample clumpy and
possibly icy science targets, a percussive scoop could be
used. A percussive scoop uses repeated impact force to
dig into samples and a rotary actuation to collect the
samples. Percussive scooping can reduce the amount of downward force required by about two to four
times depending on the cohesion of the soil and the depth of the sampling. The goal for this project is to
build a working prototype of a percussive scoop for Axel.", "descriptionType" => "Abstract" }]}
let(:doi) { create(:doi, client: client, doi: "10.14454/05mb-q396", xml: xml, event: "publish") }
let(:update_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"descriptions" => descriptions
}
}
}
end

before { patch "/dois/#{doi.doi}", params: update_attributes.to_json, headers: headers }

it 'updates the Doi' do
expect(json.dig('data', 'attributes', 'descriptions')).to eq(descriptions)
expect(json.dig('data', 'attributes', 'container')).to be nil
end
end

context 'remove series_information via xml' do
let(:xml) { Base64.strict_encode64(File.read(file_fixture('datacite_series_information.xml'))) }
let(:xml_new) { Base64.strict_encode64(File.read(file_fixture('datacite_no_series_information.xml'))) }
let(:doi) { create(:doi, client: client, doi: "10.14454/05mb-q396", event: "publish") }
let(:update_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"xml" => xml
}
}
}
end
let(:update_attributes_again) do
{
"data" => {
"type" => "dois",
"attributes" => {
"xml" => xml_new
}
}
}
end

before { get "/dois/#{doi.doi}", headers: headers }

it 'updates the Doi' do
expect(json.dig('data', 'attributes', 'descriptions')).to eq([{"description"=>"Data from: A new malaria agent in African hominids."}])
expect(json.dig('data', 'attributes', 'container')).to be nil

patch "/dois/#{doi.doi}", params: update_attributes.to_json, headers: headers

expect(json.dig('data', 'attributes', 'descriptions').size).to eq(2)
expect(json.dig('data', 'attributes', 'descriptions').last).to eq("description"=>"Keck Institute for Space Studies", "descriptionType"=>"SeriesInformation")
expect(json.dig('data', 'attributes', 'container')).to eq("title"=>"Keck Institute for Space Studies", "type"=>"Series")

patch "/dois/#{doi.doi}", params: update_attributes_again.to_json, headers: headers

expect(json.dig('data', 'attributes', 'descriptions').size).to eq(1)
expect(json.dig('data', 'attributes', 'container')).to be_empty
end
end

context 'landing page' do
let(:url) { "https://blog.datacite.org/re3data-science-europe/" }
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
Expand Down

0 comments on commit 6f9a297

Please sign in to comment.