Skip to content

Commit

Permalink
Coerce UploadedFile to an array and use upstream Job
Browse files Browse the repository at this point in the history
Restore log methods, increase rubocop ClassLength
  • Loading branch information
cldambrosio committed Jul 11, 2018
1 parent 93cb695 commit e6a358a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 38 deletions.
5 changes: 4 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ Performance/RegexpMatch:
Exclude:
- 'lib/importer/csv_parser.rb'
- 'app/services/solr_config_uploader.rb'
- 'app/models/account.rb'
- 'app/models/account.rb'

ClassLength:
Max: 120
14 changes: 0 additions & 14 deletions lib/importer/attach_files_to_work.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/importer/csv_parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Importer
# rubocop:disable Metrics/ClassLength
class CSVParser
include Enumerable

Expand Down
2 changes: 1 addition & 1 deletion lib/importer/factory/collection_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def update
run_callbacks(:save) do
object.save!
end
# log_updated(object)
log_updated(object)
end
end
end
Expand Down
38 changes: 17 additions & 21 deletions lib/importer/factory/object_factory.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'importer/log_subscriber'
require 'importer/attach_files_to_work'
module Importer
module Factory
class ObjectFactory
Expand Down Expand Up @@ -30,9 +29,11 @@ def run
## currently the file_set is replaced on update
def update
raise "Object doesn't exist" unless object
work_actor.update(environment(update_attributes))
@attr = update_attributes
work_actor.update(environment(@attr))
destroy_existing_file_set if object.file_sets.present?
attach_file_to_work
log_updated(object)
end

def create_attributes
Expand Down Expand Up @@ -64,23 +65,22 @@ def search_by_identifier
# https://github.com/projecthydra/active_fedora/issues/874
# 2+ years later, still open!
def create
attrs = create_attributes
@attr = create_attributes
@object = klass.new
klass == Collection ? create_collection(attrs) : work_actor.create(environment(attrs))
klass == Collection ? create_collection(@attr) : work_actor.create(environment(@attr))
attach_file_to_work
log_created(object)
end

## below methods are commented out to pass rubocop inspection ("Class has too many line");
## the logs already mention the CREATE and UPDATE actions once done
# def log_created(obj)
# msg = "Created #{klass.model_name.human} #{obj.id}"
# Rails.logger.info("#{msg} (#{Array(attributes[system_identifier_field]).first})")
# end
#
# def log_updated(obj)
# msg = "Updated #{klass.model_name.human} #{obj.id}"
# Rails.logger.info("#{msg} (#{Array(attributes[system_identifier_field]).first})")
# end
def log_created(obj)
msg = "Created #{klass.model_name.human} #{obj.id}"
Rails.logger.info("#{msg} (#{Array(attributes[system_identifier_field]).first})")
end

def log_updated(obj)
msg = "Updated #{klass.model_name.human} #{obj.id}"
Rails.logger.info("#{msg} (#{Array(attributes[system_identifier_field]).first})")
end

private

Expand All @@ -94,10 +94,6 @@ def work_actor
Hyrax::CurationConcern.actor
end

def file_set_actor(w)
Hyrax::Actors::FileSetActor.new(FileSet.create, w.user)
end

def create_collection(attrs)
@object.attributes = attrs
@object.apply_depositor_metadata(User.batch_user)
Expand Down Expand Up @@ -131,8 +127,8 @@ def import_file(path)
## TO DO: handle invalid file in CSV
## currently the importer stops if no file corresponding to a given file_name is found
def attach_file_to_work
imported_file = import_file(file_paths.first) if file_paths
AttachFilesToWork.new.perform(object, imported_file, file_set_actor(imported_file)) if imported_file
imported_file = [import_file(file_paths.first)] if file_paths
AttachFilesToWorkJob.new.perform(object, imported_file, @attr) if imported_file
end

def destroy_existing_file_set
Expand Down

0 comments on commit e6a358a

Please sign in to comment.