Skip to content

Commit

Permalink
Support importing in ImportExportJob
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Sep 22, 2016
1 parent 4693565 commit 7774d9c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
14 changes: 8 additions & 6 deletions app/jobs/import_export_job.rb
@@ -1,6 +1,7 @@
require 'open3'

class ImportExportJob < ActiveJob::Base
attr_reader :mode
include Open3

# @param [String] uri of the resource
Expand All @@ -14,16 +15,17 @@ class ImportExportJob < ActiveJob::Base
# * import features are not yet available
# * exporting bags is not yet supported
def perform(uri, options = {})
export(uri,
options.fetch(:desc_dir, CurationConcerns.config.descriptions_directory),
options.fetch(:bin_dir, CurationConcerns.config.binaries_directory),
options.fetch(:profile, nil))
@mode = options.fetch(:mode, "export")
call(uri,
options.fetch(:desc_dir, CurationConcerns.config.descriptions_directory),
options.fetch(:bin_dir, CurationConcerns.config.binaries_directory),
options.fetch(:profile, nil))
end

private

def export(uri, desc_dir, bin_dir, _profile = nil)
command = "java -jar #{CurationConcerns.config.import_export_jar_file_path} --mode export --resource #{uri} --descDir #{desc_dir} --binDir #{bin_dir}"
def call(uri, desc_dir, bin_dir, _profile = nil)
command = "java -jar #{CurationConcerns.config.import_export_jar_file_path} --mode #{mode} --resource #{uri} --descDir #{desc_dir} --binDir #{bin_dir}"
internal_call(command)
end

Expand Down
24 changes: 19 additions & 5 deletions spec/jobs/import_export_job_spec.rb
Expand Up @@ -3,12 +3,26 @@
describe ImportExportJob do
let(:work) { create(:work) }
let(:job) { described_class.new(work.uri.to_s) }
let(:command) do
"java -jar tmp/fcrepo-import-export.jar --mode export --resource #{work.uri} --descDir tmp/descriptions --binDir tmp/binaries"

describe "when exporting" do
let(:command) do
"java -jar tmp/fcrepo-import-export.jar --mode export --resource #{work.uri} --descDir tmp/descriptions --binDir tmp/binaries"
end

it "runs the export command" do
expect(job).to receive(:internal_call).with(command)
job.perform(work.uri.to_s)
end
end

it "exports the work" do
expect(job).to receive(:internal_call).with(command)
job.perform(work.uri.to_s)
describe "when importing" do
let(:command) do
"java -jar tmp/fcrepo-import-export.jar --mode import --resource #{work.uri} --descDir tmp/descriptions --binDir tmp/binaries"
end

it "runs the import command" do
expect(job).to receive(:internal_call).with(command)
job.perform(work.uri.to_s, mode: "import")
end
end
end

0 comments on commit 7774d9c

Please sign in to comment.