iiif_print 1.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/Gemfile.lock +2 -2
  4. data/README.md +4 -0
  5. data/app/actors/iiif_print/actors/file_set_actor_decorator.rb +1 -1
  6. data/app/indexers/concerns/iiif_print/child_work_indexer.rb +27 -0
  7. data/app/indexers/concerns/iiif_print/file_set_indexer.rb +37 -22
  8. data/{lib → app/jobs}/iiif_print/jobs/application_job.rb +2 -1
  9. data/{lib → app/jobs}/iiif_print/jobs/child_works_from_pdf_job.rb +14 -9
  10. data/{lib → app/jobs}/iiif_print/jobs/create_relationships_job.rb +10 -20
  11. data/app/listeners/iiif_print/listener.rb +31 -0
  12. data/app/models/concerns/iiif_print/set_child_flag.rb +1 -1
  13. data/app/models/concerns/iiif_print/solr/document.rb +5 -3
  14. data/app/presenters/iiif_print/file_set_presenter_decorator.rb +11 -0
  15. data/app/presenters/iiif_print/iiif_manifest_presenter_factory_behavior.rb +1 -1
  16. data/app/presenters/iiif_print/work_show_presenter_decorator.rb +5 -2
  17. data/app/services/iiif_print/manifest_builder_service_behavior.rb +4 -2
  18. data/app/services/iiif_print/pluggable_derivative_service.rb +5 -1
  19. data/app/services/iiif_print/simple_schema_loader_decorator.rb +11 -0
  20. data/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb +34 -0
  21. data/app/transactions/hyrax/transactions/steps/conditionally_destroy_children_from_split.rb +32 -0
  22. data/app/transactions/hyrax/transactions/steps/delete_all_file_sets_decorator.rb +35 -0
  23. data/app/views/hyrax/file_sets/_show_actions.html.erb +1 -1
  24. data/config/initializers/simple_schema_loader.rb +1 -0
  25. data/config/metadata/child_works_from_pdf_splitting.yaml +17 -0
  26. data/db/migrate/20181214181358_create_iiif_print_derivative_attachments.rb +8 -6
  27. data/db/migrate/20190107165909_create_iiif_print_ingest_file_relations.rb +7 -5
  28. data/db/migrate/20230109000000_create_iiif_print_pending_relationships.rb +8 -6
  29. data/db/migrate/20231110163052_add_model_details_to_iiif_print_pending_relationships.rb +3 -3
  30. data/iiif_print.gemspec +1 -1
  31. data/lib/iiif_print/base_derivative_service.rb +13 -2
  32. data/lib/iiif_print/blacklight_iiif_search/annotation_decorator.rb +2 -2
  33. data/lib/iiif_print/catalog_search_builder.rb +2 -2
  34. data/lib/iiif_print/configuration.rb +65 -5
  35. data/lib/iiif_print/data/fileset_helper.rb +2 -2
  36. data/lib/iiif_print/data/work_derivatives.rb +1 -1
  37. data/lib/iiif_print/engine.rb +46 -2
  38. data/lib/iiif_print/homepage_search_builder.rb +2 -2
  39. data/lib/iiif_print/jp2_derivative_service.rb +4 -1
  40. data/lib/iiif_print/lineage_service.rb +19 -6
  41. data/lib/iiif_print/pdf_derivative_service.rb +3 -1
  42. data/lib/iiif_print/persistence_layer/active_fedora_adapter.rb +189 -0
  43. data/lib/iiif_print/persistence_layer/valkyrie_adapter.rb +183 -0
  44. data/lib/iiif_print/persistence_layer.rb +118 -0
  45. data/lib/iiif_print/split_pdfs/base_splitter.rb +11 -0
  46. data/lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb +19 -9
  47. data/lib/iiif_print/split_pdfs/destroy_pdf_child_works_service.rb +5 -16
  48. data/lib/iiif_print/text_extraction_derivative_service.rb +4 -2
  49. data/lib/iiif_print/text_formats_from_alto_service.rb +3 -1
  50. data/lib/iiif_print/tiff_derivative_service.rb +3 -1
  51. data/lib/iiif_print/version.rb +1 -1
  52. data/lib/iiif_print.rb +79 -44
  53. metadata +19 -192
  54. data/app/indexers/concerns/iiif_print/child_indexer.rb +0 -40
  55. data/app/views/hyrax/file_sets/_actions.html.erb +0 -46
  56. data/bin/rails +0 -13
  57. data/spec/.keep.txt +0 -1
  58. data/spec/factories/ability.rb +0 -6
  59. data/spec/factories/newspaper_issue.rb +0 -7
  60. data/spec/factories/newspaper_page.rb +0 -7
  61. data/spec/factories/newspaper_page_solr_document.rb +0 -20
  62. data/spec/factories/newspaper_title.rb +0 -8
  63. data/spec/factories/uploaded_pdf_file.rb +0 -9
  64. data/spec/factories/uploaded_txt_file.rb +0 -9
  65. data/spec/factories/user.rb +0 -13
  66. data/spec/fixtures/authorities/licenses.yml +0 -4
  67. data/spec/fixtures/authorities/rights_statements.yml +0 -4
  68. data/spec/fixtures/files/4.1.07.jp2 +0 -0
  69. data/spec/fixtures/files/4.1.07.tiff +0 -0
  70. data/spec/fixtures/files/README.md +0 -7
  71. data/spec/fixtures/files/alto-2-0.xsd +0 -714
  72. data/spec/fixtures/files/broken-truncated.pdf +0 -0
  73. data/spec/fixtures/files/credits.md +0 -16
  74. data/spec/fixtures/files/lowres-gray-via-ndnp-sample.tiff +0 -0
  75. data/spec/fixtures/files/minimal-1-page.pdf +0 -0
  76. data/spec/fixtures/files/minimal-2-page.pdf +0 -0
  77. data/spec/fixtures/files/minimal-alto.xml +0 -31
  78. data/spec/fixtures/files/ndnp-alto-sample.xml +0 -24
  79. data/spec/fixtures/files/ndnp-sample1-json.json +0 -1
  80. data/spec/fixtures/files/ndnp-sample1-txt.txt +0 -1
  81. data/spec/fixtures/files/ndnp-sample1.pdf +0 -0
  82. data/spec/fixtures/files/ocr_alto.xml +0 -202
  83. data/spec/fixtures/files/ocr_alto_scaled_4pts_per_px.xml +0 -202
  84. data/spec/fixtures/files/ocr_color.tiff +0 -0
  85. data/spec/fixtures/files/ocr_gray.jp2 +0 -0
  86. data/spec/fixtures/files/ocr_gray.tiff +0 -0
  87. data/spec/fixtures/files/ocr_mono.tiff +0 -0
  88. data/spec/fixtures/files/ocr_mono_text_hocr.html +0 -78
  89. data/spec/fixtures/files/page1.tiff +0 -0
  90. data/spec/fixtures/files/sample-4page-issue.pdf +0 -0
  91. data/spec/fixtures/files/sample-color-newsletter.pdf +0 -0
  92. data/spec/fixtures/files/thumbnail.jpg +0 -0
  93. data/spec/helpers/hyrax/iiif_helper_spec.rb +0 -65
  94. data/spec/helpers/iiif_print_helper_spec.rb +0 -43
  95. data/spec/iiif_print/base_derivative_service_spec.rb +0 -28
  96. data/spec/iiif_print/blacklight_iiif_search/annotation_decorator_spec.rb +0 -59
  97. data/spec/iiif_print/catalog_search_builder_spec.rb +0 -60
  98. data/spec/iiif_print/configuration_spec.rb +0 -193
  99. data/spec/iiif_print/data/work_derivatives_spec.rb +0 -245
  100. data/spec/iiif_print/data/work_file_spec.rb +0 -99
  101. data/spec/iiif_print/data/work_files_spec.rb +0 -237
  102. data/spec/iiif_print/image_tool_spec.rb +0 -109
  103. data/spec/iiif_print/jobs/child_works_from_pdf_job_spec.rb +0 -35
  104. data/spec/iiif_print/jobs/create_relationships_job_spec.rb +0 -118
  105. data/spec/iiif_print/jp2_image_metadata_spec.rb +0 -37
  106. data/spec/iiif_print/lineage_service_spec.rb +0 -13
  107. data/spec/iiif_print/metadata_spec.rb +0 -249
  108. data/spec/iiif_print/split_pdfs/base_splitter_spec.rb +0 -27
  109. data/spec/iiif_print/split_pdfs/derivative_rodeo_splitter_spec.rb +0 -80
  110. data/spec/iiif_print/split_pdfs/destroy_pdf_child_works_service_spec.rb +0 -92
  111. data/spec/iiif_print/split_pdfs/pages_to_jpgs_splitter_spec.rb +0 -22
  112. data/spec/iiif_print/split_pdfs/pages_to_pngs_splitter_spec.rb +0 -18
  113. data/spec/iiif_print/split_pdfs/pages_to_tiffs_splitter_spec.rb +0 -19
  114. data/spec/iiif_print/text_extraction/alto_reader_spec.rb +0 -49
  115. data/spec/iiif_print/text_extraction/hocr_reader_spec.rb +0 -45
  116. data/spec/iiif_print/text_extraction/page_ocr_spec.rb +0 -84
  117. data/spec/iiif_print/text_extraction/render_alto_spec.rb +0 -54
  118. data/spec/iiif_print/text_extraction/word_coords_builder_spec.rb +0 -44
  119. data/spec/iiif_print_spec.rb +0 -171
  120. data/spec/misc_shared.rb +0 -111
  121. data/spec/models/iiif_print/derivative_attachment_spec.rb +0 -37
  122. data/spec/models/iiif_print/iiif_search_decorator_spec.rb +0 -27
  123. data/spec/models/iiif_print/ingest_file_relation_spec.rb +0 -56
  124. data/spec/models/solr_document_spec.rb +0 -14
  125. data/spec/presenters/iiif_print/iiif_manifest_presenter_behavior_spec.rb +0 -70
  126. data/spec/presenters/iiif_print/iiif_manifest_presenter_factory_behavior_spec.rb +0 -49
  127. data/spec/samvera/derivatives/configuration_spec.rb +0 -41
  128. data/spec/samvera/derivatives/hyrax_spec.rb +0 -62
  129. data/spec/samvera/derivatives_spec.rb +0 -54
  130. data/spec/services/iiif_print/derivative_rodeo_service_spec.rb +0 -103
  131. data/spec/services/iiif_print/jp2_derivative_service_spec.rb +0 -59
  132. data/spec/services/iiif_print/manifest_builder_service_behavior_spec.rb +0 -20
  133. data/spec/services/iiif_print/pdf_derivative_service_spec.rb +0 -66
  134. data/spec/services/iiif_print/pluggable_derivative_service_spec.rb +0 -175
  135. data/spec/services/iiif_print/text_extraction_derivative_service_spec.rb +0 -82
  136. data/spec/services/iiif_print/text_formats_from_alto_service_spec.rb +0 -127
  137. data/spec/services/iiif_print/tiff_derivative_service_spec.rb +0 -65
  138. data/spec/spec_helper.rb +0 -181
  139. data/spec/support/controller_level_helpers.rb +0 -28
  140. data/spec/support/iiif_print_models.rb +0 -127
  141. data/spec/test_app_templates/blacklight.yml +0 -9
  142. data/spec/test_app_templates/fedora.yml +0 -15
  143. data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -40
  144. data/spec/test_app_templates/redis.yml +0 -9
  145. data/spec/test_app_templates/solr/conf/schema.xml +0 -362
  146. data/spec/test_app_templates/solr/conf/solrconfig.xml +0 -322
  147. data/spec/test_app_templates/solr.yml +0 -7
  148. /data/{lib → app/jobs}/iiif_print/jobs/request_split_pdf_job.rb +0 -0
@@ -1,49 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe IiifPrint::IiifManifestPresenterBehavior do
4
- let(:parent_fs_attributes) do
5
- { "id" => "parent_fs123",
6
- "title_tesim" => ["My Parent FileSet"],
7
- "has_model_ssim" => ["FileSet"] }
8
- end
9
- let(:child_work_attributes) do
10
- { "id" => "child_work123",
11
- "title_tesim" => ["My Child Image"],
12
- "has_model_ssim" => ["Image"],
13
- "file_set_ids_ssim" => ["child_image_fs123"] }
14
- end
15
- let(:child_fs_attributes) do
16
- { "id" => "child_fs123",
17
- "title_tesim" => ["My Child FileSet"],
18
- "has_model_ssim" => ["FileSet"] }
19
- end
20
- let(:parent_fs_solr_doc) { SolrDocument.new(parent_fs_attributes) }
21
- let(:child_work_solr_doc) { SolrDocument.new(child_work_attributes) }
22
- let(:child_fs_solr_doc) { SolrDocument.new(child_fs_attributes) }
23
- let(:ids) { [parent_fs_solr_doc.id, child_work_solr_doc.id] }
24
- let(:presenter_class) { Hyrax::IiifManifestPresenter }
25
-
26
- subject(:presenter_factory) do
27
- Hyrax::IiifManifestPresenter::Factory.new(
28
- ids: ids,
29
- presenter_class: presenter_class,
30
- presenter_args: []
31
- )
32
- end
33
-
34
- describe "#build" do
35
- it "returns an Array of DisplayImagePresenters" do
36
- allow_any_instance_of(Hyrax::IiifManifestPresenter::Factory)
37
- .to receive(:load_docs).and_return([parent_fs_solr_doc, child_work_solr_doc])
38
- allow_any_instance_of(IiifPrint::IiifManifestPresenterFactoryBehavior)
39
- .to receive(:load_file_set_docs).and_return([child_fs_solr_doc])
40
- allow(child_work_solr_doc).to receive(:hydra_model).and_return(MyWork)
41
- allow(Hyrax.config).to receive(:curation_concerns).and_return([MyWork])
42
-
43
- expect(subject.build).to be_an Array
44
- expect(subject.build.size).to eq ids.size
45
- expect(subject.build.map(&:class).uniq.size).to eq 1
46
- expect(subject.build.first.class).to eq Hyrax::IiifManifestPresenter::DisplayImagePresenter
47
- end
48
- end
49
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'samvera/derivatives/configuration'
5
-
6
- RSpec.describe Samvera::Derivatives::Configuration do
7
- let(:file_set) { double(:file_set) }
8
- let(:config) { described_class.new }
9
-
10
- describe '#registry_for' do
11
- it 'has a applicable_for that is falsey' do
12
- register = config.registry_for(type: :thumbnail)
13
- expect(register.applicable_for?(file_set: file_set)).to be_falsey
14
- end
15
- end
16
-
17
- describe '#register' do
18
- it 'amends the existing registry' do
19
- locator = double
20
- type = :thumbnail
21
- expect do
22
- config.register(type: type, locators: [locator], applicators: [])
23
- end.to change { config.registry_for(type: type).locators }.from([]).to([locator])
24
- end
25
-
26
- context 'validation' do
27
- it 'defaults to a truthy validator' do
28
- registry = config.register(type: :thumbnail, locators: [], applicators: [])
29
- expect(registry.applicable_for?(file_set: file_set)).to be_truthy
30
- end
31
-
32
- it 'allows for block configuration' do
33
- registry = config.register(type: :thumbnail, locators: [], applicators: []) do |_file_set|
34
- false
35
- end
36
-
37
- expect(registry.applicable_for?(file_set: file_set)).to be_falsey
38
- end
39
- end
40
- end
41
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
- require 'samvera/derivatives'
4
- require 'samvera/derivatives/hyrax'
5
-
6
- RSpec.describe Samvera::Derivatives::Hyrax::ServiceShim do
7
- let(:config) { Samvera::Derivatives::Configuration.new }
8
- let(:file_set) { FileSet.new }
9
- let(:other_locator) { double('Locator', locate: nil) }
10
- let(:other_applicator) { double('Applicator', apply!: nil) }
11
- before do
12
- config.register(
13
- type: :thumbnail,
14
- locators: [other_locator, Samvera::Derivatives::Hyrax::FileLocatorStrategy],
15
- applicators: [other_applicator, Samvera::Derivatives::Hyrax::FileApplicatorStrategy]
16
- ) { |_file_set| true }
17
- config.register(
18
- type: :jpg,
19
- locators: [other_locator, Samvera::Derivatives::Hyrax::FileLocatorStrategy],
20
- applicators: [other_applicator, Samvera::Derivatives::Hyrax::FileApplicatorStrategy]
21
- ) { |_file_set| true }
22
- end
23
-
24
- let(:shim) { described_class.new(file_set, candidate_derivative_types: [:thumnail, :jpg], config: config) }
25
-
26
- subject { shim }
27
-
28
- it { is_expected.to be_valid }
29
-
30
- describe '#create_derivatives' do
31
- let(:file_path) { __FILE__ }
32
- subject { shim.create_derivatives(file_path) }
33
-
34
- context 'when other locator and applicator are not applicable' do
35
- it 'locates and applies the derivatives using the underlying service' do
36
- expect_any_instance_of(Samvera::Derivatives::Hyrax::FileApplicatorStrategy).to receive(:apply!).and_call_original
37
- expect_any_instance_of(Samvera::Derivatives::Hyrax::FileSetDerivativesServiceWrapper).to receive(:apply!).and_call_original
38
- expect_any_instance_of(::Hyrax::FileSetDerivativesService).to receive(:valid?).and_return(true)
39
- expect_any_instance_of(::Hyrax::FileSetDerivativesService).to receive(:create_derivatives).with(file_path)
40
- expect(other_applicator).to receive(:apply!)
41
-
42
- subject
43
- end
44
- end
45
-
46
- context 'when the other locator finds the derivative' do
47
- let(:other_locator) { double(locate: file_path) }
48
-
49
- it 'uses that located derivative and applies it' do
50
- # Yes, we will attempt to apply the derivative...
51
- expect_any_instance_of(Samvera::Derivatives::Hyrax::FileApplicatorStrategy).to receive(:apply!).and_call_original
52
- # ...however, we won't be leveraging the wrapper's derivative work; meaning no default behavior.
53
- expect_any_instance_of(Samvera::Derivatives::Hyrax::FileSetDerivativesServiceWrapper).not_to receive(:apply!)
54
- expect_any_instance_of(::Hyrax::FileSetDerivativesService).not_to receive(:valid?)
55
- expect_any_instance_of(::Hyrax::FileSetDerivativesService).not_to receive(:create_derivatives)
56
- expect(other_applicator).to receive(:apply!)
57
-
58
- subject
59
- end
60
- end
61
- end
62
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
- require 'samvera/derivatives'
4
-
5
- RSpec.describe Samvera::Derivatives do
6
- describe '.config' do
7
- subject { described_class.config }
8
-
9
- it { is_expected.to be_a(described_class::Configuration) }
10
- end
11
-
12
- describe '.locate_and_apply_derivative_for' do
13
- let(:file_set) { double(FileSet) }
14
- let(:file_path) { __FILE__ }
15
- let(:applicability) { true }
16
- let(:type) { :thumbnail }
17
- let(:locator) { described_class::FileLocator::Strategy }
18
- let(:applicator) { described_class::FileApplicator::Strategy }
19
-
20
- let(:derivative) do
21
- described_class::Configuration::RegisteredType.new(
22
- type: type,
23
- applicators: [applicator],
24
- locators: [locator],
25
- applicability: ->(_) { applicability }
26
- )
27
- end
28
-
29
- subject do
30
- described_class.locate_and_apply_derivative_for(
31
- file_set: file_set,
32
- derivative: derivative,
33
- file_path: file_path
34
- )
35
- end
36
-
37
- context 'when not applicable' do
38
- let(:applicability) { false }
39
-
40
- it { is_expected.to be_falsey }
41
- end
42
-
43
- context 'when applicable' do
44
- let(:from_location) { :from_location }
45
-
46
- it 'locates then applies the derivative' do
47
- expect(locator).to receive(:locate).and_return(from_location)
48
- expect(applicator).to receive(:apply!).with(file_set: file_set, derivative_type: type, from_location: from_location)
49
-
50
- subject
51
- end
52
- end
53
- end
54
- end
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe IiifPrint::DerivativeRodeoService do
6
- let(:work) { double("Work", { :id => 'work-5678', described_class.parent_work_identifier_property_name => 'hello-1234-id' }) }
7
- let(:file_set) { FileSet.new.tap { |fs| fs.save!(validate: false) } }
8
- let(:generator) { DerivativeRodeo::Generators::CopyGenerator }
9
- let(:output_extension) { "rb" }
10
-
11
- before do
12
- allow(file_set).to receive(:parent).and_return(work)
13
-
14
- # TODO: This is a hack that leverages the internals oof Hydra::Works; not excited about it but
15
- # this part is only one piece of the over all integration.
16
- allow(file_set).to receive(:original_file).and_return(double(original_filename: __FILE__))
17
- end
18
-
19
- let(:instance) { described_class.new(file_set) }
20
-
21
- subject(:klass) { described_class }
22
-
23
- describe '.preprocessed_location_adapter_name' do
24
- subject { described_class.preprocessed_location_adapter_name }
25
- it { is_expected.to eq 's3' }
26
- end
27
-
28
- describe '.parent_work_identifier_property_name' do
29
- subject { described_class.parent_work_identifier_property_name }
30
- it { is_expected.to be_a String }
31
- end
32
-
33
- describe '.named_derivatives_and_generators_by_type' do
34
- subject { described_class.named_derivatives_and_generators_by_type }
35
- it { is_expected.to be_a Hash }
36
- end
37
-
38
- describe '.derivative_rodeo_uri' do
39
- subject { described_class.derivative_rodeo_uri(file_set: file_set, filename: __FILE__) }
40
-
41
- context 'when the file_set does not have a parent' do
42
- xit 'is expected to raise an error' do
43
- expect { subject }.to raise_error(IiifPrint::DataError)
44
- end
45
- end
46
-
47
- context 'when the file_set has a parent' do
48
- it { is_expected.to start_with("#{described_class.preprocessed_location_adapter_name}://") }
49
- it { is_expected.to end_with(File.basename(__FILE__)) }
50
- end
51
-
52
- context 'for a thumbnail based on a PDF' do
53
- let(:extension) { DerivativeRodeo::Generators::ThumbnailGenerator.output_extension }
54
- let(:filename) { "/tmp/d20230714-1897-1wgmauo/#{work.aark_id}.ARCHIVAL.pdf" }
55
- it 'has the correct filename' do
56
- expect(described_class.derivative_rodeo_uri(file_set: file_set, filename: filename, extension: extension,
57
- adapter_name: 'file')).to eq("file://#{work.aark_id}/#{work.aark_id}.ARCHIVAL.#{extension}")
58
- end
59
- end
60
-
61
- context 'for the original file' do
62
- let(:extension) { nil }
63
- let(:filename) { "/tmp/d20230714-1897-1wgmauo/#{work.aark_id}.ARCHIVAL.pdf" }
64
- it 'has the correct filename' do
65
- expect(described_class.derivative_rodeo_uri(file_set: file_set, filename: filename, extension: extension, adapter_name: 'file')).to eq("file://#{work.aark_id}/#{work.aark_id}.ARCHIVAL.pdf")
66
- end
67
- end
68
- end
69
-
70
- # TODO: Need Faux Bucket for Derivative Rodeo
71
- xdescribe '#valid?' do
72
- subject { instance.valid? }
73
-
74
- before do
75
- allow(file_set).to receive(:mime_type).and_return(mime_type)
76
- allow(file_set).to receive(:parent).and_return(work)
77
- end
78
-
79
- context 'when the mime_type of the file is not supported' do
80
- let(:mime_type) { "text/plain" }
81
- it { is_expected.to be_falsey }
82
- end
83
-
84
- context 'when derivative rodeo has not pre-processed the file set' do
85
- before { instance.preprocessed_location_adapter_name = "file" }
86
-
87
- let(:mime_type) { "application/pdf" }
88
- it { is_expected.to be_falsey }
89
- end
90
-
91
- context 'when the mime type is supported and the derivative rodeo has pre-processed the file set' do
92
- before do
93
- # TODO: write to the rodeo; consider using AWS's spec support; I want to be able to "fake" S3
94
- # with a "fake" bucket.
95
- #
96
- # Dependent on https://github.com/scientist-softserv/derivative_rodeo/pull/37
97
- end
98
-
99
- let(:mime_type) { "application/pdf" }
100
- it { is_expected.to be_truthy }
101
- end
102
- end
103
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
- RSpec.describe IiifPrint::JP2DerivativeService do
3
- let(:valid_file_set) do
4
- file_set = FileSet.new
5
- file_set.save!(validate: false)
6
- file_set
7
- end
8
-
9
- let(:fixture_path) do
10
- File.join(
11
- IiifPrint::GEM_PATH, 'spec', 'fixtures', 'files'
12
- )
13
- end
14
-
15
- describe "Creates JP2 derivatives" do
16
- def source_image(name)
17
- File.join(fixture_path, name)
18
- end
19
-
20
- def expected_path(file_set)
21
- Hyrax::DerivativePath.derivative_path_for_reference(file_set, 'jp2')
22
- end
23
-
24
- def metadata_match_checker(source, target)
25
- target_meta = IiifPrint::ImageTool.new(target).metadata
26
- source_meta = IiifPrint::ImageTool.new(source).metadata
27
- expect(target_meta[:content_type]).to eq 'image/jp2'
28
- expect(target_meta[:width]).to eq source_meta[:width]
29
- expect(target_meta[:height]).to eq source_meta[:height]
30
- end
31
-
32
- def makes_jp2(filename)
33
- expected = expected_path(valid_file_set)
34
- expect(File.exist?(expected)).to be false
35
- svc = described_class.new(valid_file_set)
36
- source_path = source_image(filename)
37
- svc.create_derivatives(source_path)
38
- expect(File.exist?(expected)).to be true
39
- metadata_match_checker(source_path, expected)
40
- svc.cleanup_derivatives
41
- end
42
-
43
- it "creates gray JP2 derivative from one-bit source" do
44
- makes_jp2('ocr_mono.tiff')
45
- end
46
-
47
- it "creates gray JP2 from grayscale source" do
48
- makes_jp2('lowres-gray-via-ndnp-sample.tiff')
49
- end
50
-
51
- it "creates color JP2 from color source" do
52
- makes_jp2('4.1.07.tiff')
53
- end
54
-
55
- it "creates JP2 from PDF source, robust to multi-page" do
56
- makes_jp2('sample-color-newsletter.pdf')
57
- end
58
- end
59
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- RSpec.describe IiifPrint::ManifestBuilderServiceBehavior do
5
- context '#initialize' do
6
- it 'uses defaults to set the version' do
7
- builder_service = Hyrax::ManifestBuilderService.new
8
- expect(builder_service.manifest_factory).to eq(::IIIFManifest::ManifestFactory)
9
- expect(builder_service.version).to eq(IiifPrint.config.default_iiif_manifest_version)
10
- end
11
-
12
- it 'allows version overrides' do
13
- # This in part verifies the expected interaction of the version as a parameter being picked up
14
- # by another parameter.
15
- builder_service = Hyrax::ManifestBuilderService.new(version: 3)
16
- expect(builder_service.manifest_factory).to eq(::IIIFManifest::V3::ManifestFactory)
17
- expect(builder_service.version).to eq(3)
18
- end
19
- end
20
- end
@@ -1,66 +0,0 @@
1
- require 'spec_helper'
2
- RSpec.describe IiifPrint::PDFDerivativeService do
3
- let(:valid_file_set) do
4
- file_set = FileSet.new
5
- file_set.save!(validate: false)
6
- file_set
7
- end
8
-
9
- let(:fixture_path) do
10
- File.join(
11
- IiifPrint::GEM_PATH, 'spec', 'fixtures', 'files'
12
- )
13
- end
14
-
15
- describe "Creates PDF derivatives" do
16
- def source_image(name)
17
- File.join(fixture_path, name)
18
- end
19
-
20
- def expected_path(file_set)
21
- Hyrax::DerivativePath.derivative_path_for_reference(file_set, 'pdf')
22
- end
23
-
24
- # given output file name, check DPI is 150
25
- def check_dpi(expected)
26
- metadata = IiifPrint::ImageTool.new(expected).metadata
27
- # get width of pdf in points (via imagemagick), should be 864x == 12in
28
- page_width = metadata[:width]
29
- expect(page_width).to eq 864
30
- # get total width of image in pixels from pdfimages -list, ==> 1800
31
- image_width = 1800
32
- im_list = `pdfimages -list #{expected}`
33
- expect(im_list.lines[-1].split(' ')[3]).to eq image_width.to_s
34
- # this combination of page pt width, image px width ==> 150ppi
35
- expect(image_width / (page_width / 72.0)).to eq 150.0
36
- end
37
-
38
- def makes_pdf(filename)
39
- expected = expected_path(valid_file_set)
40
- expect(File.exist?(expected)).to be false
41
- svc = described_class.new(valid_file_set)
42
- svc.create_derivatives(source_image(filename))
43
- expect(File.exist?(expected)).to be true
44
- metadata = IiifPrint::ImageTool.new(expected).metadata
45
- expect(metadata[:content_type]).to eq 'application/pdf'
46
- check_dpi(expected)
47
- svc.cleanup_derivatives
48
- end
49
-
50
- it "creates gray PDF derivative from one-bit source" do
51
- makes_pdf('ocr_mono.tiff')
52
- end
53
-
54
- it "creates gray PDF from grayscale source" do
55
- makes_pdf('lowres-gray-via-ndnp-sample.tiff')
56
- end
57
-
58
- it "creates color PDF from color source" do
59
- makes_pdf('4.1.07.tiff')
60
- end
61
-
62
- it "creates color PDF from color JP2 source" do
63
- makes_pdf('4.1.07.jp2')
64
- end
65
- end
66
- end
@@ -1,175 +0,0 @@
1
- require 'fileutils'
2
- require 'spec_helper'
3
-
4
- RSpec.describe IiifPrint::PluggableDerivativeService do
5
- let(:persisted_file_set) do
6
- fs = FileSet.new
7
- work.title = ['This is a page!']
8
- work.members.push(fs)
9
- fs.instance_variable_set(:@mime_type, 'image/tiff')
10
- fs.save!(validate: false)
11
- work.save!(validate: false)
12
- fs
13
- end
14
-
15
- let(:fixture_path) do
16
- File.join(
17
- IiifPrint::GEM_PATH, 'spec', 'fixtures', 'files'
18
- )
19
- end
20
-
21
- describe "service registration" do
22
- # integration test with Hyrax, verify services is registered
23
-
24
- it "is registered with Hyrax" do
25
- expect(Hyrax::DerivativeService.services).to include described_class
26
- end
27
-
28
- it "is the first valid service found" do
29
- file_set = double(FileSet,
30
- class: FileSet,
31
- mime_type: 'application/pdf',
32
- parent: MyIiifConfiguredWorkWithAllDerivativeServices.new)
33
- found = Hyrax::DerivativeService.for(file_set)
34
- expect(found).to be_a described_class
35
- end
36
- end
37
-
38
- context "when the FileSet's parent is not IiifPrint configured" do
39
- before do
40
- allow(persisted_file_set).to receive(:in_works).and_return([work])
41
- end
42
-
43
- let(:work) { MyWork.new }
44
-
45
- describe "#plugins" do
46
- it "uses the default derivatives service" do
47
- file_set = double(FileSet,
48
- class: FileSet,
49
- mime_type: 'application/pdf',
50
- parent: MyWork.new)
51
- service = described_class.new(file_set)
52
- expect(service.plugins).to eq [Hyrax::FileSetDerivativesService]
53
- end
54
- end
55
- end
56
-
57
- context "when the FileSet's parent is IiifPrint configured" do
58
- describe "calls the configured derivative plugins" do
59
- before do
60
- allow(persisted_file_set).to receive(:in_works).and_return([work])
61
- allow_any_instance_of(Hyrax::FileSetDerivativesService).to receive(:send)
62
- end
63
-
64
- let(:work) { MyIiifConfiguredWork.new }
65
- let(:plugin) { FakeDerivativeService.new }
66
-
67
- it "calls each plugin on create" do
68
- service = described_class.new(persisted_file_set, plugins: [plugin])
69
- expect do
70
- service.create_derivatives('not_a_real_filename')
71
- end.to change(plugin, :create_called).by(1)
72
- end
73
-
74
- def touch_fake_derivative_file(file_set, ext)
75
- path = Hyrax::DerivativePath.derivative_path_for_reference(file_set, ext)
76
- FileUtils.mkdir_p(File.join(path.split('/')[0..-2]))
77
- FileUtils.touch(path)
78
- end
79
-
80
- it "does not re-create existing derivative" do
81
- service = described_class.new(persisted_file_set, plugins: [plugin])
82
- expect(persisted_file_set.id).not_to be_nil
83
- expect do
84
- touch_fake_derivative_file(persisted_file_set, plugin.target_extension)
85
- service.create_derivatives('/nonsense/source/path/ignored ')
86
- end.not_to change(plugin, :create_called)
87
- end
88
-
89
- it "calls each plugin on cleanup" do
90
- service = described_class.new(persisted_file_set, plugins: [plugin])
91
- expect { service.cleanup_derivatives }.to change(plugin, :cleanup_called).by(1)
92
- end
93
- end
94
-
95
- context "integration tests for plugins" do
96
- before do
97
- allow(persisted_file_set).to receive(:in_works).and_return([work])
98
- end
99
-
100
- let(:work) { MyIiifConfiguredWorkWithAllDerivativeServices.new }
101
-
102
- describe "calls all derivative plugins" do
103
- def source_image(name)
104
- File.join(fixture_path, name)
105
- end
106
-
107
- def derivatives_for(file_set)
108
- Hyrax::DerivativePath.derivatives_for_reference(file_set)
109
- end
110
-
111
- def expected_plugins
112
- [
113
- Hyrax::FileSetDerivativesService,
114
- IiifPrint::TextExtractionDerivativeService
115
- ]
116
- end
117
-
118
- # The expected set of Plugins that will run for file set
119
- it "has expected valid plugins configured" do
120
- plugins = described_class.new(persisted_file_set).plugins
121
- fs = persisted_file_set
122
- services = plugins.map { |plugin| plugin.new(fs) }.select(&:valid?)
123
- expect(services.length).to eq 2
124
- used_plugins = services.map(&:class)
125
- expected_plugins.each do |plugin|
126
- expect(used_plugins).to include plugin
127
- end
128
- end
129
-
130
- it "creates expected derivatives from TIFF source" do
131
- svc = described_class.new(persisted_file_set)
132
- svc.create_derivatives(source_image('4.1.07.tiff'))
133
- made = derivatives_for(persisted_file_set)
134
- made.each { |path| expect(File.exist?(path)) }
135
- extensions = made.map { |path| path.split('.')[-1] }
136
- expect(extensions).not_to include 'tiff'
137
- # Thumbnail, created by Hyrax:
138
- expect(extensions).to include 'jpeg'
139
- end
140
- end
141
-
142
- describe "ingest integration" do
143
- def log_attachment(file_set)
144
- # create a log entry for the fileset given destination name 'jp2'
145
- IiifPrint::DerivativeAttachment.create(
146
- fileset_id: file_set.id,
147
- path: '/some/arbitrary/path/to.jp2',
148
- destination_name: 'jp2'
149
- )
150
- end
151
-
152
- def text_plugin?(plugins)
153
- r = plugins.select { |p| p.is_a? IiifPrint::TextExtractionDerivativeServiceService }
154
- !r.empty?
155
- end
156
-
157
- # TODO: This is not working with the default configuration and is part of a larger refactor
158
- # regarding specs.
159
- xit "will not attempt creating over pre-made derivative" do
160
- service = described_class.new(persisted_file_set)
161
- # this should be respected, evaluate by obtaining filtered
162
- # services list, which must omit JP2DerivativeService
163
- plugins = service.services(:create_derivatives)
164
- # initially has jp2 plugin
165
- expect(jp2_plugin?(plugins)).to be true
166
- # deny jp2 by effect of log entry of pre-made attachment
167
- log_attachment(service.file_set)
168
- # omits, after logging intent of previous attachment:
169
- plugins = service.services(:create_derivatives)
170
- expect(jp2_plugin?(plugins)).to be false
171
- end
172
- end
173
- end
174
- end
175
- end