Skip to content

Commit

Permalink
Merge 40a455d into 22db2ac
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmcbride committed Jul 3, 2020
2 parents 22db2ac + 40a455d commit 893e27d
Show file tree
Hide file tree
Showing 37 changed files with 919 additions and 894 deletions.
47 changes: 36 additions & 11 deletions .rubocop.yml
@@ -1,20 +1,43 @@
inherit_gem:
bixby: bixby_default.yml
bixby: bixby_default.yml

RSpec/ExampleLength:
Max: 15
Exclude:
- 'spec/lib/newspaper_works/data/work_derivatives_spec.rb'
- 'spec/lib/newspaper_works/ingest/ndnp/issue_ingester_spec.rb'
Style/FrozenStringLiteralComment:
Enabled: false

AllCops:
TargetRubyVersion: 2.1
TargetRubyVersion: 2.4
DisplayCopNames: true
Exclude:
- 'db/**/*'
- 'script/**/*'
- 'spec/test_app_templates/**/*'
- 'vendor/**/*'
# Resole the issues below
- 'app/helpers/newspaper_works/breadcrumb_helper.rb'
- 'app/helpers/newspaper_works/newspaper_works_helper_behavior.rb'
- 'app/helpers/newspaper_works/newspaper_works_helper_behavior.rb'
- 'app/models/newspaper_article.rb'
- 'app/validators/newspaper_works/publication_date_start_end_validator.rb'
- 'app/validators/newspaper_works/publication_date_validator.rb'
- 'lib/newspaper_works/data/work_derivatives.rb'
- 'lib/newspaper_works/data/work_files.rb'
- 'lib/newspaper_works/ingest.rb'
- 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb'
- 'app/indexers/newspaper_issue_indexer.rb'
- 'lib/newspaper_works/ingest/pdf_pages.rb'
- 'lib/newspaper_works/page_finder.rb'
- 'lib/newspaper_works/text_extraction/hocr_reader.rb'
- 'lib/tasks/newspaper_works_tasks.rake'
- 'spec/lib/newspaper_works/data/work_derivatives_spec.rb'
- 'spec/lib/newspaper_works/data/work_files_spec.rb'
- 'spec/lib/newspaper_works/ingest/ndnp/container_ingester_spec.rb'
- 'tasks/newspaperworks_dev.rake'

Layout/LineLength:
Exclude:
- 'spec/lib/newspaper_works/data/work_derivatives_spec.rb'
- 'spec/lib/newspaper_works/ingest/ndnp/issue_ingester_spec.rb'
- 'lib/generators/newspaper_works/catalog_controller_generator.rb'

Lint/ImplicitStringConcatenation:
Exclude:
Expand All @@ -41,10 +64,6 @@ Metrics/ClassLength:
- 'lib/newspaper_works/ingest/ndnp/page_ingester.rb'
- 'lib/newspaper_works/ingest/lc_publication_info.rb'

Metrics/LineLength:
Exclude:
- 'lib/generators/newspaper_works/catalog_controller_generator.rb'

Metrics/MethodLength:
Exclude:
- 'app/helpers/newspaper_works/breadcrumb_helper.rb'
Expand Down Expand Up @@ -141,3 +160,9 @@ RSpec/LeadingSubject:

RSpec/VerifiedDoubles:
Enabled: false

RSpec/ExampleLength:
Max: 19

Rails/RakeEnvironment:
Enabled: false
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -32,7 +32,7 @@ Jump in: [![Slack Status](http://slack.samvera.org/badge.svg)](http://slack.samv
# Overview
NewspaperWorks is a gem (Rails "engine") for [Hyrax](https://hyrax.samvera.org/) -based digital repository applications to support ingest, management, and display of digitzed newspaper content.

NewspaperWorks is not a stand-alone application. It is designed to be integrated into a new or existing Hyrax (2.5.x) application, providing content models, ingest workflows, and feature-rich UX for newspaper repository use-cases.
NewspaperWorks is not a stand-alone application. It is designed to be integrated into a new or existing Hyrax (2.6) application, providing content models, ingest workflows, and feature-rich UX for newspaper repository use-cases.

NewspaperWorks supports:
* models for Title, Issue, Page, and Article
Expand All @@ -55,7 +55,7 @@ A set of helpful documents to help you learn more and deploy NewspaperWorks can
* [Ruby](https://rubyonrails.org/) >=2.4
* [Rails](https://rubyonrails.org/) ~>5.1
* [Bundler](http://bundler.io/)
* [Hyrax](https://github.com/samvera/hyrax) ~>2.5
* [Hyrax](https://github.com/samvera/hyrax) ~>2.6
- ..._and various [Samvera dependencies](https://github.com/samvera/hyrax#getting-started) that entails_.
* A Hyrax-based Rails application

Expand All @@ -73,7 +73,7 @@ A set of helpful documents to help you learn more and deploy NewspaperWorks can
See the [wiki](https://github.com/samvera-labs/newspaper_works/wiki/Installing,-Developing,-and-Testing) for more details on how to install and configure dependencies.

# Installation
NewspaperWorks easily integrates with your Hyrax 2.5.x applications.
NewspaperWorks easily integrates with your Hyrax 2.6 applications.

* Add `gem 'newspaper_works'` to your Gemfile.
* Run `bundle install`
Expand Down
120 changes: 60 additions & 60 deletions app/controllers/newspaper_works/newspapers_controller.rb
Expand Up @@ -43,75 +43,75 @@ def page

private

# override from Hyrax::WorksControllerBehavior
# or else this evals to 'dashboard'
def decide_layout
File.join(theme, '1_column')
end
# override from Hyrax::WorksControllerBehavior
# or else this evals to 'dashboard'
def decide_layout
File.join(theme, '1_column')
end

# override from Hyrax::BreadcrumbsForWorks; copy of Hyrax::Breadcrumbs
# so method gets called despite action_name != 'show'
def build_breadcrumbs
if request.referer
trail_from_referer
else
default_trail
end
# override from Hyrax::BreadcrumbsForWorks; copy of Hyrax::Breadcrumbs
# so method gets called despite action_name != 'show'
def build_breadcrumbs
if request.referer
trail_from_referer
else
default_trail
end
end

def bad_url_handler
raise(ActionController::RoutingError, 'Not Found')
end
def bad_url_handler
raise(ActionController::RoutingError, 'Not Found')
end

def find_title
unique_id_field = NewspaperWorks.config.publication_unique_id_field
solr_params = ["has_model_ssim:\"NewspaperTitle\""]
solr_params << "#{unique_id_field}:\"#{params[:unique_id]}\""
@title = find_object(solr_params.join(' AND '))
end
def find_title
unique_id_field = NewspaperWorks.config.publication_unique_id_field
solr_params = ["has_model_ssim:\"NewspaperTitle\""]
solr_params << "#{unique_id_field}:\"#{params[:unique_id]}\""
@title = find_object(solr_params.join(' AND '))
end

def find_issue
return nil unless @title
solr_params = ["has_model_ssim:\"NewspaperIssue\""]
solr_params << "publication_id_ssi:\"#{@title['id']}\""
solr_params << "publication_date_dtsi:\"#{params[:date]}T00:00:00Z\""
solr_params << "edition_number_tesim:\"#{edition_for_search}\""
@issue = find_object(solr_params.join(' AND '))
end
def find_issue
return nil unless @title
solr_params = ["has_model_ssim:\"NewspaperIssue\""]
solr_params << "publication_id_ssi:\"#{@title['id']}\""
solr_params << "publication_date_dtsi:\"#{params[:date]}T00:00:00Z\""
solr_params << "edition_number_tesim:\"#{edition_for_search}\""
@issue = find_object(solr_params.join(' AND '))
end

def find_page
return nil unless @issue
page_index = pagenum_to_index
pages = pages_for_issue(@issue['id'])
return nil if pages.blank? || pages[page_index].blank?
search_result_document(id: pages[page_index]['id'])
end
def find_page
return nil unless @issue
page_index = pagenum_to_index
pages = pages_for_issue(@issue['id'])
return nil if pages.blank? || pages[page_index].blank?
search_result_document(id: pages[page_index]['id'])
end

def find_object(solr_params)
begin
solr_resp = Blacklight.default_index.search(fq: solr_params)
rescue # in case of RSolr::Error, etc.
return nil
end
return nil unless solr_resp.documents.count == 1
object_id = solr_resp.documents.first['id']
# we run the search again, to add permissions/access filters
# invoked by Hyrax::WorkSearchBuilder
search_result_document(id: object_id)
def find_object(solr_params)
begin
solr_resp = Blacklight.default_index.search(fq: solr_params)
rescue # in case of RSolr::Error, etc.
return nil
end
return nil unless solr_resp.documents.count == 1
object_id = solr_resp.documents.first['id']
# we run the search again, to add permissions/access filters
# invoked by Hyrax::WorkSearchBuilder
search_result_document(id: object_id)
end

def edition_for_search
edition = params[:edition]
default = '1'
return default if edition.nil?
edition = edition.gsub(/\Aed-/, '')
return default unless edition.to_i.positive?
edition
end
def edition_for_search
edition = params[:edition]
default = '1'
return default if edition.nil?
edition = edition.gsub(/\Aed-/, '')
return default unless edition.to_i.positive?
edition
end

def pagenum_to_index
page_i = params[:page].gsub(/\Aseq-/, '').to_i
(page_i - 1).negative? ? 0 : (page_i - 1)
end
def pagenum_to_index
page_i = params[:page].gsub(/\Aseq-/, '').to_i
(page_i - 1).negative? ? 0 : (page_i - 1)
end
end
end
18 changes: 9 additions & 9 deletions app/controllers/newspaper_works/newspapers_search_controller.rb
Expand Up @@ -11,16 +11,16 @@ def search

private

# we need this for proper routing of search forms/links
def search_action_url(*args)
main_app.search_catalog_url(*args)
end
# we need this for proper routing of search forms/links
def search_action_url(*args)
main_app.search_catalog_url(*args)
end

def newspaper_search_facets
response, = search_results(params) do |search_builder|
search_builder.except(:add_advanced_search_to_solr)
end
response
def newspaper_search_facets
response, = search_results(params) do |search_builder|
search_builder.except(:add_advanced_search_to_solr)
end
response
end
end
end
Expand Up @@ -22,61 +22,61 @@ def canvas_uri_for_annotation

private

##
# return a string like "#xywh=100,100,250,20"
# corresponding to coordinates of query term on image
# @return [String]
def coordinates
return default_coords if query.blank?
coords_json = fetch_and_parse_coords
return default_coords unless coords_json && coords_json['coords']
query_terms = query.split(' ').map(&:downcase)
matches = coords_json['coords'].select do |k, _v|
k.downcase =~ /(#{query_terms.join('|')})/
end
return default_coords if matches.blank?
coords_array = matches.values.flatten(1)[hl_index]
return default unless coords_array
"#xywh=#{coords_array.join(',')}"
##
# return a string like "#xywh=100,100,250,20"
# corresponding to coordinates of query term on image
# @return [String]
def coordinates
return default_coords if query.blank?
coords_json = fetch_and_parse_coords
return default_coords unless coords_json && coords_json['coords']
query_terms = query.split(' ').map(&:downcase)
matches = coords_json['coords'].select do |k, _v|
k.downcase =~ /(#{query_terms.join('|')})/
end
return default_coords if matches.blank?
coords_array = matches.values.flatten(1)[hl_index]
return default unless coords_array
"#xywh=#{coords_array.join(',')}"
end

##
# return the JSON word-coordinates file contents
# @return [JSON]
def fetch_and_parse_coords
coords = NewspaperWorks::Data::WorkDerivatives.new(file_set_id).data('json')
return nil if coords.blank?
begin
JSON.parse(coords)
rescue JSON::ParserError
nil
end
##
# return the JSON word-coordinates file contents
# @return [JSON]
def fetch_and_parse_coords
coords = NewspaperWorks::Data::WorkDerivatives.new(file_set_id).data('json')
return nil if coords.blank?
begin
JSON.parse(coords)
rescue JSON::ParserError
nil
end
end

##
# a default set of coordinates
# @return [String]
def default_coords
'#xywh=0,0,0,0'
end
##
# a default set of coordinates
# @return [String]
def default_coords
'#xywh=0,0,0,0'
end

##
# the base URL for the Newspaper object
# use polymorphic_url, since we deal with multiple object types
# @return [String]
def base_url
host = controller.request.base_url
controller.polymorphic_url(parent_document, host: host, locale: nil)
end
##
# the base URL for the Newspaper object
# use polymorphic_url, since we deal with multiple object types
# @return [String]
def base_url
host = controller.request.base_url
controller.polymorphic_url(parent_document, host: host, locale: nil)
end

##
# return the first file set id
# @return [String]
def file_set_id
file_set_ids = document['file_set_ids_ssim']
raise "#{self.class}: NO FILE SET ID" if file_set_ids.blank?
file_set_ids.first
end
##
# return the first file set id
# @return [String]
def file_set_id
file_set_ids = document['file_set_ids_ssim']
raise "#{self.class}: NO FILE SET ID" if file_set_ids.blank?
file_set_ids.first
end
end
end
end
16 changes: 8 additions & 8 deletions app/presenters/hyrax/newspaper_article_presenter.rb
Expand Up @@ -26,13 +26,13 @@ def page_titles

private

def iiif_metadata_fields
[:title, :alternative_title, :place_of_publication, :issn, :lccn,
:oclcnum, :held_by, :text_direction, :page_number, :section, :genre,
:author, :photographer, :volume, :edition, :issue_number,
:geographic_coverage, :extent, :publication_date, :resource_type,
:creator, :contributor, :description, :license, :rights_statement,
:publisher, :subject, :language, :identifier]
end
def iiif_metadata_fields
[:title, :alternative_title, :place_of_publication, :issn, :lccn,
:oclcnum, :held_by, :text_direction, :page_number, :section, :genre,
:author, :photographer, :volume, :edition, :issue_number,
:geographic_coverage, :extent, :publication_date, :resource_type,
:creator, :contributor, :description, :license, :rights_statement,
:publisher, :subject, :language, :identifier]
end
end
end

0 comments on commit 893e27d

Please sign in to comment.