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,65 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- # @note This spec was brought over from Hyrax 3.4.2
5
- # @see https://github.com/samvera/hyrax/blob/afdda8240494ed382301f7d0ab0fd7bafe79185e/spec/helpers/hyrax/iiif_helper_spec.rb
6
- RSpec.describe Hyrax::IiifHelper, type: :helper do
7
- let(:solr_document) { SolrDocument.new }
8
- let(:request) { double }
9
- let(:ability) { nil }
10
- let(:presenter) { Hyrax::WorkShowPresenter.new(solr_document, ability, request) }
11
- let(:uv_partial_path) { 'hyrax/base/iiif_viewers/universal_viewer' }
12
-
13
- describe '#iiif_viewer_display' do
14
- before do
15
- allow(helper).to receive(:iiif_viewer_display_partial).with(presenter)
16
- .and_return(uv_partial_path)
17
- end
18
-
19
- it "renders a partial" do
20
- expect(helper).to receive(:render)
21
- .with(uv_partial_path, presenter: presenter)
22
- helper.iiif_viewer_display(presenter)
23
- end
24
-
25
- it "takes options" do
26
- expect(helper).to receive(:render)
27
- .with(uv_partial_path, presenter: presenter, transcript_id: '123')
28
- helper.iiif_viewer_display(presenter, transcript_id: '123')
29
- end
30
- end
31
-
32
- describe '#iiif_viewer_display_partial' do
33
- subject { helper.iiif_viewer_display_partial(presenter) }
34
-
35
- it 'defaults to universal viewer' do
36
- expect(subject).to eq uv_partial_path
37
- end
38
-
39
- context "with #iiif_viewer override" do
40
- let(:iiif_viewer) { :mirador }
41
-
42
- before do
43
- allow(presenter).to receive(:iiif_viewer).and_return(iiif_viewer)
44
- end
45
-
46
- it { is_expected.to eq 'hyrax/base/iiif_viewers/mirador' }
47
- end
48
- end
49
-
50
- describe '#universal_viewer_base_url' do
51
- subject { helper.universal_viewer_base_url }
52
-
53
- it 'defaults to universal viewer base path' do
54
- expect(subject).to eq "http://test.host/uv/uv.html"
55
- end
56
- end
57
-
58
- describe '#universal_viewer_config_url' do
59
- subject { helper.universal_viewer_config_url }
60
-
61
- it 'defaults to universal viewer base path' do
62
- expect(subject).to eq "http://test.host/uv/uv-config.json"
63
- end
64
- end
65
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe IiifPrintHelper do
4
- let(:query_term) { 'suffrage' }
5
- let(:query_params_hash) { { q: query_term } }
6
- let(:document) { build(:newspaper_page_solr_document) }
7
-
8
- describe '#iiif_search_anchor' do
9
- it 'returns the correct string' do
10
- expect(helper.iiif_search_anchor({})).to eq nil
11
- expect(helper.iiif_search_anchor(query_params_hash)).to eq("?h=#{query_term}")
12
- end
13
- end
14
-
15
- describe '#search_query' do
16
- it 'returns the correct string' do
17
- expect(helper.search_query({})).to eq nil
18
- expect(helper.search_query(query_params_hash)).to eq(query_term)
19
- end
20
- end
21
-
22
- describe '#highlight_matches' do
23
- let(:hl_fl) { 'all_text_tsimv' }
24
-
25
- describe 'when highlighting is present in Solr response' do
26
- before do
27
- allow(document).to receive(:highlight_field).with(hl_fl).and_return(['foo <em>bar</em> baz'.html_safe])
28
- end
29
- it 'returns the matching terms when highlighting present' do
30
- expect(helper.highlight_matches(document, hl_fl, 'em')).to eq 'bar'
31
- end
32
- end
33
-
34
- describe 'when highlighting is not present' do
35
- before do
36
- allow(document).to receive(:highlight_field).with(hl_fl).and_return([])
37
- end
38
- it 'returns the matching terms when highlighting present' do
39
- expect(helper.highlight_matches(document, hl_fl, 'em')).to eq nil
40
- end
41
- end
42
- end
43
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe IiifPrint::BaseDerivativeService do
4
- let(:file_set) { double(FileSet) }
5
- let(:service) { described_class.new(file_set) }
6
-
7
- describe '#valid?' do
8
- subject { service.valid? }
9
-
10
- context 'when given an image file' do
11
- let(:file_set) { double(FileSet, mime_type: 'image/tiff', class: FileSet) }
12
-
13
- it { is_expected.to be_truthy }
14
- end
15
-
16
- context 'when given a non-image file' do
17
- let(:file_set) { double(FileSet, mime_type: 'audio/mpeg', class: FileSet) }
18
-
19
- it { is_expected.to be_falsey }
20
- end
21
- end
22
-
23
- describe "instance" do
24
- subject { service }
25
-
26
- it { is_expected.to respond_to :target_extension }
27
- end
28
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe IiifPrint::BlacklightIiifSearch::AnnotationDecorator do
4
- let(:parent_id) { 'abc123' }
5
- let(:page_document) do
6
- doc = build(:newspaper_page_solr_document)
7
- doc['is_page_of_ssim'] = [parent_id]
8
- doc
9
- end
10
- let(:controller) { CatalogController.new }
11
- let(:coordinates) do
12
- JSON.parse("{\"coords\":{\"software\":[[2641,4102,512,44]]}}")
13
- end
14
- let(:parent_document) do
15
- SolrDocument.new('id' => parent_id,
16
- 'has_model_ssim' => ['NewspaperIssue'])
17
- end
18
- let(:query) { "software AND (is_page_of_ssim:#{parent_id} OR id:#{parent_id})" }
19
- let(:iiif_search_annotation) do
20
- BlacklightIiifSearch::IiifSearchAnnotation.new(page_document, query,
21
- 0, nil, controller,
22
- parent_document)
23
- end
24
- let(:file_set) { build(:file_set_solr_document) }
25
- let(:test_request) { ActionDispatch::TestRequest.new({}) }
26
-
27
- before do
28
- allow(controller).to receive(:request).and_return(test_request)
29
- allow(controller).to receive(:polymorphic_url)
30
- .with(parent_document, host: test_request.base_url, locale: nil)
31
- .and_return("/#{page_document[:issue_id_ssi]}")
32
- allow(SolrDocument).to receive(:find).with(file_set.id).and_return(file_set)
33
- end
34
-
35
- describe '#annotation_id' do
36
- subject { iiif_search_annotation.annotation_id }
37
- it 'returns a properly formatted URL' do
38
- expect(subject).to include("#{page_document[:issue_id_ssi]}/manifest/canvas/#{page_document[:file_set_ids_ssim].first}/annotation/0")
39
- end
40
- end
41
-
42
- describe '#canvas_uri_for_annotation' do
43
- before { allow(iiif_search_annotation).to receive(:fetch_and_parse_coords).and_return(coordinates) }
44
-
45
- subject { iiif_search_annotation.canvas_uri_for_annotation }
46
- it 'returns a properly formatted URL' do
47
- expect(subject).to include("#{page_document[:issue_id_ssi]}/manifest/canvas/#{page_document[:file_set_ids_ssim].first}")
48
- end
49
-
50
- describe 'private methods' do
51
- # test #coordinates based on output of #canvas_uri_for_annotation, which calls it
52
- describe '#coordinates' do
53
- it 'gets the expected value from #coordinates' do
54
- expect(subject).to include("#xywh=2641,4102,512,44")
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe IiifPrint::CatalogSearchBuilder do
4
- # specs for IiifPrint::HighlightSearchParams
5
- describe 'highlight_search_params' do
6
- let(:solr_parameters) { { q: 'abolition' } }
7
- subject { described_class.new(solr_parameters) }
8
-
9
- it 'is included in the default_processor_chain' do
10
- expect(described_class.default_processor_chain).to include(:highlight_search_params)
11
- end
12
-
13
- before { subject.highlight_search_params(solr_parameters) }
14
- it 'adds the highlight fields to solr_parameters' do
15
- expect(solr_parameters[:hl]).to be_truthy
16
- expect(solr_parameters[:'hl.fl']).to eq('*')
17
- end
18
- end
19
-
20
- # specs for IiifPrint::ExcludeModels
21
- describe 'exclude_models' do
22
- let(:solr_parameters) { { all_fields: 'prohibition' } }
23
- subject { described_class.new(solr_parameters) }
24
-
25
- it 'is included in the default_processor_chain' do
26
- expect(described_class.default_processor_chain).to include(:exclude_models)
27
- end
28
-
29
- context 'with configured model name solr field values' do
30
- before do
31
- config = IiifPrint::Configuration.new.tap { |c| c.excluded_model_name_solr_field_values = ['Excluded Model', 'Another Excluded Model'] }
32
- subject.exclude_models(solr_parameters, config: config)
33
- end
34
-
35
- it 'adds the facet fields to solr_parameters with default key' do
36
- expect(solr_parameters[:fq]).to be_truthy
37
- expect(solr_parameters[:fq]).to(
38
- include("-human_readable_type_sim:\"Excluded Model\"", "-human_readable_type_sim:\"Another Excluded Model\"")
39
- )
40
- end
41
-
42
- context 'with configured model name solr field key' do
43
- before do
44
- config = IiifPrint::Configuration.new.tap do |c|
45
- c.excluded_model_name_solr_field_values = ['ExcludedModel', 'AnotherExcludedModel']
46
- c.excluded_model_name_solr_field_key = 'has_model_ssim'
47
- end
48
- subject.exclude_models(solr_parameters, config: config)
49
- end
50
-
51
- it 'adds the facet fields to solr_parameters with configured key' do
52
- expect(solr_parameters[:fq]).to be_truthy
53
- expect(solr_parameters[:fq]).to(
54
- include("-has_model_ssim:\"ExcludedModel\"", "-has_model_ssim:\"AnotherExcludedModel\"")
55
- )
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,193 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe IiifPrint::Configuration do
4
- let(:config) { described_class.new }
5
-
6
- describe '#ancestory_identifier_function' do
7
- subject(:function) { config.ancestory_identifier_function }
8
- it "is expected to be a lambda with an arity of one" do
9
- expect(function.arity).to eq(1)
10
- end
11
-
12
- it "is configurable" do
13
- expect do
14
- config.ancestory_identifier_function = ->(w) { w.object_id }
15
- end.to change { config.ancestory_identifier_function.object_id }
16
- end
17
- end
18
-
19
- describe '#unique_child_title_generator_function' do
20
- subject(:function) { config.unique_child_title_generator_function }
21
-
22
- it "is expected to be a lambda with keyword args" do
23
- expect(function.parameters).to eq([[:keyreq, :original_pdf_path],
24
- [:keyreq, :image_path],
25
- [:keyreq, :parent_work],
26
- [:keyreq, :page_number],
27
- [:keyreq, :page_padding]])
28
- end
29
-
30
- it 'works as originally designed' do
31
- work = double(title: ["My Title"], id: '1234')
32
- expect(function.call(
33
- original_pdf_path: "/hello/world/nice.pdf",
34
- image_path: __FILE__,
35
- parent_work: work,
36
- page_number: 23,
37
- page_padding: 5
38
- )).to eq("1234 - nice.pdf Page 00024")
39
- end
40
-
41
- it "is configurable" do
42
- expect do
43
- config.unique_child_title_generator_function = ->(**kwargs) { kwargs }
44
- end.to change { config.unique_child_title_generator_function.object_id }
45
- end
46
- end
47
-
48
- describe "#metadata_fields" do
49
- subject { config.metadata_fields }
50
-
51
- it { is_expected.to be_a Hash }
52
- it "allows for an override" do
53
- original = config.metadata_fields
54
- config.metadata_fields = { title: {} }
55
- expect(config.metadata_fields).not_to eq original
56
- end
57
- end
58
-
59
- describe "#handle_after_create_fileset" do
60
- let(:file_set) { double(FileSet) }
61
- let(:user) { double(User) }
62
- subject(:called_function) { config.handle_after_create_fileset(file_set, user) }
63
-
64
- context "without configuration" do
65
- it "calls IiifPrint::Data.handle_after_create_fileset" do
66
- expect(IiifPrint::Data).to receive(:handle_after_create_fileset).with(file_set, user)
67
-
68
- called_function
69
- end
70
- end
71
-
72
- context "with configuration" do
73
- let(:config_func) { ->(_file_set, _user) { :yup } }
74
-
75
- it "calls the given configured lambda" do
76
- config.after_create_fileset_handler = config_func
77
- expect(IiifPrint::Data).not_to receive(:handle_after_create_fileset)
78
- expect(config_func).to receive(:call).with(file_set, user)
79
- called_function
80
- end
81
- end
82
- end
83
-
84
- describe '#additional_tesseract_options' do
85
- context "by default" do
86
- subject { config.additional_tesseract_options }
87
- it { is_expected.not_to be_present }
88
- end
89
-
90
- it "can be configured" do
91
- expect do
92
- config.additional_tesseract_options = "-l esperanto"
93
- end.to change(config, :additional_tesseract_options)
94
- .from("")
95
- .to("-l esperanto")
96
- end
97
- end
98
-
99
- describe '#default_iiif_manifest_version' do
100
- subject { config.default_iiif_manifest_version }
101
-
102
- context 'default' do
103
- it { is_expected.to eq 2 }
104
- end
105
-
106
- context 'when set to empty' do
107
- before { config.default_iiif_manifest_version = '' }
108
- it { is_expected.to eq 2 }
109
- end
110
-
111
- it 'can be set' do
112
- expect { config.default_iiif_manifest_version = 3 }
113
- .to change(config, :default_iiif_manifest_version)
114
- .from(2)
115
- .to(3)
116
- end
117
- end
118
-
119
- describe '#child_work_attributes_function' do
120
- subject(:function) { config.child_work_attributes_function }
121
-
122
- it "is expected to be a lambda with keyword args" do
123
- expect(function.parameters).to eq([[:keyreq, :parent_work],
124
- [:keyreq, :admin_set_id]])
125
- end
126
- end
127
-
128
- describe "#sort_iiif_manifest_canvases_by" do
129
- subject { config.sort_iiif_manifest_canvases_by }
130
-
131
- it { is_expected.to be_a NilClass }
132
- it "allows for an override" do
133
- original = config.sort_iiif_manifest_canvases_by
134
- config.sort_iiif_manifest_canvases_by = :title
135
- expect(config.metadata_fields).not_to eq original
136
- end
137
- end
138
-
139
- describe "#ocr_coords_from_json_function" do
140
- subject(:function) { config.ocr_coords_from_json_function }
141
-
142
- it "is expected to be a lambda with one keyword arg and optional args" do
143
- expect(function.parameters).to eq([[:keyreq, :file_set_id], [:keyrest]])
144
- end
145
- end
146
-
147
- describe "#all_text_generator_function" do
148
- subject(:function) { config.all_text_generator_function }
149
-
150
- it "is expected to be a lambda with one keyword arg" do
151
- expect(function.parameters).to eq([[:keyreq, :object]])
152
- end
153
- end
154
-
155
- describe "#iiif_metadata_field_presentation_order" do
156
- subject { config.iiif_metadata_field_presentation_order }
157
-
158
- it { is_expected.to be_a NilClass }
159
- it "allows for an override" do
160
- original = config.iiif_metadata_field_presentation_order
161
- config.iiif_metadata_field_presentation_order = :title
162
- expect(config.iiif_metadata_field_presentation_order).not_to eq original
163
- end
164
- end
165
-
166
- describe "#questioning_authority_fields" do
167
- subject { config.questioning_authority_fields }
168
-
169
- it { is_expected.to be_a Array }
170
- context "by default" do
171
- it { is_expected.to eq ['rights_statement', 'license'] }
172
- end
173
-
174
- it "allows for an override" do
175
- expect do
176
- config.questioning_authority_fields = ['rights_statement', 'license', 'subject']
177
- end.to change(config, :questioning_authority_fields).from(['rights_statement', 'license']).to(['rights_statement', 'license', 'subject'])
178
- end
179
- end
180
-
181
- describe '#skip_splitting_pdf_files_that_end_with_these_texts' do
182
- subject { config.skip_splitting_pdf_files_that_end_with_these_texts }
183
- context 'by default' do
184
- it { is_expected.to be_empty }
185
- end
186
-
187
- context 'is configurable' do
188
- before { config.skip_splitting_pdf_files_that_end_with_these_texts = ['.READER.pdf'] }
189
-
190
- it { is_expected.not_to be_empty }
191
- end
192
- end
193
- end
@@ -1,245 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
- require 'misc_shared'
5
-
6
- RSpec.describe IiifPrint::Data::WorkDerivatives do
7
- include_context "shared setup"
8
-
9
- let(:bare_work) do
10
- work = NewspaperPage.new
11
- work.title = ['Another one']
12
- work.save!
13
- work
14
- end
15
-
16
- let(:work) do
17
- # sample work comes from shared setup, but we need derivative, save...
18
- mk_txt_derivative(sample_work)
19
- sample_work.save!(validate: false)
20
- sample_work
21
- end
22
-
23
- let(:adapter) { described_class.new(work) }
24
-
25
- let(:txt1) do
26
- registered_dirs = IiifPrint.config.registered_ingest_dirs
27
- registered_dirs.push('/tmp') unless registered_dirs.include?('/tmp')
28
- file = Tempfile.new(['txt1', '.txt'])
29
- file.write('hello')
30
- file.flush
31
- file
32
- end
33
-
34
- let(:txt2) do
35
- file = Tempfile.new('txt2.txt')
36
- file.write('bye')
37
- file.flush
38
- file
39
- end
40
-
41
- let(:encoded_text) do
42
- file = Tempfile.new('txt_encoded.txt', encoding: 'UTF-8')
43
- file.write('Gorgonzola Dolce® — on sale for £12.50/kg')
44
- file.flush
45
- file
46
- end
47
-
48
- describe "enumerates available derivatives like hash" do
49
- xit "includes expected derivative path for work" do
50
- expect(adapter.keys).to include 'txt'
51
- end
52
-
53
- xit "can be introspected for quantity of derivatives" do
54
- # `size` method without argument is count of derivatives,
55
- # functions equivalently to adapter.keys.size
56
- expect(adapter.size).to eq adapter.keys.size
57
- end
58
-
59
- xit "enumerates expected derivative extension for work" do
60
- ext_found = adapter.keys
61
- expect(ext_found).to include 'txt'
62
- end
63
-
64
- xit "enumerates expected derivative extension for file set" do
65
- file_set = work.members.detect { |m| m.is_a? FileSet }
66
- adapter = described_class.new(file_set)
67
- ext_found = adapter.keys
68
- expect(ext_found).to include 'txt'
69
- end
70
-
71
- xit "enumerates expected derivative extension for file set id" do
72
- file_set = work.members.detect { |m| m.is_a? FileSet }
73
- adapter = described_class.new(file_set.id)
74
- ext_found = adapter.keys
75
- expect(ext_found).to include 'txt'
76
- end
77
- end
78
-
79
- describe "loads derivatives for a work" do
80
- xit "Loads text derivative path" do
81
- expect(File.exist?(adapter.path('txt'))).to be true
82
- expect(adapter.exist?('txt')).to be true
83
- end
84
-
85
- xit "Loads text derivative data" do
86
- expect(adapter.data('txt')).to include 'mythical'
87
- end
88
-
89
- xit "Handles character encoding on read" do
90
- # replace fixture text derivative for work with encoded text
91
- adapter.attach(encoded_text.path, 'txt')
92
- data = adapter.data('txt')
93
- expect(data).to include '—' # em-dash
94
- expect(data).to include '£' # gb-pound sign
95
- expect(data.encoding.to_s).to eq 'UTF-8'
96
- end
97
-
98
- xit "Loads thumbnail derivative data" do
99
- mk_thumbnail_derivative(work)
100
- # get size by loading data
101
- expect(adapter.data('thumbnail').bytes.size).to eq 16_743
102
- # get size by File.size via .size method
103
- expect(adapter.size('thumbnail')).to eq 16_743
104
- end
105
-
106
- xit "Can access jp2 derivative" do
107
- mk_jp2_derivative(work)
108
- expect(File.exist?(adapter.path('jp2'))).to be true
109
- expect(adapter.exist?('jp2')).to be true
110
- end
111
- end
112
-
113
- describe "create, update, delete derivatives" do
114
- xit "will queue derivative file assignment" do
115
- adapter = described_class.new(bare_work)
116
- adapter.assign(example_gray_jp2)
117
- expect(adapter.assigned).to include example_gray_jp2
118
- end
119
-
120
- xit "will fail to assign file in non-registered dirs" do
121
- adapter = described_class.new(bare_work)
122
- # need a non-whitlisted file that exists:
123
- bad_path = File.expand_path("../../spec_helper.rb", fixture_path)
124
- expect { adapter.assign(bad_path) }.to raise_error(SecurityError)
125
- end
126
-
127
- xit "will remove file assignment from queue" do
128
- adapter = described_class.new(bare_work)
129
- expect(adapter.state).to eq 'empty'
130
- adapter.assign(example_gray_jp2)
131
- expect(adapter.assigned).to include example_gray_jp2
132
- expect(adapter.state).to eq 'dirty'
133
- adapter.unassign(example_gray_jp2)
134
- expect(adapter.assigned).not_to include example_gray_jp2
135
- expect(adapter.state).to eq 'empty'
136
- end
137
-
138
- xit "will queue a deletion" do
139
- # Given a work with a derivative (txt) already assigned
140
- expect(adapter.state).to eq 'saved'
141
- # unassigning path...
142
- adapter.unassign('txt')
143
- # will lead to queued unassignment (intent to delete)...
144
- expect(adapter.unassigned).to include 'txt'
145
- # and a 'dirty' adapter state (unflushed changes):
146
- expect(adapter.state).to eq 'dirty'
147
- end
148
-
149
- xit "will flush a removal and addition on commit!" do
150
- # Given a work with a derivative (txt) already assigned
151
- expect(adapter.keys).to include 'txt'
152
- expect(adapter.keys).not_to include 'jp2'
153
- # unassigning path...
154
- adapter.unassign('txt')
155
- # and assigning another attachment:
156
- adapter.assign(example_gray_jp2)
157
- # ...committing these will flush the changes (synchronously):
158
- adapter.commit!
159
- expect(adapter.keys).not_to include 'txt'
160
- expect(adapter.keys).to include 'jp2'
161
- expect(adapter.size('jp2')).to eq 27_703
162
- end
163
-
164
- xit "can attach derivative from file" do
165
- expect(adapter.keys).not_to include 'jp2'
166
- adapter.attach(example_gray_jp2, 'jp2')
167
- expect(adapter.exist?('jp2')).to be true
168
- expect(adapter.path('jp2')).not_to be nil
169
- expect(File.size(adapter.path('jp2'))).to eq File.size(example_gray_jp2)
170
- expect(adapter.keys).to include 'jp2'
171
- d_path = path_factory.derivative_path_for_reference(adapter.fileset_id, 'jp2')
172
- expect(adapter.values).to include d_path
173
- end
174
-
175
- xit "can replace aderivative with new attachment" do
176
- adapter.attach(txt1.path, 'txt')
177
- expect(adapter.data('txt')).to eq 'hello'
178
- adapter.attach(txt2.path, 'txt')
179
- expect(adapter.data('txt')).to eq 'bye'
180
- end
181
-
182
- xit "can delete an attached derivative" do
183
- adapter.attach(txt1.path, 'txt')
184
- expect(adapter.keys).to include 'txt'
185
- expect(adapter.data('txt')).to eq 'hello'
186
- adapter.delete('txt')
187
- expect(adapter.path('txt')).to be nil
188
- expect(adapter.keys).not_to include 'txt'
189
- end
190
-
191
- xit "persists log of attachment to RDBMS" do
192
- adapter.assign(txt1.path)
193
- result = IiifPrint::DerivativeAttachment.find_by(
194
- fileset_id: adapter.fileset.id,
195
- path: txt1.path,
196
- destination_name: 'txt'
197
- )
198
- expect(result).not_to be_nil
199
- end
200
-
201
- xit "persists a log of path relation to primary file" do
202
- # this is an integration test by practical necessity, with
203
- # WorkFiles adapting a bare work with no fileset.
204
- work_files = IiifPrint::Data::WorkFiles.of(bare_work)
205
- work_files.assign(example_gray_jp2)
206
- adapter = work_files.derivatives
207
- adapter.assign(txt1.path)
208
- result = IiifPrint::IngestFileRelation.find_by(
209
- derivative_path: txt1.path,
210
- file_path: example_gray_jp2
211
- )
212
- expect(result).not_to be_nil
213
- end
214
-
215
- xit "commits queued derivatives" do
216
- IiifPrint::IngestFileRelation.where(file_path: example_gray_jp2).delete_all
217
- work_files = IiifPrint::Data::WorkFiles.of(bare_work)
218
- work_files.assign(example_gray_jp2)
219
- adapter = work_files.derivatives
220
- adapter.assign(txt1.path)
221
- expect(File.exist?(txt1.path)).to be true
222
- expect(adapter.keys.size).to eq 0
223
- # we need a fileset, saved with import_url, attached to work:
224
- fileset = valid_file_set
225
- fileset.import_url = 'file://' + example_gray_jp2
226
- fileset.save!
227
- bare_work.members.push(fileset)
228
- bare_work.save!
229
- fileset.reload
230
- expect(fileset.member_of[0].id).to eq bare_work.id
231
- # with a new adapter instance...
232
- adapter2 = described_class.of(bare_work)
233
- # call .commit_queued! with our fileset...
234
- expect(File.exist?(txt1.path)).to be true
235
- adapter2.commit_queued!(fileset)
236
- # ...which should result in saved, reloaded derivative...
237
- expect(adapter2.keys.size).to eq 1
238
- expect(File.size(adapter2.values[0])).to eq File.size(txt1.path)
239
- # ...also found via Hyrax::DerviativePath:
240
- found = Hyrax::DerivativePath.derivatives_for_reference(fileset.id)
241
- expect(found.size).to eq 1
242
- expect(File.size(found[0])).to eq File.size(txt1.path)
243
- end
244
- end
245
- end