Skip to content

Commit

Permalink
Works and FileSets
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 7, 2015
1 parent 580f9b3 commit 9d8ebf1
Show file tree
Hide file tree
Showing 161 changed files with 943 additions and 950 deletions.
20 changes: 10 additions & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AllCops:
- 'script/**/*'
- 'vendor/**/*'
- 'spec/internal/**/*'
- 'curation_concerns-models/app/models/concerns/curation_concerns/generic_file/export.rb'
- 'curation_concerns-models/app/models/concerns/curation_concerns/file_set/export.rb'

Lint/AssignmentInCondition:
Exclude:
Expand All @@ -25,20 +25,20 @@ Metrics/AbcSize:

Metrics/CyclomaticComplexity:
Exclude:
- 'curation_concerns-models/app/services/curation_concerns/generic_file_audit_service.rb'
- 'app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb'
- 'curation_concerns-models/app/services/curation_concerns/file_set_audit_service.rb'
- 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb'
- 'app/helpers/curation_concerns/curation_concerns_helper_behavior.rb'
- 'app/helpers/curation_concerns/attribute_helper.rb'
- 'curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb'
- 'curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb'
- 'curation_concerns-models/app/actors/curation_concerns/work_actor_behavior.rb'

Metrics/PerceivedComplexity:
Exclude:
- 'curation_concerns-models/app/services/curation_concerns/generic_file_audit_service.rb'
- 'app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb'
- 'curation_concerns-models/app/services/curation_concerns/file_set_audit_service.rb'
- 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb'
- 'app/helpers/curation_concerns/curation_concerns_helper_behavior.rb'
- 'app/helpers/curation_concerns/attribute_helper.rb'
- 'curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb'
- 'curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb'

Metrics/MethodLength:
Enabled: false
Expand All @@ -47,14 +47,14 @@ Metrics/ClassLength:
Exclude:
- 'lib/generators/curation_concerns/templates/catalog_controller.rb'
- 'curation_concerns-models/app/models/datastreams/fits_datastream.rb'
- 'curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb'
- 'curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb'

Metrics/ModuleLength:
Exclude:
- 'app/controllers/concerns/curation_concerns/curation_concern_controller.rb'
- 'app/controllers/concerns/curation_concerns/users_controller_behavior.rb'
- 'app/controllers/concerns/curation_concerns/catalog_controller.rb'
- 'app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb'
- 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb'
- 'app/helpers/curation_concerns/curation_concerns_helper_behavior.rb'
- 'curation_concerns-models/app/models/concerns/curation_concerns/solr_document_behavior.rb'

Expand Down Expand Up @@ -138,7 +138,7 @@ Style/ClassVars:
Exclude:
- 'curation_concerns-models/lib/curation_concerns/models.rb'
- 'curation_concerns-models/lib/curation_concerns/models/engine.rb'
- 'curation_concerns-models/app/models/concerns/curation_concerns/generic_file/versions.rb'
- 'curation_concerns-models/app/models/concerns/curation_concerns/file_set/versions.rb'

Style/SignalException:
Enabled: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def show
wants.json do
# load and authorize @curation_concern manually because it's skipped for html
# This has to use #find instead of #load_instance_from_solr because
# we want to return values like generic_file_ids in the json
# we want to return values like file_set_ids in the json
@curation_concern = curation_concern_type.find(params[:id]) unless curation_concern
authorize! :show, @curation_concern
render :show, status: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
def destroy
EmbargoActor.new(curation_concern).destroy
flash[:notice] = curation_concern.embargo_history.last
if curation_concern.works_generic_work? && curation_concern.generic_files.present?
if curation_concern.work? && curation_concern.file_sets.present?
redirect_to confirm_curation_concerns_permission_path(curation_concern)
else
redirect_to edit_embargo_path(curation_concern)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module CurationConcerns
module GenericFilesControllerBehavior
module FileSetsControllerBehavior
extend ActiveSupport::Concern

included do
include CurationConcerns::ThemedLayoutController
with_themed_layout '1_column'
load_and_authorize_resource class: ::GenericFile, except: :show
load_and_authorize_resource class: ::FileSet, except: :show
helper_method :curation_concern
include CurationConcerns::ParentContainer
include Blacklight::Base
Expand All @@ -14,7 +14,7 @@ module GenericFilesControllerBehavior
end

def curation_concern
@generic_file
@file_set
end

# routed to /files/new
Expand All @@ -33,9 +33,9 @@ def create

def create_from_upload(params)
# check error condition No files
return render_json_response(response_type: :bad_request, options: { message: 'Error! No file to save' }) unless params.key?(:generic_file) && params.fetch(:generic_file).key?(:files)
return render_json_response(response_type: :bad_request, options: { message: 'Error! No file to save' }) unless params.key?(:file_set) && params.fetch(:file_set).key?(:files)

file = params[:generic_file][:files].detect { |f| f.respond_to?(:original_filename) }
file = params[:file_set][:files].detect { |f| f.respond_to?(:original_filename) }
if !file
render_json_response(response_type: :bad_request, options: { message: 'Error! No file for upload', description: 'unknown file' })
elsif empty_file?(file)
Expand All @@ -44,7 +44,7 @@ def create_from_upload(params)
process_file(file)
end
rescue RSolr::Error::Http => error
logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error}\n #{error.backtrace.join("\n")}\n\n"
logger.error "FileSetController::create rescued #{error.class}\n\t#{error}\n #{error.backtrace.join("\n")}\n\n"
render_json_response(response_type: :internal_error, options: { message: 'Error occurred while creating generic file.' })
ensure
# remove the tempfile (only if it is a temp file)
Expand All @@ -55,15 +55,15 @@ def create_from_upload(params)
def show
respond_to do |wants|
wants.html do
_, document_list = search_results(params, [:add_access_controls_to_solr_params, :find_one, :only_generic_files])
_, document_list = search_results(params, [:add_access_controls_to_solr_params, :find_one, :only_file_sets])
curation_concern = document_list.first
raise CanCan::AccessDenied unless curation_concern
@presenter = show_presenter.new(curation_concern, current_ability)
end
wants.json do
# load and authorize @curation_concern manually because it's skipped for html
@generic_file = curation_concern_type.load_instance_from_solr(params[:id]) unless curation_concern
authorize! :show, @generic_file
@file_set = curation_concern_type.load_instance_from_solr(params[:id]) unless curation_concern
authorize! :show, @file_set
render :show, status: :ok
end
additional_response_formats(wants)
Expand All @@ -73,42 +73,42 @@ def show
# Gives the class of the show presenter. Override this if you want
# to use a different presenter.
def show_presenter
CurationConcerns::GenericFilePresenter
CurationConcerns::FileSetPresenter
end

def destroy
actor.destroy
redirect_to [main_app, :curation_concerns, @generic_file.generic_works.first], notice: 'The file has been deleted.'
redirect_to [main_app, :curation_concerns, @file_set.in_works.first], notice: 'The file has been deleted.'
end

# routed to /files/:id (PUT)
def update
success = if wants_to_revert?
actor.revert_content(params[:revision])
elsif params.key?(:generic_file)
if params[:generic_file].key?(:files)
actor.update_content(params[:generic_file][:files].first)
elsif params.key?(:file_set)
if params[:file_set].key?(:files)
actor.update_content(params[:file_set][:files].first)
else
update_metadata
end
end
if success
respond_to do |wants|
wants.html do
redirect_to [main_app, :curation_concerns, @generic_file], notice:
"The file #{view_context.link_to(@generic_file, [main_app, :curation_concerns, @generic_file])} has been updated."
redirect_to [main_app, :curation_concerns, @file_set], notice:
"The file #{view_context.link_to(@file_set, [main_app, :curation_concerns, @file_set])} has been updated."
end
wants.json { render :show, status: :ok, location: polymorphic_path([main_app, :curation_concerns, @generic_file]) }
wants.json { render :show, status: :ok, location: polymorphic_path([main_app, :curation_concerns, @file_set]) }
end
else
respond_to do |wants|
wants.html { render 'edit', status: :unprocessable_entity }
wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: @generic_file.errors }) }
wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: @file_set.errors }) }
end
end
rescue RSolr::Error::Http => error
flash[:error] = error.message
logger.error "GenericFilesController::update rescued #{error.class}\n\t#{error.message}\n #{error.backtrace.join("\n")}\n\n"
logger.error "FileSetsController::update rescued #{error.class}\n\t#{error.message}\n #{error.backtrace.join("\n")}\n\n"
render action: 'edit'
end

Expand All @@ -119,7 +119,7 @@ def versions
# this is provided so that implementing application can override this behavior and map params to different attributes
def update_metadata
# attrs_without_visibility_info = actor.interpret_visibility(attributes)
file_attributes = CurationConcerns::Forms::GenericFileEditForm.model_attributes(attributes)
file_attributes = CurationConcerns::Forms::FileSetEditForm.model_attributes(attributes)
actor.update_metadata(file_attributes, attributes)
end

Expand All @@ -131,26 +131,26 @@ def additional_response_formats(_)
# nop
end

def generic_file_params
params.require(:generic_file).permit(
def file_set_params
params.require(:file_set).permit(
:visibility_during_embargo, :embargo_release_date, :visibility_after_embargo, :visibility_during_lease, :lease_expiration_date, :visibility_after_lease, :visibility, title: [])
end

def version_list
CurationConcerns::VersionListPresenter.new(@generic_file.original_file.versions.all)
CurationConcerns::VersionListPresenter.new(@file_set.original_file.versions.all)
end

def wants_to_revert?
params.key?(:revision) && params[:revision] != @generic_file.latest_content_version.label
params.key?(:revision) && params[:revision] != @file_set.latest_content_version.label
end

def actor
@actor ||= ::CurationConcerns::GenericFileActor.new(@generic_file, current_user)
@actor ||= ::CurationConcerns::FileSetActor.new(@file_set, current_user)
end

def attributes
# params.fetch(:generic_file, {}).dup # use a copy of the hash so that original params stays untouched when interpret_visibility modifies things
params.fetch(:generic_file, {}).except(:files).permit!.dup # use a copy of the hash so that original params stays untouched when interpret_visibility modifies things
# params.fetch(:file_set, {}).dup # use a copy of the hash so that original params stays untouched when interpret_visibility modifies things
params.fetch(:file_set, {}).except(:files).permit!.dup # use a copy of the hash so that original params stays untouched when interpret_visibility modifies things
end

def _prefixes
Expand All @@ -164,22 +164,22 @@ def empty_file?(file)

def process_file(file)
update_metadata_from_upload_screen
actor.create_metadata(params[:upload_set_id], parent_id, params[:generic_file])
actor.create_metadata(params[:upload_set_id], parent_id, params[:file_set])
if actor.create_content(file)
respond_to do |format|
format.html do
if request.xhr?
render 'jq_upload', formats: 'json', content_type: 'text/html'
else
redirect_to [main_app, :curation_concerns, @generic_file.generic_works.first]
redirect_to [main_app, :curation_concerns, @file_set.in_works.first]
end
end
format.json do
render 'jq_upload', status: :created, location: polymorphic_path([main_app, :curation_concerns, curation_concern])
end
end
else
msg = @generic_file.errors.full_messages.join(', ')
msg = @file_set.errors.full_messages.join(', ')
flash[:error] = msg
json_error "Error creating generic file: #{msg}"
end
Expand All @@ -188,11 +188,11 @@ def process_file(file)
# this is provided so that implementing application can override this behavior and map params to different attributes
def update_metadata_from_upload_screen
# Relative path is set by the jquery uploader when uploading a directory
@generic_file.relative_path = params[:relative_path] if params[:relative_path]
@file_set.relative_path = params[:relative_path] if params[:relative_path]
end

def curation_concern_type
::GenericFile
::FileSet
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def index
def destroy
LeaseActor.new(curation_concern).destroy
flash[:notice] = curation_concern.lease_history.last
if curation_concern.works_generic_work? && curation_concern.generic_files.present?
if curation_concern.work? && curation_concern.file_sets.present?
redirect_to confirm_curation_concerns_permission_path(curation_concern)
else
redirect_to edit_lease_path(curation_concern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module SingleUseLinksViewerControllerBehavior
rescue_from CanCan::AccessDenied, with: :render_single_use_error
rescue_from ActiveRecord::RecordNotFound, with: :render_single_use_error
class_attribute :presenter_class
self.presenter_class = CurationConcerns::GenericFilePresenter
self.presenter_class = CurationConcerns::FileSetPresenter
copy_blacklight_config_from(::CatalogController)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module UploadSetsControllerBehavior
with_themed_layout '1_column'

class_attribute :edit_form_class
self.edit_form_class = CurationConcerns::Forms::GenericFileEditForm
self.edit_form_class = CurationConcerns::Forms::FileSetEditForm
end

def edit
Expand All @@ -21,7 +21,7 @@ def update
@upload_set = UploadSet.find_or_create(params[:id])
@upload_set.status = ["processing"]
@upload_set.save
file_attributes = edit_form_class.model_attributes(params[:generic_file])
file_attributes = edit_form_class.model_attributes(params[:file_set])
UploadSetUpdateJob.perform_later(current_user.user_key, params[:id], params[:title], file_attributes, params[:visibility])
flash[:notice] = 'Your files are being processed by ' + t('curation_concerns.product_name') + ' in the background. The metadata and access controls you specified are being applied. Files will be marked <span class="label label-danger" title="Private">Private</span> until this process is complete (shouldn\'t take too long, hang in there!). You may need to refresh your dashboard to see these updates.'

Expand All @@ -31,8 +31,8 @@ def update
protected

def edit_form
generic_file = ::GenericFile.new(creator: [current_user.user_key], title: @upload_set.generic_files.map(&:label))
edit_form_class.new(generic_file)
file_set = ::FileSet.new(creator: [current_user.user_key], title: @upload_set.file_sets.map(&:label))
edit_form_class.new(file_set)
end
end
end
5 changes: 5 additions & 0 deletions app/controllers/curation_concerns/file_sets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module CurationConcerns
class FileSetsController < ApplicationController
include CurationConcerns::FileSetsControllerBehavior
end
end
5 changes: 0 additions & 5 deletions app/controllers/curation_concerns/generic_files_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module CurationConcerns
module Forms
class GenericFileEditForm
class FileSetEditForm
include HydraEditor::Form
include HydraEditor::Form::Permissions
self.required_fields = [:title, :creator, :tag, :rights]

self.model_class = ::GenericFile
self.model_class = ::FileSet

self.terms = [:resource_type, :title, :creator, :contributor, :description, :tag, :rights,
:publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url]
Expand Down
31 changes: 31 additions & 0 deletions app/helpers/curation_concerns/file_set_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module CurationConcerns::FileSetHelper
def parent_path(parent)
if parent.is_a?(Collection)
main_app.collection_path(parent)
else
polymorphic_path([main_app, :curation_concerns, parent])
end
end

def media_display(file_set, locals = {})
render media_display_partial(file_set),
locals.merge(file_set: file_set)
end

def media_display_partial(file_set)
'curation_concerns/file_sets/media_display/' +
if file_set.image?
'image'
elsif file_set.video?
'video'
elsif file_set.audio?
'audio'
elsif file_set.pdf?
'pdf'
elsif file_set.office_document?
'office_document'
else
'default'
end
end
end
Loading

0 comments on commit 9d8ebf1

Please sign in to comment.