valkyrie 1.7.1 → 2.0.0.RC1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +6 -86
- data/.gitignore +0 -1
- data/.rubocop.yml +0 -5
- data/CHANGELOG.md +1 -160
- data/README.md +62 -84
- data/Rakefile +2 -8
- data/lib/valkyrie.rb +4 -39
- data/lib/valkyrie/id.rb +0 -8
- data/lib/valkyrie/persistence/fedora.rb +3 -7
- data/lib/valkyrie/persistence/fedora/list_node.rb +11 -28
- data/lib/valkyrie/persistence/fedora/metadata_adapter.rb +1 -8
- data/lib/valkyrie/persistence/fedora/permissive_schema.rb +0 -16
- data/lib/valkyrie/persistence/fedora/query_service.rb +6 -8
- data/lib/valkyrie/persistence/memory/metadata_adapter.rb +0 -5
- data/lib/valkyrie/persistence/memory/persister.rb +1 -1
- data/lib/valkyrie/persistence/memory/query_service.rb +6 -11
- data/lib/valkyrie/persistence/postgres.rb +1 -14
- data/lib/valkyrie/persistence/postgres/metadata_adapter.rb +0 -5
- data/lib/valkyrie/persistence/postgres/orm_converter.rb +1 -1
- data/lib/valkyrie/persistence/postgres/persister.rb +1 -9
- data/lib/valkyrie/persistence/postgres/query_service.rb +4 -6
- data/lib/valkyrie/persistence/solr.rb +0 -7
- data/lib/valkyrie/persistence/solr/metadata_adapter.rb +0 -5
- data/lib/valkyrie/persistence/solr/model_converter.rb +2 -11
- data/lib/valkyrie/persistence/solr/orm_converter.rb +2 -2
- data/lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb +4 -4
- data/lib/valkyrie/persistence/solr/queries/find_members_query.rb +4 -11
- data/lib/valkyrie/persistence/solr/query_service.rb +4 -7
- data/lib/valkyrie/resource.rb +21 -62
- data/lib/valkyrie/specs/shared_specs.rb +0 -5
- data/lib/valkyrie/specs/shared_specs/change_set_persister.rb +9 -9
- data/lib/valkyrie/specs/shared_specs/persister.rb +1 -3
- data/lib/valkyrie/specs/shared_specs/queries.rb +17 -45
- data/lib/valkyrie/specs/shared_specs/resource.rb +6 -11
- data/lib/valkyrie/specs/shared_specs/solr_indexer.rb +3 -3
- data/lib/valkyrie/specs/shared_specs/storage_adapter.rb +4 -17
- data/lib/valkyrie/storage/disk.rb +1 -2
- data/lib/valkyrie/storage/fedora.rb +16 -29
- data/lib/valkyrie/storage/memory.rb +1 -2
- data/lib/valkyrie/types.rb +6 -24
- data/lib/valkyrie/version.rb +1 -1
- data/solr/config/schema.xml +1 -0
- data/tasks/dev.rake +0 -3
- data/tasks/docker.rake +2 -2
- data/valkyrie.gemspec +6 -7
- metadata +49 -62
- data/.tool-versions +0 -1
- data/Appraisals +0 -8
- data/CODE_OF_CONDUCT.md +0 -36
- data/CONTRIBUTING.md +0 -161
- data/SUPPORT.md +0 -5
- data/gemfiles/activerecord_5_1.gemfile +0 -7
- data/gemfiles/activerecord_5_2.gemfile +0 -7
data/Rakefile
CHANGED
@@ -57,14 +57,8 @@ namespace :db do
|
|
57
57
|
scope = ENV['SCOPE']
|
58
58
|
verbose_was = ActiveRecord::Migration.verbose
|
59
59
|
ActiveRecord::Migration.verbose = verbose
|
60
|
-
|
61
|
-
|
62
|
-
scope.blank? || scope == migration.scope
|
63
|
-
end
|
64
|
-
else
|
65
|
-
ActiveRecord::Base.connection.migration_context.migrate(version) do |migration|
|
66
|
-
scope.blank? || scope == migration.scope
|
67
|
-
end
|
60
|
+
ActiveRecord::Migrator.migrate(MIGRATIONS_DIR, version) do |migration|
|
61
|
+
scope.blank? || scope == migration.scope
|
68
62
|
end
|
69
63
|
ActiveRecord::Base.clear_cache!
|
70
64
|
ensure
|
data/lib/valkyrie.rb
CHANGED
@@ -14,6 +14,7 @@ require 'valkyrie/rdf_patches'
|
|
14
14
|
require 'json/ld'
|
15
15
|
require 'logger'
|
16
16
|
require 'rdf/vocab'
|
17
|
+
require 'rails'
|
17
18
|
|
18
19
|
module Valkyrie
|
19
20
|
require 'valkyrie/id'
|
@@ -48,15 +49,11 @@ module Valkyrie
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def environment
|
51
|
-
|
52
|
-
Rails.env
|
53
|
-
else
|
54
|
-
ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
55
|
-
end
|
52
|
+
Rails.env
|
56
53
|
end
|
57
54
|
|
58
55
|
def config_root_path
|
59
|
-
if const_defined?(:Rails) && Rails.
|
56
|
+
if const_defined?(:Rails) && Rails.root
|
60
57
|
Rails.root
|
61
58
|
else
|
62
59
|
Pathname.new(Dir.pwd)
|
@@ -71,11 +68,6 @@ module Valkyrie
|
|
71
68
|
@logger = logger
|
72
69
|
end
|
73
70
|
|
74
|
-
def warn_about_standard_queries!
|
75
|
-
warn "[DEPRECATION] Please enable query normalization to avoid inconsistent results between different adapters by adding `standardize_query_results: true` to your environment block" \
|
76
|
-
" in config\/valkyrie.yml. This will be the behavior in Valkyrie 2.0."
|
77
|
-
end
|
78
|
-
|
79
71
|
class Config < OpenStruct
|
80
72
|
def initialize(hsh = {})
|
81
73
|
super(defaults.merge(hsh))
|
@@ -89,40 +81,13 @@ module Valkyrie
|
|
89
81
|
Valkyrie::StorageAdapter.find(super.to_sym)
|
90
82
|
end
|
91
83
|
|
92
|
-
# @api public
|
93
|
-
#
|
94
|
-
# The returned anonymous method (e.g. responds to #call) has a signature of
|
95
|
-
# an unamed parameter that is a string. Calling the anonymous method should
|
96
|
-
# return a Valkyrie::Resource from which Valkyrie will map the persisted
|
97
|
-
# data into.
|
98
|
-
#
|
99
|
-
# @return [#call] with method signature of 1
|
100
|
-
#
|
101
|
-
# @see #default_resource_class_resolver for full interface
|
102
|
-
def resource_class_resolver
|
103
|
-
super
|
104
|
-
end
|
105
|
-
|
106
|
-
# @!attribute [w] resource_class_resolver=
|
107
|
-
# The setter for #resource_class_resolver; see it's implementation
|
108
|
-
|
109
84
|
private
|
110
85
|
|
111
86
|
def defaults
|
112
87
|
{
|
113
|
-
standardize_query_result: false,
|
114
|
-
resource_class_resolver: method(:default_resource_class_resolver)
|
115
88
|
}
|
116
89
|
end
|
117
|
-
|
118
|
-
# String constantize is a "by convention" factory. This works, but assumes
|
119
|
-
# the ruby class once used to persist is the model used to now reify.
|
120
|
-
#
|
121
|
-
# @param [String] class_name
|
122
|
-
def default_resource_class_resolver(class_name)
|
123
|
-
class_name.constantize
|
124
|
-
end
|
125
90
|
end
|
126
91
|
|
127
|
-
module_function :config, :logger, :logger=, :config_root_path, :environment, :
|
92
|
+
module_function :config, :logger, :logger=, :config_root_path, :environment, :config_file, :config_hash
|
128
93
|
end
|
data/lib/valkyrie/id.rb
CHANGED
@@ -21,14 +21,6 @@ module Valkyrie
|
|
21
21
|
end
|
22
22
|
alias == eql?
|
23
23
|
|
24
|
-
# @deprecated Please use {.uri_for} instead
|
25
|
-
def to_uri
|
26
|
-
return RDF::Literal.new(id.to_s, datatype: RDF::URI("http://example.com/valkyrie_id")) if id.to_s.include?("://")
|
27
|
-
warn "[DEPRECATION] `to_uri` is deprecated and will be removed in the next major release. " \
|
28
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
29
|
-
::RDF::URI(ActiveFedora::Base.id_to_uri(id))
|
30
|
-
end
|
31
|
-
|
32
24
|
protected
|
33
25
|
|
34
26
|
def state
|
@@ -1,14 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
#
|
2
3
|
module Valkyrie::Persistence
|
3
4
|
# Implements the DataMapper Pattern to store metadata into Fedora
|
4
5
|
module Fedora
|
5
|
-
|
6
|
-
|
7
|
-
matches = File.readlines(path).select { |l| l =~ /gem ['"]ldp\b/ }
|
8
|
-
if matches.empty?
|
9
|
-
warn "[DEPRECATION] ldp will not be included as a dependency in Valkyrie's gemspec as of the next major release. Please add the gem directly to your Gemfile if you use a fedora adapter."
|
10
|
-
end
|
11
|
-
require 'active_fedora'
|
6
|
+
require 'active_triples'
|
7
|
+
require 'ldp'
|
12
8
|
require 'valkyrie/persistence/fedora/permissive_schema'
|
13
9
|
require 'valkyrie/persistence/fedora/metadata_adapter'
|
14
10
|
require 'valkyrie/persistence/fedora/persister'
|
@@ -63,7 +63,7 @@ module Valkyrie::Persistence::Fedora
|
|
63
63
|
g.proxy_in = proxy_in.try(:uri)
|
64
64
|
g.next = self.next.try(:rdf_subject)
|
65
65
|
g.prev = prev.try(:rdf_subject)
|
66
|
-
g
|
66
|
+
g
|
67
67
|
end
|
68
68
|
|
69
69
|
# Resolves the URI for the value of the list expression
|
@@ -104,10 +104,10 @@ module Valkyrie::Persistence::Fedora
|
|
104
104
|
# Populates attributes for the LinkedNode
|
105
105
|
# @param instance [ListNode]
|
106
106
|
def populate(instance)
|
107
|
-
instance.proxy_for = resource.proxy_for
|
108
|
-
instance.proxy_in = resource.proxy_in
|
109
|
-
instance.next_uri = resource.next
|
110
|
-
instance.prev_uri = resource.prev
|
107
|
+
instance.proxy_for = resource.proxy_for.first
|
108
|
+
instance.proxy_in = resource.proxy_in.first
|
109
|
+
instance.next_uri = resource.next.first
|
110
|
+
instance.prev_uri = resource.prev.first
|
111
111
|
end
|
112
112
|
|
113
113
|
private
|
@@ -115,33 +115,16 @@ module Valkyrie::Persistence::Fedora
|
|
115
115
|
# Constructs a set of triples using ActiveTriples as objects
|
116
116
|
# @return [Valkyrie::Persistence::Fedora::ListNode::Resource]
|
117
117
|
def resource
|
118
|
-
@resource ||= Resource.new(uri,
|
118
|
+
@resource ||= Resource.new(uri, data: graph)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
# Class for providing a set of triples modeling linked list nodes
|
123
|
-
class Resource
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
define_method "#{property}=" do |val|
|
130
|
-
return if val.nil?
|
131
|
-
graph << [uri, predicate, val]
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
property :proxy_for, predicate: ::RDF::Vocab::ORE.proxyFor
|
136
|
-
property :proxy_in, predicate: ::RDF::Vocab::ORE.proxyIn
|
137
|
-
property :next, predicate: ::RDF::Vocab::IANA.next
|
138
|
-
property :prev, predicate: ::RDF::Vocab::IANA.prev
|
139
|
-
|
140
|
-
attr_reader :graph, :uri
|
141
|
-
def initialize(uri, graph: RDF::Graph.new)
|
142
|
-
@uri = uri
|
143
|
-
@graph = graph
|
144
|
-
end
|
123
|
+
class Resource < ActiveTriples::Resource
|
124
|
+
property :proxy_for, predicate: ::RDF::Vocab::ORE.proxyFor, cast: false
|
125
|
+
property :proxy_in, predicate: ::RDF::Vocab::ORE.proxyIn, cast: false
|
126
|
+
property :next, predicate: ::RDF::Vocab::IANA.next, cast: false
|
127
|
+
property :prev, predicate: ::RDF::Vocab::IANA.prev, cast: false
|
145
128
|
end
|
146
129
|
end
|
147
130
|
end
|
@@ -15,13 +15,11 @@ module Valkyrie::Persistence::Fedora
|
|
15
15
|
# @param [String] base_path
|
16
16
|
# @param [Valkyrie::Persistence::Fedora::PermissiveSchema] schema
|
17
17
|
# @param [Integer] fedora_version
|
18
|
-
def initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new, fedora_version:
|
18
|
+
def initialize(connection:, base_path: "/", schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new, fedora_version: 5)
|
19
19
|
@connection = connection
|
20
20
|
@base_path = base_path
|
21
21
|
@schema = schema
|
22
22
|
@fedora_version = fedora_version
|
23
|
-
|
24
|
-
warn "[DEPRECATION] `fedora_version` will default to 5 in the next major release." unless fedora_version
|
25
23
|
end
|
26
24
|
|
27
25
|
# Construct the query service object using this adapter
|
@@ -78,10 +76,5 @@ module Valkyrie::Persistence::Fedora
|
|
78
76
|
def connection_prefix
|
79
77
|
"#{connection.http.url_prefix}/#{base_path}"
|
80
78
|
end
|
81
|
-
|
82
|
-
def standardize_query_result?
|
83
|
-
Valkyrie.warn_about_standard_queries! if Valkyrie.config.standardize_query_result != true
|
84
|
-
Valkyrie.config.standardize_query_result == true
|
85
|
-
end
|
86
79
|
end
|
87
80
|
end
|
@@ -22,27 +22,11 @@ module Valkyrie::Persistence::Fedora
|
|
22
22
|
uri_for(:id)
|
23
23
|
end
|
24
24
|
|
25
|
-
# @deprecated Please use {.uri_for} instead
|
26
|
-
def self.alternate_ids
|
27
|
-
warn "[DEPRECATION] `alternate_ids` is deprecated and will be removed in the next major release. " \
|
28
|
-
"It was never used internally - please use `uri_for(:alternate_ids)` " \
|
29
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
30
|
-
uri_for(:alternate_ids)
|
31
|
-
end
|
32
|
-
|
33
25
|
# @return [RDF::URI]
|
34
26
|
def self.member_ids
|
35
27
|
uri_for(:member_ids)
|
36
28
|
end
|
37
29
|
|
38
|
-
# @deprecated Please use {.uri_for} instead
|
39
|
-
def self.references
|
40
|
-
warn "[DEPRECATION] `references` is deprecated and will be removed in the next major release. " \
|
41
|
-
"It was never used internally - please use `uri_for(:references)` " \
|
42
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
43
|
-
uri_for(:references)
|
44
|
-
end
|
45
|
-
|
46
30
|
# @return [RDF::URI]
|
47
31
|
def self.valkyrie_bool
|
48
32
|
uri_for(:valkyrie_bool)
|
@@ -29,7 +29,7 @@ module Valkyrie::Persistence::Fedora
|
|
29
29
|
|
30
30
|
# (see Valkyrie::Persistence::Memory::QueryService#find_many_by_ids)
|
31
31
|
def find_many_by_ids(ids:)
|
32
|
-
ids = ids.uniq
|
32
|
+
ids = ids.uniq
|
33
33
|
ids.map do |id|
|
34
34
|
begin
|
35
35
|
find_by(id: id)
|
@@ -43,7 +43,7 @@ module Valkyrie::Persistence::Fedora
|
|
43
43
|
def find_parents(resource:)
|
44
44
|
content = content_with_inbound(id: resource.id)
|
45
45
|
parent_ids = content.graph.query([nil, RDF::Vocab::ORE.proxyFor, nil]).map(&:subject).map { |x| x.to_s.gsub(/#.*/, '') }.map { |x| adapter.uri_to_id(x) }
|
46
|
-
parent_ids.uniq!
|
46
|
+
parent_ids.uniq!
|
47
47
|
parent_ids.lazy.map do |id|
|
48
48
|
find_by(id: id)
|
49
49
|
end
|
@@ -111,10 +111,8 @@ module Valkyrie::Persistence::Fedora
|
|
111
111
|
# Find all resources referencing a given resource (e. g. parents)
|
112
112
|
# *This is done by iterating through the ID of each resource referencing the resource in the query, and requesting each resource over the HTTP*
|
113
113
|
# *Also, an initial request is made to find the URIs of the resources referencing the resource in the query*
|
114
|
-
def find_inverse_references_by(resource
|
115
|
-
|
116
|
-
ensure_persisted(resource) if resource
|
117
|
-
resource ||= find_by(id: id)
|
114
|
+
def find_inverse_references_by(resource:, property:)
|
115
|
+
ensure_persisted(resource)
|
118
116
|
if ordered_property?(resource: resource, property: property)
|
119
117
|
find_inverse_references_by_ordered(resource: resource, property: property)
|
120
118
|
else
|
@@ -133,14 +131,14 @@ module Valkyrie::Persistence::Fedora
|
|
133
131
|
content = content_with_inbound(id: resource.id)
|
134
132
|
property_uri = adapter.schema.predicate_for(property: property, resource: nil)
|
135
133
|
ids = content.graph.query([nil, property_uri, adapter.id_to_uri(resource.id)]).map(&:subject).map { |x| x.to_s.gsub(/#.*/, '') }.map { |x| adapter.uri_to_id(x) }
|
136
|
-
ids.uniq!
|
134
|
+
ids.uniq!
|
137
135
|
ids.lazy.map { |id| find_by(id: id) }
|
138
136
|
end
|
139
137
|
|
140
138
|
def find_inverse_references_by_ordered(resource:, property:)
|
141
139
|
content = content_with_inbound(id: resource.id)
|
142
140
|
ids = content.graph.query([nil, ::RDF::Vocab::ORE.proxyFor, adapter.id_to_uri(resource.id)]).map(&:subject).map { |x| x.to_s.gsub(/#.*/, '') }.map { |x| adapter.uri_to_id(x) }
|
143
|
-
ids.uniq!
|
141
|
+
ids.uniq!
|
144
142
|
ids.lazy.map { |id| find_by(id: id) }.select { |o| o[property].include?(resource.id) }
|
145
143
|
end
|
146
144
|
|
@@ -29,10 +29,5 @@ module Valkyrie::Persistence::Memory
|
|
29
29
|
def id
|
30
30
|
@id ||= Valkyrie::ID.new(Digest::MD5.hexdigest(self.class.to_s))
|
31
31
|
end
|
32
|
-
|
33
|
-
def standardize_query_result?
|
34
|
-
Valkyrie.warn_about_standard_queries! if Valkyrie.config.standardize_query_result != true
|
35
|
-
Valkyrie.config.standardize_query_result == true
|
36
|
-
end
|
37
32
|
end
|
38
33
|
end
|
@@ -86,7 +86,7 @@ module Valkyrie::Persistence::Memory
|
|
86
86
|
def generate_lock_token(resource)
|
87
87
|
return unless resource.optimistic_locking_enabled?
|
88
88
|
token = Valkyrie::Persistence::OptimisticLockToken.new(adapter_id: adapter.id, token: Time.now.to_r)
|
89
|
-
resource.
|
89
|
+
resource.set_value(Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK, token)
|
90
90
|
end
|
91
91
|
|
92
92
|
# Check whether a resource is current.
|
@@ -36,10 +36,7 @@ module Valkyrie::Persistence::Memory
|
|
36
36
|
def find_by_alternate_identifier(alternate_identifier:)
|
37
37
|
alternate_identifier = Valkyrie::ID.new(alternate_identifier.to_s) if alternate_identifier.is_a?(String)
|
38
38
|
validate_id(alternate_identifier)
|
39
|
-
cache.select
|
40
|
-
next unless resource[:alternate_ids]
|
41
|
-
resource[:alternate_ids].include?(alternate_identifier)
|
42
|
-
end.values.first || raise(::Valkyrie::Persistence::ObjectNotFoundError)
|
39
|
+
cache.select { |_key, resource| resource[:alternate_ids].include?(alternate_identifier) }.values.first || raise(::Valkyrie::Persistence::ObjectNotFoundError)
|
43
40
|
end
|
44
41
|
|
45
42
|
# Get a batch of resources by ID.
|
@@ -47,7 +44,7 @@ module Valkyrie::Persistence::Memory
|
|
47
44
|
# @raise [ArgumentError] Raised when any ID is not a String or a Valkyrie::ID
|
48
45
|
# @return [Array<Valkyrie::Resource>] All requested objects that were found
|
49
46
|
def find_many_by_ids(ids:)
|
50
|
-
ids = ids.uniq
|
47
|
+
ids = ids.uniq
|
51
48
|
ids.map do |id|
|
52
49
|
begin
|
53
50
|
find_by(id: id)
|
@@ -100,7 +97,7 @@ module Valkyrie::Persistence::Memory
|
|
100
97
|
nil
|
101
98
|
end
|
102
99
|
end.reject(&:nil?)
|
103
|
-
refs.uniq!
|
100
|
+
refs.uniq! unless ordered_property?(resource: resource, property: property)
|
104
101
|
refs
|
105
102
|
end
|
106
103
|
|
@@ -113,12 +110,10 @@ module Valkyrie::Persistence::Memory
|
|
113
110
|
# @return [Array<Valkyrie::Resource>] All resources in the persistence backend
|
114
111
|
# which have the ID of the given `resource` in their `property` property. Not
|
115
112
|
# in order.
|
116
|
-
def find_inverse_references_by(resource
|
117
|
-
|
118
|
-
ensure_persisted(resource) if resource
|
119
|
-
id ||= resource.id
|
113
|
+
def find_inverse_references_by(resource:, property:)
|
114
|
+
ensure_persisted(resource)
|
120
115
|
find_all.select do |obj|
|
121
|
-
Array.wrap(obj[property]).include?(id)
|
116
|
+
Array.wrap(obj[property]).include?(resource.id)
|
122
117
|
end
|
123
118
|
end
|
124
119
|
|
@@ -1,21 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
#
|
2
3
|
module Valkyrie::Persistence
|
3
4
|
# Implements the DataMapper Pattern to store metadata into Postgres
|
4
5
|
module Postgres
|
5
|
-
# :nocov:
|
6
|
-
# Deprecation to allow us to make pg an optional dependency
|
7
|
-
path = Bundler.definition.gemfiles.first
|
8
|
-
matches = File.readlines(path).select { |l| l =~ /gem ['"]pg\b/ }
|
9
|
-
if matches.empty?
|
10
|
-
warn "[DEPRECATION] pg will not be included as a dependency in Valkyrie's gemspec as of the next major release. Please add the gem directly to your Gemfile if you use a postgres adapter."
|
11
|
-
end
|
12
|
-
matches = File.readlines(path).select { |l| l =~ /gem ['"]activerecord\b/ }
|
13
|
-
if matches.empty?
|
14
|
-
warn "[DEPRECATION] activerecord will not be included as a dependency in Valkyrie's gemspec as of the next major release." \
|
15
|
-
"Please add the gem directly to your Gemfile if you use a postgres adapter."
|
16
|
-
end
|
17
|
-
# :nocov:
|
18
|
-
|
19
6
|
require 'valkyrie/persistence/postgres/metadata_adapter'
|
20
7
|
end
|
21
8
|
end
|
@@ -35,10 +35,5 @@ module Valkyrie::Persistence::Postgres
|
|
35
35
|
Valkyrie::ID.new(Digest::MD5.hexdigest(to_hash))
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
39
|
-
def standardize_query_result?
|
40
|
-
Valkyrie.warn_about_standard_queries! if Valkyrie.config.standardize_query_result != true
|
41
|
-
Valkyrie.config.standardize_query_result == true
|
42
|
-
end
|
43
38
|
end
|
44
39
|
end
|
@@ -56,7 +56,7 @@ module Valkyrie::Persistence::Postgres
|
|
56
56
|
# Retrieve the Class used to construct the Valkyrie Resource
|
57
57
|
# @return [Class]
|
58
58
|
def resource_klass
|
59
|
-
|
59
|
+
internal_resource.constantize
|
60
60
|
end
|
61
61
|
|
62
62
|
# Access the String for the Valkyrie Resource type within the attributes
|
@@ -19,15 +19,7 @@ module Valkyrie::Persistence::Postgres
|
|
19
19
|
# was modified in the database between been read into memory and persisted
|
20
20
|
def save(resource:)
|
21
21
|
orm_object = resource_factory.from_resource(resource: resource)
|
22
|
-
orm_object.
|
23
|
-
orm_object.save!
|
24
|
-
if resource.id && resource.id.to_s != orm_object.id
|
25
|
-
warn "[DEPRECATION] Postgres' primary key column can not save with the given ID #{resource.id}. " \
|
26
|
-
"For now a new ID has been assigned (#{orm_object.id}), but in the next major version this will throw an exception and not save. " \
|
27
|
-
"To avoid this warning, set the ID to be nil via `resource.id = nil` before you save it. \n" \
|
28
|
-
"Called from #{Gem.location_of_caller.join(':')}"
|
29
|
-
end
|
30
|
-
end
|
22
|
+
orm_object.save!
|
31
23
|
resource_factory.to_resource(object: orm_object)
|
32
24
|
rescue ActiveRecord::StaleObjectError
|
33
25
|
raise Valkyrie::Persistence::StaleObjectError, "The object #{resource.id} has been updated by another process."
|
@@ -112,11 +112,9 @@ module Valkyrie::Persistence::Postgres
|
|
112
112
|
# @param [Valkyrie::Resource] resource
|
113
113
|
# @param [String] property
|
114
114
|
# @return [Array<Valkyrie::Resource>]
|
115
|
-
def find_inverse_references_by(resource
|
116
|
-
|
117
|
-
|
118
|
-
id ||= resource.id
|
119
|
-
internal_array = "{\"#{property}\": [{\"id\": \"#{id}\"}]}"
|
115
|
+
def find_inverse_references_by(resource:, property:)
|
116
|
+
ensure_persisted(resource)
|
117
|
+
internal_array = "{\"#{property}\": [{\"id\": \"#{resource.id}\"}]}"
|
120
118
|
run_query(find_inverse_references_query, internal_array)
|
121
119
|
end
|
122
120
|
|
@@ -191,7 +189,7 @@ module Valkyrie::Persistence::Postgres
|
|
191
189
|
# @return [String]
|
192
190
|
def find_references_query
|
193
191
|
<<-SQL
|
194
|
-
SELECT
|
192
|
+
SELECT DISTINCT member.* FROM orm_resources a,
|
195
193
|
jsonb_array_elements(a.metadata->?) AS b(member)
|
196
194
|
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
|
197
195
|
SQL
|