Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release-4.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Coble committed Nov 1, 2018
2 parents 40ba6a7 + 7c41aec commit c932592
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 53 deletions.
5 changes: 3 additions & 2 deletions app/controllers/standard_ingests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ def create
if @standard_ingest.valid?
Resque.enqueue(StandardIngestJob,
'admin_set' => @standard_ingest.admin_set,
'basepath' => @standard_ingest.basepath,
'batch_user' => @standard_ingest.user.user_key,
'collection_id' => @standard_ingest.collection_id,
'config_file' => @standard_ingest.config_file,
'folder_path' => @standard_ingest.folder_path)
'subpath' => @standard_ingest.subpath)
render "queued"
else
render "new"
Expand All @@ -22,7 +23,7 @@ def create
private

def create_params
params.require(:standard_ingest).permit(:folder_path, :admin_set, :collection_id, :config_file)
params.require(:standard_ingest).permit(:basepath, :admin_set, :collection_id, :config_file, :subpath)
end

def authorize_create
Expand Down
11 changes: 5 additions & 6 deletions app/helpers/standard_ingest_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module StandardIngestHelper

def standard_ingest_folder_options_for_select
options_for_select(standard_ingest_folders.collect { |f| [ f, File.join(DulHydra.standard_ingest_base_path, f) ] }, @standard_ingest.folder_path)
end
# For convenience, for now, we assume that standard ingest will always use the default configuration file
# (StandardIngest::DEFAULT_CONFIG_FILE), though StandardIngest is coded to permit passing in a different
# config file.

def standard_ingest_folders
base = DulHydra.standard_ingest_base_path
Dir.entries(base).select {|e| File.directory? File.join(base, e) }.reject{ |e| e.starts_with?('.') }
def permitted_standard_ingest_bases
StandardIngest.default_basepaths
end

end
3 changes: 2 additions & 1 deletion app/jobs/standard_ingest_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def self.perform(args)
model_stats = results.inspection_results.content_model_stats if results.inspection_results
ActiveSupport::Notifications.instrument(StandardIngest::FINISHED,
user_key: args['batch_user'],
folder_path: args['folder_path'],
basepath: args['basepath'],
subpath: args['subpath'],
collection_id: args['collection_id'],
file_count: file_count,
model_stats: model_stats,
Expand Down
19 changes: 16 additions & 3 deletions app/models/standard_ingest.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class StandardIngest
include ActiveModel::Model

attr_reader :admin_set, :collection_id, :config_file, :configuration, :folder_path
attr_reader :admin_set, :basepath, :collection_id, :config_file, :configuration, :subpath
attr_accessor :results, :user

# Lifecycle events
Expand All @@ -14,7 +14,7 @@ class StandardIngest
DEFAULT_CONFIG_FILE = Rails.root.join('config', 'standard_ingest.yml')
METADATA_FILE = 'metadata.txt'

validates_presence_of(:folder_path, :user)
validates_presence_of(:basepath, :subpath, :user)
with_options if: 'folder_path.present?' do |folder|
folder.validate :folder_directory_must_exist
folder.validate :data_directory_must_exist
Expand All @@ -26,12 +26,21 @@ class StandardIngest
validate :collection_must_exist, if: 'collection_id.present?'
validates_presence_of(:admin_set, unless: 'collection_id.present?')

def self.default_config
YAML.load(File.read(DEFAULT_CONFIG_FILE)).deep_symbolize_keys
end

def self.default_basepaths
default_config[:basepaths]
end

def initialize(args)
@admin_set = args['admin_set']
@basepath = args['basepath']
@collection_id = args['collection_id']
@config_file = args['config_file'] || DEFAULT_CONFIG_FILE.to_s
@configuration = load_configuration
@folder_path = args['folder_path']
@subpath = args['subpath']
@user = User.find_by_user_key(args['batch_user'])
@results = Results.new
end
Expand Down Expand Up @@ -134,6 +143,10 @@ def metadata_provider
@metadata_provider ||= IngestMetadata.new(File.join(data_path, METADATA_FILE), configuration[:metadata])
end

def folder_path
@folder_path ||= File.join(basepath, subpath)
end

def inspection_results
@inspection_results ||= InspectStandardIngest.new(folder_path, configuration[:scanner]).call
end
Expand Down
13 changes: 13 additions & 0 deletions app/views/standard_ingests/_folder_path.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="form-group">
<%= f.label :basepath %>
<% if permitted_standard_ingest_bases.size == 1 %>
<%= f.hidden_field :basepath, value: permitted_standard_ingest_bases.first %>
<%= permitted_standard_ingest_bases.first %>
<% else %>
<%= f.select :basepath, options_for_select(permitted_standard_ingest_bases), { prompt: true }, { class: 'form-control' } %>
<% end %>
</div>
<div class="form-group">
<%= f.label :subpath %>
<%= f.text_field :subpath, class: 'form-control' %>
</div>
9 changes: 1 addition & 8 deletions app/views/standard_ingests/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@
<%= f.hidden_field :collection_id %>
<%= @standard_ingest.collection_id.present? ? object_display_title(@standard_ingest.collection_id) : '<Will be created by Standard Ingest>' %>
</div>
<div class="form-group">
<%= f.label :base_path, "Base Path" %>
<%= DulHydra.standard_ingest_base_path %>
</div>
<div class="form-group">
<%= f.label :folder_path, "Folder" %>
<%= f.select :folder_path, standard_ingest_folder_options_for_select, { include_blank: "Select Standard Ingest Folder" }, { class: "form-control" } %>
</div>
<%= render partial: 'folder_path', locals: { f: f } %>
<div class="form-group">
<% unless @standard_ingest.collection_id.present? %>
<%= f.label :admin_set, "Admin Set" %>
Expand Down
1 change: 0 additions & 1 deletion config/initializers/dul_hydra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
}
config.metadata_file_creators_group = ENV['METADATA_FILE_CREATORS_GROUP']
config.create_menu_models = [ "Collection", "MetadataFile", "NestedFolderIngest", "StandardIngest" ]
config.standard_ingest_base_path = ENV['STANDARD_INGEST_BASE_PATH']
config.preview_banner_msg = ENV['PREVIEW_BANNER_MSG']
config.collection_report_fields = [:pid, :local_id, :content_size]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
:basepaths:
- /path/to/base/folder1/
- /path/to/base/folder2/
:scanner:
:exclude:
- .DS_Store
Expand Down
3 changes: 0 additions & 3 deletions lib/dul_hydra/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ module Configurable
[ :nested_path ]
end

# Base path for Standard Ingest folders
mattr_accessor :standard_ingest_base_path

# Entries per page on batches index display
mattr_accessor :batches_per_page do
ENV["BATCHES_PER_PAGE"] || 10
Expand Down
2 changes: 1 addition & 1 deletion lib/dul_hydra/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DulHydra
VERSION = "4.11.4"
VERSION = "4.12.0"
end
23 changes: 14 additions & 9 deletions spec/controllers/standard_ingests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
describe "#create" do
let(:user) { FactoryGirl.create(:user) }
let(:admin_set) { "foo" }
let(:folder_path) { "/foo/bar/baz" }
let(:basepath) { "/foo/bar/" }
let(:subpath) { "baz" }
let(:folder_path) { File.join(basepath, subpath) }
let(:checksum_path) { File.join(folder_path, StandardIngest::CHECKSUM_FILE).to_s }
let(:data_path) { File.join(folder_path, StandardIngest::DATA_DIRECTORY).to_s }
let(:metadata_path) { File.join(data_path, StandardIngest::METADATA_FILE).to_s }
let(:job_params) { {"admin_set" => admin_set, "batch_user" => user.user_key, "collection_id" => "",
"config_file" => StandardIngest::DEFAULT_CONFIG_FILE.to_s, "folder_path" => folder_path } }
let(:job_params) { {"admin_set" => admin_set, "basepath" => basepath, "batch_user" => user.user_key,
"collection_id" => "", "config_file" => StandardIngest::DEFAULT_CONFIG_FILE.to_s,
"subpath" => subpath} }

before do
sign_in user
Expand All @@ -20,6 +23,7 @@
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with(checksum_path) { true }
allow(File).to receive(:exist?).with(metadata_path) { true }
allow_any_instance_of(StandardIngest).to receive(:load_configuration) { {} }
allow_any_instance_of(StandardIngest).to receive(:validate_metadata_file) { nil }
end

Expand All @@ -30,7 +34,8 @@
}
it "enqueues the job and renders the 'queued' view" do
expect(Resque).to receive(:enqueue).with(StandardIngestJob, job_params)
post :create, standard_ingest: {"folder_path" => folder_path, "collection_id" => "", "admin_set" => admin_set }
post :create, standard_ingest: { "basepath" => basepath, "collection_id" => "", "admin_set" => admin_set,
"subpath" => subpath }
expect(response).to render_template(:queued)
end
describe "and the collection is specified" do
Expand All @@ -39,7 +44,7 @@
controller.current_ability.can(:add_children, "test:1")
}
it "is successful" do
post :create, standard_ingest: {"folder_path" => folder_path, "collection_id" => "test:1" }
post :create, standard_ingest: { "basepath" => basepath, "collection_id" => "test:1", "subpath" => subpath }
expect(response.response_code).to eq(200)
end
end
Expand All @@ -49,7 +54,7 @@
controller.current_ability.cannot(:add_children, "test:1")
}
it "is forbidden" do
post :create, standard_ingest: {"folder_path" => folder_path, "collection_id" => "test:1" }
post :create, standard_ingest: {"basepath" => basepath, "collection_id" => "test:1", "subpath" => subpath }
expect(response.response_code).to eq(403)
end
end
Expand All @@ -61,7 +66,7 @@
}
describe "and the collection is not specified" do
it "is forbidden" do
post :create, standard_ingest: {"folder_path" => folder_path, "collection_id" => "" }
post :create, standard_ingest: {"basepath" => basepath, "collection_id" => "", "subpath" => subpath }
expect(response.response_code).to eq(403)
end
end
Expand All @@ -71,7 +76,7 @@
controller.current_ability.can(:add_children, "test:1")
}
it "is successful" do
post :create, standard_ingest: {"folder_path" => folder_path, "collection_id" => "test:1" }
post :create, standard_ingest: {"basepath" => basepath, "collection_id" => "test:1", "subpath" => subpath }
expect(response.response_code).to eq(200)
end
end
Expand All @@ -81,7 +86,7 @@
controller.current_ability.cannot(:add_children, "test:1")
}
it "is forbidden" do
post :create, standard_ingest: {"folder_path" => folder_path, "collection_id" => "test:1" }
post :create, standard_ingest: {"basepath" => basepath, "collection_id" => "test:1", "subpath" => subpath }
expect(response.response_code).to eq(403)
end
end
Expand Down
18 changes: 12 additions & 6 deletions spec/jobs/standard_ingest_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
RSpec.describe StandardIngestJob, type: :job do

let(:user_key) { 'joe@test.edu' }
let(:folder_path) { '/foo/bar/baz' }
let(:basepath) { "/foo/bar/" }
let(:subpath) { "baz" }
let(:collection_pid) { 'test:1' }
let(:batch) { double('Ddr::Batch::Batch', id: 5) }
let(:item_count) { 7 }
let(:component_count) { 10 }
let(:target_count) { 2 }
let(:job_params) { { "batch_user" => user_key, "folder_path" => folder_path } }
let(:job_params) { { "batch_user" => user_key, "basepath" => basepath, "subpath" => subpath } }

before do
allow_any_instance_of(StandardIngest).to receive(:load_configuration) { {} }
allow_any_instance_of(InspectStandardIngest).to receive(:call) { inspection_results }
end

Expand All @@ -34,7 +36,8 @@
it "should publish the appropriate notification" do
expect(ActiveSupport::Notifications).to receive(:instrument).with(StandardIngest::FINISHED,
user_key: user_key,
folder_path: folder_path,
basepath: basepath,
subpath: subpath,
collection_id: collection_pid,
file_count: file_count,
model_stats: model_stats,
Expand All @@ -48,7 +51,8 @@
it "should publish the appropriate notification" do
expect(ActiveSupport::Notifications).to receive(:instrument).with(StandardIngest::FINISHED,
user_key: user_key,
folder_path: folder_path,
basepath: basepath,
subpath: subpath,
collection_id: nil,
file_count: file_count,
model_stats: model_stats,
Expand All @@ -72,7 +76,8 @@
it "should publish the appropriate notification" do
expect(ActiveSupport::Notifications).to receive(:instrument).with(StandardIngest::FINISHED,
user_key: user_key,
folder_path: folder_path,
basepath: basepath,
subpath: subpath,
collection_id: collection_pid,
file_count: nil,
model_stats: nil,
Expand All @@ -85,7 +90,8 @@
it "should publish the appropriate notification" do
expect(ActiveSupport::Notifications).to receive(:instrument).with(StandardIngest::FINISHED,
user_key: user_key,
folder_path: folder_path,
basepath: basepath,
subpath: subpath,
collection_id: nil,
file_count: nil,
model_stats: nil,
Expand Down
7 changes: 5 additions & 2 deletions spec/models/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@
end

describe "StandardIngest abilities" do
let(:resource) { StandardIngest.new({"folder_path" => '/foo', "batch_user" => auth_context.user.user_key }) }
before { auth_context.user.save! }
let(:resource) { StandardIngest.new({"basepath" => '/foo', "batch_user" => auth_context.user.user_key, subpath: 'bar' }) }
before do
auth_context.user.save!
allow_any_instance_of(StandardIngest).to receive(:load_configuration) { {} }
end
describe "create" do
before { allow_any_instance_of(described_class).to receive(:can?).and_call_original }
describe "when the user can create collections" do
Expand Down
Loading

0 comments on commit c932592

Please sign in to comment.