-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make find_by_source_identifier dynamic
Import a csv with child works. The forming of relationships is not working. Part of the problem is the find_by_bulkrax_identifier call. From GBH, this used to be find_by_bulkrax_identifier which not all clients will configure as their source identifier. Instead we need to ask for the source identifier and use that for the sql query. This commit goes along with a PR from Hyku which currently has the find_by_source_identifier.rb files defined. Issue: - notch8/hykuup_knapsack#128 Co-Authored-By: Kirk Wang <[email protected]>
- Loading branch information
Showing
8 changed files
with
75 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
app/services/hyrax/custom_queries/find_by_source_identifier.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
module CustomQueries | ||
## | ||
# @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries | ||
class FindBySourceIdentifier | ||
def self.queries | ||
[:find_by_source_identifier] | ||
end | ||
|
||
def initialize(query_service:) | ||
@query_service = query_service | ||
end | ||
|
||
attr_reader :query_service | ||
delegate :resource_factory, to: :query_service | ||
delegate :orm_class, to: :resource_factory | ||
|
||
## | ||
# @param identifier String | ||
def find_by_source_identifier(work_identifier:, source_identifier_value:) | ||
sql_query = sql_by_source_identifier | ||
query_service.run_query(sql_query, work_identifier, source_identifier_value).first | ||
end | ||
|
||
def sql_by_source_identifier | ||
<<-SQL | ||
SELECT * FROM orm_resources | ||
WHERE metadata -> ? ->> 0 = ?; | ||
SQL | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::CustomQueries::FindBySourceIdentifier do | ||
describe '.queries' do | ||
subject { described_class.queries } | ||
let(:query_name) { :find_by_source_identifier } | ||
|
||
it { is_expected.to include(query_name) } | ||
|
||
it 'is registered with the Hyrax.query_service' do | ||
expect(Hyrax.query_service.custom_queries).to respond_to(query_name) | ||
end | ||
|
||
context ':find_by_source_identifier query' do | ||
it 'is valid SQL' do | ||
expect do | ||
Hyrax.query_service.custom_queries.find_by_source_identifier(work_identifier: 'source', source_identifier_value: "testing-bulkrax-1-2-3") | ||
end.not_to raise_error | ||
end | ||
end | ||
end | ||
end |