-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move various requires to a central location lib/bulkrax.rb, (#931)
move various requires to a central location lib/bulkrax.rb, skip rdf or bagit if those gems are not present
- Loading branch information
1 parent
b3fc743
commit e3d02b7
Showing
15 changed files
with
265 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,92 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rdf' | ||
module Bulkrax | ||
class RdfEntry < Entry | ||
serialize :raw_metadata, Bulkrax::NormalizedJson | ||
unless ENV.fetch('BULKRAX_NO_RDF', 'false').to_s == 'true' | ||
module Bulkrax | ||
class RdfEntry < Entry | ||
serialize :raw_metadata, Bulkrax::NormalizedJson | ||
|
||
def self.read_data(path) | ||
RDF::Reader.open(path) | ||
end | ||
def self.read_data(path) | ||
RDF::Reader.open(path) | ||
end | ||
|
||
def self.fields_from_data(data) | ||
data.predicates.map(&:to_s) | ||
end | ||
def self.fields_from_data(data) | ||
data.predicates.map(&:to_s) | ||
end | ||
|
||
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 | ||
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 | ||
return { | ||
source_id => reader.subjects.first.to_s, | ||
delete: delete, | ||
format: format, | ||
data: data, | ||
collection: collections, | ||
children: children | ||
} | ||
end | ||
|
||
def self.related_children_parsed_mapping | ||
return @related_children_parsed_mapping if @related_children_parsed_mapping.present? | ||
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? | ||
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 | ||
@related_children_parsed_mapping = rdf_related_children_field_mapping&.keys&.first | ||
end | ||
|
||
def record | ||
@record ||= RDF::Reader.for(self.raw_metadata['format'].to_sym).new(self.raw_metadata['data']) | ||
end | ||
def record | ||
@record ||= RDF::Reader.for(self.raw_metadata['format'].to_sym).new(self.raw_metadata['data']) | ||
end | ||
|
||
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? | ||
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]] | ||
self.parsed_metadata = {} | ||
self.parsed_metadata[work_identifier] = [self.raw_metadata[source_identifier]] | ||
|
||
record.each_statement do |statement| | ||
# Only process the subject for our record (in case other data is in the file) | ||
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'] | ||
record.each_statement do |statement| | ||
# Only process the subject for our record (in case other data is in the file) | ||
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 | ||
self.parsed_metadata | ||
end | ||
|
||
def collections_created? | ||
return true if self.raw_metadata['collection'].blank? | ||
self.raw_metadata['collection'].length == self.collection_ids.length | ||
end | ||
def collections_created? | ||
return true if self.raw_metadata['collection'].blank? | ||
self.raw_metadata['collection'].length == self.collection_ids.length | ||
end | ||
|
||
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) | ||
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 | ||
return self.collection_ids | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'nokogiri' | ||
module Bulkrax | ||
# Generic XML Entry | ||
class XmlEntry < Entry | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'marcel' | ||
|
||
module Bulkrax | ||
module ExportBehavior | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'marcel' | ||
|
||
module Bulkrax | ||
module ImporterExporterBehavior | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.