hydra-works 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +2 -5
- data/Gemfile +1 -3
- data/README.md +28 -13
- data/hydra-works.gemspec +4 -3
- data/lib/hydra/works.rb +7 -57
- data/lib/hydra/works/models/concerns/block_child_objects.rb +16 -0
- data/lib/hydra/works/models/concerns/collection_behavior.rb +27 -2
- data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +5 -13
- data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +9 -13
- data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +14 -9
- data/lib/hydra/works/models/concerns/generic_file/versioned_content.rb +18 -0
- data/lib/hydra/works/models/concerns/generic_file/virus_check.rb +48 -0
- data/lib/hydra/works/models/concerns/generic_file_behavior.rb +24 -1
- data/lib/hydra/works/models/concerns/generic_work_behavior.rb +32 -3
- data/lib/hydra/works/models/generic_file.rb +3 -0
- data/lib/hydra/works/services/generic_file/add_file_to_generic_file.rb +127 -0
- data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +1 -2
- data/lib/hydra/works/services/generic_file/persist_derivative.rb +22 -0
- data/lib/hydra/works/services/generic_file/upload_file.rb +11 -19
- data/lib/hydra/works/version.rb +1 -1
- data/lib/hydra/works/vocab/works_terms.rb +1 -1
- data/spec/fixtures/Example.ogg +0 -0
- data/spec/fixtures/charter.docx +0 -0
- data/spec/fixtures/countdown.avi +0 -0
- data/spec/fixtures/image.jp2 +0 -0
- data/spec/fixtures/piano_note.wav +0 -0
- data/spec/fixtures/test5.mp3 +0 -0
- data/spec/fixtures/world.png +0 -0
- data/spec/hydra/works/models/collection_spec.rb +499 -16
- data/spec/hydra/works/models/concerns/block_child_objects_spec.rb +19 -0
- data/spec/hydra/works/models/concerns/{file → generic_file}/contained_files_spec.rb +20 -17
- data/spec/hydra/works/models/concerns/generic_file/mime_types_spec.rb +76 -0
- data/spec/hydra/works/models/concerns/generic_file/versioned_content_spec.rb +32 -0
- data/spec/hydra/works/models/concerns/generic_file/virus_check_spec.rb +50 -0
- data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +1 -1
- data/spec/hydra/works/models/generic_file_spec.rb +201 -14
- data/spec/hydra/works/models/generic_work_spec.rb +530 -14
- data/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb +110 -0
- data/spec/hydra/works/services/generic_file/upload_file_spec.rb +45 -28
- data/spec/hydra/works/services/persist_derivatives_spec.rb +93 -0
- data/spec/hydra/works_spec.rb +35 -35
- data/spec/spec_helper.rb +6 -0
- metadata +56 -95
- data/lib/hydra/works/models/concerns/aggregates_collections.rb +0 -16
- data/lib/hydra/works/models/concerns/aggregates_generic_files.rb +0 -20
- data/lib/hydra/works/models/concerns/aggregates_generic_works.rb +0 -20
- data/lib/hydra/works/processor.rb +0 -9
- data/lib/hydra/works/services/collection/add_collection.rb +0 -19
- data/lib/hydra/works/services/collection/add_generic_work.rb +0 -19
- data/lib/hydra/works/services/collection/add_related_object.rb +0 -19
- data/lib/hydra/works/services/collection/get_collections.rb +0 -17
- data/lib/hydra/works/services/collection/get_generic_works.rb +0 -17
- data/lib/hydra/works/services/collection/get_related_objects.rb +0 -17
- data/lib/hydra/works/services/collection/remove_collection.rb +0 -19
- data/lib/hydra/works/services/collection/remove_generic_work.rb +0 -20
- data/lib/hydra/works/services/collection/remove_related_object.rb +0 -19
- data/lib/hydra/works/services/generic_file/add_file.rb +0 -55
- data/lib/hydra/works/services/generic_file/add_generic_file.rb +0 -19
- data/lib/hydra/works/services/generic_file/add_original_file.rb +0 -11
- data/lib/hydra/works/services/generic_file/add_related_object.rb +0 -19
- data/lib/hydra/works/services/generic_file/add_versioned_original_file.rb +0 -10
- data/lib/hydra/works/services/generic_file/get_generic_files.rb +0 -17
- data/lib/hydra/works/services/generic_file/get_related_objects.rb +0 -17
- data/lib/hydra/works/services/generic_file/remove_generic_file.rb +0 -20
- data/lib/hydra/works/services/generic_file/remove_related_object.rb +0 -19
- data/lib/hydra/works/services/generic_work/add_generic_file.rb +0 -19
- data/lib/hydra/works/services/generic_work/add_generic_work.rb +0 -19
- data/lib/hydra/works/services/generic_work/add_related_object.rb +0 -19
- data/lib/hydra/works/services/generic_work/get_generic_files.rb +0 -17
- data/lib/hydra/works/services/generic_work/get_generic_works.rb +0 -17
- data/lib/hydra/works/services/generic_work/get_related_objects.rb +0 -17
- data/lib/hydra/works/services/generic_work/move_generic_file.rb +0 -19
- data/lib/hydra/works/services/generic_work/remove_generic_file.rb +0 -20
- data/lib/hydra/works/services/generic_work/remove_generic_work.rb +0 -20
- data/lib/hydra/works/services/generic_work/remove_related_object.rb +0 -19
- data/spec/hydra/works/services/collection/add_collection_spec.rb +0 -166
- data/spec/hydra/works/services/collection/add_generic_work_spec.rb +0 -155
- data/spec/hydra/works/services/collection/add_related_object_spec.rb +0 -149
- data/spec/hydra/works/services/collection/get_collections_spec.rb +0 -35
- data/spec/hydra/works/services/collection/get_generic_works_spec.rb +0 -35
- data/spec/hydra/works/services/collection/get_related_objects_spec.rb +0 -49
- data/spec/hydra/works/services/collection/remove_collection_spec.rb +0 -133
- data/spec/hydra/works/services/collection/remove_generic_work_spec.rb +0 -133
- data/spec/hydra/works/services/collection/remove_related_object_spec.rb +0 -128
- data/spec/hydra/works/services/generic_file/add_file_spec.rb +0 -28
- data/spec/hydra/works/services/generic_file/add_generic_file_spec.rb +0 -174
- data/spec/hydra/works/services/generic_file/add_related_object_spec.rb +0 -150
- data/spec/hydra/works/services/generic_file/get_generic_files_spec.rb +0 -19
- data/spec/hydra/works/services/generic_file/get_related_objects_spec.rb +0 -45
- data/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb +0 -124
- data/spec/hydra/works/services/generic_file/remove_related_object_spec.rb +0 -123
- data/spec/hydra/works/services/generic_work/add_generic_file_spec.rb +0 -156
- data/spec/hydra/works/services/generic_work/add_generic_work_spec.rb +0 -157
- data/spec/hydra/works/services/generic_work/add_related_object_spec.rb +0 -148
- data/spec/hydra/works/services/generic_work/get_generic_files_spec.rb +0 -35
- data/spec/hydra/works/services/generic_work/get_generic_works_spec.rb +0 -35
- data/spec/hydra/works/services/generic_work/get_related_objects_spec.rb +0 -46
- data/spec/hydra/works/services/generic_work/move_generic_file_spec.rb +0 -21
- data/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb +0 -132
- data/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb +0 -133
- data/spec/hydra/works/services/generic_work/remove_related_object_spec.rb +0 -128
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b09c8a80126527ae1e46668a611225e85ed64b85
|
4
|
+
data.tar.gz: 863f6a4b6315edbc5825e65d560a24fcb8372910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79734196b519492daf40942ba488aedf9f303483dc3527b9f92ee400d04ef51467d69e65b4c0f4fb6ce23a74a836f3188177faeb5a073fc24ec3b6671de89905
|
7
|
+
data.tar.gz: 2266310f4f914ca326b95f8f57eb294ef2d75f7170c56620e00dbe5eacc3c629be077d785ef114e711e439221a57506a2105a3209dbc9d23e3dd7b1d2534772e
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,12 +3,10 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in hydra-works.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem 'activefedora-aggregation', github: 'projecthydra-labs/activefedora-aggregation'
|
7
|
-
gem 'active-fedora', github: 'projecthydra/active_fedora', branch: 'master'
|
8
6
|
gem 'slop', '~> 3.6' # For byebug
|
9
7
|
|
10
8
|
unless ENV['CI']
|
11
9
|
gem 'pry'
|
12
10
|
gem 'pry-byebug'
|
13
11
|
gem 'byebug'
|
14
|
-
end
|
12
|
+
end
|
data/README.md
CHANGED
@@ -36,29 +36,44 @@ class Collection < ActiveFedora::Base
|
|
36
36
|
include Hydra::Works::CollectionBehavior
|
37
37
|
end
|
38
38
|
|
39
|
-
class
|
39
|
+
class Book < ActiveFedora::Base
|
40
40
|
include Hydra::Works::GenericWorkBehavior
|
41
41
|
end
|
42
42
|
|
43
|
-
class
|
43
|
+
class Page < ActiveFedora::Base
|
44
44
|
include Hydra::Works::GenericFileBehavior
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
collection = Collection.create
|
48
|
+
book = BookWork.create
|
49
|
+
page = Page.create
|
50
|
+
|
51
|
+
collection.child_generic_works << book
|
52
|
+
collection.save
|
53
|
+
book.generic_files << page
|
54
|
+
book.save
|
55
|
+
|
56
|
+
file = page.files.build
|
57
|
+
file.content = "The quick brown fox jumped over the lazy dog."
|
58
|
+
page.save
|
59
|
+
```
|
60
|
+
|
61
|
+
## Virus Detection
|
62
|
+
|
63
|
+
To turn on virus detection, install clamav on your system and add the `clamav` gem to your Gemfile
|
50
64
|
|
51
|
-
|
52
|
-
Hydra::Works::AddGenericFileToGenericWork(bw1,bf1)
|
53
|
-
c1.save
|
54
|
-
bw1.save
|
55
|
-
bf1.save
|
65
|
+
gem 'clamav'
|
56
66
|
|
57
|
-
|
58
|
-
|
59
|
-
|
67
|
+
Then include the `VirusCheck` module in your `GenericFile` class:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
class BookFiles < ActiveFedora::Base
|
71
|
+
include Hydra::Works::GenericFileBehavior
|
72
|
+
include Hydra::Works::GenericFile::VirusCheck
|
73
|
+
end
|
60
74
|
```
|
61
75
|
|
76
|
+
|
62
77
|
## Access controls
|
63
78
|
|
64
79
|
We are using [Web ACL](http://www.w3.org/wiki/WebAccessControl) as implemented by [hydra-access-controls](https://github.com/projecthydra/hydra-head/tree/master/hydra-access-controls).
|
data/hydra-works.gemspec
CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "hydra-pcdm", "~> 0.
|
22
|
-
spec.add_dependency "hydra-derivatives", "~>
|
23
|
-
spec.add_dependency "activefedora-aggregation", "~> 0.
|
21
|
+
spec.add_dependency "hydra-pcdm", "~> 0.1"
|
22
|
+
spec.add_dependency "hydra-derivatives", "~> 2.0"
|
23
|
+
spec.add_dependency "activefedora-aggregation", "~> 0.4"
|
24
|
+
spec.add_dependency "active-fedora", "~> 9.2"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.7"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/hydra/works.rb
CHANGED
@@ -2,10 +2,10 @@ require 'hydra/works/version'
|
|
2
2
|
require 'active_fedora/aggregation'
|
3
3
|
require 'hydra/pcdm'
|
4
4
|
require 'hydra/derivatives'
|
5
|
-
require 'hydra/works/processor'
|
6
5
|
|
7
6
|
module Hydra
|
8
7
|
module Works
|
8
|
+
extend ActiveSupport::Autoload
|
9
9
|
|
10
10
|
# vocabularies
|
11
11
|
autoload :WorksVocabularies, 'hydra/works/vocab/works_terms'
|
@@ -14,68 +14,18 @@ module Hydra
|
|
14
14
|
autoload :Collection, 'hydra/works/models/collection'
|
15
15
|
autoload :GenericWork, 'hydra/works/models/generic_work'
|
16
16
|
autoload :GenericFile, 'hydra/works/models/generic_file'
|
17
|
-
|
17
|
+
|
18
18
|
#behaviors
|
19
19
|
autoload :CollectionBehavior, 'hydra/works/models/concerns/collection_behavior'
|
20
20
|
autoload :GenericWorkBehavior, 'hydra/works/models/concerns/generic_work_behavior'
|
21
21
|
autoload :GenericFileBehavior, 'hydra/works/models/concerns/generic_file_behavior'
|
22
|
-
autoload :AggregatesGenericFiles, 'hydra/works/models/concerns/aggregates_generic_files'
|
23
|
-
autoload :AggregatesGenericWorks, 'hydra/works/models/concerns/aggregates_generic_works'
|
24
|
-
autoload :AggregatesCollections, 'hydra/works/models/concerns/aggregates_collections'
|
25
22
|
autoload :GenericFile, 'hydra/works/models/generic_file'
|
26
|
-
|
27
|
-
# collection services
|
28
|
-
autoload :AddCollectionToCollection, 'hydra/works/services/collection/add_collection'
|
29
|
-
autoload :AddGenericWorkToCollection, 'hydra/works/services/collection/add_generic_work'
|
30
|
-
autoload :AddRelatedObjectToCollection, 'hydra/works/services/collection/add_related_object'
|
31
|
-
autoload :GetCollectionsFromCollection, 'hydra/works/services/collection/get_collections'
|
32
|
-
autoload :GetGenericWorksFromCollection, 'hydra/works/services/collection/get_generic_works'
|
33
|
-
autoload :GetRelatedObjectsFromCollection, 'hydra/works/services/collection/get_related_objects'
|
34
|
-
autoload :RemoveCollectionFromCollection, 'hydra/works/services/collection/remove_collection'
|
35
|
-
autoload :RemoveGenericWorkFromCollection, 'hydra/works/services/collection/remove_generic_work'
|
36
|
-
autoload :RemoveRelatedObjectFromCollection, 'hydra/works/services/collection/remove_related_object'
|
37
|
-
|
38
|
-
# generic_work services
|
39
|
-
autoload :AddGenericWorkToGenericWork, 'hydra/works/services/generic_work/add_generic_work'
|
40
|
-
autoload :AddGenericFileToGenericWork, 'hydra/works/services/generic_work/add_generic_file'
|
41
|
-
autoload :AddRelatedObjectToGenericWork, 'hydra/works/services/generic_work/add_related_object'
|
42
|
-
autoload :GetGenericWorksFromGenericWork, 'hydra/works/services/generic_work/get_generic_works'
|
43
|
-
autoload :GetGenericFilesFromGenericWork, 'hydra/works/services/generic_work/get_generic_files'
|
44
|
-
autoload :GetRelatedObjectsFromGenericWork, 'hydra/works/services/generic_work/get_related_objects'
|
45
|
-
autoload :MoveGenericFileToGenericWork, 'hydra/works/services/generic_work/move_generic_file'
|
46
|
-
autoload :RemoveGenericWorkFromGenericWork, 'hydra/works/services/generic_work/remove_generic_work'
|
47
|
-
autoload :RemoveGenericFileFromGenericWork, 'hydra/works/services/generic_work/remove_generic_file'
|
48
|
-
autoload :RemoveRelatedObjectFromGenericWork, 'hydra/works/services/generic_work/remove_related_object'
|
23
|
+
autoload :BlockChildObjects, 'hydra/works/models/concerns/block_child_objects'
|
49
24
|
|
50
25
|
# generic_file services
|
51
|
-
autoload :
|
52
|
-
autoload :
|
53
|
-
autoload :
|
54
|
-
autoload :
|
55
|
-
autoload :GetGenericFilesFromGenericFile, 'hydra/works/services/generic_file/get_generic_files'
|
56
|
-
autoload :GetRelatedObjectsFromGenericFile, 'hydra/works/services/generic_file/get_related_objects'
|
57
|
-
autoload :RemoveGenericFileFromGenericFile, 'hydra/works/services/generic_file/remove_generic_file'
|
58
|
-
autoload :RemoveRelatedObjectFromGenericFile, 'hydra/works/services/generic_file/remove_related_object'
|
59
|
-
autoload :UploadFileToGenericFile, 'hydra/works/services/generic_file/upload_file'
|
60
|
-
autoload :AddOriginalFile, 'hydra/works/services/generic_file/add_original_file'
|
61
|
-
autoload :AddVersionedOriginalFile, 'hydra/works/services/generic_file/add_versioned_original_file'
|
62
|
-
autoload :GenerateThumbnail, 'hydra/works/services/generic_file/generate/thumbnail'
|
63
|
-
|
64
|
-
# model validations
|
65
|
-
def self.collection? collection
|
66
|
-
return false unless collection.respond_to? :type
|
67
|
-
collection.type.include? WorksVocabularies::WorksTerms.Collection
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.generic_work? generic_work
|
71
|
-
return false unless generic_work.respond_to? :type
|
72
|
-
generic_work.type.include? WorksVocabularies::WorksTerms.GenericWork
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.generic_file? generic_file
|
76
|
-
return false unless generic_file.respond_to? :type
|
77
|
-
generic_file.type.include? WorksVocabularies::WorksTerms.GenericFile
|
78
|
-
end
|
79
|
-
|
26
|
+
autoload :AddFileToGenericFile, 'hydra/works/services/generic_file/add_file_to_generic_file'
|
27
|
+
autoload :GenerateThumbnail, 'hydra/works/services/generic_file/generate/thumbnail'
|
28
|
+
autoload :UploadFileToGenericFile, 'hydra/works/services/generic_file/upload_file'
|
29
|
+
autoload :PersistDerivative, 'hydra/works/services/generic_file/persist_derivative'
|
80
30
|
end
|
81
31
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Hydra::Works
|
2
|
+
# Do not allow aggregation of child objects
|
3
|
+
module BlockChildObjects
|
4
|
+
|
5
|
+
def child_objects= objects
|
6
|
+
raise StandardError, "method `child_objects=' not allowed for #{self}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def child_objects
|
10
|
+
raise StandardError, "method `child_objects' not allowed for #{self}"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
@@ -20,8 +20,33 @@ module Hydra::Works
|
|
20
20
|
|
21
21
|
included do
|
22
22
|
type [RDFVocabularies::PCDMTerms.Collection,WorksVocabularies::WorksTerms.Collection]
|
23
|
-
include Hydra::Works::
|
24
|
-
|
23
|
+
include Hydra::Works::BlockChildObjects
|
24
|
+
|
25
|
+
filters_association :members, as: :child_collections, condition: :works_collection?
|
26
|
+
filters_association :members, as: :child_generic_works, condition: :works_generic_work?
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean] whether this instance is a Hydra::Works Collection.
|
30
|
+
def works_collection?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Boolean] whether this instance is a Hydra::Works Generic Work.
|
35
|
+
def works_generic_work?
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Boolean] whether this instance is a Hydra::Works Generic File.
|
40
|
+
def works_generic_file?
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
def parents
|
45
|
+
aggregated_by
|
46
|
+
end
|
47
|
+
|
48
|
+
def parent_collections
|
49
|
+
aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::CollectionBehavior) }
|
25
50
|
end
|
26
51
|
|
27
52
|
end
|
@@ -2,21 +2,13 @@ module Hydra::Works::GenericFile::ContainedFiles
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
# HydraWorks supports only one each of original_file, thumbnail, and extracted_text. However
|
5
|
-
# you are free to add an unlimited number of
|
5
|
+
# you are free to add an unlimited number of additional types such as different resolutions
|
6
6
|
# of images, different derivatives, etc, and use any established vocabulary you choose.
|
7
7
|
|
8
8
|
# TODO: se PCDM vocab class when projecthydra-labs/hydra-pcdm#80 is merged
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
included do
|
10
|
+
directly_contains_one :original_file, through: :files, type: ::RDF::URI("http://pcdm.org/use#OriginalFile"), class_name: "Hydra::PCDM::File"
|
11
|
+
directly_contains_one :thumbnail, through: :files, type: ::RDF::URI("http://pcdm.org/use#ThumbnailImage"), class_name: "Hydra::PCDM::File"
|
12
|
+
directly_contains_one :extracted_text, through: :files, type: ::RDF::URI("http://pcdm.org/use#ExtractedText"), class_name: "Hydra::PCDM::File"
|
12
13
|
end
|
13
|
-
|
14
|
-
def thumbnail
|
15
|
-
file_of_type(::RDF::URI("http://pcdm.org/ThumbnailImage"))
|
16
|
-
end
|
17
|
-
|
18
|
-
def extracted_text
|
19
|
-
file_of_type(::RDF::URI("http://pcdm.org/ExtractedText"))
|
20
|
-
end
|
21
|
-
|
22
14
|
end
|
@@ -5,28 +5,24 @@ module Hydra::Works::GenericFile
|
|
5
5
|
included do
|
6
6
|
include Hydra::Derivatives
|
7
7
|
|
8
|
+
# Sets output_file_service to PersistDerivative instead of default Hydra::Derivatives::PersistBasicContainedOutputFileService
|
9
|
+
Hydra::Derivatives.output_file_service = Hydra::Works::PersistDerivative
|
10
|
+
|
8
11
|
# This was taken directly from Sufia's GenericFile::Derivatives and modified to exclude any processing that modified the original file
|
9
12
|
makes_derivatives do |obj|
|
10
|
-
case obj.mime_type
|
13
|
+
case obj.original_file.mime_type
|
11
14
|
when *pdf_mime_types
|
12
|
-
obj.transform_file :original_file,
|
15
|
+
obj.transform_file :original_file, thumbnail: { format: 'jpg', size: '338x493' }
|
13
16
|
when *office_document_mime_types
|
14
|
-
obj.transform_file :original_file, { thumbnail: { format: 'jpg', size: '200x150>'
|
17
|
+
obj.transform_file :original_file, { thumbnail: { format: 'jpg', size: '200x150>' } }, processor: :document
|
15
18
|
when *video_mime_types
|
16
|
-
obj.transform_file :original_file, { thumbnail: { format: 'jpg'
|
19
|
+
obj.transform_file :original_file, { thumbnail: { format: 'jpg' } }, processor: :video
|
17
20
|
when *image_mime_types
|
18
|
-
obj.transform_file :original_file,
|
21
|
+
obj.transform_file :original_file, thumbnail: { format: 'jpg', size: '200x150>' }
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
25
|
end
|
23
26
|
|
24
|
-
# This bit was not in Sufia, but needs to be here for derivatives to work
|
25
|
-
# TODO: delegate mime type somewhere else?
|
26
|
-
def mime_type
|
27
|
-
return nil unless self.original_file
|
28
|
-
self.original_file.mime_type
|
29
|
-
end
|
30
|
-
|
31
27
|
end
|
32
|
-
end
|
28
|
+
end
|
@@ -4,23 +4,23 @@ module Hydra::Works::GenericFile
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def pdf?
|
7
|
-
self.class.pdf_mime_types.include?
|
7
|
+
self.class.pdf_mime_types.include? mime_type
|
8
8
|
end
|
9
9
|
|
10
10
|
def image?
|
11
|
-
self.class.image_mime_types.include?
|
11
|
+
self.class.image_mime_types.include? mime_type
|
12
12
|
end
|
13
13
|
|
14
14
|
def video?
|
15
|
-
self.class.video_mime_types.include?
|
15
|
+
self.class.video_mime_types.include? mime_type
|
16
16
|
end
|
17
17
|
|
18
18
|
def audio?
|
19
|
-
self.class.audio_mime_types.include?
|
19
|
+
self.class.audio_mime_types.include? mime_type
|
20
20
|
end
|
21
21
|
|
22
22
|
def office_document?
|
23
|
-
self.class.office_document_mime_types.include?
|
23
|
+
self.class.office_document_mime_types.include? mime_type
|
24
24
|
end
|
25
25
|
|
26
26
|
# TODO: remove?
|
@@ -29,10 +29,15 @@ module Hydra::Works::GenericFile
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def file_format
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
if mime_type.present? && format_label.present?
|
33
|
+
"#{mime_type.split('/').last} (#{format_label.join(", ")})"
|
34
|
+
elsif mime_type.present?
|
35
|
+
mime_type.split('/').last
|
36
|
+
elsif format_label.present?
|
37
|
+
format_label
|
38
|
+
else
|
39
|
+
nil
|
40
|
+
end
|
36
41
|
end
|
37
42
|
|
38
43
|
module ClassMethods
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Hydra::Works::GenericFile
|
2
|
+
# Allows a GenericFile to treat the version history of the original_file as the GenericFile's version history
|
3
|
+
module VersionedContent
|
4
|
+
|
5
|
+
def content_versions
|
6
|
+
self.original_file.versions.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def latest_content_version
|
10
|
+
self.original_file.versions.last
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_content_version_uri
|
14
|
+
self.original_file.versions.last.uri
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Hydra::Works::GenericFile
|
2
|
+
module VirusCheck
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
validate :detect_viruses
|
7
|
+
end
|
8
|
+
|
9
|
+
# Default behavior is to raise a validation error and halt the save if a virus is found
|
10
|
+
def detect_viruses
|
11
|
+
return unless original_file && original_file.new_record?
|
12
|
+
|
13
|
+
path = original_file.is_a?(String) ? original_file : local_path_for_file(original_file)
|
14
|
+
unless defined?(ClamAV)
|
15
|
+
warn "Virus checking disabled, #{path} not checked"
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
scan_result = ClamAV.instance.scanfile(path)
|
20
|
+
if scan_result == 0
|
21
|
+
true
|
22
|
+
else
|
23
|
+
virus_message = "A virus was found in #{path}: #{scan_result}"
|
24
|
+
warn(virus_message)
|
25
|
+
errors.add(:base, virus_message)
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Returns a path for reading the content of +file+
|
33
|
+
# @param [File] file object to retrieve a path for
|
34
|
+
def local_path_for_file(file)
|
35
|
+
if file.respond_to?(:path)
|
36
|
+
file.path
|
37
|
+
else
|
38
|
+
Tempfile.open('') do |t|
|
39
|
+
t.binmode
|
40
|
+
t.write(file)
|
41
|
+
t.close
|
42
|
+
t.path
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -15,11 +15,34 @@ module Hydra::Works
|
|
15
15
|
included do
|
16
16
|
type [RDFVocabularies::PCDMTerms.Object,WorksVocabularies::WorksTerms.GenericFile]
|
17
17
|
|
18
|
-
include Hydra::Works::AggregatesGenericFiles
|
19
18
|
include Hydra::Works::GenericFile::ContainedFiles
|
20
19
|
include Hydra::Works::GenericFile::Derivatives
|
21
20
|
include Hydra::Works::GenericFile::MimeTypes
|
21
|
+
include Hydra::Works::GenericFile::VersionedContent
|
22
|
+
include Hydra::Works::BlockChildObjects
|
22
23
|
end
|
23
24
|
|
25
|
+
# @return [Boolean] whether this instance is a Hydra::Works Collection.
|
26
|
+
def works_collection?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean] whether this instance is a Hydra::Works Generic Work.
|
31
|
+
def works_generic_work?
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] whether this instance is a Hydra::Works Generic File.
|
36
|
+
def works_generic_file?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def parents
|
41
|
+
aggregated_by
|
42
|
+
end
|
43
|
+
|
44
|
+
def generic_works
|
45
|
+
aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::GenericWorkBehavior) }
|
46
|
+
end
|
24
47
|
end
|
25
48
|
end
|