Class: IiifPrint::PersistenceLayer::ActiveFedoraAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/iiif_print/persistence_layer/active_fedora_adapter.rb

Class Method Summary collapse

Methods inherited from AbstractAdapter

solr_field_query

Class Method Details

.clean_for_tests!Object



71
72
73
74
75
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 71

def self.clean_for_tests!
  super do
    ActiveFedora::Cleaner.clean!
  end
end

.copy_derivatives_from_data_storeTrueClass

does nothing for ActiveFedora; allows valkyrie works to have an extra step to create the Hyrax::Metadata objects.

Parameters:

  • []

Returns:

  • (TrueClass)


175
176
177
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 175

def self.copy_derivatives_from_data_store(*)
  true
end

.create_relationship_between(child_record:, parent_record:) ⇒ TrueClass

Add a child record as a member of a parent record

Parameters:

  • model (child_record)

    an ActiveFedora::Base model

  • model (parent_record)

    an ActiveFedora::Base model

Returns:

  • (TrueClass)


121
122
123
124
125
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 121

def self.create_relationship_between(child_record:, parent_record:)
  return true if parent_record.ordered_members.to_a.include?(child_record)
  parent_record.ordered_members << child_record
  true
end

.decorate_form_with_adapter_logic(work_type:) ⇒ Object

Returns indexer for the given :work_type.

Parameters:

  • work_type (Class<ActiveFedora::Base>)

Returns:

  • indexer for the given :work_type



29
30
31
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 29

def self.decorate_form_with_adapter_logic(work_type:)
  work_type.indexer
end

.decorate_with_adapter_logic(work_type:) ⇒ Object

Returns indexer for the given :work_type.

Parameters:

  • work_type (Class<ActiveFedora::Base>)

Returns:

  • indexer for the given :work_type



21
22
23
24
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 21

def self.decorate_with_adapter_logic(work_type:)
  work_type.send(:include, IiifPrint::SetChildFlag) unless work_type.included_modules.include?(IiifPrint::SetChildFlag)
  work_type.indexer
end

.destroy_children_split_from(file_set:, work:, model:, **_args) ⇒ Object

Parameters:

  • file_set (Object)
  • work (Object)
  • model (Class)

    The class name for which we’ll split children.



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 97

def self.destroy_children_split_from(file_set:, work:, model:, **_args)
  # look first for children by the file set id they were split from
  children = model.where(split_from_pdf_id: file_set.id)
  if children.blank?
    # find works where file name and work `to_param` are both in the title
    children = model.where(title: file_set.label).where(title: work.to_param)
  end
  return if children.blank?
  children.each do |rcd|
    rcd.destroy(eradicate: true)
  end
  true
end

.extract_text_for(file_set:) ⇒ String

Extract text from the derivatives

Parameters:

  • an (FileSet)

    ActiveFedora fileset

Returns:

  • (String)

    Text from fileset’s file



184
185
186
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 184

def self.extract_text_for(file_set:)
  IiifPrint.config.all_text_generator_function.call(object: file_set) || ''
end

.find_by(id:) ⇒ Array<ActiveFedora::Base]

find a work or file_set

Parameters:

  • id (String)

Returns:

  • (Array<ActiveFedora::Base])

    Array<ActiveFedora::Base]



144
145
146
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 144

def self.find_by(id:)
  ActiveFedora::Base.find(id)
end

.find_by_title_for(title:, model:) ⇒ Object

find a work by title We should only find one, but there is no guarantee of that and ‘:where` returns an array.

Parameters:

  • title (String)
  • model (String)

    an ActiveFedora::Base model



133
134
135
136
137
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 133

def self.find_by_title_for(title:, model:)
  work_type = model.constantize

  work_type.where(title: title)
end

.grandparent_for(file_set) ⇒ #work?, ...

Return the parent’s parent of the given :file_set.

Parameters:

  • file_set (FileSet)

Returns:

  • (#work?, Hydra::PCDM::Work)
  • (NilClass)

    when no grand parent is found.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 51

def self.grandparent_for(file_set)
  parent_of_file_set = parent_for(file_set)
  # HACK: This is an assumption about the file_set structure, namely that an image page split from
  # a PDF is part of a file set that is a child of a work that is a child of a single work.  That
  # is, it only has one grand parent.  Which is a reasonable assumption for IIIF Print but is not
  # valid when extended beyond IIIF Print.  That is GenericWork does not have a parent method but
  # does have a parents method.
  parent_of_file_set.try(:parent_works).try(:first) ||
    parent_of_file_set.try(:parents).try(:first) ||
    parent_of_file_set&.member_of&.find(&:work?)
end

.index_works(objects:) ⇒ TrueClass

reindex an array of works and their file_sets

Parameters:

  • objects (Array<ActiveFedora::Base])

    bjects [Array<ActiveFedora::Base]

Returns:

  • (TrueClass)


161
162
163
164
165
166
167
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 161

def self.index_works(objects:)
  objects.each do |work|
    work.update_index
    work.file_sets.each(&:update_index) if work.respond_to?(:file_sets)
  end
  true
end

.object_in_works(object) ⇒ Array<SolrDocument>

Parameters:

  • object (ActiveFedora::Base)

Returns:

  • (Array<SolrDocument>)


7
8
9
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 7

def self.object_in_works(object)
  object.in_works
end

.object_ordered_works(object) ⇒ Array<SolrDocument>

Parameters:

  • object (ActiveFedora::Base)

Returns:

  • (Array<SolrDocument>)


14
15
16
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 14

def self.object_ordered_works(object)
  object.ordered_works
end

.parent_for(file_set) ⇒ #work?, ...

Return the immediate parent of the given :file_set.

Parameters:

  • file_set (FileSet)

Returns:

  • (#work?, Hydra::PCDM::Work)
  • (NilClass)

    when no parent is found.



39
40
41
42
43
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 39

def self.parent_for(file_set)
  # fallback to Fedora-stored relationships if work's aggregation of
  #   file set is not indexed in Solr
  file_set.parent || file_set.member_of.find(&:work?)
end

.pdf?(file_set) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 111

def self.pdf?(file_set)
  file_set.class.pdf_mime_types.include?(file_set.mime_type)
end

.pdf_path_for(file_set:) ⇒ String

Location of the file for resplitting

Parameters:

  • an (FileSet)

    ActiveFedora fileset

Returns:

  • (String)

    location of the original file



193
194
195
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 193

def self.pdf_path_for(file_set:)
  Hyrax::WorkingDirectory.find_or_retrieve(file_set.files.first.id, file_set.id)
end

.save(object:) ⇒ Object

save a work

Parameters:

  • object (Array<ActiveFedora::Base])

    bject [Array<ActiveFedora::Base]



152
153
154
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 152

def self.save(object:)
  object.save!
end

.solr_construct_query(*args) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 63

def self.solr_construct_query(*args)
  if defined?(Hyrax::SolrQueryBuilderService)
    Hyrax::SolrQueryBuilderService.construct_query(*args)
  else
    ActiveFedora::SolrQueryBuilder.construct_query(*args)
  end
end

.solr_name(field_name) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 85

def self.solr_name(field_name)
  if defined?(Hyrax) && Hyrax.config.respond_to?(:index_field_mapper)
    Hyrax.config.index_field_mapper.solr_name(field_name.to_s)
  else
    ::ActiveFedora.index_field_mapper.solr_name(field_name.to_s)
  end
end

.solr_query(query, **args) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/iiif_print/persistence_layer/active_fedora_adapter.rb', line 77

def self.solr_query(query, **args)
  if defined?(ActiveFedora::SolrService)
    ActiveFedora::SolrService.query(query, **args)
  else
    Hyrax::SolrService.query(query, **args)
  end
end