-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
510 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
module CurationConcerns | ||
module CurationConcern | ||
def self.actor(curation_concern, *args) | ||
# Returns the top-level actor on the stack | ||
def self.actor(curation_concern, current_user, attributes) | ||
AddToCollectionActor.new(curation_concern, current_user, attributes, | ||
[AssignRepresentativeActor, | ||
AttachFilesActor, | ||
ApplyOrderActor, | ||
InterpretVisibilityActor, | ||
model_actor(curation_concern), | ||
AssignIdentifierActor]) | ||
end | ||
|
||
def self.model_actor(curation_concern) | ||
actor_identifier = curation_concern.class.to_s.split('::').last | ||
klass = "CurationConcerns::#{actor_identifier}Actor".constantize | ||
klass.new(curation_concern, *args) | ||
"CurationConcerns::#{actor_identifier}Actor".constantize | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
curation_concerns-models/app/actors/curation_concerns/abstract_actor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module CurationConcerns | ||
# The CurationConcern Abstract actor responds to two primary actions: | ||
# * #create | ||
# * #update | ||
# | ||
# and the following attributes | ||
# | ||
# * next_actor | ||
# * curation_concern | ||
# * user | ||
# | ||
# it must instantiate the next actor in the chain and instantiate it. | ||
# it should respond to curation_concern, user and attributes. | ||
# it ha to next_actor | ||
class AbstractActor | ||
attr_reader :next_actor, :attributes | ||
|
||
def initialize(curation_concern, user, attributes, more_actors) | ||
@attributes = attributes.with_indifferent_access | ||
next_actor_class = more_actors.shift || RootActor | ||
@next_actor = next_actor_class.new(curation_concern, user, attributes, more_actors) | ||
end | ||
|
||
delegate :curation_concern, :user, to: :next_actor | ||
|
||
delegate :create, to: :next_actor | ||
|
||
delegate :update, to: :next_actor | ||
end | ||
end |
42 changes: 42 additions & 0 deletions
42
curation_concerns-models/app/actors/curation_concerns/add_to_collection_actor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module CurationConcerns | ||
class AddToCollectionActor < AbstractActor | ||
def initialize(curation_concern, user, attributes, more_actors) | ||
@collection_ids = attributes.delete(:collection_ids) | ||
super | ||
end | ||
|
||
def create | ||
true && next_actor.create | ||
end | ||
|
||
def update | ||
add_to_collections(@collection_ids) && | ||
next_actor.create | ||
end | ||
|
||
private | ||
|
||
# The default behavior of active_fedora's aggregates association, | ||
# when assigning the id accessor (e.g. collection_ids = ['foo:1']) is to add | ||
# to new collections, but not remove from old collections. | ||
# This method ensures it's removed from the old collections. | ||
def add_to_collections(new_collection_ids) | ||
return true unless new_collection_ids | ||
# remove from old collections | ||
# TODO: Implement in_collection_ids https://github.com/projecthydra-labs/hydra-pcdm/issues/157 | ||
(curation_concern.in_collections.map(&:id) - new_collection_ids).each do |old_id| | ||
collection = Collection.find(old_id) | ||
collection.members.delete(curation_concern) | ||
collection.save | ||
end | ||
|
||
# add to new | ||
new_collection_ids.each do |coll_id| | ||
collection = Collection.find(coll_id) | ||
collection.members << curation_concern | ||
collection.save | ||
end | ||
true | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
curation_concerns-models/app/actors/curation_concerns/apply_order_actor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module CurationConcerns | ||
class ApplyOrderActor < AbstractActor | ||
attr_reader :next_actor | ||
def initialize(curation_concern, user, attributes, more_actors) | ||
@ordered_member_ids = attributes.delete(:ordered_member_ids) | ||
super | ||
end | ||
|
||
delegate :create, to: :next_actor | ||
|
||
def update | ||
apply_order(@ordered_member_ids) && next_actor.update | ||
end | ||
|
||
private | ||
|
||
def apply_order(new_order) | ||
return true unless new_order | ||
curation_concern.ordered_member_proxies.each_with_index do |proxy, index| | ||
unless new_order[index] | ||
proxy.prev.next = curation_concern.ordered_member_proxies.last.next | ||
break | ||
end | ||
proxy.proxy_for = ActiveFedora::Base.id_to_uri(new_order[index]) | ||
proxy.target = nil | ||
end | ||
curation_concern.list_source.order_will_change! | ||
true | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
curation_concerns-models/app/actors/curation_concerns/assign_identifier_actor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module CurationConcerns | ||
class AssignIdentifierActor < AbstractActor | ||
def create | ||
curation_concern.assign_id && next_actor.create | ||
end | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
curation_concerns-models/app/actors/curation_concerns/assign_representative_actor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module CurationConcerns | ||
class AssignRepresentativeActor < AbstractActor | ||
def create | ||
next_actor.create && assign_representative | ||
end | ||
|
||
private | ||
|
||
def assign_representative | ||
unless curation_concern.representative_id | ||
# TODO: Possible optimization here. Does this cause a fetch of ordered_members if they're already loaded? | ||
representative = nil # curation_concern.ordered_members.association.reader.first.target | ||
curation_concern.representative = representative if representative | ||
end | ||
curation_concern.save | ||
end | ||
end | ||
end |
41 changes: 41 additions & 0 deletions
41
curation_concerns-models/app/actors/curation_concerns/attach_files_actor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module CurationConcerns | ||
class AttachFilesActor < AbstractActor | ||
attr_reader :next_actor | ||
def initialize(curation_concern, user, attributes, more_actors) | ||
@files = [attributes.delete(:files)].flatten.compact | ||
super | ||
end | ||
|
||
def create | ||
attach_files && next_actor.create | ||
end | ||
|
||
def update | ||
next_actor.update && attach_files | ||
end | ||
|
||
private | ||
|
||
def attach_files | ||
@files.all? do |file| | ||
attach_file(file) | ||
end | ||
end | ||
|
||
def attach_file(file) | ||
file_set = ::FileSet.new | ||
file_set_actor = CurationConcerns::FileSetActor.new(file_set, user) | ||
file_set_actor.create_metadata(curation_concern, visibility_attributes) | ||
file_set_actor.create_content(file) | ||
end | ||
|
||
# The attributes used for visibility - used to send as initial params to | ||
# created FileSets. | ||
def visibility_attributes | ||
attributes.slice(:visibility, :visibility_during_lease, | ||
:visibility_after_lease, :lease_expiration_date, | ||
:embargo_release_date, :visibility_during_embargo, | ||
:visibility_after_embargo) | ||
end | ||
end | ||
end |
27 changes: 10 additions & 17 deletions
27
curation_concerns-models/app/actors/curation_concerns/base_actor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.