valkyrie 0.1.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.ctags +2 -0
  3. data/.rubocop.yml +5 -0
  4. data/.rubocop_todo.yml +3 -0
  5. data/CHANGELOG.md +43 -0
  6. data/Gemfile +0 -4
  7. data/LICENSE +15 -0
  8. data/README.md +13 -8
  9. data/Rakefile +15 -1
  10. data/bin/jetty_wait +14 -0
  11. data/bin/rspec +29 -0
  12. data/browserslist +3 -0
  13. data/circle.yml +17 -0
  14. data/config/fedora.yml +10 -0
  15. data/db/migrate/20161007101725_create_orm_resources.rb +9 -1
  16. data/db/migrate/20171011224121_create_path_gin_index.rb +6 -0
  17. data/db/migrate/20171204224121_create_internal_resource_index.rb +6 -0
  18. data/db/migrate/20180212092225_create_updated_at_index.rb +6 -0
  19. data/lib/generators/valkyrie/templates/resource_spec.rb.erb +1 -1
  20. data/lib/valkyrie.rb +1 -7
  21. data/lib/valkyrie/change_set.rb +21 -7
  22. data/lib/valkyrie/engine.rb +2 -0
  23. data/lib/valkyrie/id.rb +1 -0
  24. data/lib/valkyrie/indexers/access_controls_indexer.rb +50 -6
  25. data/lib/valkyrie/metadata_adapter.rb +29 -1
  26. data/lib/valkyrie/persistence.rb +27 -0
  27. data/lib/valkyrie/persistence/buffered_persister.rb +17 -1
  28. data/lib/valkyrie/persistence/composite_persister.rb +14 -2
  29. data/lib/valkyrie/persistence/custom_query_container.rb +63 -0
  30. data/lib/valkyrie/persistence/delete_tracking_buffer.rb +8 -0
  31. data/lib/valkyrie/persistence/fedora.rb +3 -0
  32. data/lib/valkyrie/persistence/fedora/list_node.rb +5 -2
  33. data/lib/valkyrie/persistence/fedora/metadata_adapter.rb +13 -11
  34. data/lib/valkyrie/persistence/fedora/ordered_list.rb +2 -2
  35. data/lib/valkyrie/persistence/fedora/ordered_reader.rb +3 -2
  36. data/lib/valkyrie/persistence/fedora/permissive_schema.rb +75 -0
  37. data/lib/valkyrie/persistence/fedora/persister.rb +22 -0
  38. data/lib/valkyrie/persistence/fedora/persister/model_converter.rb +110 -25
  39. data/lib/valkyrie/persistence/fedora/persister/orm_converter.rb +49 -17
  40. data/lib/valkyrie/persistence/fedora/persister/resource_factory.rb +2 -0
  41. data/lib/valkyrie/persistence/fedora/query_service.rb +46 -3
  42. data/lib/valkyrie/persistence/memory.rb +5 -0
  43. data/lib/valkyrie/persistence/memory/metadata_adapter.rb +6 -1
  44. data/lib/valkyrie/persistence/memory/persister.rb +19 -1
  45. data/lib/valkyrie/persistence/memory/query_service.rb +49 -8
  46. data/lib/valkyrie/persistence/postgres.rb +2 -0
  47. data/lib/valkyrie/persistence/postgres/metadata_adapter.rb +8 -1
  48. data/lib/valkyrie/persistence/postgres/orm.rb +1 -0
  49. data/lib/valkyrie/persistence/postgres/orm/resource.rb +12 -0
  50. data/lib/valkyrie/persistence/postgres/orm_converter.rb +99 -74
  51. data/lib/valkyrie/persistence/postgres/persister.rb +16 -0
  52. data/lib/valkyrie/persistence/postgres/query_service.rb +94 -6
  53. data/lib/valkyrie/persistence/postgres/resource_converter.rb +3 -1
  54. data/lib/valkyrie/persistence/postgres/resource_factory.rb +5 -5
  55. data/lib/valkyrie/persistence/solr.rb +2 -0
  56. data/lib/valkyrie/persistence/solr/composite_indexer.rb +29 -0
  57. data/lib/valkyrie/persistence/solr/metadata_adapter.rb +26 -1
  58. data/lib/valkyrie/persistence/solr/model_converter.rb +38 -8
  59. data/lib/valkyrie/persistence/solr/orm_converter.rb +43 -20
  60. data/lib/valkyrie/persistence/solr/persister.rb +16 -0
  61. data/lib/valkyrie/persistence/solr/queries.rb +3 -0
  62. data/lib/valkyrie/persistence/solr/queries/default_paginator.rb +2 -0
  63. data/lib/valkyrie/persistence/solr/queries/find_all_query.rb +3 -1
  64. data/lib/valkyrie/persistence/solr/queries/find_by_id_query.rb +4 -2
  65. data/lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb +2 -0
  66. data/lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb +21 -0
  67. data/lib/valkyrie/persistence/solr/queries/find_members_query.rb +13 -5
  68. data/lib/valkyrie/persistence/solr/queries/find_references_query.rb +7 -3
  69. data/lib/valkyrie/persistence/solr/query_service.rb +30 -2
  70. data/lib/valkyrie/persistence/solr/repository.rb +14 -2
  71. data/lib/valkyrie/persistence/solr/resource_factory.rb +3 -1
  72. data/lib/valkyrie/resource.rb +11 -4
  73. data/lib/valkyrie/resource/access_controls.rb +13 -0
  74. data/lib/valkyrie/specs/shared_specs.rb +1 -2
  75. data/lib/valkyrie/specs/shared_specs/change_set.rb +75 -0
  76. data/lib/valkyrie/specs/shared_specs/metadata_adapter.rb +3 -0
  77. data/lib/valkyrie/specs/shared_specs/persister.rb +145 -15
  78. data/lib/valkyrie/specs/shared_specs/queries.rb +153 -27
  79. data/lib/valkyrie/specs/shared_specs/storage_adapter.rb +8 -3
  80. data/lib/valkyrie/storage.rb +29 -0
  81. data/lib/valkyrie/storage/disk.rb +17 -5
  82. data/lib/valkyrie/storage/fedora.rb +14 -1
  83. data/lib/valkyrie/storage/memory.rb +15 -2
  84. data/lib/valkyrie/storage_adapter.rb +26 -4
  85. data/lib/valkyrie/types.rb +65 -7
  86. data/lib/valkyrie/version.rb +1 -1
  87. data/solr/config/_rest_managed.json +3 -0
  88. data/solr/config/admin-extra.html +31 -0
  89. data/solr/config/elevate.xml +36 -0
  90. data/solr/config/mapping-ISOLatin1Accent.txt +246 -0
  91. data/solr/config/protwords.txt +21 -0
  92. data/solr/config/schema.xml +366 -0
  93. data/solr/config/scripts.conf +24 -0
  94. data/solr/config/solrconfig.xml +322 -0
  95. data/solr/config/spellings.txt +2 -0
  96. data/solr/config/stopwords.txt +58 -0
  97. data/solr/config/stopwords_en.txt +58 -0
  98. data/solr/config/synonyms.txt +31 -0
  99. data/solr/config/xslt/example.xsl +132 -0
  100. data/solr/config/xslt/example_atom.xsl +67 -0
  101. data/solr/config/xslt/example_rss.xsl +66 -0
  102. data/solr/config/xslt/luke.xsl +337 -0
  103. data/solr/solr.xml +35 -0
  104. data/tasks/dev.rake +66 -0
  105. data/valkyrie.gemspec +6 -6
  106. metadata +58 -63
  107. data/lib/valkyrie/decorators/decorator_list.rb +0 -15
  108. data/lib/valkyrie/decorators/decorator_with_arguments.rb +0 -14
  109. data/lib/valkyrie/derivative_service.rb +0 -42
  110. data/lib/valkyrie/file_characterization_service.rb +0 -42
  111. data/lib/valkyrie/local_file_service.rb +0 -11
  112. data/lib/valkyrie/persist_derivatives.rb +0 -29
  113. data/lib/valkyrie/persistence/postgres/queries.rb +0 -8
  114. data/lib/valkyrie/persistence/postgres/queries/find_inverse_references_query.rb +0 -31
  115. data/lib/valkyrie/persistence/postgres/queries/find_members_query.rb +0 -33
  116. data/lib/valkyrie/persistence/postgres/queries/find_references_query.rb +0 -33
  117. data/lib/valkyrie/specs/shared_specs/derivative_service.rb +0 -30
  118. data/lib/valkyrie/specs/shared_specs/file_characterization_service.rb +0 -33
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'hydra/derivatives'
3
- module Valkyrie
4
- ##
5
- # Container for registering DerivativeServices.
6
- #
7
- # To add a new service:
8
- # DerivativeService.services << MyDerivativeService
9
- class DerivativeService
10
- require 'valkyrie/local_file_service'
11
- require 'valkyrie/persist_derivatives'
12
- Hydra::Derivatives.source_file_service = Valkyrie::LocalFileService
13
- Hydra::Derivatives.output_file_service = Valkyrie::PersistDerivatives
14
- class_attribute :services
15
- self.services = []
16
- # Returns a derivative service for a change_set.
17
- # @param resource [Valkyrie::ChangeSet]
18
- # @return [Valkyrie::DerivativeService]
19
- def self.for(change_set)
20
- services.map { |service| service.new(change_set) }.find(&:valid?) ||
21
- new(change_set)
22
- end
23
- attr_reader :change_set
24
- delegate :mime_type, :uri, to: :change_set
25
- # @param resource [Valkyrie::Resource]
26
- def initialize(change_set)
27
- @change_set = change_set
28
- end
29
-
30
- # Deletes any derivatives generated.
31
- def cleanup_derivatives; end
32
-
33
- # Creates derivatives.
34
- def create_derivatives; end
35
-
36
- # Returns true if the given resource is valid for this derivative service.
37
- # @return [Boolean]
38
- def valid?
39
- true
40
- end
41
- end
42
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'ruby_tika_app'
3
-
4
- module Valkyrie
5
- # Abstract base class for file characterization
6
- # registers file characterization service a ValkyrieFileCharacterization service
7
- # initializes the interface for file characterization
8
- # @since 0.1.0
9
- class FileCharacterizationService
10
- class_attribute :services
11
- self.services = []
12
- # initializes the file characterization service
13
- # @param file_node [FileNode] the FileNode to be characterized
14
- # @param persister [AppendingPersister] the Persister used to save the FileNode
15
- # @return [TikaFileCharacterizationService] the file characterization service, currently only TikaFileCharacterizationService is implemented
16
- def self.for(file_node:, persister:)
17
- services.map { |service| service.new(file_node: file_node, persister: persister) }.find(&:valid?) ||
18
- new(file_node: file_node, persister: persister)
19
- end
20
- attr_reader :file_node, :persister
21
- delegate :mime_type, :height, :width, :checksum, to: :file_node
22
- def initialize(file_node:, persister:)
23
- @file_node = file_node
24
- @persister = persister
25
- end
26
-
27
- # characterizes the file_node passed into this service
28
- # Default options are:
29
- # save: true
30
- # @param save [Boolean] should the persister save the file_node after Characterization
31
- # @return [FileNode]
32
- def characterize(save: true)
33
- persister.save(resource: @file_node) if save
34
- @file_node
35
- end
36
-
37
- # Stub function that sets this service as valid for all FileNode types
38
- def valid?
39
- true
40
- end
41
- end
42
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
- module Valkyrie
3
- class LocalFileService
4
- # @param [String] file_name path to the file
5
- # @param [Hash] _options
6
- # @yield [File] opens the file and yields it to the block
7
- def self.call(file_name, _options)
8
- yield File.open(file_name)
9
- end
10
- end
11
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
- module Valkyrie
3
- class PersistDerivatives < Hydra::Derivatives::PersistOutputFileService
4
- # Persists a derivative to the local file system.
5
- # This Service conforms to the signature of `Hydra::Derivatives::PersistOutputFileService`.
6
- # This service is an alternative to the default Hydra::Derivatives::PersistOutputFileService.
7
- # This service will always update existing and does not do versioning of persisted files.
8
- #
9
- # @param [#read] stream the derivative filestream
10
- # @param [Hash] directives
11
- # @option directives [String] :url a url to the file destination
12
- def self.call(stream, directives)
13
- output_file(directives) do |output|
14
- IO.copy_stream(stream, output)
15
- end
16
- end
17
-
18
- # Open the output file to write and yield the block to the
19
- # file. It makes the directories in the path if necessary.
20
- def self.output_file(directives, &blk)
21
- raise ArgumentError, "No :url was provided in the transcoding directives" unless directives.key?(:url)
22
- uri = URI(directives.fetch(:url))
23
- raise ArgumentError, "Must provide a file uri" unless uri.scheme == 'file'
24
- output_file_dir = File.dirname(uri.path)
25
- FileUtils.mkdir_p(output_file_dir) unless File.directory?(output_file_dir)
26
- File.open(uri.path, 'wb', &blk)
27
- end
28
- end
29
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'valkyrie/persistence/postgres/queries/find_inverse_references_query'
3
- require 'valkyrie/persistence/postgres/queries/find_members_query'
4
- require 'valkyrie/persistence/postgres/queries/find_references_query'
5
- module Valkyrie::Persistence::Postgres
6
- module Queries
7
- end
8
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
- module Valkyrie::Persistence::Postgres::Queries
3
- class FindInverseReferencesQuery
4
- delegate :orm_class, to: :resource_factory
5
- attr_reader :obj, :property, :resource_factory
6
- def initialize(obj, property, resource_factory:)
7
- @obj = obj
8
- @property = property
9
- @resource_factory = resource_factory
10
- end
11
-
12
- def run
13
- relation.lazy.map do |orm_object|
14
- resource_factory.to_resource(object: orm_object)
15
- end
16
- end
17
-
18
- private
19
-
20
- def relation
21
- orm_class.find_by_sql([query, property, "[{\"id\": \"#{obj.id}\"}]"])
22
- end
23
-
24
- def query
25
- <<-SQL
26
- SELECT * FROM orm_resources WHERE
27
- metadata->? @> ?
28
- SQL
29
- end
30
- end
31
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
- module Valkyrie::Persistence::Postgres::Queries
3
- class FindMembersQuery
4
- attr_reader :obj, :resource_factory
5
- delegate :orm_class, to: :resource_factory
6
- def initialize(obj, resource_factory:)
7
- @obj = obj
8
- @resource_factory = resource_factory
9
- end
10
-
11
- def run
12
- return [] if obj.id.blank?
13
- relation.lazy.map do |orm_object|
14
- resource_factory.to_resource(object: orm_object)
15
- end
16
- end
17
-
18
- private
19
-
20
- def relation
21
- orm_class.find_by_sql([query, obj.id.to_s])
22
- end
23
-
24
- def query
25
- <<-SQL
26
- SELECT member.* FROM orm_resources a,
27
- jsonb_array_elements(a.metadata->'member_ids') WITH ORDINALITY AS b(member, member_pos)
28
- JOIN orm_resources member ON (b.member->>'id')::uuid = member.id WHERE a.id = ?
29
- ORDER BY b.member_pos
30
- SQL
31
- end
32
- end
33
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
- module Valkyrie::Persistence::Postgres::Queries
3
- class FindReferencesQuery
4
- delegate :orm_class, to: :resource_factory
5
- attr_reader :obj, :property, :resource_factory
6
- def initialize(obj, property, resource_factory:)
7
- @obj = obj
8
- @property = property
9
- @resource_factory = resource_factory
10
- end
11
-
12
- def run
13
- return [] if obj.id.blank? || obj[property].blank?
14
- relation.lazy.map do |orm_object|
15
- resource_factory.to_resource(object: orm_object)
16
- end
17
- end
18
-
19
- private
20
-
21
- def relation
22
- orm_class.find_by_sql([query, property, obj.id.to_s])
23
- end
24
-
25
- def query
26
- <<-SQL
27
- SELECT member.* FROM orm_resources a,
28
- jsonb_array_elements(a.metadata->?) AS b(member)
29
- JOIN orm_resources member ON (b.member->>'id')::uuid = member.id WHERE a.id = ?
30
- SQL
31
- end
32
- end
33
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
- RSpec.shared_examples 'a Valkyrie::DerivativeService' do
3
- before do
4
- raise 'valid_change_set must be set with `let(:valid_change_set)`' unless
5
- defined? valid_change_set
6
- raise 'derivative_service must be set with `let(:derivative_service)`' unless
7
- defined? derivative_service
8
- end
9
-
10
- subject { derivative_service.new(valid_change_set) }
11
-
12
- it { is_expected.to respond_to(:create_derivatives).with(0).arguments }
13
-
14
- it { is_expected.to respond_to(:cleanup_derivatives).with(0).arguments }
15
-
16
- it { is_expected.to respond_to(:change_set) }
17
-
18
- it { is_expected.to respond_to(:mime_type) }
19
-
20
- describe "#valid?" do
21
- context "when given a resource it handles" do
22
- it { is_expected.to be_valid }
23
- end
24
- end
25
-
26
- it "takes a change_set as an argument" do
27
- obj = derivative_service.new(valid_change_set)
28
- expect(obj.change_set.resource).to eq valid_change_set.resource
29
- end
30
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'a Valkyrie::FileCharacterizationService' do
4
- before do
5
- raise 'valid_file_node must be set with `let(:valid_file_node)`' unless
6
- defined? valid_file_node
7
- raise 'persister must be set with `let(:persister)`' unless
8
- defined? persister
9
- raise 'file_characterization_service must be set with `let(:file_characterization_service)`' unless
10
- defined? file_characterization_service
11
- end
12
-
13
- let(:file_node) { valid_file_node }
14
- subject { file_characterization_service.new(file_node: file_node, persister: persister) }
15
-
16
- it { is_expected.to respond_to(:characterize).with(0).arguments }
17
- it 'returns a file node' do
18
- expect(subject.characterize).to be_a(FileNode)
19
- end
20
-
21
- describe '#valid?' do
22
- context 'when given a file_node it handles' do
23
- let(:file_node) { valid_file_node }
24
- it { is_expected.to be_valid }
25
- end
26
- end
27
-
28
- it 'takes a file_node and a persister as arguments' do
29
- obj = file_characterization_service.new(file_node: file_node, persister: persister)
30
- expect(obj.file_node).to eq valid_file_node
31
- expect(obj.persister).to eq persister
32
- end
33
- end