Skip to content

Commit

Permalink
Merge pull request #778 from datacite/repo-search
Browse files Browse the repository at this point in the history
Repo search
  • Loading branch information
jrhoads authored Jan 24, 2022
2 parents bab0c14 + 055a688 commit 69f2b9e
Show file tree
Hide file tree
Showing 14 changed files with 584 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8344,7 +8344,7 @@ type Query {
conferencePaper(id: ID!): ConferencePaper!
conferencePapers(after: String, facetCount: Int = 10, fieldOfScience: String, first: Int = 25, hasAffiliation: Boolean, hasCitations: Int, hasDownloads: Int, hasFunder: Boolean, hasMember: Boolean, hasOrganization: Boolean, hasParts: Int, hasPerson: Boolean, hasVersions: Int, hasViews: Int, ids: [String!], language: String, license: String, memberId: String, published: String, query: String, registrationAgency: String, repositoryId: String, userId: String): ConferencePaperConnectionWithTotal!
dataCatalog(id: ID!): DataCatalog!
dataCatalogs(after: String, first: Int = 25, query: String): DataCatalogConnectionWithTotal!
dataCatalogs(after: String, certified: String, disciplinary: String, first: Int = 25, open: String, pid: String, query: String, software: String, subject: String): DataCatalogConnectionWithTotal!
dataManagementPlan(id: ID!): DataManagementPlan!
dataManagementPlans(after: String, facetCount: Int = 10, fieldOfScience: String, first: Int = 25, hasAffiliation: Boolean, hasCitations: Int, hasDownloads: Int, hasFunder: Boolean, hasMember: Boolean, hasOrganization: Boolean, hasParts: Int, hasPerson: Boolean, hasVersions: Int, hasViews: Int, ids: [String!], language: String, license: String, memberId: String, published: String, query: String, registrationAgency: String, repositoryId: String, userId: String): DataManagementPlanConnectionWithTotal!
dataPaper(id: ID!): DataPaper!
Expand Down Expand Up @@ -8723,6 +8723,11 @@ type Repository {
"""
publications(affiliationId: String, after: String, fieldOfScience: String, first: Int = 25, funderId: String, hasAffiliation: Boolean, hasCitations: Int, hasDownloads: Int, hasFunder: Boolean, hasMember: Boolean, hasOrganization: Boolean, hasParts: Int, hasPerson: Boolean, hasVersions: Int, hasViews: Int, ids: String, language: String, license: String, memberId: String, organizationId: String, published: String, query: String, registrationAgency: String, resourceType: String, userId: String): PublicationConnectionWithTotal

"""
The re3data DataCatalog
"""
re3data: DataCatalog

"""
The re3data identifier for the repository
"""
Expand Down Expand Up @@ -9947,7 +9952,7 @@ type TextRestriction {
"""
Information
"""
text: String!
type: String!
}

"""
Expand Down
18 changes: 17 additions & 1 deletion app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,28 @@ def data_catalog(id:)

field :data_catalogs, DataCatalogConnectionWithTotalType, null: false do
argument :query, String, required: false
argument :subject, String, required: false
argument :open, String, required: false
argument :certified, String, required: false
argument :pid, String, required: false
argument :software, String, required: false
argument :disciplinary, String, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

def data_catalogs(**args)
response = DataCatalog.query(args[:query], limit: args[:first], offset: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil)
response = DataCatalog.query(
args[:query],
subject: args[:subject],
open: args[:open],
certified: args[:certified],
pid: args[:pid],
software: args[:software],
disciplinary: args[:disciplinary],
limit: args[:first],
offset: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil
)
HashConnection.new(response, context: context, first: args[:first], after: args[:after])
end

Expand Down
7 changes: 7 additions & 0 deletions app/graphql/types/repository_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class RepositoryType < BaseObject
field :re3data_id,
ID,
null: true, description: "The re3data identifier for the repository"
field :re3data,
DataCatalogType,
null: true, description: "The re3data DataCatalog"
field :name, String, null: false, description: "Repository name"
field :alternate_name,
String,
Expand Down Expand Up @@ -218,6 +221,10 @@ def type
"Repository"
end

def re3data(**args)
DataCatalog.find_by_id(object.re3data_id).fetch(:data, []).first
end

def datasets(**args)
args[:resource_type_id] = "Dataset"
ElasticsearchModelResponseConnection.new(
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/text_restriction_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
class TextRestrictionType < BaseObject
description "Information"

field :text, String, null: false, description: "Information"
field :type, String, null: false, description: "Information"
field :restriction, [TextType], null: true, description: "Restriction"
end

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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

63 changes: 63 additions & 0 deletions spec/graphql/types/data_catalog_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
it { is_expected.to have_field(:citationCount).of_type("Int") }
it { is_expected.to have_field(:viewCount).of_type("Int") }
it { is_expected.to have_field(:downloadCount).of_type("Int") }
it { is_expected.to have_field(:dataAccesses).of_type("[TextRestriction!]") }
it do
is_expected.to have_field(:datasets).of_type("DatasetConnectionWithTotal")
end
Expand Down Expand Up @@ -160,6 +161,12 @@
providerTypes
pidSystems
inLanguage
dataAccesses {
type
restriction {
text
}
}
}
}
}"
Expand Down Expand Up @@ -211,10 +218,66 @@
"eng"
]
)
expect(data_catalog.fetch("dataAccesses")).to eq(
[
{ "restriction" => nil, "type" => "restricted" },
{ "restriction" => nil, "type" => "open" }
]
)

expect(data_catalog.fetch("softwareApplication")).to eq(
[{ "name" => "DataVerse", "softwareVersion" => nil, "url" => nil }],
)
end
end

describe "more data_catalogs queries", elasticsearch: true, vcr: true do
let(:filtered_query) do
"query($query: String, $subject: String, $open: String, $certified: String, $pid: String, $software: String, $disciplinary: String){
dataCatalogs( query: $query, subject: $subject, open: $open, certified: $certified, pid: $pid, software: $software, disciplinary: $disciplinary){
totalCount
}
}"
end
it "has no filters" do
response = LupoSchema.execute(filtered_query, variables: { query: "" }).as_json
expect(response.dig("data", "dataCatalogs", "totalCount")).to eq(1938)
end

it "filters based on query" do
response = LupoSchema.execute(filtered_query, variables: { query: "Dataverse" }).as_json
expect(response.dig("data", "dataCatalogs", "totalCount")).to eq(112)
end

it "filters based on subject" do
response = LupoSchema.execute(filtered_query, variables: { subject: "23" }).as_json
expect(response.dig("data", "dataCatalogs", "totalCount")).to eq(159)
end

it "filters for FAIRS FAIR" do
response = LupoSchema.execute(
filtered_query,
variables: {
subject: "",
open: "true",
pid: "true",
certified: "true"
}
).as_json
expect(response.dig("data", "dataCatalogs", "totalCount")).to eq(131)
end

it "filters for Enabling FAIR Data Project" do
response = LupoSchema.execute(
filtered_query,
variables: {
subject: "34",
open: "true",
pid: "true",
certified: ""
}
).as_json
expect(response.dig("data", "dataCatalogs", "totalCount")).to eq(255)
end
end
end
81 changes: 81 additions & 0 deletions spec/graphql/types/repository_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
)
end
it { is_expected.to have_field(:works).of_type("WorkConnectionWithTotal") }
it { is_expected.to have_field(:re3data).of_type("DataCatalog") }
end

describe "query repositories", elasticsearch: true do
Expand Down Expand Up @@ -299,4 +300,84 @@
# expect(work.dig("citationCount")).to eq(2)
end
end

describe "query repository with re3data", elasticsearch: true, vcr: true do
let(:provider) { create(:provider, symbol: "TESTX") }
let!(:client) do
create(:client, symbol: "TESTX.TESTR3", software: "Dataverse", re3data_id: "10.17616/r3bw5r", provider: provider)
end
before do
Provider.import
Client.import
sleep 2
end

let(:query) do
"query {
repository(id: \"testx.testr3\") {
id
name
alternateName
re3data {
id
name
contacts
description
}
}
}"
end

it "returns repository with re3data" do
response = LupoSchema.execute(query).as_json
re3data = response.dig("data", "repository", "re3data")
expect(re3data.fetch("id")).to eq("10.17616/r3bw5r")
expect(re3data.fetch("name")).to eq(
"UCLA Social Science Data Archive Dataverse",
)
expect(re3data.fetch("description")).to start_with(
"The Social Science Data Archive is still active and maintained as part of the UCLA Library",
)
expect(re3data.fetch("contacts")).to eq(
[
"[email protected]",
"[email protected]"
],
)
end
end

describe "query repository without re3data", elasticsearch: true, vcr: true do
let(:provider) { create(:provider, symbol: "TESTY") }
let!(:client) do
create(:client, symbol: "TESTY.TESTR4", software: "Dataverse", provider: provider)
end
before do
Provider.import
Client.import
sleep 2
end

let(:query) do
"query {
repository(id: \"testy.testr4\") {
id
name
alternateName
re3data {
id
name
contacts
description
}
}
}"
end

it "returns repository with re3data as nil" do
response = LupoSchema.execute(query).as_json
re3data = response.dig("data", "repository", "re3data")
expect(re3data).to be_nil
end
end
end

0 comments on commit 69f2b9e

Please sign in to comment.