Last active
January 7, 2019 18:41
-
-
Save seanupton/eb06d3fedcf3ee421bfa416d241552d4 to your computer and use it in GitHub Desktop.
Commiting queued derivative assignment after fileset creation
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
module NewspaperWorks | |
module Data | |
class WorkDerviatives | |
#... | |
# Given a fileset meeting both of the following conditions: | |
# 1. a non-nil import_url value; | |
# 2. is attached to a work (persisted in Fedora, if not yet in Solr)... | |
# ...this method shall get associated derivative paths queued and attach all. | |
def commit_queued!(file_set) | |
raise ArgumentError('FileSet has no import_url') if file_set.import_url.nil? | |
import_path = file_url_to_path(file_set.import_url) | |
work = file_set.member_of.select(&:work?)[0] | |
raise ArgumentError('Work not found for fileset') if work.nil? | |
derivatives = WorkDerivatives.of(work, file_set) | |
IngestFileRelation.derivatives_for_file(import_path).each |path| do | |
next unless File.exist?(path) | |
attachment_record = DerivativeAttachment.where(path: path).first | |
derivatives.attach(path, attachment_record.destination_name) | |
end | |
end | |
private | |
def file_url_to_path(url) | |
url.gsub('file://') | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment