Class: Bulkrax::RdfEntry
- Inherits:
-
Entry
show all
- Defined in:
- app/models/bulkrax/rdf_entry.rb
Instance Attribute Summary
Attributes inherited from Entry
#all_attrs
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Entry
#build, #exporter?, #fetch_field_mapping, #find_collection, #importer?, #last_run, parent_field, #source_identifier, #work_identifier
#add_local
Methods included from StatusInfo
#current_status, #failed?, #last_error, #set_status_info, #skipped?, #status, #status_at, #succeeded?
#build_export_metadata, #build_for_exporter, #filename, #hyrax_record
#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
#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
Class Method Details
.data_for_entry(data, source_id, parser) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/models/bulkrax/rdf_entry.rb', line 16
def self.data_for_entry(data, source_id, parser)
reader = data
format = reader.class.format.to_sym
collections = []
children = []
delete = nil
data = RDF::Writer.for(format).buffer do |writer|
reader.each_statement do |statement|
collections << statement.object.to_s if parent_field(parser).present? && parent_field(parser) == statement.predicate.to_s
children << statement.object.to_s if related_children_parsed_mapping.present? && related_children_parsed_mapping == statement.predicate.to_s
delete = statement.object.to_s if /deleted/.match?(statement.predicate.to_s)
writer << statement
end
end
return {
source_id => reader.subjects.first.to_s,
delete: delete,
format: format,
data: data,
collection: collections,
children: children
}
end
|
.fields_from_data(data) ⇒ Object
12
13
14
|
# File 'app/models/bulkrax/rdf_entry.rb', line 12
def self.fields_from_data(data)
data.predicates.map(&:to_s)
end
|
.read_data(path) ⇒ Object
8
9
10
|
# File 'app/models/bulkrax/rdf_entry.rb', line 8
def self.read_data(path)
RDF::Reader.open(path)
end
|
40
41
42
43
44
45
46
47
|
# File 'app/models/bulkrax/rdf_entry.rb', line 40
def self.related_children_parsed_mapping
return @related_children_parsed_mapping if @related_children_parsed_mapping.present?
rdf_related_children_field_mapping = Bulkrax.field_mappings['Bulkrax::RdfParser']&.select { |_, h| h.key?('related_children_field_mapping') }
return if rdf_related_children_field_mapping.blank?
@related_children_parsed_mapping = rdf_related_children_field_mapping&.keys&.first
end
|
Instance Method Details
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/models/bulkrax/rdf_entry.rb', line 53
def build_metadata
raise StandardError, 'Record not found' if record.nil?
raise StandardError, "Missing source identifier (#{source_identifier})" if self.raw_metadata[source_identifier].blank?
self.parsed_metadata = {}
self.parsed_metadata[work_identifier] = [self.raw_metadata[source_identifier]]
record.each_statement do |statement|
next unless statement.subject.to_s == self.raw_metadata[source_identifier]
add_metadata(statement.predicate.to_s, statement.object.to_s)
end
add_visibility
add_rights_statement
add_admin_set_id
add_collections
add_local
self.parsed_metadata['file'] = self.raw_metadata['file']
self.parsed_metadata
end
|
#collections_created? ⇒ Boolean
75
76
77
78
|
# File 'app/models/bulkrax/rdf_entry.rb', line 75
def collections_created?
return true if self.raw_metadata['collection'].blank?
self.raw_metadata['collection'].length == self.collection_ids.length
end
|
#find_collection_ids ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'app/models/bulkrax/rdf_entry.rb', line 80
def find_collection_ids
return self.collection_ids if collections_created?
if self.raw_metadata['collection'].present?
self.raw_metadata['collection'].each do |collection|
c = find_collection(collection)
self.collection_ids << c.id unless c.blank? || self.collection_ids.include?(c.id)
end
end
return self.collection_ids
end
|
#record ⇒ Object
49
50
51
|
# File 'app/models/bulkrax/rdf_entry.rb', line 49
def record
@record ||= RDF::Reader.for(self.raw_metadata['format'].to_sym).new(self.raw_metadata['data'])
end
|