Skip to content

Commit

Permalink
Fix method visibility. Made some internal methods private
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 17, 2015
1 parent 89780fa commit 6cc654d
Showing 1 changed file with 58 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,6 @@ def create_metadata(upload_set_id, work_id, generic_file_params = {})
yield(generic_file) if block_given?
end

# Adds a GenericFile to the work using ore:Aggregations.
# Locks to ensure that only one process is operating on
# the list at a time.
def attach_file_to_work(work_id, generic_file, generic_file_params)
acquire_lock_for(work_id) do
work = ActiveFedora::Base.find(work_id)

unless assign_visibility?(generic_file_params)
copy_visibility(work, generic_file)
end
work.generic_files << generic_file
# Save the work so the association between the work and the generic_file is persisted (head_id)
work.save
end
end

def acquire_lock_for(lock_key, &block)
lock_manager.lock(lock_key, &block)
end

def lock_manager
@lock_manager ||= CurationConcerns::LockManager.new(
CurationConcerns.config.lock_time_to_live,
CurationConcerns.config.lock_retry_count,
CurationConcerns.config.lock_retry_delay)
end

def assign_visibility?(generic_file_params = {})
!((generic_file_params || {}).keys & %w(visibility embargo_release_date lease_expiration_date)).empty?
end

def create_content(file)
# Tell UploadFileToGenericFile service to skip versioning because versions will be minted by VersionCommitter (called by save_characterize_and_record_committer) when necessary
Hydra::Works::UploadFileToGenericFile.call(generic_file, file, versioning: false)
Expand Down Expand Up @@ -125,47 +94,76 @@ def destroy
CurationConcerns.config.after_destroy.call(generic_file.id, user) if CurationConcerns.config.respond_to?(:after_destroy)
end

# Saves the generic file, queues a job to characterize it, and records the committer.
# Takes a block which is run if the save was successful.
def save_characterize_and_record_committer
save do
push_characterize_job
CurationConcerns::VersioningService.create(generic_file.original_file, user)
private

# Saves the generic file, queues a job to characterize it, and records the committer.
# Takes a block which is run if the save was successful.
def save_characterize_and_record_committer
save do
push_characterize_job
CurationConcerns::VersioningService.create(generic_file.original_file, user)
yield if block_given?
end
end

# Takes an optional block and executes the block if the save was successful.
# returns false if the save was unsuccessful
def save
save_tries = 0
begin
return false unless generic_file.save
rescue RSolr::Error::Http => error
ActiveFedora::Base.logger.warn "CurationConcerns::GenericFileActor#save Caught RSOLR error #{error.inspect}"
save_tries += 1
# fail for good if the tries is greater than 3
raise error if save_tries >= 3
sleep 0.01
retry
end
yield if block_given?
true
end
end

# Takes an optional block and executes the block if the save was successful.
# returns false if the save was unsuccessful
def save
save_tries = 0
begin
return false unless generic_file.save
rescue RSolr::Error::Http => error
ActiveFedora::Base.logger.warn "CurationConcerns::GenericFileActor#save Caught RSOLR error #{error.inspect}"
save_tries += 1
# fail for good if the tries is greater than 3
raise error if save_tries >= 3
sleep 0.01
retry
def push_characterize_job
CharacterizeJob.perform_later(@generic_file.id)
end
yield if block_given?
true
end

def push_characterize_job
CharacterizeJob.perform_later(@generic_file.id)
end
# Adds a GenericFile to the work using ore:Aggregations.
# Locks to ensure that only one process is operating on
# the list at a time.
def attach_file_to_work(work_id, generic_file, generic_file_params)
acquire_lock_for(work_id) do
work = ActiveFedora::Base.find(work_id)

unless assign_visibility?(generic_file_params)
copy_visibility(work, generic_file)
end
work.generic_files << generic_file
# Save the work so the association between the work and the generic_file is persisted (head_id)
work.save
end
end

protected
def acquire_lock_for(lock_key, &block)
lock_manager.lock(lock_key, &block)
end

def lock_manager
@lock_manager ||= CurationConcerns::LockManager.new(
CurationConcerns.config.lock_time_to_live,
CurationConcerns.config.lock_retry_count,
CurationConcerns.config.lock_retry_delay)
end

def assign_visibility?(generic_file_params = {})
!((generic_file_params || {}).keys & %w(visibility embargo_release_date lease_expiration_date)).empty?
end

# This method can be overridden in case there is a custom approach for visibility (e.g. embargo)
def update_visibility(attributes)
interpret_visibility(attributes) # relies on CurationConcerns::ManagesEmbargoesActor to interpret and apply visibility
end

private

# copy visibility from source_concern to destination_concern
def copy_visibility(source_concern, destination_concern)
destination_concern.visibility = source_concern.visibility
Expand Down

0 comments on commit 6cc654d

Please sign in to comment.