hydra-works 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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +72 -0
  4. data/Gemfile +5 -4
  5. data/README.md +17 -11
  6. data/Rakefile +18 -8
  7. data/config/solrconfig.xml +223 -0
  8. data/hydra-works.gemspec +15 -15
  9. data/lib/hydra/works.rb +28 -17
  10. data/lib/hydra/works/errors/full_text_extraction_error.rb +5 -0
  11. data/lib/hydra/works/models/concerns/block_child_objects.rb +12 -6
  12. data/lib/hydra/works/models/concerns/collection_behavior.rb +44 -6
  13. data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +3 -3
  14. data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +2 -4
  15. data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +1 -3
  16. data/lib/hydra/works/models/concerns/generic_file/versioned_content.rb +4 -6
  17. data/lib/hydra/works/models/concerns/generic_file/virus_check.rb +13 -14
  18. data/lib/hydra/works/models/concerns/generic_file_behavior.rb +13 -3
  19. data/lib/hydra/works/models/concerns/generic_work_behavior.rb +34 -9
  20. data/lib/hydra/works/models/generic_file.rb +0 -3
  21. data/lib/hydra/works/services/generic_file/add_file_to_generic_file.rb +14 -16
  22. data/lib/hydra/works/services/generic_file/full_text_extraction_service.rb +57 -0
  23. data/lib/hydra/works/services/generic_file/generate_thumbnail.rb +13 -0
  24. data/lib/hydra/works/services/generic_file/persist_derivative.rb +3 -5
  25. data/lib/hydra/works/services/generic_file/{upload_file.rb → upload_file_to_generic_file.rb} +1 -3
  26. data/lib/hydra/works/version.rb +1 -1
  27. data/lib/hydra/works/vocab/works_terms.rb +9 -9
  28. data/lib/tasks/hydra-works_tasks.rake +80 -0
  29. data/lib/tasks/jetty.rake +15 -0
  30. data/spec/hydra/works/models/collection_spec.rb +258 -246
  31. data/spec/hydra/works/models/concerns/block_child_objects_spec.rb +6 -8
  32. data/spec/hydra/works/models/concerns/generic_file/contained_files_spec.rb +40 -48
  33. data/spec/hydra/works/models/concerns/generic_file/mime_types_spec.rb +16 -18
  34. data/spec/hydra/works/models/concerns/generic_file/versioned_content_spec.rb +11 -11
  35. data/spec/hydra/works/models/concerns/generic_file/virus_check_spec.rb +11 -8
  36. data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +1 -1
  37. data/spec/hydra/works/models/generic_file_spec.rb +87 -85
  38. data/spec/hydra/works/models/generic_work_spec.rb +167 -169
  39. data/spec/hydra/works/services/full_text_extraction_service_spec.rb +89 -0
  40. data/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb +36 -38
  41. data/spec/hydra/works/services/generic_file/generate/thumbnail_spec.rb +10 -12
  42. data/spec/hydra/works/services/generic_file/upload_file_spec.rb +39 -42
  43. data/spec/hydra/works/services/persist_derivatives_spec.rb +2 -3
  44. data/spec/hydra/works_spec.rb +57 -61
  45. data/spec/spec_helper.rb +2 -4
  46. metadata +23 -15
  47. data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +0 -18
data/lib/hydra/works.rb CHANGED
@@ -7,25 +7,36 @@ module Hydra
7
7
  module Works
8
8
  extend ActiveSupport::Autoload
9
9
 
10
- # vocabularies
11
- autoload :WorksVocabularies, 'hydra/works/vocab/works_terms'
10
+ module Vocab
11
+ extend ActiveSupport::Autoload
12
+ eager_autoload do
13
+ autoload :WorksTerms
14
+ end
15
+ end
12
16
 
13
- # models
14
- autoload :Collection, 'hydra/works/models/collection'
15
- autoload :GenericWork, 'hydra/works/models/generic_work'
16
- autoload :GenericFile, 'hydra/works/models/generic_file'
17
+ autoload_under 'models' do
18
+ autoload :Collection
19
+ autoload :GenericWork
20
+ autoload :GenericFile
21
+ end
17
22
 
18
- #behaviors
19
- autoload :CollectionBehavior, 'hydra/works/models/concerns/collection_behavior'
20
- autoload :GenericWorkBehavior, 'hydra/works/models/concerns/generic_work_behavior'
21
- autoload :GenericFileBehavior, 'hydra/works/models/concerns/generic_file_behavior'
22
- autoload :GenericFile, 'hydra/works/models/generic_file'
23
- autoload :BlockChildObjects, 'hydra/works/models/concerns/block_child_objects'
23
+ autoload_under 'models/concerns' do
24
+ autoload :CollectionBehavior
25
+ autoload :GenericWorkBehavior
26
+ autoload :GenericFileBehavior
27
+ autoload :BlockChildObjects
28
+ end
24
29
 
25
- # generic_file services
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'
30
+ autoload_under 'services/generic_file' do
31
+ autoload :AddFileToGenericFile
32
+ autoload :GenerateThumbnail
33
+ autoload :UploadFileToGenericFile
34
+ autoload :PersistDerivative
35
+ autoload :FullTextExtractionService
36
+ end
37
+
38
+ autoload_under 'errors' do
39
+ autoload :FullTextExtractionError
40
+ end
30
41
  end
31
42
  end
@@ -0,0 +1,5 @@
1
+ module Hydra::Works #:nodoc:
2
+ # Raised when full text extraction fails.
3
+ class FullTextExtractionError < StandardError
4
+ end
5
+ end
@@ -1,16 +1,22 @@
1
1
  module Hydra::Works
2
2
  # Do not allow aggregation of child objects
3
3
  module BlockChildObjects
4
+ def objects=(_objects)
5
+ fail StandardError, "method `objects=' not allowed for #{self}"
6
+ end
4
7
 
5
- def child_objects= objects
6
- raise StandardError, "method `child_objects=' not allowed for #{self}"
8
+ def objects
9
+ fail StandardError, "method `objects' not allowed for #{self}"
7
10
  end
8
11
 
9
- def child_objects
10
- raise StandardError, "method `child_objects' not allowed for #{self}"
12
+ def child_objects=(new_objects)
13
+ warn '[DEPRECATION] `child_objects=` is deprecated in Hydra::Works. Please use `objects=` instead. This has a target date for removal of 10-31-2015'
14
+ self.objects = new_objects
11
15
  end
12
16
 
17
+ def child_objects
18
+ warn '[DEPRECATION] `child_objects` is deprecated in Hydra::Works. Please use `objects` instead. This has a target date for removal of 10-31-2015'
19
+ objects
20
+ end
13
21
  end
14
22
  end
15
-
16
-
@@ -1,5 +1,4 @@
1
1
  module Hydra::Works
2
-
3
2
  # This module provides all of the Behaviors of a Hydra::Works::Collection
4
3
  #
5
4
  # behavior:
@@ -19,11 +18,11 @@ module Hydra::Works
19
18
  include Hydra::PCDM::CollectionBehavior
20
19
 
21
20
  included do
22
- type [RDFVocabularies::PCDMTerms.Collection,WorksVocabularies::WorksTerms.Collection]
21
+ type [Hydra::PCDM::Vocab::PCDMTerms.Collection, Vocab::WorksTerms.Collection]
23
22
  include Hydra::Works::BlockChildObjects
24
23
 
25
- filters_association :members, as: :child_collections, condition: :works_collection?
26
- filters_association :members, as: :child_generic_works, condition: :works_generic_work?
24
+ filters_association :members, as: :collections, condition: :works_collection?
25
+ filters_association :members, as: :generic_works, condition: :works_generic_work?
27
26
  end
28
27
 
29
28
  # @return [Boolean] whether this instance is a Hydra::Works Collection.
@@ -41,13 +40,52 @@ module Hydra::Works
41
40
  false
42
41
  end
43
42
 
44
- def parents
43
+ def member_of
45
44
  aggregated_by
46
45
  end
47
46
 
48
- def parent_collections
47
+ def parents
48
+ warn '[DEPRECATION] `parents` is deprecated in Hydra::Works. Please use `member_of` instead. This has a target date for removal of 10-31-2015'
49
+ member_of
50
+ end
51
+
52
+ def in_collections
49
53
  aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::CollectionBehavior) }
50
54
  end
51
55
 
56
+ def parent_collections
57
+ warn '[DEPRECATION] `parent_collections` is deprecated in Hydra::Works. Please use `in_collections` instead. This has a target date for removal of 10-31-2015'
58
+ in_collections
59
+ end
60
+
61
+ def child_collections
62
+ warn '[DEPRECATION] `child_collections` is deprecated in Hydra::Works. Please use `collections` instead. This has a target date for removal of 10-31-2015'
63
+ collections
64
+ end
65
+
66
+ def child_collections=(new_collections)
67
+ warn '[DEPRECATION] `child_collections=` is deprecated in Hydra::Works. Please use `collections=` instead. This has a target date for removal of 10-31-2015'
68
+ self.collections = new_collections
69
+ end
70
+
71
+ def child_collection_ids
72
+ warn '[DEPRECATION] `child_collection_ids` is deprecated in Hydra::Works. Please use `collection_ids` instead. This has a target date for removal of 10-31-2015'
73
+ collection_ids
74
+ end
75
+
76
+ def child_generic_works
77
+ warn '[DEPRECATION] `child_generic_works` is deprecated in Hydra::Works. Please use `generic_works` instead. This has a target date for removal of 10-31-2015'
78
+ generic_works
79
+ end
80
+
81
+ def child_generic_works=(new_generic_works)
82
+ warn '[DEPRECATION] `child_generic_works=` is deprecated in Hydra::Works. Please use `generic_works=` instead. This has a target date for removal of 10-31-2015'
83
+ self.generic_works = new_generic_works
84
+ end
85
+
86
+ def child_generic_work_ids
87
+ warn '[DEPRECATION] `child_generic_work_ids` is deprecated in Hydra::Works. Please use `generic_work_ids` instead. This has a target date for removal of 10-31-2015'
88
+ generic_work_ids
89
+ end
52
90
  end
53
91
  end
@@ -7,8 +7,8 @@ module Hydra::Works::GenericFile::ContainedFiles
7
7
 
8
8
  # TODO: se PCDM vocab class when projecthydra-labs/hydra-pcdm#80 is merged
9
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"
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'
13
13
  end
14
14
  end
@@ -1,7 +1,7 @@
1
1
  module Hydra::Works::GenericFile
2
2
  module Derivatives
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do
6
6
  include Hydra::Derivatives
7
7
 
@@ -21,8 +21,6 @@ module Hydra::Works::GenericFile
21
21
  obj.transform_file :original_file, thumbnail: { format: 'jpg', size: '200x150>' }
22
22
  end
23
23
  end
24
-
25
24
  end
26
-
27
25
  end
28
- end
26
+ end
@@ -30,13 +30,11 @@ module Hydra::Works::GenericFile
30
30
 
31
31
  def file_format
32
32
  if mime_type.present? && format_label.present?
33
- "#{mime_type.split('/').last} (#{format_label.join(", ")})"
33
+ "#{mime_type.split('/').last} (#{format_label.join(', ')})"
34
34
  elsif mime_type.present?
35
35
  mime_type.split('/').last
36
36
  elsif format_label.present?
37
37
  format_label
38
- else
39
- nil
40
38
  end
41
39
  end
42
40
 
@@ -1,18 +1,16 @@
1
1
  module Hydra::Works::GenericFile
2
2
  # Allows a GenericFile to treat the version history of the original_file as the GenericFile's version history
3
3
  module VersionedContent
4
-
5
4
  def content_versions
6
- self.original_file.versions.all
5
+ original_file.versions.all
7
6
  end
8
7
 
9
8
  def latest_content_version
10
- self.original_file.versions.last
9
+ original_file.versions.last
11
10
  end
12
11
 
13
12
  def current_content_version_uri
14
- self.original_file.versions.last.uri
13
+ original_file.versions.last.uri
15
14
  end
16
-
17
15
  end
18
- end
16
+ end
@@ -1,7 +1,7 @@
1
1
  module Hydra::Works::GenericFile
2
2
  module VirusCheck
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do
6
6
  validate :detect_viruses
7
7
  end
@@ -29,20 +29,19 @@ module Hydra::Works::GenericFile
29
29
 
30
30
  private
31
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
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
43
44
  end
44
45
  end
45
- end
46
-
47
46
  end
48
47
  end
@@ -13,7 +13,7 @@ module Hydra::Works
13
13
  include Hydra::PCDM::ObjectBehavior
14
14
 
15
15
  included do
16
- type [RDFVocabularies::PCDMTerms.Object,WorksVocabularies::WorksTerms.GenericFile]
16
+ type [Hydra::PCDM::Vocab::PCDMTerms.Object, Vocab::WorksTerms.GenericFile]
17
17
 
18
18
  include Hydra::Works::GenericFile::ContainedFiles
19
19
  include Hydra::Works::GenericFile::Derivatives
@@ -37,12 +37,22 @@ module Hydra::Works
37
37
  true
38
38
  end
39
39
 
40
- def parents
40
+ def member_of
41
41
  aggregated_by
42
42
  end
43
43
 
44
- def generic_works
44
+ def parents
45
+ warn '[DEPRECATION] `parents` is deprecated in Hydra::Works. Please use `member_of` instead. This has a target date for removal of 10-31-2015'
46
+ member_of
47
+ end
48
+
49
+ def in_generic_works
45
50
  aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::GenericWorkBehavior) }
46
51
  end
52
+
53
+ def generic_works
54
+ warn '[DEPRECATION] `generic_works` is deprecated in Hydra::Works. Please use `in_generic_works` instead. This has a target date for removal of 10-31-2015'
55
+ in_generic_works
56
+ end
47
57
  end
48
58
  end
@@ -17,17 +17,13 @@ module Hydra::Works
17
17
  include Hydra::PCDM::ObjectBehavior
18
18
 
19
19
  included do
20
- type [RDFVocabularies::PCDMTerms.Object,WorksVocabularies::WorksTerms.GenericWork]
20
+ type [Hydra::PCDM::Vocab::PCDMTerms.Object, Vocab::WorksTerms.GenericWork]
21
21
  include Hydra::Works::BlockChildObjects
22
22
 
23
- filters_association :members, as: :child_generic_works, condition: :works_generic_work?
23
+ filters_association :members, as: :generic_works, condition: :works_generic_work?
24
24
  filters_association :members, as: :generic_files, condition: :works_generic_file?
25
25
  end
26
26
 
27
- def contains= files
28
- raise NoMethodError, "works can not directly contain files. You must add a GenericFile to the work's members and add files to that GenericFile."
29
- end
30
-
31
27
  # @return [Boolean] whether this instance is a Hydra::Works Collection.
32
28
  def works_collection?
33
29
  false
@@ -43,17 +39,46 @@ module Hydra::Works
43
39
  false
44
40
  end
45
41
 
46
- def parents
42
+ def member_of
47
43
  aggregated_by
48
44
  end
49
45
 
50
- def parent_generic_works
46
+ def parents
47
+ warn '[DEPRECATION] `parents` is deprecated in Hydra::Works. Please use `member_of` instead. This has a target date for removal of 10-31-2015'
48
+ member_of
49
+ end
50
+
51
+ def in_generic_works
51
52
  aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::GenericWorkBehavior) }
52
53
  end
53
54
 
54
- def parent_collections
55
+ def parent_generic_works
56
+ warn '[DEPRECATION] `parent_generic_works` is deprecated in Hydra::Works. Please use `in_generic_works` instead. This has a target date for removal of 10-31-2015'
57
+ in_generic_works
58
+ end
59
+
60
+ def in_collections
55
61
  aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::CollectionBehavior) }
56
62
  end
57
63
 
64
+ def parent_collections
65
+ warn '[DEPRECATION] `parent_collections` is deprecated in Hydra::Works. Please use `in_collections` instead. This has a target date for removal of 10-31-2015'
66
+ in_collections
67
+ end
68
+
69
+ def child_generic_works
70
+ warn '[DEPRECATION] `child_generic_works` is deprecated in Hydra::Works. Please use `generic_works` instead. This has a target date for removal of 10-31-2015'
71
+ generic_works
72
+ end
73
+
74
+ def child_generic_works=(new_generic_works)
75
+ warn '[DEPRECATION] `child_generic_works=` is deprecated in Hydra::Works. Please use `generic_works=` instead. This has a target date for removal of 10-31-2015'
76
+ self.generic_works = new_generic_works
77
+ end
78
+
79
+ def child_generic_work_ids
80
+ warn '[DEPRECATION] `child_generic_work_ids` is deprecated in Hydra::Works. Please use `generic_work_ids` instead. This has a target date for removal of 10-31-2015'
81
+ generic_work_ids
82
+ end
58
83
  end
59
84
  end
@@ -1,7 +1,6 @@
1
1
  module Hydra::Works
2
2
  # Namespace for Modules with functionality specific to GenericFiles
3
3
  module GenericFile
4
-
5
4
  extend ActiveSupport::Concern
6
5
 
7
6
  autoload :Derivatives, 'hydra/works/models/concerns/generic_file/derivatives'
@@ -10,11 +9,9 @@ module Hydra::Works
10
9
  autoload :VersionedContent, 'hydra/works/models/concerns/generic_file/versioned_content'
11
10
  autoload :VirusCheck, 'hydra/works/models/concerns/generic_file/virus_check'
12
11
 
13
-
14
12
  # Base class for creating objects that behave like Hydra::Works::GenericFiles
15
13
  class Base < ActiveFedora::Base
16
14
  include Hydra::Works::GenericFileBehavior
17
15
  end
18
-
19
16
  end
20
17
  end
@@ -1,6 +1,5 @@
1
1
  module Hydra::Works
2
2
  class AddFileToGenericFile
3
-
4
3
  # Adds a file to the generic_file
5
4
  # @param [Hydra::PCDM::GenericFile::Base] generic_file the file will be added to
6
5
  # @param [IO,File,Rack::Multipart::UploadedFile, #read] object that will be the contents. If file responds to :mime_type, :content_type, :original_name, or :original_filename, those will be called to provide metadata.
@@ -9,10 +8,10 @@ module Hydra::Works
9
8
  # @param [Boolean] versioning whether to create new version entries (only applicable if +type+ corresponds to a versionable file)
10
9
 
11
10
  def self.call(generic_file, file, type, update_existing: true, versioning: true)
12
- raise ArgumentError, "supplied object must be a generic file" unless generic_file.works_generic_file?
13
- raise ArgumentError, "supplied file must respond to read" unless file.respond_to? :read
11
+ fail ArgumentError, 'supplied object must be a generic file' unless generic_file.works_generic_file?
12
+ fail ArgumentError, 'supplied file must respond to read' unless file.respond_to? :read
14
13
 
15
- # TODO required as a workaround for https://github.com/projecthydra/active_fedora/pull/858
14
+ # TODO: required as a workaround for https://github.com/projecthydra/active_fedora/pull/858
16
15
  generic_file.save unless generic_file.persisted?
17
16
 
18
17
  updater_class = versioning ? VersioningUpdater : Updater
@@ -48,7 +47,7 @@ module Hydra::Works
48
47
  end
49
48
  end
50
49
 
51
- def attach_attributes(file)
50
+ def attach_attributes(file)
52
51
  current_file.content = file
53
52
  current_file.original_name = determine_original_name(file)
54
53
  current_file.mime_type = determine_mime_type(file)
@@ -64,7 +63,7 @@ module Hydra::Works
64
63
  elsif file.respond_to? :path
65
64
  return Hydra::PCDM::GetMimeTypeForFile.call(file.path)
66
65
  else
67
- return "application/octet-stream"
66
+ return 'application/octet-stream'
68
67
  end
69
68
  end
70
69
 
@@ -78,7 +77,7 @@ module Hydra::Works
78
77
  elsif file.respond_to? :path
79
78
  return ::File.basename(file.path)
80
79
  else
81
- return ""
80
+ return ''
82
81
  end
83
82
  end
84
83
 
@@ -87,10 +86,10 @@ module Hydra::Works
87
86
  def find_or_create_file(type, update_existing)
88
87
  if type.instance_of? Symbol
89
88
  association = generic_file.association(type)
90
- raise ArgumentError, "you're attempting to add a file to a generic_file using '#{type}' association but the generic_file does not have an association called '#{type}''" unless association
89
+ fail ArgumentError, "you're attempting to add a file to a generic_file using '#{type}' association but the generic_file does not have an association called '#{type}''" unless association
91
90
 
92
91
  current_file = association.reader if update_existing
93
- current_file ||= association.build
92
+ current_file || association.build
94
93
  else
95
94
  current_file = generic_file.filter_files_by_type(type_to_uri(type)).first if update_existing
96
95
  unless current_file
@@ -112,16 +111,15 @@ module Hydra::Works
112
111
  when String
113
112
  ::RDF::URI(type)
114
113
  else
115
- raise ArgumentError, "Invalid file type. You must submit a URI or a symbol."
114
+ fail ArgumentError, 'Invalid file type. You must submit a URI or a symbol.'
116
115
  end
117
116
  end
118
- end
117
+ end
119
118
 
120
- class VersioningUpdater < Updater
121
- def update(*)
122
- super && current_file.create_version
123
- end
119
+ class VersioningUpdater < Updater
120
+ def update(*)
121
+ super && current_file.create_version
124
122
  end
123
+ end
125
124
  end
126
125
  end
127
-