Skip to content

Commit

Permalink
only show known resource-type-general in resourceTypes aggregation. #472
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 18, 2020
1 parent 48a319c commit c6a2215
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1055,13 +1055,17 @@ def uid
end

def resource_type_id
types["resourceTypeGeneral"].underscore.dasherize if types.to_h["resourceTypeGeneral"].present?
r = types.to_h["resourceTypeGeneral"]
r.underscore.dasherize if RESOURCE_TYPES_GENERAL[r].present?
rescue TypeError
nil
end

def resource_type_id_and_name
"#{resource_type_id}:#{types["resourceTypeGeneral"].titleize}" if types.to_h["resourceTypeGeneral"].present?
r = types.to_h["resourceTypeGeneral"]
"#{r.underscore.dasherize}:#{RESOURCE_TYPES_GENERAL[r]}" if RESOURCE_TYPES_GENERAL[r].present?
rescue TypeError
nil
end

def media_ids
Expand Down
18 changes: 18 additions & 0 deletions config/initializers/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ class IdentifierError < RuntimeError; end
"AMER" => "Americas"
}

RESOURCE_TYPES_GENERAL = {
"Audiovisual" => "Audiovisual",
"Collection" => "Collection",
"Dataset" => "Dataset",
"DataPaper" => "Data Paper",
"Event" => "Event",
"Image" => "Image",
"InteractiveResource" => "Interactive Resource",
"Model" => "Model",
"PhysicalObject" => "Physical Object",
"Service" => "Service",
"Sound" => "Sound",
"Software" => "Software",
"Text" => "Text",
"Workflow" => "Workflow",
"Other" => "Other"
}

LAST_SCHEMA_VERSION = "http://datacite.org/schema/kernel-4"

METADATA_FORMATS = [
Expand Down
22 changes: 21 additions & 1 deletion spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
sleep 3
end

it 'filter for instruments' do
it 'filter for interactive resources' do
get "/dois?resource-type-id=interactive-resource", nil, headers

expect(last_response.status).to eq(200)
Expand All @@ -296,6 +296,26 @@
expect(json.dig('meta', 'resourceTypes')).to eq([{"count"=>3, "id"=>"interactive-resource", "title"=>"Interactive Resource"}])
end
end

describe 'GET /dois for fake resources', elasticsearch: true, vcr: true do
let!(:dois) { create_list(:doi, 3, types: { "resourceTypeGeneral" => "Fake", "resourceType" => "Presentation" }, client: client) }

before do
Doi.import
sleep 3
end

it 'filter for fake resources' do
get "/dois?resource-type-id=fake", nil, headers

expect(last_response.status).to eq(200)
expect(json['data'].size).to eq(3)
expect(json.dig('meta', 'total')).to eq(3)
expect(json.dig('data', 0, 'attributes', 'publicationYear')).to eq(2011)
expect(json.dig('data', 0, 'attributes', 'types')).to eq("resourceType"=>"Presentation", "resourceTypeGeneral"=>"Fake")
expect(json.dig('meta', 'resourceTypes')).to eq([])
end
end

describe 'GET /dois with views and downloads', elasticsearch: true, vcr: true do
let(:doi) { create(:doi, client: client, aasm_state: "findable") }
Expand Down

0 comments on commit c6a2215

Please sign in to comment.