Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 23, 2019
2 parents f172494 + d8d1d82 commit 6368a91
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/error_serializable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def serialize_errors(errors)
source = err.keys.first

Array.wrap(err.values.first).each do |title|
sum << { source: source, title: title.is_a?(String) ? title.capitalize : title.to_s }
sum << { source: source, title: title.is_a?(String) ? title.sub(/^./, &:upcase) : title.to_s }
end

sum
Expand Down
1 change: 1 addition & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def validate
def create
logger = Logger.new(STDOUT)
# logger.info safe_params.inspect
fail CanCan::AuthorizationNotPerformed unless current_user.present?

@doi = Doi.new(safe_params)

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def organizations
page_num = 2
while page_num <= total_pages
page = { size: 1000, number: page_num }
response = Client.query(nil, page: page)
response = Client.query(nil, page: page, include_deleted: true)
clients = clients + response.records.to_a
page_num += 1
end
Expand Down
6 changes: 3 additions & 3 deletions app/validators/xml_schema_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ def validate_each(record, attribute, value)
record.errors[:xml] << "Schema #{record.schema_version} is no longer supported"
return false
end

filepath = Bundler.rubygems.find_name('bolognese').first.full_gem_path + "/resources/#{kernel}/metadata.xsd"
schema = Nokogiri::XML::Schema(open(filepath))

schema.validate(Nokogiri::XML(value, nil, 'UTF-8')).reduce({}) do |sum, error|
location, level, source, text = error.message.split(": ", 4)
line, column = location.split(":", 2)
title = text.to_s.strip + " at line #{line}, column #{column}" if line.present?
source = source.split("}").last[0..-2] if line.present?
source = schema_attributes(source) if source.present?
source = schema_attributes(source) if source.present?
record.errors[source.to_sym] << title
end
rescue Nokogiri::XML::SyntaxError => e
Expand Down
29 changes: 20 additions & 9 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

ActiveRecord::Schema.define(version: 2019_08_07_002912) do

create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC", force: :cascade do |t|
create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t|
t.string "name", limit: 191, null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
Expand All @@ -22,7 +22,7 @@
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end

create_table "active_storage_blobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC", force: :cascade do |t|
create_table "active_storage_blobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t|
t.string "key", limit: 191, null: false
t.string "filename", limit: 191, null: false
t.string "content_type", limit: 191
Expand Down Expand Up @@ -85,7 +85,7 @@
t.index ["prefixes"], name: "FKE7FBD674AF86A1C7"
end

create_table "audits", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC", force: :cascade do |t|
create_table "audits", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t|
t.integer "auditable_id"
t.string "auditable_type"
t.integer "associated_id"
Expand All @@ -107,6 +107,17 @@
t.index ["user_id", "user_type"], name: "user_index"
end

create_table "contacts", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t|
t.bigint "allocator"
t.string "email"
t.string "given_name"
t.string "family_name"
t.string "role"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["allocator"], name: "fk_rails_5c598567a8"
end

create_table "datacentre", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t|
t.text "comments", limit: 4294967295
t.string "system_email", null: false
Expand All @@ -128,8 +139,7 @@
t.text "url"
t.string "software", limit: 191
t.text "description"
t.string "client_type", limit: 191, default: "repository"
t.string "doaj_journal_id", limit: 191
t.string "client_type", limit: 191
t.json "issn"
t.json "certificate"
t.json "repository_type"
Expand Down Expand Up @@ -211,7 +221,7 @@
t.index ["url"], name: "index_dataset_on_url", length: 100
end

create_table "events", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC", force: :cascade do |t|
create_table "events", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.text "uuid", null: false
t.text "subj_id", null: false
t.text "obj_id"
Expand All @@ -238,7 +248,7 @@
t.index ["uuid"], name: "index_events_on_uuid", unique: true, length: 36
end

create_table "media", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
create_table "media", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t|
t.datetime "created"
t.string "media_type", limit: 80
t.datetime "updated"
Expand All @@ -250,7 +260,7 @@
t.index ["url"], name: "index_media_on_url", length: 100
end

create_table "metadata", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
create_table "metadata", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t|
t.datetime "created"
t.integer "metadata_version"
t.integer "version"
Expand All @@ -262,7 +272,7 @@
t.index ["dataset"], name: "FKE52D7B2F4D3D6B1B"
end

create_table "prefix", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
create_table "prefix", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t|
t.datetime "created"
t.string "prefix", limit: 80, null: false
t.integer "version"
Expand Down Expand Up @@ -301,6 +311,7 @@

add_foreign_key "allocator_prefixes", "allocator", column: "allocator", name: "FKE7FBD67446EBD781"
add_foreign_key "allocator_prefixes", "prefix", column: "prefixes", name: "FKE7FBD674AF86A1C7"
add_foreign_key "contacts", "allocator", column: "allocator"
add_foreign_key "datacentre", "allocator", column: "allocator", name: "FK6695D60546EBD781"
add_foreign_key "datacentre_prefixes", "datacentre", column: "datacentre", name: "FK13A1B3BA47B5F5FF"
add_foreign_key "datacentre_prefixes", "prefix", column: "prefixes", name: "FK13A1B3BAAF86A1C7"
Expand Down
44 changes: 44 additions & 0 deletions spec/fixtures/files/datacite_malformed_creator_name_type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<resource xmlns="http://datacite.org/schema/kernel-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
<identifier identifierType="DOI">10.25670/oi2018-001on</identifier>
<titles>
<title xml:lang="sl">Učinkovitost kanabinoidov pri zdravljenju raka</title>
<title xml:lang="sl" titleType="Subtitle">mit ali resnica</title>
<title xml:lang="en" titleType="TranslatedTitle">Therapeutic Efficacy of Cannabinoids in Cancer Treatment</title>
<title xml:lang="en" titleType="Subtitle">Myth or Fact</title>
</titles>
<creators>
<creator>
<creatorName nameType="personal">Grošelj, Blaž</creatorName>
<givenName>Blaž</givenName>
<familyName>Grošelj</familyName>
<affiliation>Onkološki inštitut Ljubljana</affiliation>
</creator>
</creators>
<publisher>Onkološki inštitut Ljubljana</publisher>
<publicationYear>2018</publicationYear>
<resourceType resourceTypeGeneral="Text">Journal Article</resourceType>
<subjects>
<subject subjectScheme="DDC">610 Medical sciences; Medicine</subject>
<subject xml:lang="en">cancer</subject>
<subject xml:lang="en">cannabinoids</subject>
</subjects>
<dates>
<date dateType="Issued">2018-06-20</date>
</dates>
<relatedIdentifiers>
<relatedIdentifier relatedIdentifierType="ISSN" relationType="IsPartOf">1581-3215</relatedIdentifier>
</relatedIdentifiers>
<descriptions>
<description xml:lang="en" descriptionType="Other">The use of cannabis derivatives (cannabinoids) in oncology is sometimes indicated in the symptomatic treatment of nausea and vomiting, in pain management and in some neuropsychiatric disorders. In the recent years, there has been a growing interest in determining the anticancer effects of cannabinoids. Based on our clinical experience, we know that many patients use cannabinoids, among them also those with the aim of curing their disease. But despite the extensive and convincing data on the anticancer properties of cannabinoids from in vitro studies on cell cultures and studies on animal models, these properties have not (yet) been confirmed in a clinical trial. This paper summarises the currently available data on the potential of cannabinoid use in the clinical practice of oncology.</description>
<description descriptionType="SeriesInformation" xml:lang="sl">Onkologija, leto XXII, št. 1, junij 2018</description>
<description descriptionType="SeriesInformation" xml:lang="en">Onkologija, Volume XXII, No. 1, June 2018</description>
</descriptions>
<language>sl</language>
<formats>
<format>pdf</format>
</formats>
<rightsList>
<rights rightsURI="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International license (CC BY 4.0)</rights>
</rightsList>
</resource>
64 changes: 55 additions & 9 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@

it 'updates the doi' do
put "/dois/#{doi.doi}", valid_attributes, admin_headers

expect(last_response.status).to eq(200)
expect(json.dig('data', 'attributes', 'sizes')).to eq(sizes)
end
Expand Down Expand Up @@ -386,7 +386,7 @@
put "/dois/#{doi.doi}", valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json["errors"]).to eq([{"source"=>"creators", "title"=>"Missing child element(s). expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0"}])
expect(json["errors"]).to eq([{"source"=>"creators", "title"=>"Missing child element(s). Expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0"}])
end
end

Expand Down Expand Up @@ -502,7 +502,7 @@
put "/dois/#{doi_id}", valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json["errors"]).to eq([{"source"=>"creators", "title"=>"Missing child element(s). expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0"}])
expect(json["errors"]).to eq([{"source"=>"creators", "title"=>"Missing child element(s). Expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0"}])
end
end

Expand All @@ -528,7 +528,7 @@
put "/dois/#{doi_id}", valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json["errors"]).to eq([{"source"=>"creators", "title"=>"Missing child element(s). expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0"}])
expect(json["errors"]).to eq([{"source"=>"creators", "title"=>"Missing child element(s). Expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0"}])
end
end

Expand Down Expand Up @@ -616,7 +616,7 @@
patch "/dois/#{doi.doi}", valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json['errors']).to eq([{"source"=>"titles", "title"=>"Title 'submitted chemical data for inchikey=yapqbxqyljrxsa-uhfffaoysa-n' should be an object instead of a string."}])
expect(json['errors']).to eq([{"source"=>"titles", "title"=>"Title 'Submitted chemical data for InChIKey=YAPQBXQYLJRXSA-UHFFFAOYSA-N' should be an object instead of a string."}])
end
end

Expand Down Expand Up @@ -966,6 +966,30 @@
end
end

context 'when the request is valid no password' do
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"source" => "test",
"event" => "publish"
}
}
}
end

it 'fails to create a Doi' do
post '/dois', valid_attributes

expect(last_response.status).to eq(401)
end
end

context 'when the request is valid random doi' do
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
let(:valid_attributes) do
Expand Down Expand Up @@ -1216,7 +1240,7 @@
}
HEREDOC
) }

let(:valid_attributes) do
{
"data" => {
Expand Down Expand Up @@ -1975,7 +1999,7 @@
post '/dois', not_valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json["errors"]).to eq([{"source"=>"creators", "title"=>"Missing child element(s). expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0"}])
expect(json["errors"]).to eq([{"source"=>"creators", "title"=>"Missing child element(s). Expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0"}])
end
end

Expand Down Expand Up @@ -2068,7 +2092,7 @@

expect(last_response.status).to eq(200)
expect(json['errors'].size).to eq(1)
expect(json['errors'].first).to eq("source"=>"creators", "title"=>"Missing child element(s). expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0")
expect(json['errors'].first).to eq("source"=>"creators", "title"=>"Missing child element(s). Expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0")
end
end

Expand All @@ -2091,7 +2115,29 @@

expect(last_response.status).to eq(200)
expect(json['errors'].size).to eq(1)
expect(json['errors'].first).to eq("source"=>"creatorName", "title"=>"This element is not expected. expected is ( {http://datacite.org/schema/kernel-4}affiliation ). at line 16, column 0")
expect(json['errors'].first).to eq("source"=>"creatorName", "title"=>"This element is not expected. Expected is ( {http://datacite.org/schema/kernel-4}affiliation ). at line 16, column 0")
end
end

context 'when attribute type names are wrong' do
let(:xml) { ::Base64.strict_encode64(File.read(file_fixture('datacite_malformed_creator_name_type.xml'))) }
let(:params) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"xml" => xml,
}
}
}
end

it 'validates types are in right format' do
post '/dois/validate', params, headers

expect(last_response.status).to eq(200)
expect(json['errors'].first).to eq("source"=>"creatorName', attribute 'nameType","title"=>"[facet 'enumeration'] The value 'personal' is not an element of the set {'Organizational', 'Personal'}. at line 12, column 0")
end
end

Expand Down

0 comments on commit 6368a91

Please sign in to comment.