Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata Decorators for OAI:DC and OAI:ETDMS #1460

Merged
merged 8 commits into from
Feb 13, 2020
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and releases in Jupiter project adheres to [Semantic Versioning](http://semver.o
- Version 1 of AIP API
- Added and set up papertrail gem
- Added Draper and re-organized facet presenters
- Metadata Presenters for OAI:DC & OAI:ETDMS

### Changed
- bump rubocop-rails to 2.4.1 Rails/FilePath default changed to slashes [PR#1398](https://github.com/ualbertalib/jupiter/pull/1398)
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gem 'active_link_to'
gem 'simple_form'

# RDF stuff
gem 'acts_as_rdfable', github: 'ualbertalib/acts_as_rdfable', ref: 'ac8acad'
gem 'acts_as_rdfable', github: 'ualbertalib/acts_as_rdfable', ref: '37915a9581713524f95f28425a10fdfee4335d06'
gem 'rdf', '~> 3.1.0'
gem 'rdf-n3'
gem 'rdf-vocab', '~> 3.1.2'
Expand Down Expand Up @@ -70,7 +70,7 @@ gem 'rollbar'

# OAI-PMH
gem 'builder_deferred_tagging', github: 'ualbertalib/builder_deferred_tagging', tag: 'v0.01'
gem 'oaisys', github: 'ualbertalib/oaisys', ref: '6827c1d'
gem 'oaisys', github: 'ualbertalib/oaisys', ref: 'e98b73f8bc45f39ad8b6bb224bcedba16948f6bd'

# Seeds
group :development, :test, :uat do
Expand Down
74 changes: 36 additions & 38 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/ualbertalib/acts_as_rdfable.git
revision: ac8acadd866a120d27763a7b5eb17601b7bc2bc9
ref: ac8acad
revision: 37915a9581713524f95f28425a10fdfee4335d06
ref: 37915a9581713524f95f28425a10fdfee4335d06
specs:
acts_as_rdfable (0.2.1)
rails (>= 5.2.3)
Expand All @@ -17,8 +17,8 @@ GIT

GIT
remote: https://github.com/ualbertalib/oaisys.git
revision: 6827c1df6ceb6ebf8d8fd2dd3b04a3a04fbc3845
ref: 6827c1d
revision: e98b73f8bc45f39ad8b6bb224bcedba16948f6bd
ref: e98b73f8bc45f39ad8b6bb224bcedba16948f6bd
specs:
oaisys (0.1.0)
builder (~> 3.0)
Expand Down Expand Up @@ -98,7 +98,7 @@ GEM
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.0)
autoprefixer-rails (9.7.4)
autoprefixer-rails (9.7.3)
execjs
better_errors (2.5.1)
coderay (>= 1.0.0)
Expand All @@ -115,7 +115,7 @@ GEM
sassc-rails (>= 2.0.0)
brakeman (4.7.2)
builder (3.2.4)
bump (0.9.0)
bump (0.8.0)
byebug (11.1.1)
capybara (3.31.0)
addressable
Expand All @@ -141,22 +141,22 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.6)
danger (6.2.2)
danger (6.2.0)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
cork (~> 0.1)
faraday (~> 0.9)
faraday-http-cache (~> 2.0)
git (~> 1.6)
git (~> 1.5)
kramdown (~> 2.0)
kramdown-parser-gfm (~> 1.0)
no_proxy_fix
octokit (~> 4.7)
terminal-table (~> 1)
debug_inspector (0.0.3)
docile (1.3.2)
draper (4.0.0)
draper (3.1.0)
actionpack (>= 5.0)
activemodel (>= 5.0)
activemodel-serializers-xml (>= 1.0)
Expand All @@ -180,14 +180,13 @@ GEM
multipart-post (>= 1.2, < 3)
faraday-http-cache (2.0.0)
faraday (~> 0.8)
ffi (1.12.1)
ffi (1.11.3)
font-awesome-rails (4.7.0.5)
railties (>= 3.2, < 6.1)
fugit (1.3.3)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.1)
git (1.6.0)
rchardet (~> 1.8)
git (1.5.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
haikunator (1.1.0)
Expand All @@ -201,26 +200,26 @@ GEM
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
jaro_winkler (1.5.4)
jbuilder (2.10.0)
activesupport (>= 5.0.0)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
jquery-rails (4.3.5)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json-schema (2.8.1)
addressable (>= 2.4)
kaminari (1.2.0)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.0)
kaminari-activerecord (= 1.2.0)
kaminari-core (= 1.2.0)
kaminari-actionview (1.2.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.2.0)
kaminari-activerecord (1.2.0)
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.2.0)
kaminari-core (1.2.0)
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
kramdown (2.1.0)
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
Expand Down Expand Up @@ -256,7 +255,7 @@ GEM
no_proxy_fix (0.1.2)
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
octokit (4.16.0)
octokit (4.15.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
omniauth (1.9.0)
Expand All @@ -278,7 +277,7 @@ GEM
pg (1.2.2)
polyamorous (2.3.2)
activerecord (>= 5.2.1)
popper_js (1.16.0)
popper_js (1.14.5)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
Expand All @@ -293,7 +292,7 @@ GEM
pundit (1.1.0)
activesupport (>= 3.0.0)
raabro (1.1.6)
rack (2.1.2)
rack (2.2.2)
rack-protection (2.0.8.1)
rack
rack-test (1.1.0)
Expand Down Expand Up @@ -334,7 +333,6 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.1)
ffi (~> 1.0)
rchardet (1.8.0)
rdf (3.1.1)
hamster (~> 3.0)
link_header (~> 0.0, >= 0.0.8)
Expand Down Expand Up @@ -374,8 +372,8 @@ GEM
nokogiri (>= 1.5.10)
ruby-vips (2.0.17)
ffi (~> 1.9)
ruby2_keywords (0.0.2)
rubyzip (2.1.0)
ruby2_keywords (0.0.1)
rubyzip (2.0.0)
rufus-scheduler (3.6.0)
fugit (~> 1.1, >= 1.1.6)
safe_yaml (1.0.5)
Expand Down Expand Up @@ -417,13 +415,13 @@ GEM
concurrent-ruby (~> 1.0, >= 1.0.5)
sidekiq (>= 4.0, < 7.0)
thor (~> 0)
simple_form (5.0.2)
simple_form (5.0.1)
actionpack (>= 5.0)
activemodel (>= 5.0)
simplecov (0.18.2)
simplecov (0.18.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.0)
simplecov-html (~> 0.11.0)
simplecov-html (0.11.0)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
Expand Down Expand Up @@ -470,16 +468,16 @@ GEM
vcr (5.0.0)
voight_kampff (1.1.3)
rack (>= 1.4, < 3.0)
web-console (4.0.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
railties (>= 5.0)
webdrivers (4.2.0)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (>= 3.0, < 4.0)
webmock (3.8.2)
webmock (3.8.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/downloads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ class DownloadsController < ApplicationController
# Used to serve files from the "permanent" vanity URLS /items/item_id/view/file_set_id/filesname and
# /items/item_id/download/file_set_id/
def view
file_name = params[:file_name]
raise JupiterCore::ObjectNotFound unless file_name == @file.filename.to_s
requested_filename = params[:file_name]
filename = @file.filename.to_s

# We distribute view URLs via OAI that have all spaces mapped to underscores, because
# LAC, who we have to support with our OAI implementation, absolutely cannot handle spaces
# special-casing this is the easiest work-around ¯\_(ツ)_/¯
raise JupiterCore::ObjectNotFound unless (requested_filename == filename) ||
(requested_filename == filename.tr(' ', '_'))

send_data(ActiveStorage::Blob.service.download(@file.blob.key), disposition: 'inline',
type: @file.blob.content_type)
Expand Down
14 changes: 14 additions & 0 deletions app/decorators/application_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class ApplicationDecorator < Draper::Decorator

# see https://github.com/drapergem/draper/issues/859 for why we never want to NOT
# delgate the id method
delegate :id

# URL Helpers. Normally you can access through the viewcontext via +h.helper_method+, BUT
# this comes with the caveat that the URL helpers the viewcontext can *see* depends on what
# engine the decorator is run from, which leads to varying and unpredictable behaviour of
# decorated methods involving paths. By directly importing the Rails application instance's
# URL helpers, we can ensure the decorated methods behave consistently.
include Rails.application.routes.url_helpers

end
33 changes: 33 additions & 0 deletions app/decorators/metadata/oai_dc/item_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Metadata::OaiDc::ItemDecorator < ApplicationDecorator

delegate :description, :publisher, :subject, :title, :updated_at

def creator
object.creators
end

def contributor
object.contributors
end

def rights
object.license.presence || object.rights
end

def identifiers
[item_url(object), object.doi]
end

def date
object.creation_date
end

def type
I18n.t("controlled_vocabularies.item_type_with_status.#{object.item_type_with_status_code}")
end

def languages
object.languages.map { |l| h.humanize_uri(:language, l) }
end

end
54 changes: 54 additions & 0 deletions app/decorators/metadata/oai_etdms/thesis_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class Metadata::OaiEtdms::ThesisDecorator < ApplicationDecorator

delegate :degree, :subject, :title, :updated_at

def creator
object.dissertant
end

def description
"Abstract: #{object.abstract}" if object.abstract.present?
end

def contributor
object.supervisors
end

def type
I18n.t("controlled_vocabularies.item_type_with_status.#{object.item_type_with_status_code}")
end

def date
# TODO: need to talk to metadata about fallback if date accepted is not present, which it isn't for legacy theses
object.date_accepted || object.created_at
end

def identifiers
files = object.files.map do |file|
# LAC requires that there be no spaces in the URL, for whatever questionable reasons
file_view_item_url(id: file.record.id,
file_set_id: file.fileset_uuid,
file_name: file.filename.to_s).tr(' ', '_')
end
[item_url(object), object.doi, files].flatten
end

delegate :rights, to: :object

def language
h.humanize_uri(:language, object.language)
end

def degree_level
object.thesis_level
end

def discipline
object.departments.first
end

def institution
h.humanize_uri(:institution, object.institution)
end

end
2 changes: 1 addition & 1 deletion app/models/item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Item < JupiterCore::Doiable

acts_as_rdfable
acts_as_rdfable formats: :oai_dc

has_solr_exporter Exporters::Solr::ItemExporter

Expand Down
Loading