Class: IiifPrint::PersistenceLayer::ValkyrieAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- IiifPrint::PersistenceLayer::ValkyrieAdapter
- Defined in:
- lib/iiif_print/persistence_layer/valkyrie_adapter.rb
Class Method Summary collapse
- .clean_for_tests! ⇒ Object
-
.copy_derivatives_from_data_store(stream:, directives:) ⇒ TrueClass
Performs an extra step to create the Hyrax::Metadata objects for derivatives.
-
.create_relationship_between(child_record:, parent_record:) ⇒ TrueClass
Add a child record as a member of a parent record.
-
.decorate_form_with_adapter_logic(work_type:) ⇒ Object
Form for the given :work_type.
-
.decorate_with_adapter_logic(work_type:) ⇒ Object
The indexer for the given :work_type.
-
.destroy_children_split_from(file_set:, work:, model:, user:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
.extract_text_for(file_set:) ⇒ String
Extract text from the derivatives.
-
.find_by(id:) ⇒ Object
find a work or file_set.
-
.find_by_title_for(title:, model:) ⇒ Array<Valkyrie::Resource]
find a work by title We should only find one, but there is no guarantee of that.
-
.grandparent_for(file_set) ⇒ #work?, ...
Return the parent’s parent of the given :file_set.
-
.index_works(objects:) ⇒ TrueClass
reindex an array of works and their file_sets.
- .object_in_works(object) ⇒ Array<Valkyrie::Resource>
- .object_ordered_works(object) ⇒ Array<Valkyrie::Resource>
-
.parent_for(file_set) ⇒ #work?, ...
Return the immediate parent of the given :file_set.
- .pdf?(file_set) ⇒ Boolean
-
.save(object:) ⇒ Object
save a work.
- .solr_construct_query(*args) ⇒ Object
- .solr_name(field_name) ⇒ Object
- .solr_query(query, **args) ⇒ Object
Methods inherited from AbstractAdapter
Class Method Details
.clean_for_tests! ⇒ Object
67 68 69 70 71 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 67 def self.clean_for_tests! # For Fedora backed repositories, we'll want to consider some cleaning mechanism. For # database backed repositories, we can rely on the database_cleaner gem. raise NotImplementedError end |
.copy_derivatives_from_data_store(stream:, directives:) ⇒ TrueClass
Performs an extra step to create the Hyrax::Metadata objects for derivatives.
164 165 166 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 164 def self.copy_derivatives_from_data_store(stream:, directives:) Hyrax::ValkyriePersistDerivatives.call(stream, directives) end |
.create_relationship_between(child_record:, parent_record:) ⇒ TrueClass
Add a child record as a member of a parent record
103 104 105 106 107 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 103 def self.create_relationship_between(child_record:, parent_record:) return true if parent_record.member_ids.include?(child_record.id) parent_record.member_ids << child_record.id true end |
.decorate_form_with_adapter_logic(work_type:) ⇒ Object
Returns form for the given :work_type.
34 35 36 37 38 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 34 def self.decorate_form_with_adapter_logic(work_type:) form = "#{work_type}Form".constantize form.send(:include, Hyrax::FormFields(:child_works_from_pdf_splitting)) unless form.included_modules.include?(Hyrax::FormFields(:child_works_from_pdf_splitting)) form end |
.decorate_with_adapter_logic(work_type:) ⇒ Object
Returns the indexer for the given :work_type.
23 24 25 26 27 28 29 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 23 def self.decorate_with_adapter_logic(work_type:) work_type.send(:include, Hyrax::Schema(:child_works_from_pdf_splitting)) unless work_type.included_modules.include?(Hyrax::Schema(:child_works_from_pdf_splitting)) # TODO: Use `Hyrax::ValkyrieIndexer.indexer_class_for` once changes are merged. indexer = "#{work_type}Indexer".constantize indexer.send(:include, Hyrax::Indexer(:child_works_from_pdf_splitting)) unless indexer.included_modules.include?(Hyrax::Indexer(:child_works_from_pdf_splitting)) indexer end |
.destroy_children_split_from(file_set:, work:, model:, user:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 82 def self.destroy_children_split_from(file_set:, work:, model:, user:) # rubocop:enable Lint/UnusedMethodArgument # look for child records by the file set id they were split from Hyrax.query_service.find_inverse_references_by(resource: file_set, property: :split_from_pdf_id, model: model).each do |child| Hyrax.persister.delete(resource: child) Hyrax.indexing_service.delete(resource: child) Hyrax.publisher.publish('object.deleted', object: child, user: user) end true end |
.extract_text_for(file_set:) ⇒ String
Extract text from the derivatives
173 174 175 176 177 178 179 180 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 173 def self.extract_text_for(file_set:) fm = Hyrax.custom_queries.(resource: file_set, use: Hyrax::FileMetadata::Use.uri_for(use: :extracted_file)) return if fm.empty? text_fm = fm.find { |t| t.mime_type == Marcel::MimeType.for(extension: 'txt') } return if text_fm.nil? text_fm.content end |
.find_by(id:) ⇒ Object
find a work or file_set
128 129 130 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 128 def self.find_by(id:) Hyrax.query_service.find_by(id: id) end |
.find_by_title_for(title:, model:) ⇒ Array<Valkyrie::Resource]
find a work by title We should only find one, but there is no guarantee of that
115 116 117 118 119 120 121 122 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 115 def self.find_by_title_for(title:, model:) work_type = model.constantize # TODO: This creates a hard dependency on Bulkrax because that is where this custom query is defined # Is this adequate? Array.wrap(Hyrax.query_service.custom_query.find_by_model_and_property_value(model: work_type, property: :title, value: title)) end |
.grandparent_for(file_set) ⇒ #work?, ...
Return the parent’s parent of the given :file_set.
57 58 59 60 61 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 57 def self.grandparent_for(file_set) parent = parent_for(file_set) return nil unless parent Hyrax.query_service.find_parents(resource: parent).first end |
.index_works(objects:) ⇒ TrueClass
reindex an array of works and their file_sets
148 149 150 151 152 153 154 155 156 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 148 def self.index_works(objects:) objects.each do |work| Hyrax.index_adapter.save(resource: work) Hyrax.custom_queries.find_child_file_sets(resource: work).each do |file_set| Hyrax.index_adapter.save(resource: file_set) end end true end |
.object_in_works(object) ⇒ Array<Valkyrie::Resource>
7 8 9 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 7 def self.object_in_works(object) Array.wrap(Hyrax.custom_queries.find_parent_work(resource: object)) end |
.object_ordered_works(object) ⇒ Array<Valkyrie::Resource>
14 15 16 17 18 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 14 def self.object_ordered_works(object) child_file_sets = Hyrax.custom_queries.find_child_file_sets(resource: object).to_a child_works = Hyrax.custom_queries.find_child_works(resource: object).to_a child_works + child_file_sets end |
.parent_for(file_set) ⇒ #work?, ...
Return the immediate parent of the given :file_set.
46 47 48 49 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 46 def self.parent_for(file_set) file_set = Hyrax.query_service.find_by(id: file_set.file_set_id) if file_set.is_a?(Hyrax::FileMetadata) Hyrax.query_service.find_parents(resource: file_set).first end |
.pdf?(file_set) ⇒ Boolean
93 94 95 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 93 def self.pdf?(file_set) file_set.original_file.pdf? end |
.save(object:) ⇒ Object
save a work
136 137 138 139 140 141 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 136 def self.save(object:) Hyrax.persister.save(resource: object) Hyrax.index_adapter.save(resource: object) Hyrax.publisher.publish('object.membership.updated', object: object, user: object.depositor) end |
.solr_construct_query(*args) ⇒ Object
63 64 65 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 63 def self.solr_construct_query(*args) Hyrax::SolrQueryBuilderService.construct_query(*args) end |
.solr_name(field_name) ⇒ Object
77 78 79 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 77 def self.solr_name(field_name) Hyrax.config.index_field_mapper.solr_name(field_name.to_s) end |
.solr_query(query, **args) ⇒ Object
73 74 75 |
# File 'lib/iiif_print/persistence_layer/valkyrie_adapter.rb', line 73 def self.solr_query(query, **args) Hyrax::SolrService.query(query, **args) end |