Skip to content

Commit

Permalink
Bibliography service (#477)
Browse files Browse the repository at this point in the history
* initial skeleton for ServicesController

* initial version of Zotero bibliography service

* Add the ServicesController for the BibliographyService.

* Add the BibliographyService model to persist exhibit specific service configurations.

* Inject a concern to Spotlight::Exhibit to add the has_one :bibliography_service relationship

* Add the Bibliography service edit form.

* Override Spotlight's configuration_sidebar partial to add our Services link.

* Regen .rubocop_todo.yml

* Add breadcrumbs to the Service configuration page.

* Rename BibliographyService service to SyncBibliographyService.

* update spotlight dependency to master to use 6d04466c4521e44a41307e5fb04f87ec51595455

* Add service to hookup Zotero API and API Configuration classes for sync (#454)

* move modules included into SyncBibliographyService into namespaced classes

* refactor of ZoteroApi::Client to simplify for accessing bibs by druid

* provide for a sorted bibliography to be returned for each druid

* Remove errant view copied into the spec directory.

* Add logic to the SyncBibliographyService class.

* Add a comment to the ZoteroApi::Client class.

* Add a job to invoke the bibliography service sync and hook it into the create action.

* Sync the bibliography service when the configuration has been updated.

* Autogen rubocop_todo.

* adds display of bibliography information on show page

* view bib as ul/li

* setup sync button to work

* use form-control-static for styling instead of our own

* use f.primary instead of explicitly specifying btn classes

* move bibliography_service assignment logic from controller to model

* nix custom find method on Bibliography

* make druid regex configurable

* Push update + bibliography sync to the BibliographyService class.

* handle cases where an author is not present, or partial author

* exclude fixtures from rubocop

* add migration to change sidecar data to MEDIUMTEXT

* set the production log level for sidekiq to WARN

* add *_tsi field and use that for bibliography
  • Loading branch information
mejackreed authored and csbailey5t committed May 10, 2017
1 parent 8bb2055 commit ef17505
Show file tree
Hide file tree
Showing 47 changed files with 1,323 additions and 66 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AllCops:
- 'db/**/*'
- 'config/**/*'
- 'vendor/**/*'
- 'spec/fixtures/**/*'

Rails:
Enabled: true
Expand Down
46 changes: 29 additions & 17 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,74 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-01-23 13:59:29 -0800 using RuboCop version 0.47.1.
# on 2017-03-19 00:57:52 -0700 using RuboCop version 0.47.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Offense count: 4
Metrics/AbcSize:
Max: 19

# Offense count: 30
# Offense count: 41
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Exclude:
- 'Rakefile'
- '**/*.rake'
- 'spec/**/*.rb'
- 'app/controllers/catalog_controller.rb'
- 'app/models/spotlight/dor/indexer.rb'
Max: 639

# Offense count: 1
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 11
Max: 87

# Offense count: 2
RSpec/AnyInstance:
Exclude:
- 'spec/features/exhibit_spec.rb'
- 'spec/models/dor_harvester_spec.rb'
- 'spec/services/sync_bibliography_service_spec.rb'

# Offense count: 2
# Offense count: 4
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/features/bibliography_service_feature_spec.rb'
- 'spec/models/spotlight/dor/indexer_spec.rb'

# Offense count: 23
# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
Exclude:
- 'spec/models/zotero_api/client_spec.rb'

# Offense count: 37
RSpec/MultipleExpectations:
Max: 5
Max: 7

# Offense count: 21
# Offense count: 28
# Configuration parameters: Max.
RSpec/NestedGroups:
Exclude:
- 'spec/models/spotlight/dor/indexer_spec.rb'
- 'spec/models/zotero_api/client_spec.rb'
- 'spec/requests/bibliography_service_spec.rb'
- 'spec/services/dor_solr_document_builder_spec.rb'

# Offense count: 4
# Offense count: 8
RSpec/SubjectStub:
Exclude:
- 'spec/models/dor_harvester_spec.rb'
- 'spec/models/spotlight/dor/indexer_spec.rb'
- 'spec/models/zotero_api/client_spec.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'app/models/spotlight/dor/indexer.rb'

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'app/services/sync_bibliography_service.rb'
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ gem 'bootstrap-sass', '~> 3.3.5'
gem 'blacklight', '~> 6.3'
gem 'blacklight-gallery', '~> 0.3'
gem 'blacklight_heatmaps'
gem 'blacklight-spotlight', '~> 0.34'
gem 'blacklight-spotlight', git: 'https://github.com/projectblacklight/spotlight', branch: 'master'
gem 'blacklight_advanced_search'
gem 'devise'
gem 'devise-guests', '~> 0.3'
Expand Down
90 changes: 48 additions & 42 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
GIT
remote: https://github.com/projectblacklight/spotlight
revision: 3514a0535c46ecc4e457f791f4db42fea0bf2f8e
branch: master
specs:
blacklight-spotlight (0.34.1)
acts-as-taggable-on (~> 4.0)
almond-rails (~> 0.0.1)
autoprefixer-rails
blacklight (~> 6.3)
blacklight-gallery (>= 0.3.0)
blacklight-oembed (>= 0.0.3)
bootstrap_form (~> 2.2)
breadcrumbs_on_rails (~> 2.3.0)
cancancan
carrierwave
clipboard-rails (~> 1.5)
devise (>= 3.0)
devise_invitable (~> 1.6)
faraday
faraday_middleware
friendly_id (~> 5.2)
github-markup
iiif_manifest
legato
mini_magick
nokogiri
oauth2
openseadragon
paper_trail (~> 5.0, >= 5.2.1)
rails (>= 4.2.0, < 6)
riiif (~> 1.0)
roar (~> 1.1)
roar-rails
signet
sir_trevor_rails (~> 0.5)
sprockets-es6
tophat
underscore-rails (~> 1.6)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -74,40 +114,6 @@ GEM
bootstrap-sass (~> 3.0)
rails
ruby-oembed
blacklight-spotlight (0.34.0)
acts-as-taggable-on (~> 4.0)
almond-rails (~> 0.0.1)
autoprefixer-rails
blacklight (~> 6.3)
blacklight-gallery (>= 0.3.0)
blacklight-oembed (>= 0.0.3)
bootstrap_form (~> 2.2)
breadcrumbs_on_rails (~> 2.3.0)
cancancan
carrierwave
clipboard-rails (~> 1.5)
devise (>= 3.0)
devise_invitable (~> 1.6)
faraday
faraday_middleware
friendly_id (~> 5.2)
github-markup
iiif_manifest
legato
mini_magick
nokogiri
oauth2
openseadragon
paper_trail (~> 5.0, >= 5.2.1)
rails (>= 4.2.0, < 6)
riiif (~> 1.0)
roar (~> 1.1)
roar-rails
signet
sir_trevor_rails (~> 0.5)
sprockets-es6
tophat
underscore-rails (~> 1.6)
blacklight_advanced_search (6.2.1)
blacklight (~> 6.0, >= 6.0.1)
parslet
Expand Down Expand Up @@ -162,7 +168,7 @@ GEM
activesupport (>= 4.0.0)
mime-types (>= 1.16)
chronic (0.10.2)
clipboard-rails (1.6.0)
clipboard-rails (1.6.1)
coffee-rails (4.2.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.2.x)
Expand Down Expand Up @@ -237,7 +243,7 @@ GEM
rsolr
stanford-mods (~> 2.2, >= 2.2.1)
trollop
github-markup (1.4.1)
github-markup (1.4.4)
globalid (0.3.7)
activesupport (>= 4.1.0)
harvestdor (0.3.1)
Expand Down Expand Up @@ -326,8 +332,8 @@ GEM
activesupport (>= 3.2.18)
i18n
nokogiri
oauth2 (1.3.0)
faraday (>= 0.8, < 0.11)
oauth2 (1.3.1)
faraday (>= 0.8, < 0.12)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
Expand Down Expand Up @@ -403,13 +409,13 @@ GEM
railties (>= 4.2, < 6)
roar (1.1.0)
representable (~> 3.0.0)
roar-rails (1.0.1)
roar-rails (1.1.0)
actionpack
railties (>= 3.0.0)
responders
roar (>= 1.0.0, <= 1.1.0)
roar (~> 1.1.0)
test_xml (>= 0.1.6)
uber (>= 0.0.5)
uber (< 0.2.0)
rsolr (1.1.2)
builder (>= 2.1.2)
rspec-core (3.5.4)
Expand Down Expand Up @@ -568,7 +574,7 @@ PLATFORMS
DEPENDENCIES
blacklight (~> 6.3)
blacklight-gallery (~> 0.3)
blacklight-spotlight (~> 0.34)
blacklight-spotlight!
blacklight_advanced_search
blacklight_heatmaps
bootstrap-sass (~> 3.3.5)
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/modules/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ a[aria-expanded=true] .glyphicon-chevron-right {
a[aria-expanded=false] .glyphicon-chevron-down {
display: none;
}

.text-as-label {
font-weight: bold;
}
5 changes: 5 additions & 0 deletions app/assets/stylesheets/modules/bibliography.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.show-document {
h3 {
color: $brand-primary;
}
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/sul_theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "modules/mixins";
@import "modules/layout";
@import "modules/bibliography";
@import "modules/home";
@import "modules/admin";
@import "modules/bootstrap_overrides";
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class CatalogController < ApplicationController
config.show.partials.insert(1, :osd_or_embed)
config.show.tile_source_field = :content_metadata_image_iiif_info_ssm

config.show.partials << :bibliography

config.view.list.thumbnail_field = :thumbnail_square_url_ssm
config.view.list.partials = [:thumbnail, :index_header, :index]
config.view.gallery.partials = [:index_header, :index]
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/services_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
###
# A controller to handle any external services that need to be configured by an admin
class ServicesController < Spotlight::ApplicationController
before_action :authenticate_user!
load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
before_action :build_resource
load_and_authorize_resource :bibliography_service, through: :exhibit, singleton: true

def edit
add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), [spotlight, @exhibit]
add_breadcrumb t(:'spotlight.configuration.sidebar.header'), spotlight.exhibit_dashboard_path(@exhibit)
add_breadcrumb t(:'services.menu_link'), edit_exhibit_services_path(@exhibit)
end

def update
if @bibliography_service.update_and_sync_bibliography(update_params)
redirect_to edit_exhibit_services_path(@exhibit), notice: I18n.t('services.update.notice')
else
redirect_to edit_exhibit_services_path(@exhibit), alert: I18n.t('services.update.error')
end
end

def create
if @bibliography_service.update_and_sync_bibliography(update_params)
redirect_to edit_exhibit_services_path(@exhibit), notice: I18n.t('services.create.notice')
else
redirect_to edit_exhibit_services_path(@exhibit), alert: I18n.t('services.create.error')
end
end

def sync
@exhibit.sync_bibliography
redirect_to edit_exhibit_services_path(@exhibit), notice: I18n.t('services.sync.started')
end

private

def build_resource
@bibliography_service = @exhibit.bibliography_service || @exhibit.build_bibliography_service
end

def update_params
params.require(:bibliography_service).permit(:header, :api_id, :api_type)
end
end
7 changes: 7 additions & 0 deletions app/jobs/sync_bibliography_service_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
##
# Background job to sync bibliography service
class SyncBibliographyServiceJob < ActiveJob::Base
def perform(exhibit)
SyncBibliographyService.new(exhibit).sync
end
end
2 changes: 2 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def initialize(user)
# We're doing this temporarily until spotlight#1752 is solved (which may just end up doing this)
can :create, Spotlight::FeaturedImage if user.roles.any?

can :manage, BibliographyService, exhibit_id: user.exhibit_roles.pluck(:resource_id)

# disable spotlight functionality we don't want to expose in spotlight:

# disable exhibit import/export
Expand Down
28 changes: 28 additions & 0 deletions app/models/bibliography_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The bibliography service configurations for an exhibit
class BibliographyService < ActiveRecord::Base
belongs_to :exhibit, class_name: Spotlight::Exhibit
delegate :sync_bibliography, to: :exhibit

def header
super || I18n.t('services.bibliography_service.default_header')
end

def initial_sync_complete?
sync_completed_at.present?
end

def api_settings_changed?
api_id_previously_changed? || api_type_previously_changed?
end

def mark_as_updated!
update(sync_completed_at: DateTime.current)
end

def update_and_sync_bibliography(update_params)
updated = update(update_params)
return unless updated
sync_bibliography if api_settings_changed?
updated
end
end
8 changes: 8 additions & 0 deletions app/models/concerns/bibliography_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
##
# A concern to be mixed into SolrDocument for accessing a document's
# bibliography
module BibliographyConcern
def bibliography
fetch(Settings.zotero_api.solr_document_field, nil)
end
end
14 changes: 14 additions & 0 deletions app/models/concerns/exhibit_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
##
# A concern to be mixed into the Spotlight::Exhibit
# class in order to add ActiveRecord relationship(s)
module ExhibitExtension
extend ActiveSupport::Concern

included do
has_one :bibliography_service
end

def sync_bibliography
SyncBibliographyServiceJob.perform_later(self)
end
end

0 comments on commit ef17505

Please sign in to comment.