Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into validate_collections_exist
- Loading branch information
Showing
13 changed files
with
318 additions
and
16 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
app/actors/hyrax/actors/create_with_files_and_pass_types_actor.rb
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Hyrax | ||
module Actors | ||
# Creates a work and attaches files to the work, | ||
# passes types through to the attach files job | ||
class CreateWithFilesAndPassTypesActor < CreateWithFilesActor | ||
def create(env) | ||
@thumbnail = env.attributes.delete(:thumbnail) | ||
@transcript = env.attributes.delete(:transcript) | ||
@representative = env.attributes.delete(:representative) | ||
super | ||
end | ||
|
||
## | ||
# @return [TrueClass]nnn | ||
def attach_files(files, env) | ||
return true if files.blank? | ||
attributes = env.attributes.merge(file_type_attributes) | ||
AttachTypedFilesToWorkJob.perform_later(env.curation_concern, files, attributes.to_h.symbolize_keys) | ||
true | ||
end | ||
|
||
def file_type_attributes | ||
types = {} | ||
types[:thumbnail] = @thumbnail if @thumbnail.present? | ||
types[:transcript] = @transcript if @transcript.present? | ||
types[:representative] = @representative if @representative.present? | ||
types | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Converts UploadedFiles into FileSets and attaches them to works. | ||
class AttachTypedFilesToWorkJob < AttachFilesToWorkJob | ||
# @param [ActiveFedora::Base] work - the work object | ||
# @param [Array<Hyrax::UploadedFile>] uploaded_files - an array of files to attach | ||
def perform(work, uploaded_files, **work_attributes) | ||
validate_files!(uploaded_files) | ||
user = User.find_by_user_key(work.depositor) # BUG? file depositor ignored | ||
work_permissions = work.permissions.map(&:to_hash) | ||
metadata = visibility_attributes(work_attributes) | ||
uploaded_files.each do |uploaded_file| | ||
actor = Hyrax::Actors::FileSetActor.new(FileSet.create, user) | ||
actor.create_metadata(metadata) | ||
actor.create_content(uploaded_file) | ||
set_filetypes(work: work, file_set: actor.file_set, filename: uploaded_file.file.file.original_filename, **work_attributes) | ||
actor.attach_to_work(work) | ||
actor.file_set.permissions_attributes = work_permissions | ||
uploaded_file.update(file_set_uri: actor.file_set.uri) | ||
end | ||
end | ||
|
||
## | ||
# Sets the file types on the work. | ||
# | ||
# Simply returns if no opts are passed. Otherwise, sets representative, | ||
# thumbnail, and transcript roles for the given fileset if filename matches | ||
# the set name for that role. | ||
# | ||
# If the work does not support a file type, attempts to set this relation are | ||
# ignored. | ||
# | ||
# @return [Boolean] true if the file types have been set sucessfully | ||
def set_filetypes(work:, file_set:, filename:, **opts) | ||
return true if opts.empty? | ||
|
||
[:representative, :thumbnail, :transcript].each do |type| | ||
work.public_send(:"#{type}_id=", file_set.id) if | ||
work.respond_to?(:"#{type}_id=") && opts[type] == filename | ||
end | ||
|
||
# NOTE: the work may not be valid, in which case this save doesn't do anything | ||
# see https://github.com/samvera/hyrax/blob/403d95cb2ada27fe366dd9e8df91240f3b46c461/app/actors/hyrax/actors/file_set_actor.rb#L81 | ||
work.save | ||
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ | ||
http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> | ||
<responseDate>2017-09-01T19:20:30Z</responseDate> | ||
<request verb="ListRecords" from="1998-01-15" | ||
set="any:set" | ||
metadataPrefix="mira_import"> | ||
http://example.com/OAI</request> | ||
<ListRecords> | ||
<record> | ||
<metadata> | ||
<mira_import xmlns:model="info:fedora/fedora-system:def/model#" xmlns:fcrepo4="http://fedora.info/definitions/v4/repository#" xmlns:iana="http://www.iana.org/assignments/relation/" xmlns:marcrelators="http://id.loc.gov/vocabulary/relators/" xmlns:dc="http://purl.org/dc/terms/" xmlns:fedoraresourcestatus="http://fedora.info/definitions/1/0/access/ObjState#" xmlns:scholarsphere="http://scholarsphere.psu.edu/ns#" xmlns:opaquehydra="http://opaquenamespace.org/ns/hydra/" xmlns:bibframe="http://bibframe.org/vocab/" xmlns:dc11="http://purl.org/dc/elements/1.1/" xmlns:ebucore="http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#" xmlns:premis="http://www.loc.gov/premis/rdf/v1#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#" xmlns:tufts="http://dl.tufts.edu/terms#" xmlns:edm="http://www.europeana.eu/schemas/edm/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> | ||
<tufts:filename type="transcript">2.pdf</tufts:filename> | ||
<tufts:filename type="representative">pdf-sample.pdf</tufts:filename> | ||
<tufts:displays_in>dl</tufts:displays_in> | ||
<model:hasModel>Audio</model:hasModel> | ||
<dc:title>Record with Representative and Transcript</dc:title> | ||
</mira_import> | ||
</metadata> | ||
</record> | ||
<record> | ||
<metadata> | ||
<mira_import xmlns:model="info:fedora/fedora-system:def/model#" xmlns:fcrepo4="http://fedora.info/definitions/v4/repository#" xmlns:iana="http://www.iana.org/assignments/relation/" xmlns:marcrelators="http://id.loc.gov/vocabulary/relators/" xmlns:dc="http://purl.org/dc/terms/" xmlns:fedoraresourcestatus="http://fedora.info/definitions/1/0/access/ObjState#" xmlns:scholarsphere="http://scholarsphere.psu.edu/ns#" xmlns:opaquehydra="http://opaquenamespace.org/ns/hydra/" xmlns:bibframe="http://bibframe.org/vocab/" xmlns:dc11="http://purl.org/dc/elements/1.1/" xmlns:ebucore="http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#" xmlns:premis="http://www.loc.gov/premis/rdf/v1#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#" xmlns:tufts="http://dl.tufts.edu/terms#" xmlns:edm="http://www.europeana.eu/schemas/edm/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> | ||
<tufts:filename>3.pdf</tufts:filename> | ||
<tufts:filename type="thumbnail">fake.png</tufts:filename> | ||
<tufts:displays_in>dl</tufts:displays_in> | ||
<model:hasModel>Pdf</model:hasModel> | ||
<dc:title>Record with Representative and Thumbnail</dc:title> | ||
</mira_import> | ||
</metadata> | ||
</record> | ||
</ListRecords> | ||
</OAI-PMH> |
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
Oops, something went wrong.