Skip to content
Open
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
50 changes: 48 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,8 @@ def as_indexed_json(_options = {})
"created" => created.try(:iso8601),
"updated" => updated.try(:iso8601),
"published" => published.try(:iso8601),
"client" => client.try(:as_indexed_json, exclude_associations: true),
"provider" => provider.try(:as_indexed_json, exclude_associations: true),
"client" => doi_client_indexed_json,
"provider" => doi_provider_indexed_json,
"resource_type" => resource_type.try(:as_indexed_json),
"media" => media.map { |m| m.try(:as_indexed_json) },
"reference_ids" => reference_ids,
Expand All @@ -839,6 +839,52 @@ def extra_indexed_fields
{}
end

def doi_client_indexed_json
return nil if client.blank?

{
"id" => client.uid,
"uid" => client.uid,
"re3data_id" => client.re3data_id,
"opendoar_id" => client.opendoar_id,
"name" => client.name,
"alternate_name" => client.alternate_name,
"description" => client.description,
"language" => client.language,
"client_type" => client.client_type,
"certificate" => Array.wrap(client.certificate),
"is_active" => client.is_active,
"symbol" => client.symbol,
"year" => client.year,
"domains" => client.domains,
"url" => client.url,
"created" => client.created.try(:iso8601),
"updated" => client.updated.try(:iso8601),
}
end

def doi_provider_indexed_json
return nil if provider.blank?

{
"id" => provider.uid,
"uid" => provider.uid,
"name" => provider.name,
"display_name" => provider.display_name,
"description" => provider.description,
"website" => provider.website,
"logo_url" => provider.logo_url,
"region" => provider.region,
"country_code" => provider.country_code,
"member_type" => provider.member_type,
"organization_type" => provider.organization_type,
"focus_area" => provider.focus_area,
"is_active" => provider.is_active,
"joined" => provider.joined.try(:iso8601),
"ror_id" => provider.ror_id,
}
end

def has_enrichments
return @has_enrichments if defined?(@has_enrichments)

Expand Down
37 changes: 37 additions & 0 deletions spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,43 @@
end
end

describe "as_indexed_json" do
it "uses slim client and provider snapshots" do
provider = create(:provider, ror_id: "https://ror.org/01abcde23")
client = create(
:client,
provider: provider,
re3data_id: "10.17616/R3XS37",
opendoar_id: 1234,
certificate: ["CoreTrustSeal"],
client_type: "repository",
)
doi = create(:doi, client: client)

client_json = doi.as_indexed_json["client"]
provider_json = doi.as_indexed_json["provider"]

expect(client_json).to include(
"uid" => client.uid,
"re3data_id" => "10.17616/R3XS37",
"opendoar_id" => 1234,
"certificate" => ["CoreTrustSeal"],
"client_type" => "repository",
"is_active" => client.is_active,
)
expect(client_json).not_to include("password", "salesforce_id", "globus_uuid", "system_email", "service_contact", "provider", "provider_id", "provider_id_and_name", "consortium_id", "repository_type", "software", "cache_key", "subjects")

expect(provider_json).to include(
"uid" => provider.uid,
"ror_id" => "https://ror.org/01abcde23",
"name" => provider.name,
"display_name" => provider.display_name,
"is_active" => provider.is_active,
)
expect(provider_json).not_to include("password", "billing_information", "technical_contact", "service_contact", "consortium")
end
end

describe "update publisher" do
let(:doi) { create(:doi) }

Expand Down
Loading