curation_concerns 1.0.0.beta1 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/app/actors/curation_concerns/actors/abstract_actor.rb +30 -0
  3. data/app/actors/curation_concerns/actors/actor_stack.rb +29 -0
  4. data/app/actors/curation_concerns/actors/add_to_collection_actor.rb +40 -0
  5. data/app/actors/curation_concerns/actors/apply_order_actor.rb +26 -0
  6. data/app/actors/curation_concerns/actors/assign_identifier_actor.rb +9 -0
  7. data/app/actors/curation_concerns/actors/assign_representative_actor.rb +20 -0
  8. data/app/actors/curation_concerns/actors/attach_files_actor.rb +41 -0
  9. data/app/actors/curation_concerns/actors/base_actor.rb +78 -0
  10. data/app/actors/curation_concerns/actors/embargo_actor.rb +21 -0
  11. data/app/actors/curation_concerns/actors/file_actor.rb +81 -0
  12. data/app/actors/curation_concerns/actors/file_set_actor.rb +159 -0
  13. data/app/actors/curation_concerns/actors/interpret_visibility_actor.rb +125 -0
  14. data/app/actors/curation_concerns/actors/lease_actor.rb +21 -0
  15. data/app/actors/curation_concerns/actors/root_actor.rb +19 -0
  16. data/app/actors/curation_concerns/actors/work_actor_behavior.rb +12 -0
  17. data/app/actors/curation_concerns/actors.rb +18 -0
  18. data/app/controllers/concerns/curation_concerns/embargoes_controller_behavior.rb +2 -2
  19. data/app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb +21 -15
  20. data/app/controllers/concerns/curation_concerns/leases_controller_behavior.rb +2 -2
  21. data/app/forms/curation_concerns/forms/collection_edit_form.rb +1 -1
  22. data/app/forms/curation_concerns/forms/file_set_edit_form.rb +2 -2
  23. data/app/forms/curation_concerns/forms/work_form.rb +1 -1
  24. data/app/forms/curation_concerns/forms.rb +14 -0
  25. data/app/helpers/curation_concerns/collections_helper.rb +10 -8
  26. data/app/jobs/audit_job.rb +0 -2
  27. data/app/jobs/characterize_job.rb +1 -1
  28. data/app/jobs/create_derivatives_job.rb +1 -1
  29. data/app/jobs/import_url_job.rb +2 -2
  30. data/app/jobs/ingest_file_job.rb +1 -1
  31. data/app/jobs/ingest_local_file_job.rb +2 -2
  32. data/app/jobs/resolrize_job.rb +0 -2
  33. data/app/jobs/visibility_copy_job.rb +0 -2
  34. data/app/models/concerns/curation_concerns/basic_metadata.rb +1 -1
  35. data/app/models/concerns/curation_concerns/characterization.rb +41 -0
  36. data/app/models/concerns/curation_concerns/collection.rb +0 -1
  37. data/app/models/concerns/curation_concerns/file_set_behavior.rb +1 -1
  38. data/app/models/concerns/curation_concerns/solr_document_behavior.rb +6 -5
  39. data/app/presenters/curation_concerns/collection_presenter.rb +1 -1
  40. data/app/presenters/curation_concerns/file_set_presenter.rb +1 -1
  41. data/app/presenters/curation_concerns/presents_attributes.rb +1 -1
  42. data/app/renderers/curation_concerns/renderers/attribute_renderer.rb +100 -0
  43. data/app/renderers/curation_concerns/renderers/configured_microdata.rb +42 -0
  44. data/app/renderers/renderers.rb +11 -0
  45. data/app/services/curation_concerns/actors/actor_factory.rb +26 -0
  46. data/app/services/curation_concerns/curation_concern.rb +1 -1
  47. data/app/services/curation_concerns/thumbnail_path_service.rb +1 -1
  48. data/app/views/collections/show.html.erb +7 -3
  49. data/app/views/curation_concerns/base/_representative_media.html.erb +1 -1
  50. data/app/views/curation_concerns/file_sets/show.html.erb +1 -1
  51. data/config/locales/curation_concerns.en.yml +4 -4
  52. data/curation_concerns.gemspec +1 -4
  53. data/lib/curation_concerns/configuration.rb +7 -0
  54. data/lib/curation_concerns/version.rb +1 -1
  55. data/lib/generators/curation_concerns/templates/catalog_controller.rb +4 -4
  56. data/lib/generators/curation_concerns/work/templates/actor.rb.erb +2 -2
  57. data/lib/generators/curation_concerns/work/templates/actor_spec.rb.erb +1 -1
  58. data/lib/generators/curation_concerns/work/work_generator.rb +2 -2
  59. data/spec/actors/curation_concerns/add_to_collections_actor_spec.rb +6 -6
  60. data/spec/actors/curation_concerns/embargo_actor_spec.rb +1 -1
  61. data/spec/actors/curation_concerns/file_actor_spec.rb +1 -1
  62. data/spec/actors/curation_concerns/file_set_actor_spec.rb +11 -10
  63. data/spec/actors/curation_concerns/interpret_visibility_actor_spec.rb +6 -6
  64. data/spec/actors/curation_concerns/lease_actor_spec.rb +1 -1
  65. data/spec/actors/curation_concerns/work_actor_spec.rb +1 -1
  66. data/spec/controllers/curation_concerns/collections_controller_spec.rb +3 -3
  67. data/spec/controllers/curation_concerns/file_sets_controller_spec.rb +4 -4
  68. data/spec/controllers/embargoes_controller_spec.rb +1 -1
  69. data/spec/controllers/leases_controller_spec.rb +1 -1
  70. data/spec/factories/generic_works.rb +1 -1
  71. data/spec/features/add_file_spec.rb +1 -1
  72. data/spec/features/work_generator_spec.rb +1 -1
  73. data/spec/forms/collection_edit_form_spec.rb +2 -2
  74. data/spec/forms/file_set_edit_form_spec.rb +1 -1
  75. data/spec/forms/work_form_spec.rb +2 -2
  76. data/spec/indexers/file_set_indexer_spec.rb +12 -9
  77. data/spec/jobs/import_url_job_spec.rb +2 -2
  78. data/spec/jobs/ingest_local_file_job_spec.rb +1 -1
  79. data/spec/models/curation_concerns/collection_behavior_spec.rb +12 -3
  80. data/spec/models/file_set_spec.rb +25 -19
  81. data/spec/presenters/curation_concerns/collection_presenter_spec.rb +1 -1
  82. data/spec/presenters/curation_concerns/file_set_presenter_spec.rb +1 -1
  83. data/spec/presenters/curation_concerns/work_show_presenter_spec.rb +2 -2
  84. data/spec/renderers/curation_concerns/{attribute_renderer_spec.rb → renderers/attribute_renderer_spec.rb} +2 -2
  85. data/spec/services/curation_concern_spec.rb +1 -1
  86. data/spec/services/thumbnail_path_service_spec.rb +13 -9
  87. data/spec/support/curation_concerns/factory_helpers.rb +18 -0
  88. metadata +28 -50
  89. data/app/actors/curation_concerns/abstract_actor.rb +0 -28
  90. data/app/actors/curation_concerns/actor_stack.rb +0 -27
  91. data/app/actors/curation_concerns/add_to_collection_actor.rb +0 -38
  92. data/app/actors/curation_concerns/apply_order_actor.rb +0 -24
  93. data/app/actors/curation_concerns/assign_identifier_actor.rb +0 -7
  94. data/app/actors/curation_concerns/assign_representative_actor.rb +0 -18
  95. data/app/actors/curation_concerns/attach_files_actor.rb +0 -39
  96. data/app/actors/curation_concerns/base_actor.rb +0 -76
  97. data/app/actors/curation_concerns/embargo_actor.rb +0 -19
  98. data/app/actors/curation_concerns/file_actor.rb +0 -79
  99. data/app/actors/curation_concerns/file_set_actor.rb +0 -157
  100. data/app/actors/curation_concerns/interpret_visibility_actor.rb +0 -123
  101. data/app/actors/curation_concerns/lease_actor.rb +0 -19
  102. data/app/actors/curation_concerns/root_actor.rb +0 -17
  103. data/app/actors/curation_concerns/work_actor_behavior.rb +0 -8
  104. data/app/renderers/curation_concerns/attribute_renderer.rb +0 -98
  105. data/app/renderers/curation_concerns/configured_microdata.rb +0 -40
  106. data/app/services/curation_concerns/actor_factory.rb +0 -24
@@ -1,76 +0,0 @@
1
- module CurationConcerns
2
- # The CurationConcern base actor responds to two primary actions:
3
- # * #create
4
- # * #update
5
- # it must instantiate the next actor in the chain and instantiate it.
6
- # it should respond to curation_concern, user and attributes.
7
- class BaseActor < AbstractActor
8
- attr_reader :cloud_resources
9
-
10
- def create(attributes)
11
- @cloud_resources = attributes.delete(:cloud_resources.to_s)
12
- apply_creation_data_to_curation_concern
13
- apply_save_data_to_curation_concern(attributes)
14
- next_actor.create(attributes) && save && run_callbacks(:after_create_concern)
15
- end
16
-
17
- def update(attributes)
18
- apply_update_data_to_curation_concern
19
- apply_save_data_to_curation_concern(attributes)
20
- next_actor.update(attributes) && save && run_callbacks(:after_update_metadata)
21
- end
22
-
23
- protected
24
-
25
- def run_callbacks(hook)
26
- CurationConcerns.config.callback.run(hook, curation_concern, user)
27
- true
28
- end
29
-
30
- def apply_creation_data_to_curation_concern
31
- apply_depositor_metadata
32
- apply_deposit_date
33
- end
34
-
35
- def apply_update_data_to_curation_concern
36
- true
37
- end
38
-
39
- def apply_depositor_metadata
40
- curation_concern.apply_depositor_metadata(user.user_key)
41
- curation_concern.edit_users += [user.user_key]
42
- end
43
-
44
- def apply_deposit_date
45
- curation_concern.date_uploaded = CurationConcerns::TimeService.time_in_utc
46
- end
47
-
48
- def save
49
- curation_concern.save
50
- end
51
-
52
- def apply_save_data_to_curation_concern(attributes)
53
- attributes[:rights] = Array.wrap(attributes[:rights]) if attributes.key? :rights
54
- remove_blank_attributes!(attributes)
55
- curation_concern.attributes = attributes.symbolize_keys
56
- curation_concern.date_modified = CurationConcerns::TimeService.time_in_utc
57
- end
58
-
59
- # If any attributes are blank remove them
60
- # e.g.:
61
- # self.attributes = { 'title' => ['first', 'second', ''] }
62
- # remove_blank_attributes!
63
- # self.attributes
64
- # => { 'title' => ['first', 'second'] }
65
- def remove_blank_attributes!(attributes)
66
- multivalued_form_attributes(attributes).each_with_object(attributes) do |(k, v), h|
67
- h[k] = v.instance_of?(Array) ? v.select(&:present?) : v
68
- end
69
- end
70
-
71
- # Return the hash of attributes that are multivalued and not uploaded files
72
- def multivalued_form_attributes(attributes)
73
- attributes.select { |_, v| v.respond_to?(:select) && !v.respond_to?(:read) }
74
- end
75
- end
76
- end
@@ -1,19 +0,0 @@
1
- module CurationConcerns
2
- class EmbargoActor
3
- attr_reader :work
4
-
5
- # @param [Hydra::Works::Work] work
6
- def initialize(work)
7
- @work = work
8
- end
9
-
10
- # Update the visibility of the work to match the correct state of the embargo, then clear the embargo date, etc.
11
- # Saves the embargo and the work
12
- def destroy
13
- work.embargo_visibility! # If the embargo has lapsed, update the current visibility.
14
- work.deactivate_embargo!
15
- work.embargo.save!
16
- work.save!
17
- end
18
- end
19
- end
@@ -1,79 +0,0 @@
1
- module CurationConcerns
2
- # actions for a file identified by file_set and relation (maps to use predicate)
3
- class FileActor
4
- attr_reader :file_set, :relation, :user
5
-
6
- # @param [FileSet] file_set the parent FileSet
7
- # @param [String] relation the type/use for the file.
8
- # @param [User] user the user to record as the Agent acting upon the file
9
- def initialize(file_set, relation, user)
10
- @file_set = file_set
11
- @relation = relation
12
- @user = user
13
- end
14
-
15
- # Puts the uploaded content into a staging directory. Then kicks off a
16
- # job to characterize and create derivatives with this on disk variant.
17
- # Simultaneously moving a preservation copy to the repostiory.
18
- # TODO: create a job to monitor this directory and prune old files that
19
- # have made it to the repo
20
- # @param [File, ActionDigest::HTTP::UploadedFile, Tempfile] file the file to save in the repository
21
- def ingest_file(file)
22
- working_file = copy_file_to_working_directory(file, file_set.id)
23
- mime_type = file.respond_to?(:content_type) ? file.content_type : nil
24
- IngestFileJob.perform_later(file_set, working_file, mime_type, user, relation)
25
- make_derivative(file_set, working_file)
26
- true
27
- end
28
-
29
- def revert_to(revision_id)
30
- repository_file = file_set.send(relation.to_sym)
31
- repository_file.restore_version(revision_id)
32
-
33
- return false unless file_set.save
34
-
35
- CurationConcerns::VersioningService.create(repository_file, user)
36
-
37
- # Retrieve a copy of the orginal file from the repository
38
- working_file = copy_repository_resource_to_working_directory(repository_file)
39
- make_derivative(file_set, working_file)
40
- true
41
- end
42
-
43
- private
44
-
45
- def make_derivative(file_set, working_file)
46
- CharacterizeJob.perform_later(file_set, working_file)
47
- end
48
-
49
- # @param [File, ActionDispatch::Http::UploadedFile] file
50
- # @param [String] id the identifer of the FileSet
51
- # @return [String] path of the working file
52
- def copy_file_to_working_directory(file, id)
53
- file_name = file.respond_to?(:original_filename) ? file.original_filename : ::File.basename(file)
54
- copy_stream_to_working_directory(id, file_name, file)
55
- end
56
-
57
- # @param [ActiveFedora::File] file the resource in the repo
58
- # @return [String] path of the working file
59
- def copy_repository_resource_to_working_directory(file)
60
- copy_stream_to_working_directory(file_set.id, file.original_name, StringIO.new(file.content))
61
- end
62
-
63
- # @param [String] id the identifer
64
- # @param [String] name the file name
65
- # @param [#read] stream the stream to copy to the working directory
66
- # @return [String] path of the working file
67
- def copy_stream_to_working_directory(id, name, stream)
68
- working_path = full_filename(id, name)
69
- FileUtils.mkdir_p(File.dirname(working_path))
70
- IO.copy_stream(stream, working_path)
71
- working_path
72
- end
73
-
74
- def full_filename(id, original_name)
75
- pair = id.scan(/..?/).first(4)
76
- File.join(CurationConcerns.config.working_path, *pair, original_name)
77
- end
78
- end
79
- end
@@ -1,157 +0,0 @@
1
- module CurationConcerns
2
- # Actions are decoupled from controller logic so that they may be called from a controller or a background job.
3
- class FileSetActor
4
- include CurationConcerns::Lockable
5
-
6
- attr_reader :file_set, :user, :attributes
7
-
8
- def initialize(file_set, user)
9
- @file_set = file_set
10
- @user = user
11
- end
12
-
13
- # Adds the appropriate metadata, visibility and relationships to file_set
14
- #
15
- # *Note*: In past versions of Sufia this method did not perform a save because it is mainly used in conjunction with
16
- # create_content, which also performs a save. However, due to the relationship between Hydra::PCDM objects,
17
- # we have to save both the parent work and the file_set in order to record the "metadata" relationship
18
- # between them.
19
- # @param [ActiveFedora::Base] work the parent work that will contain the file_set.
20
- # @param [Hash] file_set specifying the visibility, lease and/or embargo of the file set. If you don't provide at least one of visibility, embargo_release_date or lease_expiration_date, visibility will be copied from the parent.
21
-
22
- def create_metadata(work, file_set_params = {})
23
- file_set.apply_depositor_metadata(user)
24
- now = CurationConcerns::TimeService.time_in_utc
25
- file_set.date_uploaded = now
26
- file_set.date_modified = now
27
- file_set.creator = [user.user_key]
28
-
29
- ActorStack.new(file_set, user, [InterpretVisibilityActor]).create(file_set_params) if assign_visibility?(file_set_params)
30
- attach_file_to_work(work, file_set, file_set_params) if work
31
- yield(file_set) if block_given?
32
- end
33
-
34
- # @param [File, ActionDigest::HTTP::UploadedFile, Tempfile] file the file uploaded by the user.
35
- # @param [String] relation ('original_file')
36
- def create_content(file, relation = 'original_file')
37
- # If the file set doesn't have a title or label assigned, set a default.
38
- file_set.label ||= file.respond_to?(:original_filename) ? file.original_filename : ::File.basename(file)
39
- file_set.title = [file_set.label] if file_set.title.blank?
40
-
41
- # Need to save the file_set in order to get an id
42
- return false unless file_set.save
43
-
44
- file_actor_class.new(file_set, relation, user).ingest_file(file)
45
- true
46
- end
47
-
48
- # @param [String] revision_id the revision to revert to
49
- # @param [String] relation ('original_file')
50
- def revert_content(revision_id, relation = 'original_file')
51
- file_actor = file_actor_class.new(file_set, relation, user)
52
- if file_actor.revert_to(revision_id)
53
- CurationConcerns.config.callback.run(:after_revert_content, file_set, user, revision_id)
54
- true
55
- else
56
- false
57
- end
58
- end
59
-
60
- # @param [File, ActionDigest::HTTP::UploadedFile, Tempfile] file the file uploaded by the user.
61
- # @param [String] relation ('original_file')
62
- def update_content(file, relation = 'original_file')
63
- file_actor_class.new(file_set, relation, user).ingest_file(file)
64
- CurationConcerns.config.callback.run(:after_update_content, file_set, user)
65
- true
66
- end
67
-
68
- def update_metadata(attributes)
69
- stack = ActorStack.new(file_set,
70
- user,
71
- [InterpretVisibilityActor, BaseActor])
72
- stack.update(attributes)
73
- end
74
-
75
- def destroy
76
- unlink_from_work
77
- file_set.destroy
78
- CurationConcerns.config.callback.run(:after_destroy, file_set.id, user)
79
- end
80
-
81
- def file_actor_class
82
- CurationConcerns::FileActor
83
- end
84
-
85
- private
86
-
87
- # Takes an optional block and executes the block if the save was successful.
88
- # returns false if the save was unsuccessful
89
- def save
90
- save_tries = 0
91
- begin
92
- return false unless file_set.save
93
- rescue RSolr::Error::Http => error
94
- ActiveFedora::Base.logger.warn "CurationConcerns::FileSetActor#save Caught RSOLR error #{error.inspect}"
95
- save_tries += 1
96
- # fail for good if the tries is greater than 3
97
- raise error if save_tries >= 3
98
- sleep 0.01
99
- retry
100
- end
101
- yield if block_given?
102
- true
103
- end
104
-
105
- # Adds a FileSet to the work using ore:Aggregations.
106
- # Locks to ensure that only one process is operating on
107
- # the list at a time.
108
- def attach_file_to_work(work, file_set, file_set_params)
109
- acquire_lock_for(work.id) do
110
- # Ensure we have an up-to-date copy of the members association, so
111
- # that we append to the end of the list.
112
- work.reload unless work.new_record?
113
- unless assign_visibility?(file_set_params)
114
- copy_visibility(work, file_set)
115
- end
116
- work.ordered_members << file_set
117
- set_representative(work, file_set)
118
- set_thumbnail(work, file_set)
119
-
120
- # Save the work so the association between the work and the file_set is persisted (head_id)
121
- work.save
122
- end
123
- CurationConcerns.config.callback.run(:after_create_fileset, file_set, user)
124
- end
125
-
126
- def assign_visibility?(file_set_params = {})
127
- !((file_set_params || {}).keys & %w(visibility embargo_release_date lease_expiration_date)).empty?
128
- end
129
-
130
- # copy visibility from source_concern to destination_concern
131
- def copy_visibility(source_concern, destination_concern)
132
- destination_concern.visibility = source_concern.visibility
133
- end
134
-
135
- def set_representative(work, file_set)
136
- return unless work.representative_id.blank?
137
- work.representative = file_set
138
- end
139
-
140
- def set_thumbnail(work, file_set)
141
- return unless work.thumbnail_id.blank?
142
- work.thumbnail = file_set
143
- end
144
-
145
- def unlink_from_work
146
- work = file_set.parent
147
- return unless work && (work.thumbnail_id == file_set.id || work.representative_id == file_set.id)
148
- # This is required to clear the thumbnail_id and representative_id
149
- # fields on the work and force it to be re-solrized. Although
150
- # ActiveFedora clears the children nodes it leaves the work's
151
- # thumbnail_id and representative_id fields in Solr populated.
152
- work.thumbnail = nil if work.thumbnail_id == file_set.id
153
- work.representative = nil if work.representative_id == file_set.id
154
- work.save!
155
- end
156
- end
157
- end
@@ -1,123 +0,0 @@
1
- module CurationConcerns
2
- class InterpretVisibilityActor < AbstractActor
3
- class Intention
4
- def initialize(attributes)
5
- @attributes = attributes
6
- end
7
-
8
- # returns a copy of attributes with the necessary params removed
9
- # If the lease or embargo is valid, or if they selected something besides lease
10
- # or embargo, remove all the params.
11
- def sanitize_params
12
- if valid_lease?
13
- @attributes.except(:visibility,
14
- :embargo_release_date,
15
- :visibility_during_embargo,
16
- :visibility_after_embargo)
17
- elsif valid_embargo?
18
- @attributes.except(:visibility,
19
- :lease_expiration_date,
20
- :visibility_during_lease,
21
- :visibility_after_lease)
22
- elsif !wants_lease? && !wants_embargo?
23
- @attributes.except(:lease_expiration_date,
24
- :visibility_during_lease,
25
- :visibility_after_lease,
26
- :embargo_release_date,
27
- :visibility_during_embargo,
28
- :visibility_after_embargo)
29
- else
30
- @attributes
31
- end
32
- end
33
-
34
- def wants_lease?
35
- visibility == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE
36
- end
37
-
38
- def wants_embargo?
39
- visibility == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO
40
- end
41
-
42
- def valid_lease?
43
- wants_lease? && @attributes[:lease_expiration_date].present?
44
- end
45
-
46
- def valid_embargo?
47
- wants_embargo? && @attributes[:embargo_release_date].present?
48
- end
49
-
50
- def lease_params
51
- [:lease_expiration_date,
52
- :visibility_during_lease,
53
- :visibility_after_lease].map { |key| @attributes[key] }
54
- end
55
-
56
- def embargo_params
57
- [:embargo_release_date,
58
- :visibility_during_embargo,
59
- :visibility_after_embargo].map { |key| @attributes[key] }
60
- end
61
-
62
- private
63
-
64
- def visibility
65
- @attributes[:visibility]
66
- end
67
- end
68
-
69
- def create(attributes)
70
- @intention = Intention.new(attributes)
71
- attributes = @intention.sanitize_params
72
- validate && apply_visibility(attributes) && next_actor.create(attributes)
73
- end
74
-
75
- def update(attributes)
76
- @intention = Intention.new(attributes)
77
- attributes = @intention.sanitize_params
78
- validate && apply_visibility(attributes) && next_actor.update(attributes)
79
- end
80
-
81
- private
82
-
83
- def validate
84
- validate_lease && validate_embargo
85
- end
86
-
87
- def apply_visibility(attributes)
88
- result = apply_lease && apply_embargo
89
- if attributes[:visibility]
90
- curation_concern.visibility = attributes[:visibility]
91
- end
92
- result
93
- end
94
-
95
- def validate_lease
96
- return true unless @intention.wants_lease? && !@intention.valid_lease?
97
- curation_concern.errors.add(:visibility, 'When setting visibility to "lease" you must also specify lease expiration date.')
98
- false
99
- end
100
-
101
- def validate_embargo
102
- return true unless @intention.wants_embargo? && !@intention.valid_embargo?
103
- curation_concern.errors.add(:visibility, 'When setting visibility to "embargo" you must also specify embargo release date.')
104
- false
105
- end
106
-
107
- # If they want a lease, we can assume it's valid
108
- def apply_lease
109
- return true unless @intention.wants_lease?
110
- curation_concern.apply_lease(*@intention.lease_params)
111
- return unless curation_concern.lease
112
- curation_concern.lease.save # see https://github.com/projecthydra/hydra-head/issues/226
113
- end
114
-
115
- # If they want an embargo, we can assume it's valid
116
- def apply_embargo
117
- return true unless @intention.wants_embargo?
118
- curation_concern.apply_embargo(*@intention.embargo_params)
119
- return unless curation_concern.embargo
120
- curation_concern.embargo.save # see https://github.com/projecthydra/hydra-head/issues/226
121
- end
122
- end
123
- end
@@ -1,19 +0,0 @@
1
- module CurationConcerns
2
- class LeaseActor
3
- attr_reader :work
4
-
5
- # @param [Hydra::Works::Work] work
6
- def initialize(work)
7
- @work = work
8
- end
9
-
10
- # Update the visibility of the work to match the correct state of the lease, then clear the lease date, etc.
11
- # Saves the lease and the work
12
- def destroy
13
- work.lease_visibility! # If the lease has lapsed, update the current visibility.
14
- work.deactivate_lease!
15
- work.lease.save!
16
- work.save!
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- module CurationConcerns
2
- class RootActor
3
- attr_reader :curation_concern, :user, :cloud_resources
4
- def initialize(curation_concern, user, _more_actors)
5
- @curation_concern = curation_concern
6
- @user = user
7
- end
8
-
9
- def create(_)
10
- true
11
- end
12
-
13
- def update(_)
14
- true
15
- end
16
- end
17
- end
@@ -1,8 +0,0 @@
1
- module CurationConcerns::WorkActorBehavior
2
- extend ActiveSupport::Concern
3
- extend Deprecation
4
-
5
- included do
6
- Deprecation.warn(CurationConcerns::WorkActorBehavior, "CurationConcerns::WorkActorBehavior is deprecated and will be removed in CurationConcerns 1.0")
7
- end
8
- end
@@ -1,98 +0,0 @@
1
- require "rails_autolink/helpers"
2
-
3
- module CurationConcerns
4
- class AttributeRenderer
5
- include ActionView::Helpers::UrlHelper
6
- include ActionView::Helpers::TranslationHelper
7
- include ActionView::Helpers::TextHelper
8
- include ConfiguredMicrodata
9
-
10
- attr_reader :field, :values, :options
11
-
12
- # @param [Symbol] field
13
- # @param [Array] values
14
- # @param [Hash] options
15
- def initialize(field, values, options = {})
16
- @field = field
17
- @values = values
18
- @options = options
19
- end
20
-
21
- # Draw the table row for the attribute
22
- def render
23
- markup = ''
24
-
25
- return markup if !values.present? && !options[:include_empty]
26
- markup << %(<tr><th>#{label}</th>\n<td><ul class='tabular'>)
27
- attributes = microdata_object_attributes(field).merge(class: "attribute #{field}")
28
- Array.wrap(values).each do |value|
29
- markup << "<li#{html_attributes(attributes)}>#{attribute_value_to_html(value.to_s)}</li>"
30
- end
31
- markup << %(</ul></td></tr>)
32
- markup.html_safe
33
- end
34
-
35
- # @return The human-readable label for this field.
36
- # @note This is a central location for determining the label of a field
37
- # name. Can be overridden if more complicated logic is needed.
38
- def label
39
- translate(
40
- :"blacklight.search.fields.show.#{field}",
41
- default: [:"blacklight.search.fields.#{field}", options.fetch(:label, field.to_s.humanize)])
42
- end
43
-
44
- private
45
-
46
- def attribute_value_to_html(value)
47
- if field == :rights
48
- rights_attribute_to_html(value)
49
- elsif microdata_value_attributes(field).present?
50
- "<span#{html_attributes(microdata_value_attributes(field))}>#{li_value(value)}</span>"
51
- else
52
- li_value(value)
53
- end
54
- end
55
-
56
- def html_attributes(attributes)
57
- buffer = ""
58
- attributes.each do |k, v|
59
- buffer << " #{k}"
60
- buffer << %(="#{v}") unless v.blank?
61
- end
62
- buffer
63
- end
64
-
65
- def search_field
66
- options.fetch(:search_field, field)
67
- end
68
-
69
- def li_value(value)
70
- if options[:catalog_search_link]
71
- link_to(ERB::Util.h(value), search_path(value))
72
- else
73
- auto_link(ERB::Util.h(value))
74
- end
75
- end
76
-
77
- def search_path(value)
78
- Rails.application.routes.url_helpers.search_catalog_path(
79
- search_field: search_field, q: ERB::Util.h(value))
80
- end
81
-
82
- ##
83
- # Special treatment for license/rights. A URL from the Sufia gem's config/sufia.rb is stored in the descMetadata of the
84
- # curation_concern. If that URL is valid in form, then it is used as a link. If it is not valid, it is used as plain text.
85
- def rights_attribute_to_html(value)
86
- begin
87
- parsed_uri = URI.parse(value)
88
- rescue
89
- nil
90
- end
91
- if parsed_uri.nil?
92
- ERB::Util.h(value)
93
- else
94
- %(<a href=#{ERB::Util.h(value)} target="_blank">#{RightsService.label(value)}</a>)
95
- end
96
- end
97
- end
98
- end
@@ -1,40 +0,0 @@
1
- module CurationConcerns
2
- module ConfiguredMicrodata
3
- def microdata?(field)
4
- return false unless CurationConcerns.config.display_microdata
5
- key = "curation_concerns.schema_org.#{field}.property"
6
- t(key, default: false)
7
- end
8
-
9
- def microdata_object?(field)
10
- return false unless CurationConcerns.config.display_microdata
11
- key = "curation_concerns.schema_org.#{field}.type"
12
- t(key, default: false)
13
- end
14
-
15
- def microdata_object_attributes(field)
16
- if microdata_object?(field)
17
- { itemprop: microdata_property(field), itemscope: '', itemtype: microdata_type(field) }
18
- else
19
- {}
20
- end
21
- end
22
-
23
- def microdata_property(field)
24
- t("curation_concerns.schema_org.#{field}.property")
25
- end
26
-
27
- def microdata_type(field)
28
- t("curation_concerns.schema_org.#{field}.type")
29
- end
30
-
31
- def microdata_value_attributes(field)
32
- if microdata?(field)
33
- key = microdata_object?(field) ? :value : :property
34
- { itemprop: t("curation_concerns.schema_org.#{field}.#{key}") }
35
- else
36
- {}
37
- end
38
- end
39
- end
40
- end
@@ -1,24 +0,0 @@
1
- module CurationConcerns
2
- class ActorFactory
3
- def self.build(curation_concern, current_user)
4
- ActorStack.new(curation_concern,
5
- current_user,
6
- stack_actors(curation_concern))
7
- end
8
-
9
- def self.stack_actors(curation_concern)
10
- [AddToCollectionActor,
11
- AssignRepresentativeActor,
12
- AttachFilesActor,
13
- ApplyOrderActor,
14
- InterpretVisibilityActor,
15
- model_actor(curation_concern),
16
- AssignIdentifierActor]
17
- end
18
-
19
- def self.model_actor(curation_concern)
20
- actor_identifier = curation_concern.class.to_s.split('::').last
21
- "CurationConcerns::#{actor_identifier}Actor".constantize
22
- end
23
- end
24
- end