Class: Bulkrax::OaiEntry

Inherits:
Entry show all
Defined in:
app/models/bulkrax/oai_entry.rb

Direct Known Subclasses

OaiDcEntry, OaiQualifiedDcEntry, OaiSetEntry

Instance Attribute Summary collapse

Attributes inherited from Entry

#all_attrs

Instance Method Summary collapse

Methods inherited from Entry

#build, data_for_entry, #exporter?, #fetch_field_mapping, fields_from_data, #find_collection, #importer?, #last_run, parent_field, read_data, #source_identifier, #work_identifier

Methods included from HasLocalProcessing

#add_local

Methods included from StatusInfo

#current_status, #failed?, #last_error, #set_status_info, #skipped?, #status, #status_at, #succeeded?

Methods included from ExportBehavior

#build_export_metadata, #build_for_exporter, #filename, #hyrax_record

Methods included from ImportBehavior

#active_id_for_authority?, #add_admin_set_id, #add_collections, #add_rights_statement, #add_user_to_permission_templates!, #add_visibility, #build_for_importer, #child_jobs, #factory, #factory_class, #override_rights_statement, #parent_jobs, #rights_statement, #sanitize_controlled_uri_value, #sanitize_controlled_uri_values!, #validate_value

Methods included from HasMatchers

#add_metadata, #excluded?, #field_supported?, #field_to, #fields_that_are_always_multiple, #fields_that_are_always_singular, #get_object_name, #matched_metadata, #multiple?, #multiple_metadata, #schema_form_definitions, #set_parsed_data, #set_parsed_object_data, #single_metadata, #supported_bulkrax_fields

Instance Attribute Details

#raw_recordOAI::GetRecordResponse

Returns:

  • (OAI::GetRecordResponse)


18
19
20
# File 'app/models/bulkrax/oai_entry.rb', line 18

def raw_record
  @raw_record ||= client.get_record(identifier: identifier, metadata_prefix: parser.parser_fields['metadata_prefix'])
end

Instance Method Details

#add_metadata_from_recordObject



76
77
78
79
80
# File 'app/models/bulkrax/oai_entry.rb', line 76

def 
   do |node|
    (node.name, node.content)
  end
end

#add_thumbnail_urlObject



92
93
94
# File 'app/models/bulkrax/oai_entry.rb', line 92

def add_thumbnail_url
  ('thumbnail_url', thumbnail_url)
end

#build_metadataObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/bulkrax/oai_entry.rb', line 34

def 
  self. = {}
  self.[work_identifier] = [record.header.identifier]
  self. = { record: record..to_s, header: record.header.to_s }

  # We need to establish the #factory_class before we proceed with the metadata.  See
  # https://github.com/samvera-labs/bulkrax/issues/702 for further details.
  #
  # tl;dr - if we don't have the right factory_class we might skip properties that are
  # specifically assigned to the factory class
  establish_factory_class
  
  add_thumbnail_url

  add_visibility
  add_rights_statement
  add_admin_set_id
  add_collections
  add_local

  return self.
end

#collections_created?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
# File 'app/models/bulkrax/oai_entry.rb', line 57

def collections_created?
  if parser.collection_name == 'all'
    sets.blank? || (sets.present? && sets.size == self.collection_ids.size)
  else
    self.collection_ids.size == 1
  end
end

#contextObject



26
27
28
# File 'app/models/bulkrax/oai_entry.rb', line 26

def context
  @context ||= OpenStruct.new(record: record, identifier: record.header.identifier)
end

#each_candidate_metadata_node {|node| ... } ⇒ Object

A method that you could override to better handle the shape of the record’s metadata.

Yield Parameters:

  • node (Object<#name, #content>)


84
85
86
87
88
89
90
# File 'app/models/bulkrax/oai_entry.rb', line 84

def 
  record..children.each do |child|
    child.children.each do |node|
      yield(node)
    end
  end
end

#establish_factory_classObject

To ensure we capture the correct parse data, we first need to establish the factory_class.



67
68
69
70
71
72
73
74
# File 'app/models/bulkrax/oai_entry.rb', line 67

def establish_factory_class
  model_field_names = parser.model_field_mappings

   do |node|
    next unless model_field_names.include?(node.name)
    (node.name, node.content)
  end
end

#find_collection_idsObject

Retrieve list of collections for the entry; add to collection_ids If OAI-PMH doesn’t return setSpec in the headers for GetRecord, use parser.collection_name

in this case, if 'All' is selected, records will not be added to a collection.


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/models/bulkrax/oai_entry.rb', line 99

def find_collection_ids
  return self.collection_ids if defined?(@called_find_collection_ids)

  if sets.blank? || parser.collection_name != 'all'
    collection = find_collection(importerexporter.unique_collection_identifier(parser.collection_name))
    self.collection_ids << collection.id if collection.present? && !self.collection_ids.include?(collection.id)
  else # All - collections should exist for all sets
    sets.each do |set|
      c = find_collection(importerexporter.unique_collection_identifier(set.content))
      self.collection_ids << c.id if c.present? && !self.collection_ids.include?(c.id)
    end
  end

  @called_find_collection_ids = true
  return self.collection_ids
end

#setsObject



22
23
24
# File 'app/models/bulkrax/oai_entry.rb', line 22

def sets
  record.header.set_spec
end

#thumbnail_urlObject



30
31
32
# File 'app/models/bulkrax/oai_entry.rb', line 30

def thumbnail_url
  ERB.new(parser.parser_fields['thumbnail_url']).result(context.instance_eval { binding })
end