curation_concerns-models 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/app/actors/concerns/curation_concerns/manages_embargoes_actor.rb +11 -19
- data/app/actors/curation_concerns/base_actor.rb +41 -45
- data/app/actors/curation_concerns/embargo_actor.rb +19 -0
- data/app/actors/curation_concerns/file_set_actor.rb +200 -0
- data/app/actors/curation_concerns/lease_actor.rb +19 -0
- data/app/actors/curation_concerns/work_actor_behavior.rb +55 -58
- data/app/indexers/curation_concerns/collection_indexer.rb +10 -0
- data/app/indexers/curation_concerns/file_set_indexing_service.rb +24 -0
- data/app/{services/curation_concerns/generic_work_indexing_service.rb → indexers/curation_concerns/work_indexing_service.rb} +6 -6
- data/app/jobs/active_fedora_id_based_job.rb +5 -12
- data/app/jobs/audit_job.rb +11 -17
- data/app/jobs/characterize_job.rb +8 -7
- data/app/jobs/create_derivatives_job.rb +8 -11
- data/app/jobs/import_url_job.rb +12 -25
- data/app/jobs/ingest_file_job.rb +16 -0
- data/app/jobs/ingest_local_file_job.rb +14 -35
- data/app/jobs/resolrize_job.rb +3 -5
- data/app/jobs/upload_set_update_job.rb +68 -0
- data/app/models/checksum_audit_log.rb +2 -3
- data/app/models/concerns/curation_concerns/ability.rb +18 -10
- data/app/models/concerns/curation_concerns/basic_metadata.rb +1 -3
- data/app/models/concerns/curation_concerns/collection_behavior.rb +13 -14
- data/app/models/concerns/curation_concerns/file_set/belongs_to_upload_sets.rb +15 -0
- data/app/models/concerns/curation_concerns/{generic_file → file_set}/belongs_to_works.rb +8 -14
- data/app/models/concerns/curation_concerns/file_set/derivatives.rb +54 -0
- data/app/models/concerns/curation_concerns/{generic_file → file_set}/full_text_indexing.rb +1 -2
- data/app/models/concerns/curation_concerns/{generic_file → file_set}/indexing.rb +2 -2
- data/app/models/concerns/curation_concerns/{generic_file → file_set}/versions.rb +2 -3
- data/app/models/concerns/curation_concerns/file_set_behavior.rb +36 -0
- data/app/models/concerns/curation_concerns/generic_file.rb +1 -1
- data/app/models/concerns/curation_concerns/has_representative.rb +6 -7
- data/app/models/concerns/curation_concerns/human_readable_type.rb +5 -7
- data/app/models/concerns/curation_concerns/permissions.rb +2 -2
- data/app/models/concerns/curation_concerns/permissions/readable.rb +0 -1
- data/app/models/concerns/curation_concerns/permissions/writable.rb +10 -51
- data/app/models/concerns/curation_concerns/serializers.rb +3 -5
- data/app/models/concerns/curation_concerns/solr_document_behavior.rb +37 -40
- data/app/models/concerns/curation_concerns/upload_set_behavior.rb +38 -0
- data/app/models/concerns/curation_concerns/user.rb +4 -51
- data/app/models/concerns/curation_concerns/with_file_sets.rb +28 -0
- data/app/models/concerns/curation_concerns/{generic_work_behavior.rb → work_behavior.rb} +12 -6
- data/app/models/curation_concerns/classify_concern.rb +7 -7
- data/app/models/curation_concerns/quick_classification_query.rb +6 -7
- data/app/models/single_use_link.rb +34 -0
- data/app/models/upload_set.rb +3 -0
- data/app/services/curation_concerns/derivative_path.rb +32 -0
- data/app/services/curation_concerns/{generic_file_audit_service.rb → file_set_audit_service.rb} +17 -18
- data/app/services/curation_concerns/indexes_thumbnails.rb +14 -0
- data/app/services/curation_concerns/local_file_service.rb +10 -0
- data/app/services/curation_concerns/lock_manager.rb +40 -0
- data/app/services/curation_concerns/noid.rb +1 -1
- data/app/services/curation_concerns/persist_derivatives.rb +33 -0
- data/app/services/curation_concerns/persist_directly_contained_output_file_service.rb +26 -0
- data/app/services/curation_concerns/repository_audit_service.rb +1 -3
- data/app/services/curation_concerns/thumbnail_path_service.rb +46 -0
- data/app/services/curation_concerns/time_service.rb +7 -0
- data/app/services/curation_concerns/versioning_service.rb +11 -12
- data/curation_concerns-models.gemspec +6 -6
- data/lib/curation_concerns/configuration.rb +154 -0
- data/lib/curation_concerns/messages.rb +26 -26
- data/lib/curation_concerns/models.rb +5 -14
- data/lib/curation_concerns/models/engine.rb +0 -30
- data/lib/curation_concerns/models/utils.rb +4 -4
- data/lib/curation_concerns/models/version.rb +1 -1
- data/lib/generators/curation_concerns/models/abstract_migration_generator.rb +8 -7
- data/lib/generators/curation_concerns/models/clamav_generator.rb +3 -3
- data/lib/generators/curation_concerns/models/install_generator.rb +13 -20
- data/lib/generators/curation_concerns/models/templates/app/models/file_set.rb +4 -0
- data/lib/generators/curation_concerns/models/templates/config/clamav.rb +1 -1
- data/lib/generators/curation_concerns/models/templates/config/curation_concerns.rb +52 -65
- data/lib/generators/curation_concerns/models/templates/config/redis_config.rb +13 -17
- data/lib/generators/curation_concerns/models/templates/config/resque_config.rb +2 -1
- data/lib/generators/curation_concerns/models/templates/migrations/create_checksum_audit_logs.rb +3 -3
- data/lib/generators/curation_concerns/models/templates/migrations/create_single_use_links.rb +12 -0
- data/lib/tasks/curation_concerns-models_tasks.rake +4 -62
- data/lib/tasks/migrate.rake +1 -1
- data/lib/tasks/resque.rake +1 -0
- data/lib/tasks/solr_reindex.rake +1 -1
- metadata +59 -52
- data/app/actors/curation_concerns/generic_file_actor.rb +0 -150
- data/app/jobs/active_fedora_pid_based_job.rb +0 -6
- data/app/jobs/copy_permissions_job.rb +0 -24
- data/app/models/concerns/curation_concerns/generic_file/characterization.rb +0 -89
- data/app/models/concerns/curation_concerns/generic_file/content.rb +0 -8
- data/app/models/concerns/curation_concerns/generic_file/export.rb +0 -343
- data/app/models/concerns/curation_concerns/generic_file_behavior.rb +0 -44
- data/app/models/concerns/curation_concerns/with_basic_metadata.rb +0 -98
- data/app/models/concerns/curation_concerns/with_generic_files.rb +0 -29
- data/app/models/datastreams/fits_datastream.rb +0 -148
- data/app/services/curation_concerns/characterization_service.rb +0 -71
- data/app/services/curation_concerns/full_text_extraction_service.rb +0 -38
- data/app/services/curation_concerns/generic_file_indexing_service.rb +0 -14
- data/lib/curation_concerns/models/resque.rb +0 -36
- data/lib/generators/curation_concerns/models/fulltext_generator.rb +0 -28
- data/lib/generators/curation_concerns/models/templates/app/models/generic_file.rb +0 -4
- data/lib/generators/curation_concerns/models/templates/config/resque_admin.rb +0 -10
|
@@ -1,88 +1,85 @@
|
|
|
1
|
-
|
|
2
1
|
module CurationConcerns::WorkActorBehavior
|
|
3
2
|
include CurationConcerns::ManagesEmbargoesActor
|
|
3
|
+
attr_accessor :raw_attributes
|
|
4
4
|
|
|
5
5
|
def create
|
|
6
6
|
# set the @files ivar then remove the files attribute so it isn't set by default.
|
|
7
7
|
files && attributes.delete(:files)
|
|
8
|
+
self.raw_attributes = attributes.dup
|
|
8
9
|
# Files must be attached before saving in order to persist their relationship to the work
|
|
9
|
-
assign_pid && interpret_visibility && attach_files && super && assign_representative
|
|
10
|
+
assign_pid && interpret_visibility && attach_files && super && assign_representative
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
def update
|
|
13
14
|
add_to_collections(attributes.delete(:collection_ids)) &&
|
|
14
|
-
|
|
15
|
+
interpret_visibility && super && attach_files
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
delegate :visibility_changed?, to: :curation_concern
|
|
18
19
|
|
|
19
20
|
protected
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def files
|
|
27
|
-
return @files if defined?(@files)
|
|
28
|
-
@files = [attributes[:files]].flatten.compact
|
|
29
|
-
end
|
|
22
|
+
# Is this here to ensure that the curation_concern has a pid set before any of the other methods are executed?
|
|
23
|
+
def assign_pid
|
|
24
|
+
curation_concern.send(:assign_id)
|
|
25
|
+
end
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
def files
|
|
28
|
+
return @files if defined?(@files)
|
|
29
|
+
@files = [attributes[:files]].flatten.compact
|
|
34
30
|
end
|
|
35
|
-
end
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def add_to_collections(new_collection_ids)
|
|
42
|
-
return true unless new_collection_ids
|
|
43
|
-
# remove from old collections
|
|
44
|
-
# TODO Implement parent_collection_ids https://github.com/projecthydra-labs/hydra-pcdm/issues/157
|
|
45
|
-
(curation_concern.parent_collections.map(&:id) - new_collection_ids).each do |old_id|
|
|
46
|
-
Collection.find(old_id).members.delete(curation_concern)
|
|
32
|
+
def attach_files
|
|
33
|
+
files.all? do |file|
|
|
34
|
+
attach_file(file)
|
|
35
|
+
end
|
|
47
36
|
end
|
|
48
37
|
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
# The default behavior of active_fedora's aggregates association,
|
|
39
|
+
# when assigning the id accessor (e.g. collection_ids = ['foo:1']) is to add
|
|
40
|
+
# to new collections, but not remove from old collections.
|
|
41
|
+
# This method ensures it's removed from the old collections.
|
|
42
|
+
def add_to_collections(new_collection_ids)
|
|
43
|
+
return true unless new_collection_ids
|
|
44
|
+
# remove from old collections
|
|
45
|
+
# TODO: Implement in_collection_ids https://github.com/projecthydra-labs/hydra-pcdm/issues/157
|
|
46
|
+
(curation_concern.in_collections.map(&:id) - new_collection_ids).each do |old_id|
|
|
47
|
+
collection = Collection.find(old_id)
|
|
48
|
+
collection.members.delete(curation_concern)
|
|
49
|
+
collection.save
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# add to new
|
|
53
|
+
new_collection_ids.each do |coll_id|
|
|
54
|
+
collection = Collection.find(coll_id)
|
|
55
|
+
collection.members << curation_concern
|
|
56
|
+
collection.save
|
|
57
|
+
end
|
|
58
|
+
true
|
|
54
59
|
end
|
|
55
|
-
true
|
|
56
|
-
end
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
def assign_representative
|
|
62
|
+
@file_sets ||= []
|
|
63
|
+
unless curation_concern.representative_id
|
|
64
|
+
curation_concern.representative = @file_sets.first unless @file_sets.empty?
|
|
65
|
+
end
|
|
66
|
+
curation_concern.save
|
|
62
67
|
end
|
|
63
|
-
curation_concern.save
|
|
64
|
-
end
|
|
65
68
|
|
|
66
69
|
private
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
@generic_files << generic_file # This is so that other methods like assign_representative can access the generic_files wihtout reloading them from fedora
|
|
77
|
-
curation_concern.generic_files << generic_file
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def valid_file?(file_path)
|
|
81
|
-
return file_path.present? && File.exists?(file_path) && !File.zero?(file_path)
|
|
82
|
-
end
|
|
71
|
+
def attach_file(file)
|
|
72
|
+
file_set = ::FileSet.new
|
|
73
|
+
file_set_actor = CurationConcerns::FileSetActor.new(file_set, user)
|
|
74
|
+
file_set_actor.create_metadata(curation_concern.id, curation_concern, visibility_attributes)
|
|
75
|
+
file_set_actor.create_content(file)
|
|
76
|
+
@file_sets ||= []
|
|
77
|
+
@file_sets << file_set # This is so that other methods like assign_representative can access the file_sets without reloading them from fedora
|
|
78
|
+
end
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
# The attributes used for visibility - used to send as initial params to
|
|
81
|
+
# created FileSets.
|
|
82
|
+
def visibility_attributes
|
|
83
|
+
raw_attributes.slice(:visibility, :visibility_during_lease, :visibility_after_lease, :lease_expiration_date, :embargo_release_date, :visibility_during_embargo, :visibility_after_embargo)
|
|
84
|
+
end
|
|
88
85
|
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module CurationConcerns
|
|
2
|
+
class CollectionIndexer < Hydra::PCDM::CollectionIndexer
|
|
3
|
+
def generate_solr_document
|
|
4
|
+
super.tap do |solr_doc|
|
|
5
|
+
# Makes Collections show under the "Collections" tab
|
|
6
|
+
Solrizer.set_field(solr_doc, 'generic_type', 'Collection', :facetable)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module CurationConcerns
|
|
2
|
+
class FileSetIndexingService < ActiveFedora::IndexingService
|
|
3
|
+
include IndexesThumbnails
|
|
4
|
+
|
|
5
|
+
def generate_solr_document
|
|
6
|
+
super.tap do |solr_doc|
|
|
7
|
+
solr_doc[Solrizer.solr_name('hasRelatedMediaFragment', :symbol)] = object.representative_id
|
|
8
|
+
solr_doc[Solrizer.solr_name('hasRelatedImage', :symbol)] = object.thumbnail_id
|
|
9
|
+
# Label is the actual file name. It's not editable by the user.
|
|
10
|
+
solr_doc[Solrizer.solr_name('label')] = object.label
|
|
11
|
+
solr_doc[Solrizer.solr_name('label', :stored_sortable)] = object.label
|
|
12
|
+
solr_doc[Solrizer.solr_name('file_format')] = object.file_format
|
|
13
|
+
solr_doc[Solrizer.solr_name('file_format', :facetable)] = object.file_format
|
|
14
|
+
solr_doc[Solrizer.solr_name(:file_size, :symbol)] = object.file_size[0]
|
|
15
|
+
solr_doc['all_text_timv'] = object.full_text.content
|
|
16
|
+
solr_doc[Solrizer.solr_name('generic_work_ids', :symbol)] = object.generic_work_ids unless object.generic_work_ids.empty?
|
|
17
|
+
solr_doc['height_is'] = Integer(object.height.first) if object.height.present?
|
|
18
|
+
solr_doc['width_is'] = Integer(object.width.first) if object.width.present?
|
|
19
|
+
solr_doc[Solrizer.solr_name('mime_type', :stored_sortable)] = object.mime_type
|
|
20
|
+
solr_doc['thumbnail_path_ss'] = thumbnail_path
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
module CurationConcerns
|
|
2
|
-
class
|
|
3
|
-
|
|
2
|
+
class WorkIndexingService < ActiveFedora::IndexingService
|
|
3
|
+
include IndexesThumbnails
|
|
4
4
|
def generate_solr_document
|
|
5
5
|
super.tap do |solr_doc|
|
|
6
6
|
# We know that all the members of GenericWorks are GenericFiles so we can use
|
|
7
|
-
# member_ids which requires fewer Fedora API calls than
|
|
8
|
-
#
|
|
7
|
+
# member_ids which requires fewer Fedora API calls than file_set_ids.
|
|
8
|
+
# file_set_ids requires loading all the members from Fedora but member_ids
|
|
9
9
|
# looks just at solr
|
|
10
|
-
solr_doc[Solrizer.solr_name('
|
|
10
|
+
solr_doc[Solrizer.solr_name('file_set_ids', :symbol)] = object.member_ids
|
|
11
11
|
Solrizer.set_field(solr_doc, 'generic_type', 'Work', :facetable)
|
|
12
|
+
solr_doc['thumbnail_path_ss'] = thumbnail_path
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
|
-
|
|
15
15
|
end
|
|
16
16
|
end
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
class ActiveFedoraIdBasedJob
|
|
2
|
-
|
|
3
|
-
:id_based
|
|
4
|
-
end
|
|
1
|
+
class ActiveFedoraIdBasedJob < ActiveJob::Base
|
|
2
|
+
queue_as :id_based
|
|
5
3
|
|
|
6
4
|
attr_accessor :id
|
|
7
5
|
|
|
8
|
-
def initialize(id)
|
|
9
|
-
self.id = id
|
|
10
|
-
end
|
|
11
|
-
|
|
12
6
|
def object
|
|
13
7
|
@object ||= ActiveFedora::Base.find(id)
|
|
14
8
|
end
|
|
15
9
|
|
|
16
|
-
alias_method :
|
|
17
|
-
alias_method :generic_file_id, :id
|
|
10
|
+
alias_method :file_set, :object
|
|
18
11
|
|
|
19
|
-
def
|
|
20
|
-
|
|
12
|
+
def perform(_)
|
|
13
|
+
fail 'Define #run in a subclass'
|
|
21
14
|
end
|
|
22
15
|
end
|
data/app/jobs/audit_job.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
class AuditJob < ActiveFedoraIdBasedJob
|
|
2
|
-
|
|
3
|
-
:audit
|
|
4
|
-
end
|
|
2
|
+
queue_as :audit
|
|
5
3
|
|
|
6
4
|
attr_accessor :uri, :id, :file_id
|
|
7
5
|
|
|
@@ -13,21 +11,17 @@ class AuditJob < ActiveFedoraIdBasedJob
|
|
|
13
11
|
# @param [String] id of the parent object
|
|
14
12
|
# @param [String] file_id used to find the file within its parent object (usually "original_file")
|
|
15
13
|
# @param [String] uri of the specific file/version to be audited
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def run
|
|
23
|
-
fixity_ok = false
|
|
14
|
+
def perform(id, file_id, uri)
|
|
15
|
+
@id = id
|
|
16
|
+
@file_id = file_id
|
|
17
|
+
@uri = uri
|
|
24
18
|
log = run_audit
|
|
25
|
-
fixity_ok =
|
|
19
|
+
fixity_ok = log.pass == 1
|
|
26
20
|
unless fixity_ok
|
|
27
|
-
if CurationConcerns.config.
|
|
28
|
-
login =
|
|
21
|
+
if CurationConcerns.config.callback.set?(:after_audit_failure)
|
|
22
|
+
login = file_set.depositor
|
|
29
23
|
user = User.find_by_user_key(login)
|
|
30
|
-
CurationConcerns.config.
|
|
24
|
+
CurationConcerns.config.callback.run(:after_audit_failure, file_set, user, log.created_at)
|
|
31
25
|
end
|
|
32
26
|
end
|
|
33
27
|
fixity_ok
|
|
@@ -39,7 +33,7 @@ class AuditJob < ActiveFedoraIdBasedJob
|
|
|
39
33
|
begin
|
|
40
34
|
fixity_ok = ActiveFedora::FixityService.new(uri).check
|
|
41
35
|
rescue Ldp::NotFound
|
|
42
|
-
error_msg =
|
|
36
|
+
error_msg = 'resource not found'
|
|
43
37
|
end
|
|
44
38
|
|
|
45
39
|
if fixity_ok
|
|
@@ -49,7 +43,7 @@ class AuditJob < ActiveFedoraIdBasedJob
|
|
|
49
43
|
logger.warn "***AUDIT*** Audit failed for #{uri} #{error_msg}"
|
|
50
44
|
passing = 0
|
|
51
45
|
end
|
|
52
|
-
ChecksumAuditLog.create!(pass: passing,
|
|
46
|
+
ChecksumAuditLog.create!(pass: passing, file_set_id: id, version: uri, file_id: file_id)
|
|
53
47
|
end
|
|
54
48
|
|
|
55
49
|
def logger
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
class CharacterizeJob < ActiveFedoraIdBasedJob
|
|
2
|
-
|
|
3
|
-
:characterize
|
|
4
|
-
end
|
|
2
|
+
queue_as :characterize
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
# @param [String] id
|
|
5
|
+
# @param [String] filename a local path for the file to characterize. By using this, we don't have to pull a copy out of fedora.
|
|
6
|
+
def perform(id, filename)
|
|
7
|
+
@id = id
|
|
8
|
+
Hydra::Works::CharacterizationService.run(file_set, filename)
|
|
9
|
+
file_set.save
|
|
10
|
+
CreateDerivativesJob.perform_later(file_set.id, filename)
|
|
10
11
|
end
|
|
11
12
|
end
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
class CreateDerivativesJob < ActiveFedoraIdBasedJob
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
queue_as :derivatives
|
|
3
|
+
|
|
4
|
+
def perform(id, file_name)
|
|
5
|
+
@id = id
|
|
6
|
+
return if file_set.video? && !CurationConcerns.config.enable_ffmpeg
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return unless CurationConcerns.config.enable_ffmpeg
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
generic_file.create_derivatives
|
|
13
|
-
generic_file.save
|
|
8
|
+
file_set.create_derivatives(file_name)
|
|
9
|
+
# The thumbnail is indexed in the solr document, so reindex
|
|
10
|
+
file_set.update_index
|
|
14
11
|
end
|
|
15
12
|
end
|
data/app/jobs/import_url_job.rb
CHANGED
|
@@ -3,39 +3,30 @@ require 'uri'
|
|
|
3
3
|
require 'tempfile'
|
|
4
4
|
|
|
5
5
|
class ImportUrlJob < ActiveFedoraIdBasedJob
|
|
6
|
+
queue_as :import_url
|
|
6
7
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def run
|
|
12
|
-
user = User.find_by_user_key(generic_file.depositor)
|
|
8
|
+
def perform(id)
|
|
9
|
+
@id = id
|
|
10
|
+
user = User.find_by_user_key(file_set.depositor)
|
|
13
11
|
|
|
14
|
-
Tempfile.open(id.
|
|
15
|
-
copy_remote_file(
|
|
12
|
+
Tempfile.open(id.tr('/', '_')) do |f|
|
|
13
|
+
copy_remote_file(file_set.import_url, f)
|
|
16
14
|
# attach downloaded file to generic file stubbed out
|
|
17
|
-
if CurationConcerns::
|
|
18
|
-
|
|
15
|
+
if CurationConcerns::FileSetActor.new(file_set, user).create_content(f)
|
|
19
16
|
# send message to user on download success
|
|
20
|
-
|
|
21
|
-
CurationConcerns.config.after_import_url_success.call(generic_file, user)
|
|
22
|
-
end
|
|
17
|
+
CurationConcerns.config.callback.run(:after_import_url_success, file_set, user)
|
|
23
18
|
else
|
|
24
|
-
|
|
25
|
-
# send message to user on download failure
|
|
26
|
-
if CurationConcerns.config.respond_to?(:after_import_url_failure)
|
|
27
|
-
CurationConcerns.config.after_import_url_failure.call(generic_file, user)
|
|
28
|
-
end
|
|
19
|
+
CurationConcerns.config.callback.run(:after_import_url_failure, file_set, user)
|
|
29
20
|
end
|
|
30
21
|
end
|
|
31
22
|
end
|
|
32
23
|
|
|
33
|
-
def copy_remote_file(
|
|
24
|
+
def copy_remote_file(_import_url, f)
|
|
34
25
|
f.binmode
|
|
35
26
|
# download file from url
|
|
36
|
-
uri = URI(
|
|
27
|
+
uri = URI(file_set.import_url)
|
|
37
28
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
38
|
-
http.use_ssl = uri.scheme ==
|
|
29
|
+
http.use_ssl = uri.scheme == 'https' # enable SSL/TLS
|
|
39
30
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
40
31
|
mime_type = nil
|
|
41
32
|
|
|
@@ -49,8 +40,4 @@ class ImportUrlJob < ActiveFedoraIdBasedJob
|
|
|
49
40
|
end
|
|
50
41
|
f.rewind
|
|
51
42
|
end
|
|
52
|
-
|
|
53
|
-
def job_user
|
|
54
|
-
User.batchuser
|
|
55
|
-
end
|
|
56
43
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class IngestFileJob < ActiveJob::Base
|
|
2
|
+
queue_as :ingest
|
|
3
|
+
|
|
4
|
+
def perform(file_set_id, filename, mime_type, user_key)
|
|
5
|
+
file_set = FileSet.find(file_set_id)
|
|
6
|
+
file = Hydra::Derivatives::IoDecorator.new(File.open(filename, "rb"))
|
|
7
|
+
file.mime_type = mime_type
|
|
8
|
+
file.original_name = File.basename(filename)
|
|
9
|
+
|
|
10
|
+
# Tell UploadFileToGenericFile service to skip versioning because versions will be minted by VersionCommitter (called by save_characterize_and_record_committer) when necessary
|
|
11
|
+
Hydra::Works::UploadFileToFileSet.call(file_set, file, versioning: false)
|
|
12
|
+
file_set.save!
|
|
13
|
+
CurationConcerns::VersioningService.create(file_set.original_file, user_key)
|
|
14
|
+
CurationConcerns.config.callback.run(:after_create_content, file_set, user_key)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -1,48 +1,27 @@
|
|
|
1
|
-
class IngestLocalFileJob
|
|
2
|
-
attr_accessor :directory, :filename, :user_key, :
|
|
1
|
+
class IngestLocalFileJob < ActiveJob::Base
|
|
2
|
+
attr_accessor :directory, :filename, :user_key, :file_set_id
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
:ingest
|
|
6
|
-
end
|
|
4
|
+
queue_as :ingest_local
|
|
7
5
|
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
6
|
+
def perform(file_set_id, directory, filename, user_key)
|
|
7
|
+
@file_set_id = file_set_id
|
|
8
|
+
@directory = directory
|
|
9
|
+
@filename = filename
|
|
10
|
+
@user_key = user_key
|
|
14
11
|
|
|
15
|
-
def run
|
|
16
12
|
user = User.find_by_user_key(user_key)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
fail "Unable to find user for #{user_key}" unless user
|
|
14
|
+
file_set = FileSet.find(file_set_id)
|
|
15
|
+
file_set.label ||= filename
|
|
20
16
|
path = File.join(directory, filename)
|
|
21
17
|
|
|
22
|
-
actor = CurationConcerns::
|
|
18
|
+
actor = CurationConcerns::FileSetActor.new(file_set, user)
|
|
23
19
|
|
|
24
20
|
if actor.create_content(File.open(path))
|
|
25
21
|
FileUtils.rm(path)
|
|
26
|
-
|
|
27
|
-
# send message to user on import success
|
|
28
|
-
if CurationConcerns.config.respond_to?(:after_import_local_file_success)
|
|
29
|
-
CurationConcerns.config.after_import_local_file_success.call(generic_file, user, filename)
|
|
30
|
-
end
|
|
22
|
+
CurationConcerns.config.callback.run(:after_import_local_file_success, file_set, user, filename)
|
|
31
23
|
else
|
|
32
|
-
|
|
33
|
-
# send message to user on import failure
|
|
34
|
-
if CurationConcerns.config.respond_to?(:after_import_local_file_failure)
|
|
35
|
-
CurationConcerns.config.after_import_local_file_failure.call(generic_file, user, filename)
|
|
36
|
-
end
|
|
24
|
+
CurationConcerns.config.callback.run(:after_import_local_file_failure, file_set, user, filename)
|
|
37
25
|
end
|
|
38
26
|
end
|
|
39
|
-
|
|
40
|
-
def job_user
|
|
41
|
-
User.batchuser
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def mime_type(file_name)
|
|
45
|
-
mime_types = MIME::Types.of(file_name)
|
|
46
|
-
mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
|
|
47
|
-
end
|
|
48
27
|
end
|