Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use resource_type_id instead of types.resourceTypeGeneral when filtering #1036

Merged
merged 7 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/parallel_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
matrix:
# set N-1 indexes for parallel jobs
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7]
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# Set N number of parallel jobs you want to run
# Remember to update ci_node_index above to 0..N-1
ci_node_total: [8]
ci_node_total: [10]

services:
memcached:
Expand Down
10 changes: 5 additions & 5 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def self.query(query, options = {})
minimum_should_match = 0

filter << { terms: { doi: options[:ids].map(&:upcase) } } if options[:ids].present?
filter << { term: { "types.resourceTypeGeneral": options[:resource_type_id].underscore.camelize } } if options[:resource_type_id].present?
filter << { term: { resource_type_id: options[:resource_type_id].underscore.dasherize } } if options[:resource_type_id].present?
filter << { terms: { "types.resourceType": options[:resource_type].split(",") } } if options[:resource_type].present?
if options[:provider_id].present?
options[:provider_id].split(",").each { |id|
Expand Down Expand Up @@ -1196,14 +1196,14 @@ def uid
end

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

def resource_type_id_and_name
r = handleResourceType(types) # types.to_h["resourceTypeGeneral"]
r = handle_resource_type(types) # types.to_h["resourceTypeGeneral"]
"#{r.underscore.dasherize}:#{RESOURCE_TYPES_GENERAL[r]}" if RESOURCE_TYPES_GENERAL[r].present?
rescue TypeError
nil
Expand Down Expand Up @@ -2370,8 +2370,8 @@ def self.add_index_type(options = {})


# QUICK FIX UNTIL PROJECT IS A RESOURCE_TYPE_GENERAL IN THE SCHEMA
def handleResourceType(types)
if types["resourceType"] == "Project" && (types["resourceTypeGeneral"] == "Text" || types["resourceTypeGeneral"] == "Other")
def handle_resource_type(types)
if types.present? && types["resourceType"] == "Project" && (types["resourceTypeGeneral"] == "Text" || types["resourceTypeGeneral"] == "Other")
"Project"
else
types.to_h["resourceTypeGeneral"]
Expand Down
2 changes: 1 addition & 1 deletion app/models/doi/graphql_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def filters

filter = []
filter << { terms: { doi: options[:ids].map(&:upcase) } } if options[:ids].present?
filter << { term: { "types.resourceTypeGeneral": options[:resource_type_id].underscore.camelize } } if options[:resource_type_id].present?
filter << { term: { resource_type_id: options[:resource_type_id].underscore.dasherize } } if options[:resource_type_id].present?
filter << { terms: { "types.resourceType": options[:resource_type].split(",") } } if options[:resource_type].present?
filter << { terms: { agency: options[:agency].split(",").map(&:downcase) } } if options[:agency].present?
filter << { terms: { prefix: options[:prefix].to_s.split(",") } } if options[:prefix].present?
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ class IdentifierError < RuntimeError; end
"PeerReview" => "Peer Review",
"PhysicalObject" => "Physical Object",
"Preprint" => "Preprint",
"Project" => "Project",
"Report" => "Report",
"Service" => "Service",
"Sound" => "Sound",
"Software" => "Software",
"Standard" => "Standard",
"Text" => "Text",
"Workflow" => "Workflow",
"Project" => "Project",
"Other" => "Other",
}.freeze

Expand Down
16 changes: 14 additions & 2 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2068,8 +2068,9 @@
end

let(:query) do
"query($first: Int, $cursor: String, $facetCount: Int) {
works(first: $first, after: $cursor, facetCount: $facetCount) {
"query($first: Int, $cursor: String, $resourceTypeId: String) {
works(first: $first, after: $cursor, resourceTypeId: $resourceTypeId) {
totalCount
resourceTypes {
id
title
Expand All @@ -2091,4 +2092,15 @@
[{ "count" => 10, "id" => "project", "title" => "Project" }, { "count" => 5, "id" => "dataset", "title" => "Dataset" }]
)
end

it "returns projects when querying works based on resource_type_id" do
response =
LupoSchema.execute(
query,
variables: { first: 15, cursor: nil, resourceTypeId: "Project" }
).
as_json

expect(response.dig("data", "works", "totalCount")).to eq(10)
end
end
9 changes: 3 additions & 6 deletions spec/requests/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -668,15 +668,12 @@
sleep 3
end

it "filter for fake resources" do
it "filter for fake resources returns no results" 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("bibtex" => "misc", "citeproc" => "article", "resourceType" => "Presentation", "resourceTypeGeneral" => "Fake", "ris" => "GEN", "schemaOrg" => "CreativeWork")
expect(json.dig("meta", "resourceTypes")).to eq([])
expect(json["data"].size).to eq(0)
expect(json.dig("meta", "total")).to eq(0)
end
end

Expand Down