hydra-works 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +17 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +14 -0
  6. data/CONTRIBUTING.md +115 -0
  7. data/Gemfile +14 -0
  8. data/LICENSE +16 -0
  9. data/README.md +80 -0
  10. data/Rakefile +23 -0
  11. data/hydra-works.gemspec +33 -0
  12. data/lib/hydra/works.rb +81 -0
  13. data/lib/hydra/works/models/collection.rb +5 -0
  14. data/lib/hydra/works/models/concerns/aggregates_collections.rb +16 -0
  15. data/lib/hydra/works/models/concerns/aggregates_generic_files.rb +20 -0
  16. data/lib/hydra/works/models/concerns/aggregates_generic_works.rb +20 -0
  17. data/lib/hydra/works/models/concerns/collection_behavior.rb +28 -0
  18. data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +22 -0
  19. data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +32 -0
  20. data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +69 -0
  21. data/lib/hydra/works/models/concerns/generic_file_behavior.rb +25 -0
  22. data/lib/hydra/works/models/concerns/generic_work_behavior.rb +30 -0
  23. data/lib/hydra/works/models/generic_file.rb +17 -0
  24. data/lib/hydra/works/models/generic_work.rb +9 -0
  25. data/lib/hydra/works/processor.rb +9 -0
  26. data/lib/hydra/works/services/collection/add_collection.rb +19 -0
  27. data/lib/hydra/works/services/collection/add_generic_work.rb +19 -0
  28. data/lib/hydra/works/services/collection/add_related_object.rb +19 -0
  29. data/lib/hydra/works/services/collection/get_collections.rb +17 -0
  30. data/lib/hydra/works/services/collection/get_generic_works.rb +17 -0
  31. data/lib/hydra/works/services/collection/get_related_objects.rb +17 -0
  32. data/lib/hydra/works/services/collection/remove_collection.rb +19 -0
  33. data/lib/hydra/works/services/collection/remove_generic_work.rb +20 -0
  34. data/lib/hydra/works/services/collection/remove_related_object.rb +19 -0
  35. data/lib/hydra/works/services/generic_file/add_file.rb +55 -0
  36. data/lib/hydra/works/services/generic_file/add_generic_file.rb +19 -0
  37. data/lib/hydra/works/services/generic_file/add_original_file.rb +11 -0
  38. data/lib/hydra/works/services/generic_file/add_related_object.rb +19 -0
  39. data/lib/hydra/works/services/generic_file/add_versioned_original_file.rb +10 -0
  40. data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +19 -0
  41. data/lib/hydra/works/services/generic_file/get_generic_files.rb +17 -0
  42. data/lib/hydra/works/services/generic_file/get_related_objects.rb +17 -0
  43. data/lib/hydra/works/services/generic_file/remove_generic_file.rb +20 -0
  44. data/lib/hydra/works/services/generic_file/remove_related_object.rb +19 -0
  45. data/lib/hydra/works/services/generic_file/upload_file.rb +32 -0
  46. data/lib/hydra/works/services/generic_work/add_generic_file.rb +19 -0
  47. data/lib/hydra/works/services/generic_work/add_generic_work.rb +19 -0
  48. data/lib/hydra/works/services/generic_work/add_related_object.rb +19 -0
  49. data/lib/hydra/works/services/generic_work/get_generic_files.rb +17 -0
  50. data/lib/hydra/works/services/generic_work/get_generic_works.rb +17 -0
  51. data/lib/hydra/works/services/generic_work/get_related_objects.rb +17 -0
  52. data/lib/hydra/works/services/generic_work/move_generic_file.rb +19 -0
  53. data/lib/hydra/works/services/generic_work/remove_generic_file.rb +20 -0
  54. data/lib/hydra/works/services/generic_work/remove_generic_work.rb +20 -0
  55. data/lib/hydra/works/services/generic_work/remove_related_object.rb +19 -0
  56. data/lib/hydra/works/version.rb +5 -0
  57. data/lib/hydra/works/vocab/works_terms.rb +12 -0
  58. data/spec/fixtures/sample-file.pdf +0 -0
  59. data/spec/fixtures/updated-file.txt +1 -0
  60. data/spec/hydra/works/models/collection_spec.rb +41 -0
  61. data/spec/hydra/works/models/concerns/file/contained_files_spec.rb +113 -0
  62. data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +12 -0
  63. data/spec/hydra/works/models/generic_file_spec.rb +45 -0
  64. data/spec/hydra/works/models/generic_work_spec.rb +50 -0
  65. data/spec/hydra/works/services/collection/add_collection_spec.rb +166 -0
  66. data/spec/hydra/works/services/collection/add_generic_work_spec.rb +155 -0
  67. data/spec/hydra/works/services/collection/add_related_object_spec.rb +149 -0
  68. data/spec/hydra/works/services/collection/get_collections_spec.rb +35 -0
  69. data/spec/hydra/works/services/collection/get_generic_works_spec.rb +35 -0
  70. data/spec/hydra/works/services/collection/get_related_objects_spec.rb +49 -0
  71. data/spec/hydra/works/services/collection/remove_collection_spec.rb +133 -0
  72. data/spec/hydra/works/services/collection/remove_generic_work_spec.rb +133 -0
  73. data/spec/hydra/works/services/collection/remove_related_object_spec.rb +128 -0
  74. data/spec/hydra/works/services/generic_file/add_file_spec.rb +28 -0
  75. data/spec/hydra/works/services/generic_file/add_generic_file_spec.rb +174 -0
  76. data/spec/hydra/works/services/generic_file/add_related_object_spec.rb +150 -0
  77. data/spec/hydra/works/services/generic_file/generate/thumbnail_spec.rb +21 -0
  78. data/spec/hydra/works/services/generic_file/get_generic_files_spec.rb +19 -0
  79. data/spec/hydra/works/services/generic_file/get_related_objects_spec.rb +45 -0
  80. data/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb +124 -0
  81. data/spec/hydra/works/services/generic_file/remove_related_object_spec.rb +123 -0
  82. data/spec/hydra/works/services/generic_file/upload_file_spec.rb +82 -0
  83. data/spec/hydra/works/services/generic_work/add_generic_file_spec.rb +156 -0
  84. data/spec/hydra/works/services/generic_work/add_generic_work_spec.rb +157 -0
  85. data/spec/hydra/works/services/generic_work/add_related_object_spec.rb +148 -0
  86. data/spec/hydra/works/services/generic_work/get_generic_files_spec.rb +35 -0
  87. data/spec/hydra/works/services/generic_work/get_generic_works_spec.rb +35 -0
  88. data/spec/hydra/works/services/generic_work/get_related_objects_spec.rb +46 -0
  89. data/spec/hydra/works/services/generic_work/move_generic_file_spec.rb +21 -0
  90. data/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb +132 -0
  91. data/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb +133 -0
  92. data/spec/hydra/works/services/generic_work/remove_related_object_spec.rb +128 -0
  93. data/spec/hydra/works_spec.rb +149 -0
  94. data/spec/spec_helper.rb +40 -0
  95. data/use-cases/conference_event_use_case.md +16 -0
  96. data/use-cases/lafayette_college_geospatial_use_case.md +80 -0
  97. data/use-cases/northwestern_adminset_use-case.md +19 -0
  98. data/use-cases/northwestern_displayset_use_case.md +23 -0
  99. data/use-cases/northwestern_playlist_use_case.md +21 -0
  100. data/use-cases/princeton_book_use_case.md +117 -0
  101. data/use-cases/scholarsphere_use_case.md +32 -0
  102. data/use-cases/stanford_data_model_use_case.md +86 -0
  103. data/use-cases/ucin_linked_resource_use_case.md +21 -0
  104. metadata +338 -0
@@ -0,0 +1,55 @@
1
+ module Hydra::Works
2
+ class AddFileToGenericFile
3
+
4
+ # Adds the original file to the work
5
+
6
+ def self.call(object, path, type, replace=false)
7
+ raise ArgumentError, "supplied object must be a generic file" unless Hydra::Works.generic_file?(object)
8
+ raise ArgumentError, "supplied path must be a string" unless path.is_a?(String)
9
+ raise ArgumentError, "supplied path to file does not exist" unless ::File.exists?(path)
10
+
11
+ if replace
12
+ current_file = object.filter_files_by_type(self.type_to_uri(type)).first
13
+ else
14
+ object.files.build
15
+ current_file = object.files.last
16
+ end
17
+
18
+ current_file.content = ::File.open(path)
19
+ current_file.original_name = ::File.basename(path)
20
+ current_file.mime_type = Hydra::PCDM::GetMimeTypeForFile.call(path)
21
+ Hydra::PCDM::AddTypeToFile.call(current_file, self.type_to_uri(type))
22
+ current_file.save if replace
23
+ object.save
24
+ object
25
+ end
26
+
27
+ private
28
+
29
+ # Returns appropriate URI for the requested type
30
+ # * Converts supported symbols to corresponding URIs
31
+ # * Converts URI strings to RDF::URI
32
+ # * Returns RDF::URI objects as-is
33
+ def self.type_to_uri(type)
34
+ if type.instance_of?(::RDF::URI)
35
+ return type
36
+ elsif type.instance_of?(Symbol)
37
+ case type
38
+ when :original_file
39
+ return ::RDF::URI("http://pcdm.org/OriginalFile")
40
+ when :thumbnail
41
+ return ::RDF::URI("http://pcdm.org/ThumbnailImage")
42
+ when :extracted_text
43
+ return ::RDF::URI("http://pcdm.org/ExtractedText")
44
+ else
45
+ raise ArgumentError, "Invalid file type. The only valid symbols for file types are :original_file, :thumbnail, and :extracted_text. You submitted #{type}. To avoid this error, use one of those symbols or submit a URI instead of a symbol."
46
+ end
47
+ elsif type.instance_of?(String)
48
+ return ::RDF::URI(type)
49
+ else
50
+ raise ArgumentError, "Invalid file type. You must submit a URI or a symbol."
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class AddGenericFileToGenericFile
3
+
4
+ ##
5
+ # Add a generic_file to a generic_file.
6
+ #
7
+ # @param [Hydra::Works::GenericFile::Base] :parent_generic_file to which to add generic_file
8
+ # @param [Hydra::Works::GenericFile::Base] :child_generic_file being added
9
+ #
10
+ # @return [Hydra::Works::GenericFile::Base] the updated hydra works generic file
11
+
12
+ def self.call( parent_generic_file, child_generic_file )
13
+ raise ArgumentError, 'parent_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? parent_generic_file
14
+ raise ArgumentError, 'child_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? child_generic_file
15
+ Hydra::PCDM::AddObjectToObject.call( parent_generic_file, child_generic_file )
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Hydra::Works
2
+ class AddOriginalFile
3
+
4
+ # Adds the original file to the work
5
+
6
+ def self.call(object, path, replace=false)
7
+ Hydra::Works::AddFileToGenericFile.call(object, path, ::RDF::URI("http://pcdm.org/OriginalFile"), replace)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class AddRelatedObjectToGenericFile
3
+
4
+ ##
5
+ # Add a related object to a generic file.
6
+ #
7
+ # @param [Hydra::Works::GenericFile::Base] :parent_generic_file to which to add the related object
8
+ # @param [Hydra::PCDM::Object] :child_related_object being added
9
+ #
10
+ # @return [Hydra::Works::GenericFile::Base] the updated hydra works generic file
11
+
12
+ def self.call( parent_generic_file, child_related_object )
13
+ raise ArgumentError, 'parent_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? parent_generic_file
14
+ raise ArgumentError, 'child_related_object must be a pcdm object' unless Hydra::PCDM.object? child_related_object
15
+ Hydra::PCDM::AddRelatedObjectToObject.call( parent_generic_file, child_related_object )
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module Hydra::Works
2
+ class AddVersionedOriginalFile
3
+
4
+ # TODO: Create a new version of the original file instead of replacing it
5
+ def self.call(object, file)
6
+
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class GenerateThumbnail
3
+
4
+ def self.call(object, content: :original_file)
5
+ raise ArgumentError, "object has no content at #{content} from which to generate a thumbnail" if object.send(content).nil?
6
+ source = object.send(content)
7
+
8
+ # Always replace the thumbnail with whatever is from the original file
9
+ if object.thumbnail.nil?
10
+ object.files.build
11
+ AddTypeToFile.call(object.files.last, ::RDF::URI("http://pcdm.org/ThumbnailImage"))
12
+ end
13
+
14
+ object.create_derivatives
15
+ object
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Hydra::Works
2
+ class GetGenericFilesFromGenericFile
3
+
4
+ ##
5
+ # Get member generic files from a generic file in order.
6
+ #
7
+ # @param [Hydra::Works::GenericFile::Base] :parent_generic_file in which the child generic files are members
8
+ #
9
+ # @return [Array<Hydra::Works::GenericFile::Base>] all member generic files
10
+
11
+ def self.call( parent_generic_file )
12
+ raise ArgumentError, 'parent_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? parent_generic_file
13
+ parent_generic_file.generic_files
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Hydra::Works
2
+ class GetRelatedObjectsFromGenericFile
3
+
4
+ ##
5
+ # Get related objects from a generic_file.
6
+ #
7
+ # @param [Hydra::Works::GenericFile::Base] :parent_generic_file to which the child objects are related
8
+ #
9
+ # @return [Array<Hydra::Works::GenericFile::Base>] all related objects
10
+
11
+ def self.call( parent_generic_file )
12
+ raise ArgumentError, 'parent_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? parent_generic_file
13
+ Hydra::PCDM::GetRelatedObjectsFromObject.call( parent_generic_file )
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Hydra::Works
2
+ class RemoveGenericFileFromGenericFile
3
+
4
+ ##
5
+ # Remove a generic_file from a generic_file.
6
+ #
7
+ # @param [Hydra::Works::GenericFile::Base] :parent_generic_file from which to remove generic_file
8
+ # @param [Hydra::Works::GenericFile::Base] :child_generic_file being removed
9
+ # @param [Fixnum] :nth_occurrence remove nth occurrence of this generic_file in the list (default=1)
10
+ #
11
+ # @return [Hydra::Works::GenericFile::Base] the updated hydra works generic file
12
+
13
+ def self.call( parent_generic_file, child_generic_file, nth_occurrence=1 )
14
+ raise ArgumentError, 'parent_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? parent_generic_file
15
+ raise ArgumentError, 'child_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? child_generic_file
16
+ Hydra::PCDM::RemoveObjectFromObject.call( parent_generic_file, child_generic_file, nth_occurrence )
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class RemoveRelatedObjectFromGenericFile
3
+
4
+ ##
5
+ # Remove an object from a generic file.
6
+ #
7
+ # @param [Hydra::Works::GenericFile::Base] :parent_generic_file from which to remove the related object
8
+ # @param [Hydra::PCDM::Object] :child_related_object being removed
9
+ #
10
+ # @return [Hydra::Works::GenericFile::Base] the updated hydra works generic file
11
+
12
+ def self.call( parent_generic_file, child_related_object )
13
+ raise ArgumentError, 'parent_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? parent_generic_file
14
+ raise ArgumentError, 'child_related_object must be a pcdm object' unless Hydra::PCDM.object? child_related_object
15
+ Hydra::PCDM::RemoveRelatedObjectFromObject.call( parent_generic_file, child_related_object )
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ module Hydra::Works
2
+ class UploadFileToGenericFile
3
+
4
+ def self.call(object, path, additional_services=[], replace=false)
5
+ raise ArgumentError, "supplied object must be a generic file" unless Hydra::Works.generic_file?(object)
6
+ raise ArgumentError, "supplied path must be a string" unless path.is_a?(String)
7
+ raise ArgumentError, "supplied path to file does not exist" unless ::File.exists?(path)
8
+
9
+ if object.original_file.nil? || object.original_file.new_record?
10
+ Hydra::Works::AddOriginalFile.call(object, path)
11
+ else
12
+ if replace
13
+ Hydra::Works::AddOriginalFile.call(object, path, replace)
14
+ else
15
+ Hydra::Works::AddVersionedOriginalFile.call(object, path)
16
+ end
17
+ end
18
+
19
+ object.save
20
+ object.reload
21
+
22
+ # Call any additional services
23
+ additional_services.each do |service|
24
+ service.call(object)
25
+ end
26
+
27
+ object.save
28
+ object
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class AddGenericFileToGenericWork
3
+
4
+ ##
5
+ # Add a generic_file to a generic_work.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work to which to add generic_work
8
+ # @param [Hydra::Works::GenericFile::Base] :child_generic_file being added
9
+ #
10
+ # @return [Hydra::Works::GenericWork::Base] the updated hydra works generic work
11
+
12
+ def self.call( parent_generic_work, child_generic_file )
13
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
14
+ raise ArgumentError, 'child_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? child_generic_file
15
+ Hydra::PCDM::AddObjectToObject.call( parent_generic_work, child_generic_file )
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class AddGenericWorkToGenericWork
3
+
4
+ ##
5
+ # Add a generic_work to a generic_work.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work to which to add generic_work
8
+ # @param [Hydra::Works::GenericWork::Base] :child_generic_work being added
9
+ #
10
+ # @return [Hydra::Works::GenericWork::Base] the updated hydra works generic work
11
+
12
+ def self.call( parent_generic_work, child_generic_work )
13
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
14
+ raise ArgumentError, 'child_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? child_generic_work
15
+ Hydra::PCDM::AddObjectToObject.call( parent_generic_work, child_generic_work )
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class AddRelatedObjectToGenericWork
3
+
4
+ ##
5
+ # Add a related object to a generic work.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work to which to add the related object
8
+ # @param [Hydra::PCDM::Object] :child_related_object being added
9
+ #
10
+ # @return [Hydra::Works::GenericWork::Base] the updated hydra works generic work
11
+
12
+ def self.call( parent_generic_work, child_related_object )
13
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
14
+ raise ArgumentError, 'child_related_object must be a pcdm object' unless Hydra::PCDM.object? child_related_object
15
+ Hydra::PCDM::AddRelatedObjectToObject.call( parent_generic_work, child_related_object )
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Hydra::Works
2
+ class GetGenericFilesFromGenericWork
3
+
4
+ ##
5
+ # Get member generic files from a generic work in order.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work in which the child generic files are members
8
+ #
9
+ # @return [Array<Hydra::Works::GenericFile::Base>] all member generic files
10
+
11
+ def self.call( parent_generic_work )
12
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
13
+ parent_generic_work.generic_files
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Hydra::Works
2
+ class GetGenericWorksFromGenericWork
3
+
4
+ ##
5
+ # Get member generic works from a generic work in order.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work in which the child generic works are members
8
+ #
9
+ # @return [Array<Hydra::Works::GenericWork::Base>] all member generic works
10
+
11
+ def self.call( parent_generic_work )
12
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
13
+ parent_generic_work.generic_works
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Hydra::Works
2
+ class GetRelatedObjectsFromGenericWork
3
+
4
+ ##
5
+ # Get related objects from a generic_work.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work to which the child objects are related
8
+ #
9
+ # @return [Array<Hydra::Works::GenericWork::Base>] all related objects
10
+
11
+ def self.call( parent_generic_work )
12
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
13
+ Hydra::PCDM::GetRelatedObjectsFromObject.call( parent_generic_work )
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class MoveGenericFileToGenericWork
3
+
4
+ ##
5
+ # Move a generic file from one generic work to another
6
+ #
7
+ # @param [Hydra::Works::GenericWork] :old_parent_work where the generic file currently lives
8
+ # @param [Hydra::Works::GenericWork] :new_parent_work where the generic file is being moved
9
+ # @param [Hydra::Works::GenericFile] :child_generic_file being moved
10
+ #
11
+ # @return [Hydra::Works::GenericWork] the destination generic work
12
+ def self.call(old_parent_work, new_parent_work, child_generic_file)
13
+ AddGenericFileToGenericWork.call(new_parent_work, child_generic_file)
14
+ RemoveGenericFileFromGenericWork.call(old_parent_work, child_generic_file)
15
+ new_parent_work
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module Hydra::Works
2
+ class RemoveGenericFileFromGenericWork
3
+
4
+ ##
5
+ # Remove a generic_file from a generic_work.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work from which to remove generic_work
8
+ # @param [Hydra::Works::GenericFile::Base] :child_generic_file being removed
9
+ # @param [Fixnum] :nth_occurrence remove nth occurrence of this generic_work in the list (default=1)
10
+ #
11
+ # @return [Hydra::Works::GenericWork::Base] the updated hydra works generic work
12
+
13
+ def self.call( parent_generic_work, child_generic_file, nth_occurrence=1 )
14
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
15
+ raise ArgumentError, 'child_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? child_generic_file
16
+ Hydra::PCDM::RemoveObjectFromObject.call( parent_generic_work, child_generic_file, nth_occurrence )
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Hydra::Works
2
+ class RemoveGenericWorkFromGenericWork
3
+
4
+ ##
5
+ # Remove a generic_work from a generic_work.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work from which to remove generic_work
8
+ # @param [Hydra::Works::GenericWork::Base] :child_generic_work being removed
9
+ # @param [Fixnum] :nth_occurrence remove nth occurrence of this generic_work in the list (default=1)
10
+ #
11
+ # @return [Hydra::Works::GenericWork::Base] the updated hydra works generic work
12
+
13
+ def self.call( parent_generic_work, child_generic_work, nth_occurrence=1 )
14
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
15
+ raise ArgumentError, 'child_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? child_generic_work
16
+ Hydra::PCDM::RemoveObjectFromObject.call( parent_generic_work, child_generic_work, nth_occurrence )
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Hydra::Works
2
+ class RemoveRelatedObjectFromGenericWork
3
+
4
+ ##
5
+ # Remove an object from a generic work.
6
+ #
7
+ # @param [Hydra::Works::GenericWork::Base] :parent_generic_work from which to remove the related object
8
+ # @param [Hydra::PCDM::Object] :child_related_object being removed
9
+ #
10
+ # @return [Hydra::Works::GenericWork::Base] the updated hydra works generic work
11
+
12
+ def self.call( parent_generic_work, child_related_object )
13
+ raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work
14
+ raise ArgumentError, 'child_related_object must be a pcdm object' unless Hydra::PCDM.object? child_related_object
15
+ Hydra::PCDM::RemoveRelatedObjectFromObject.call( parent_generic_work, child_related_object )
16
+ end
17
+
18
+ end
19
+ end