-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use find_by_source_identifier instead of find_by_bulkrax_identifier (#…
…907) * i903 - move bulkrax identifier custom queries into bulkrax move bulkrax identifier custom queries into bulkrax Issue: - scientist-softserv/hykuup_knapsack#136 * 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: - scientist-softserv/hykuup_knapsack#128 Co-Authored-By: Kirk Wang <k3wang@gmail.com> * remove files: they live in Hyku for now Co-Authored-By: Kirk Wang <k3wang@gmail.com> * 🧹 Place custom queries back in Bulkrax * 🧹 remove misleading comment Co-Authored-By: Kirk Wang <k3wang@gmail.com> * 🧹 Entry is a required argument when initializing ObjectFactory Fix for broken specs Co-Authored-By: Kirk Wang <k3wang@gmail.com> * revert changes to pass Entry arg The object factory already has work_identifier: parser.work_identifier. we don't need the entry argument after all. ref: - https://github.com/samvera/bulkrax/blob/main/app/models/concerns/bulkrax/import_behavior.rb#L181 Co-Authored-By: Kirk Wang <k3wang@gmail.com> --------- Co-authored-by: Kirk Wang <k3wang@gmail.com> Co-authored-by: Kirk Wang <kirk.wang@scientist.com>
- Loading branch information
1 parent
756768d
commit afcfc3d
Showing
4 changed files
with
69 additions
and
3 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
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 |
28 changes: 28 additions & 0 deletions
28
app/services/wings/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,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Wings | ||
module CustomQueries | ||
class FindBySourceIdentifier | ||
# Custom query override specific to Wings | ||
|
||
def self.queries | ||
[:find_by_source_identifier] | ||
end | ||
|
||
attr_reader :query_service | ||
delegate :resource_factory, to: :query_service | ||
|
||
def initialize(query_service:) | ||
@query_service = query_service | ||
end | ||
|
||
def find_by_source_identifier(identifier:, use_valkyrie: true) | ||
af_object = ActiveFedora::Base.where("bulkrax_identifier_sim:#{identifier}").first | ||
|
||
return af_object unless use_valkyrie | ||
|
||
resource_factory.to_resource(object: af_object) | ||
end | ||
end | ||
end | ||
end |