-
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.
i903 - move bulkrax identifier custom queries into bulkrax
move bulkrax identifier custom queries into bulkrax Issue: - notch8/hykuup_knapsack#136
- Loading branch information
Shana Moore
committed
Jan 29, 2024
1 parent
91583af
commit 6075930
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
app/services/bulkrax/valkyrie/find_by_bulkrax_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 Bulkrax | ||
module Valkyrie | ||
module CustomQueries | ||
## | ||
# @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries | ||
class FindByBulkraxIdentifier | ||
def self.queries | ||
[:find_by_bulkrax_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_bulkrax_identifier(identifier:) | ||
query_service.run_query(sql_by_bulkrax_identifier, identifier).first | ||
end | ||
|
||
def sql_by_bulkrax_identifier | ||
<<-SQL | ||
SELECT * FROM orm_resources | ||
WHERE metadata -> 'bulkrax_identifier' ->> 0 = ?; | ||
SQL | ||
end | ||
end | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
app/services/wings/custom_queries/find_by_bulkrax_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,29 @@ | ||
# frozen_string_literal: true | ||
module Wings | ||
module CustomQueries | ||
class FindByBulkraxIdentifier | ||
# Custom query override specific to Wings | ||
# Use: | ||
# Hyrax.custom_queries.find_bulkrax_id(identifier: identifier, models: [ModelClass]) | ||
|
||
def self.queries | ||
[:find_by_bulkrax_identifier] | ||
end | ||
|
||
attr_reader :query_service | ||
delegate :resource_factory, to: :query_service | ||
|
||
def initialize(query_service:) | ||
@query_service = query_service | ||
end | ||
|
||
def find_by_bulkrax_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 |