Class: Hyrax::EmbargoManager
- Inherits:
-
Object
- Object
- Hyrax::EmbargoManager
- Defined in:
- app/services/hyrax/embargo_manager.rb
Overview
Provides utilities for managing the lifecycle of an ‘Hyrax::Embargo` on a `Hyrax::Resource`.
The embargo terminology used here is as follows:
- "Release Date" is the day an embargo is scheduled to be released.
- "Under Embargo" means the embargo is "active"; i.e. that its release
date is today or later.
- "Applied" means the embargo's pre-release visibility has been set on
the resource.
- "Enforced" means the object's visibility matches the pre-release
visibility of the embargo; i.e. the embargo has been applied,
but not released.
- "Released" means the embargo's post-release visibility has been set on
the resource.
- "Deactivate" means that the existing embargo will be removed, even
if it active.
Note that an resource may be ‘#under_embargo?` even if the embargo is not be `#enforced?` (in this case, the application should seek to apply the embargo, e.g. via a scheduled job). Additionally, an embargo may be `#enforced?` after its release date (in this case, the application should seek to release the embargo).
Defined Under Namespace
Classes: NotEnforcableError, NotReleasableError
Instance Attribute Summary collapse
-
#query_service ⇒ Object
readonly
Returns the value of attribute query_service.
- #resource ⇒ Hyrax::Resource
Class Method Summary collapse
- .apply_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
- .apply_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Object
-
.create_or_update_embargo_on_members(members, work) ⇒ Object
Creates or updates an existing embargo on a member to match the embargo on the parent work rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
- .deactivate_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Boolean
- .deactivate_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Boolean
- .embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
- .release_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Boolean
- .release_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Boolean
Instance Method Summary collapse
-
#apply ⇒ Boolean
Sets the visibility of the resource to the embargo’s visibility condition.
- #apply! ⇒ void
-
#copy_embargo_to(target:) ⇒ Boolean
Copies and applies the embargo to a new (target) resource.
-
#deactivate ⇒ Boolean
Deactivates the embargo.
-
#deactivate! ⇒ Boolean
Deactivates the embargo.
- #embargo ⇒ Hyrax::Embargo
- #enforced? ⇒ Boolean
-
#initialize(resource:, query_service: Hyrax.query_service) ⇒ EmbargoManager
constructor
A new instance of EmbargoManager.
-
#nullify(force: false) ⇒ Boolean
Drop the embargo by setting its release date and visibility settings to ‘nil`.
-
#release(force: false) ⇒ Boolean
Sets the visibility of the resource to the embargo’s after embargo visibility.
- #release! ⇒ void
-
#under_embargo? ⇒ Boolean
Indicates whether the date range for the embargo’s applicability includes the present date.
Constructor Details
#initialize(resource:, query_service: Hyrax.query_service) ⇒ EmbargoManager
Returns a new instance of EmbargoManager.
92 93 94 95 |
# File 'app/services/hyrax/embargo_manager.rb', line 92 def initialize(resource:, query_service: Hyrax.query_service) @query_service = query_service self.resource = resource end |
Instance Attribute Details
#query_service ⇒ Object (readonly)
Returns the value of attribute query_service.
88 89 90 |
# File 'app/services/hyrax/embargo_manager.rb', line 88 def query_service @query_service end |
#resource ⇒ Hyrax::Resource
83 84 85 |
# File 'app/services/hyrax/embargo_manager.rb', line 83 def resource @resource end |
Class Method Details
.apply_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
98 99 100 101 |
# File 'app/services/hyrax/embargo_manager.rb', line 98 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .apply end |
.apply_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Object
103 104 105 106 |
# File 'app/services/hyrax/embargo_manager.rb', line 103 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .apply! end |
.create_or_update_embargo_on_members(members, work) ⇒ Object
Creates or updates an existing embargo on a member to match the embargo on the parent work rubocop:disable Metrics/AbcSize, Metrics/MethodLength
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'app/services/hyrax/embargo_manager.rb', line 141 def (members, work) # TODO: account for all members and levels, not just file sets. ref: #6131 members.each do |member| = work..updated_at > member.&.updated_at if member. if member. && member.. = work.['embargo_release_date'] member.. = work.['visibility_during_embargo'] member.. = work.['visibility_after_embargo'] member. = Hyrax.persister.save(resource: member.) else = Hyrax::EmbargoManager.new(resource: work) .(target: member) member = Hyrax.persister.save(resource: member) end user ||= ::User.find_by_user_key(member.depositor) # the line below works in that it indexes the file set with the necessary lease properties # I do not know however if this is the best event_id to pass Hyrax.publisher.publish('object.metadata.updated', object: member, user: user) end end |
.deactivate_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Boolean
114 115 116 117 |
# File 'app/services/hyrax/embargo_manager.rb', line 114 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .deactivate end |
.deactivate_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Boolean
120 121 122 123 |
# File 'app/services/hyrax/embargo_manager.rb', line 120 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .deactivate! end |
.embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
108 109 110 111 |
# File 'app/services/hyrax/embargo_manager.rb', line 108 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) . end |
.release_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Boolean
126 127 128 129 |
# File 'app/services/hyrax/embargo_manager.rb', line 126 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .release end |
.release_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Boolean
132 133 134 135 |
# File 'app/services/hyrax/embargo_manager.rb', line 132 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .release! end |
Instance Method Details
#apply ⇒ Boolean
Sets the visibility of the resource to the embargo’s visibility condition
200 201 202 203 204 |
# File 'app/services/hyrax/embargo_manager.rb', line 200 def apply return false unless resource.visibility = . end |
#apply! ⇒ void
This method returns an undefined value.
209 210 211 |
# File 'app/services/hyrax/embargo_manager.rb', line 209 def apply! apply || raise(NotEnforcableError) end |
#copy_embargo_to(target:) ⇒ Boolean
Copies and applies the embargo to a new (target) resource.
189 190 191 192 193 194 |
# File 'app/services/hyrax/embargo_manager.rb', line 189 def (target:) return false unless target. = Hyrax.persister.save(resource: Embargo.new(clone_attributes)) self.class.(resource: target) end |
#deactivate ⇒ Boolean
Deactivates the embargo
170 171 172 173 |
# File 'app/services/hyrax/embargo_manager.rb', line 170 def deactivate release(force: true) && nullify(force: true) end |
#deactivate! ⇒ Boolean
Deactivates the embargo
178 179 180 181 |
# File 'app/services/hyrax/embargo_manager.rb', line 178 def deactivate! release(force: true) nullify(force: true) end |
#embargo ⇒ Hyrax::Embargo
222 223 224 |
# File 'app/services/hyrax/embargo_manager.rb', line 222 def resource. || Embargo.new end |
#enforced? ⇒ Boolean
215 216 217 218 |
# File 'app/services/hyrax/embargo_manager.rb', line 215 def enforced? ..present? && (..to_s == resource.visibility) end |
#nullify(force: false) ⇒ Boolean
Drop the embargo by setting its release date and visibility settings to ‘nil`.
232 233 234 235 236 237 238 239 |
# File 'app/services/hyrax/embargo_manager.rb', line 232 def nullify(force: false) return false if !force && . = nil . = nil . = nil true end |
#release(force: false) ⇒ Boolean
Sets the visibility of the resource to the embargo’s after embargo visibility. no-op if the embargo period is current and the force flag is false.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'app/services/hyrax/embargo_manager.rb', line 248 def release(force: false) return false if !force && = .active? ? 'active' : 'expired' history_record = ( , Hyrax::TimeService.time_in_utc, ., ., . ) . += [history_record] return true if ..nil? resource.visibility = . end |
#release! ⇒ void
This method returns an undefined value.
270 271 272 |
# File 'app/services/hyrax/embargo_manager.rb', line 270 def release! release || raise(NotReleasableError) end |
#under_embargo? ⇒ Boolean
Returns indicates whether the date range for the embargo’s applicability includes the present date.
277 278 279 |
# File 'app/services/hyrax/embargo_manager.rb', line 277 def .active? end |